using BO; using BO.BO.Bill; using BO.Utils; using BO.Utils.BillRpc; using BWP.WinFormControl; using BWP.WinFormControl.WeightDataFormat; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace CarcassStateWeight { public partial class CarcassStateWeightForm : Form, IAfterLogin { #region IAfterLogin public string RoleName { get { return "定级员"; } } public Form Generate() { return this; } #endregion List list; List details; Thread syncWork; private delegate void InvokeHandler(); SerialPort weightPort; int maxIndex = 0; public CarcassStateWeightForm() { InitializeComponent(); houseList = ProductEntity.Init(BaseInfoRpcUtil.GetBaseInfoEntity("GetWhiteBarList")); AddHouseBtn(); details = new List(); } private void syncBtn_Click(object sender, EventArgs e) { list = CarcassStateWeightRpc.GetCarcassStateWeightList(butcherTimeInput.Date.Value); BindDataGrid(); //tangRow = FindRowSetSelected(tangEntity); //maoRow = FindRowSetSelected(maoEntity); dataGridViewSync.Refresh(); //if (syncWork == null || !syncWork.IsAlive) //{ // syncWork = new Thread(Sync); // syncWork.Start(); // syncBtn.BackColor = Color.FromArgb(15, 215, 107); // syncBtn.ForeColor = Color.White; //} //else //{ // syncBtn.BackColor = Color.FromKnownColor(KnownColor.Control) // syncWork.Abort();; // syncBtn.ForeColor = Color.FromKnownColor(KnownColor.ControlText); //} } void Sync() { while (true) { Thread.Sleep(5000); this.Invoke(new InvokeHandler(delegate () { list = CarcassStateWeightRpc.GetCarcassStateWeightList(butcherTimeInput.Date.Value); BindDataGrid(); //tangRow = FindRowSetSelected(tangEntity); //maoRow = FindRowSetSelected(maoEntity); dataGridViewSync.Refresh(); })); } } void BindDataGrid() { dataGridViewSync.DataSource = list.OrderBy(x => x.Time).ToList(); //foreach (DataGridViewRow row in dataGridViewSync.Rows) //{ // if ((bool)row.Cells["D_Finish"].Value) // row.DefaultCellStyle.BackColor = Color.YellowGreen; //} } DataGridViewRow FindRowSetSelected(GradeAndWeight tag) { ////if (tag == null) //// return null; ////foreach (DataGridViewRow row in dataGridViewSync.Rows) ////{ //// if ((long)row.Cells["D_OrderDetail_ID"].Value == tag.OrderDetail_ID && (string)row.Cells["D_Technics_Name"].Value == tag.Technics_Name) //// { //// if (tag.Finish) //// row.DefaultCellStyle.BackColor = Color.YellowGreen; //// else //// row.DefaultCellStyle.BackColor = tag.Technics == 1 ? Color.Yellow : dataGridViewSync.RowsDefaultCellStyle.SelectionBackColor; //// if (tag.Technics == 0) //// tangEntity = row.DataBoundItem as GradeAndWeight; //// else //// maoEntity = row.DataBoundItem as GradeAndWeight; //// return row; //// } ////} return null; } private void commitBtn_Click(object sender, EventArgs e) { List listCsw = new List(); for (int i = 0; i < dataGridViewCode.Rows.Count; i++) { DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell) dataGridViewCode.Rows[i].Cells["cb_check"]; Boolean flag = Convert.ToBoolean(checkCell.Value); if (flag == true) //查找被选择的数据行 { DataGridViewRow row = dataGridViewCode.Rows[i]; BO.BO.Bill.CarcassStateWeight slectedCSW = row.DataBoundItem as BO.BO.Bill.CarcassStateWeight; listCsw.Add(slectedCSW); } } foreach (var csw in listCsw) { CarcassStateWeightRpc.UpdateOrInsertDetail(csw); details.Remove(csw); } dataGridViewCode.DataSource = null; dataGridViewCode.DataSource = details; dataGridViewCode.Refresh(); } List