public static bool UpdateThroughState(ThroughInfo info) { using (DZEntities en = new DZEntities()) { decimal CigType = Convert.ToDecimal(info.CigaretteType); decimal tType = Convert.ToDecimal(info.GroupNo); T_PRODUCE_SORTTROUGH infos = new T_PRODUCE_SORTTROUGH(); infos = en.T_PRODUCE_SORTTROUGH.Where(item => item.ID == info.ID && item.CIGARETTETYPE == CigType && item.GROUPNO == tType).FirstOrDefault(); if (info.State == "禁用") { infos.STATE = "0"; } else { infos.STATE = "10"; } return(en.SaveChanges() > 0 ? true : false); } }
private void btn_jy_Click(object sender, EventArgs e) { int count = this.troughdata.SelectedRows.Count; if (count > 0) { ThroughInfo info = new ThroughInfo(); info.ID = (decimal)this.troughdata.SelectedRows[0].Cells["ID"].Value; info.CigaretteCode = this.troughdata.SelectedRows[0].Cells["CigaretteCode"].Value.ToString(); info.CigaretteType = decimal.Parse(this.troughdata.CurrentRow.Cells["CigaretteType"].Value + ""); info.MachineSeq = (decimal)this.troughdata.SelectedRows[0].Cells["MachineSeq"].Value; info.ThroughNum = this.troughdata.SelectedRows[0].Cells["ThroughNum"].Value.ToString(); info.GroupNo = (decimal)this.troughdata.CurrentRow.Cells["GroupNo"].Value; DialogResult MsgBoxResult = MessageBox.Show("确定禁用【设备号:" + info.MachineSeq + "/通道号:" + info.ThroughNum + "】通道吗?", //对话框的显示内容 "提示", //对话框的标题 MessageBoxButtons.YesNo, //定义对话框的按钮,这里定义了YSE和NO两个按钮 MessageBoxIcon.Question, //定义对话框内的图表式样,这里是一个黄色三角型内加一个感叹号 MessageBoxDefaultButton.Button2); //定义对话框的按钮式样 if (MsgBoxResult == DialogResult.Yes) { try { info.State = "0"; ThroughClass.UpdateThroughState(info); ThroughClass.SetThroughActcount(info.CigaretteCode, info.GroupNo); MessageBox.Show("【设备号:" + info.MachineSeq + "/通道号:" + info.ThroughNum + "】的通道已禁用!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); Bind(); } catch (Exception se) { MessageBox.Show(se.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("请点击选择您要禁用的分拣通道!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }