using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Data; using System.Windows.Forms; namespace Core.StlMes.Client.Qcm { /// /// 取样要求管理 /// public partial class FrmComMSCSample : FrmBase { //提示 private string errMessage = ""; //冶金规范码 private string _msc = ""; private int isSelect = 0; //自增序号 private int _xh = 1; //用于定位 private int expanl = -1; public FrmComMSCSample() { InitializeComponent(); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": this.DoQuery(true); break; case "Save": this.DoSave(); break; case "Delete": DoUpdateOrResume(true); break; case "Resume": DoUpdateOrResume(false); break; case "Close": this.Close(); break; } } /// /// 传入冶金规范码(外部调用) /// /// 冶金规范码 public void SetMSC(string msc) { _msc = msc; DoQuery(true); } /// /// 查询 /// private void DoQuery(Boolean flag) { string msc = _msc; string valid = "1"; if (!flag) valid = "0"; ArrayList list = new ArrayList(); list.Add(_msc); list.Add(valid); DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreComMSCSample.getComMSCSample", new Object[] { list }, this.ob); GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true); //不同颜色区分是否有效数据 QcmBaseCommon.DistinguishColor(ultraGrid1, "VALIDFLAGNAME", "有效"); _xh = 1; QcmBaseCommon.SetUltraGridNoEdit(ultraGrid1); isSelect = 0; if (expanl < ultraGrid1.Rows.Count && expanl >= 0) ultraGrid1.Rows[expanl].Activate(); expanl = -1; } /// /// 操作数据项 /// /// private ArrayList GetOptionData(int i) { ArrayList list = new ArrayList(); UltraGridRow rows = ultraGrid1.Rows[i]; string msc = _msc; string xh = rows.Cells["XH"].Text.ToString().Trim(); string minD = rows.Cells["MIN_D"].Value.ToString().Trim(); if (!minD.Equals("") && !StringUtil.IsNumber(minD)) { errMessage = "最小外径请输入数字"; return null; } string maxD = rows.Cells["MAX_D"].Value.ToString().Trim(); if (!maxD.Equals("") && !StringUtil.IsNumber(maxD)) { errMessage = "最大外径请输入数字"; return null; } if (!minD.Equals("") && !maxD.Equals("") && Convert.ToDouble(minD) > Convert.ToDouble(maxD)) { errMessage = "最小外径不能大于最大外径"; return null; } string minH = rows.Cells["MIN_H"].Value.ToString().Trim(); if (!minH.Equals("") && !StringUtil.IsNumber(minH)) { errMessage = "最小壁厚请输入数字"; return null; } string maxH = rows.Cells["MAX_H"].Value.ToString().Trim(); if (!maxH.Equals("") && !StringUtil.IsNumber(maxH)) { errMessage = "最大壁厚请输入数字"; return null; } if (!minH.Equals("") && !maxH.Equals("") && Convert.ToDouble(minH) > Convert.ToDouble(maxH)) { errMessage = "最小壁厚不能大于最大壁厚"; return null; } string length = rows.Cells["LENGTH"].Text.ToString().Trim(); string descLength = rows.Cells["DESC_LENGTH"].Text.ToString().Trim(); if (descLength.Equals("")) { errMessage = "请选择取样长度"; return null; } string rate = rows.Cells["RATE"].Text.ToString().Trim(); if (rate.Equals("")) { errMessage = "请选择取样频率"; return null; } string descRate = rows.Cells["DESC_RATE"].Text.ToString().Trim(); if (descRate.Equals("")) { errMessage = "请选择取样描述"; return null; } string descCount = rows.Cells["DESC_COUNT"].Text.ToString().Trim(); string position = rows.Cells["POSITION"].Text.ToString().Trim(); if (position.Equals("")) { errMessage = "请选择位置描述"; return null; } string descPosition = rows.Cells["DESC_POSITION"].Text.ToString().Trim(); string userName = UserInfo.GetUserName(); string userTime = System.DateTime.Now.ToString(); string memo = rows.Cells["MEMO"].Text.ToString().Trim(); string validflag = rows.Cells["VALIDFLAGNAME"].Value.ToString(); if (validflag.Equals("无效")) { errMessage = "无效记录不能保存"; return null; } list.Add(msc); list.Add(xh); list.Add(minD); list.Add(maxD); list.Add(minH); list.Add(maxH); list.Add(length); list.Add(descLength); list.Add(rate); list.Add(descRate); list.Add(descCount); list.Add(position); list.Add(descPosition); list.Add(userName); list.Add(userTime); list.Add(memo); return list; } /// /// 保存 /// private void DoSave() { ultraGrid1.UpdateData(); if (isSelect == 0) { MessageBox.Show("请选择记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (MessageBox.Show("是否保存选择记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } ArrayList addList = new ArrayList(); ArrayList updateList = new ArrayList(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (Convert.ToBoolean(ultraGrid1.Rows[i].Cells["CHC"].Value.ToString())) { ArrayList list = GetOptionData(i); if (list == null) { MessageBox.Show(errMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (ultraGrid1.Rows[i].Cells["CREATE_NAME"].Text.Equals("")) { addList.Add(list); } else { list.Add(ultraGrid1.Rows[i].Cells["MSC"].Text.Trim()); list.Add(Convert.ToInt32(ultraGrid1.Rows[i].Cells["XH"].Text.Trim())); updateList.Add(list); } if (expanl == -1) expanl = i; } } if (addList.Count > 0 || updateList.Count > 0) { int count = ServerHelper.SetData("com.steering.pss.qcm.CoreComMSCSample.saveComMSCSample", new Object[] { addList, updateList }, this.ob); if (count > 0) { DoQuery(true); MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else MessageBox.Show("保存失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } /// /// 删除或者恢复 /// private void DoUpdateOrResume(Boolean flag) { ultraGrid1.UpdateData(); if (isSelect == 0) { MessageBox.Show("请选择记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (flag) { if (MessageBox.Show("作废选中记录,您是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } else { if (MessageBox.Show("恢复选中记录,您是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } ArrayList listAll = new ArrayList(); for (int i = 0; i < ultraGrid1.Rows.Count; i++) { if (Convert.ToBoolean(ultraGrid1.Rows[i].Cells["CHC"].Value.ToString())) { ArrayList list = new ArrayList(); string validflag = "0"; string userName = UserInfo.GetUserName(); string userTime = System.DateTime.Now.ToString(); if (!flag) { if (ultraGrid1.Rows[i].Cells["VALIDFLAGNAME"].Value.Equals("有效")) { MessageBox.Show("记录[" + (i + 1) + "]为有效记录,不能恢复", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } validflag = "1"; userName = ""; userTime = ""; } else { if (ultraGrid1.Rows[i].Cells["VALIDFLAGNAME"].Value.Equals("无效")) { MessageBox.Show("记录[" + (i + 1) + "]为无效记录,不能删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } string msc = _msc; int xh = Convert.ToInt32(ultraGrid1.Rows[i].Cells["XH"].Value.ToString()); list.Add(validflag); list.Add(userName); list.Add(userTime); list.Add(msc); list.Add(xh); listAll.Add(list); if (expanl == -1) expanl = i; } } if (listAll.Count > 0) { int count = ServerHelper.SetData("com.steering.pss.qcm.CoreComMSCSample.deleteComMSCSample", new Object[] { listAll, flag }, this.ob); if (count > 0) { DoQuery(false); if (flag) MessageBox.Show("作废成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show("恢复成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } /// /// 初始化下拉框 /// private void InitDownList() { QcmBaseCommon.InitDropUltraComEditor(ultraComboLength, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4010", "BASENAME", this.ob, false); QcmBaseCommon.InitDropUltraComEditor(ultraComPosition, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4011", "BASENAME", this.ob, false); QcmBaseCommon.InitDropUltraComEditor(ultraComboRace, "com.steering.pss.qcm.ComBaseQuery.geComBaseInfo4012", "BASENAME", this.ob, false); } /// /// 登陆页面事件 /// /// /// private void FrmComMSCSample_Load(object sender, EventArgs e) { SetMSC("MSC00001"); InitDownList(); } /// /// 行增加事件 /// /// /// private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e) { int xh = 1; DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreComMSCSample.getMaxXH", new Object[] { _msc }, this.ob); if (dt != null && dt.Rows.Count > 0) { int xh1 = Convert.ToInt32(dt.Rows[0][0].ToString()); if (xh1 > _xh) { xh = xh1 + 1; _xh = xh1 + 1; } else { xh = _xh + 1; _xh += 1; } } else { xh = _xh; _xh += 1; } UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow; ugr.Cells["XH"].Value = xh; if (!Convert.ToBoolean(ugr.Cells["CHC"].Value)) { for (int i = 0; i < ugr.Cells.Count; i++) { if (!ugr.Cells[i].Column.Key.Equals("CHC")) ugr.Cells[i].Activation = Activation.ActivateOnly; } } } /// /// 值变化事件 /// /// /// private void ultraGrid1_CellChange(object sender, CellEventArgs e) { ultraGrid1.UpdateData(); UltraGridRow ugr = ultraGrid1.DisplayLayout.ActiveRow; if (e.Cell.Column.Key.Equals("DESC_LENGTH")) /// 长度描述 { ugr.Cells["LENGTH"].Value = ugr.Cells["DESC_LENGTH"].Value.ToString(); } if (e.Cell.Column.Key.Equals("DESC_POSITION")) /// 位置描述 { ugr.Cells["POSITION"].Value = ugr.Cells["DESC_POSITION"].Value.ToString(); } if (e.Cell.Column.Key.Equals("DESC_RATE")) /// 频率描述 { ugr.Cells["RATE"].Value = ugr.Cells["DESC_RATE"].Value.ToString(); } if (e.Cell.Column.Key.Equals("CHC")) { Activation activation = Activation.ActivateOnly; if (Convert.ToBoolean(e.Cell.Value)) { activation = Activation.AllowEdit; isSelect += 1; } else isSelect -= 1; CellsCollection cells = e.Cell.Row.Cells; for (int i = 0; i < cells.Count; i++) { if (!cells[i].Column.Key.Equals("CHC")) { e.Cell.Row.Cells[i].Activation = activation; } } } } } }