using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.StlMes.Client.Mcp.CollarMaterial; using Core.StlMes.Client.Mcp.Control; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Core.StlMes.Client.Mcp.CollarMaterial { public partial class FrmBoxMainTenance : FrmBase { ArrayList list = new ArrayList(); bool isValid = false; public FrmBoxMainTenance() { InitializeComponent(); this.IsLoadUserView = true; } private void FrmBoxMainTenance_Load(object sender, EventArgs e) { InitComBox(); getDepartMent(); this.cmb_dw.Enabled = false; } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": DoQuery(); break; case "Add": DoAdd(); break; case "Update": DoUpdate(); break; case "Delete": DoDeleteOrResume(true); break; case "Resume": DoDeleteOrResume(false); break; case "Refresh": DoRefresh(); break; case "Export": GridHelper.ulGridToExcel(ultraGrid1, "框号维护"); break; case "Close": this.Close(); break; } } /// /// 刷新 /// private void DoRefresh() { InitComBox(); getDepartMent(); } private void getDepartMent() { DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.coup.FrmBoxMainTenance.doQueryData", new object[] { "1" }, this.ob); cmb_dw.DataSource = dt; cmb_dw.DisplayMember = "DEPARTNAME"; cmb_dw.ValueMember = "DEPARTID"; this.cmb_dw.SelectedIndex = -1; cmbManage1.DataSource = dt; cmbManage1.DisplayMember = "DEPARTNAME"; cmbManage1.ValueMember = "DEPARTID"; } /// /// 初始化下拉框 /// private void InitComBox() { YdmBaseClass.InitComboEditor(cmbRackType, "com.steering.mes.mcp.coup.FrmBoxMainTenance.getRackType", "BASECODE", this.ob, true); YdmBaseClass.InitComboEditor(cmbType1, "com.steering.mes.mcp.coup.FrmBoxMainTenance.getRackType", "BASECODE", this.ob, false); } private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e) { if (ultraCheckEditor1.Checked) { cmbRackType.ReadOnly = false; } else { cmbRackType.ReadOnly = true; } } /// /// 获取编辑区的数据 /// private bool GetData() { list = new ArrayList(); if (cmbType1.SelectedItem == null) { MessageBox.Show("请选择框号类型", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (cmbManage1.SelectedItem == null) { MessageBox.Show("请选择所属单位", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } //if (txtRackWidth.Value == null) //{ // MessageBox.Show("请输入框号宽度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return false; //} //if (txtRackHeight.Value == null) //{ // MessageBox.Show("请输入框号高度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return false; //} //if (txtRackLen.Value == null) //{ // MessageBox.Show("请输入框号长度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return false; //} list.Add(cmbType1.Text.Trim()); //用于编码类型 list.Add(cmbType1.Text.Trim()); //框号类型 list.Add(txtRackWidth.Value.ToString()); list.Add(txtRackHeight.Value.ToString()); list.Add(txtRackLen.Value.ToString()); list.Add(cmbManage1.Value.ToString()); list.Add(cmbManage1.Text.Trim()); list.Add(txtMemo.Text.Trim()); list.Add(this.UserInfo.GetUserName()); return true; } /// /// 新增数据 /// private void DoAdd() { if (!GetData()) return; if (list.Count <= 0) return; int count = ServerHelper.SetData("com.steering.mes.mcp.coup.FrmBoxMainTenance.doAdd", new Object[] { list }, this.ob); if (count > 0) { MessageBox.Show("数据新增成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); DoQuery(); } } /// /// 查询 /// private void DoQuery() { string manage = ""; string racktype = ""; if (this.ultraCheckEditor2.Checked) { if (string.IsNullOrEmpty(cmb_dw.Text.Trim())) { MessageBox.Show("请选择框号所属单位!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { manage = cmb_dw.Text.ToString(); } } else { manage = ""; } if (cmbRackType.SelectedItem != null && cmbRackType.Text != "") racktype = cmbRackType.Text; else racktype = "%"; DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.coup.FrmBoxMainTenance.doQuery", new Object[] { manage, racktype, isValid }, this.ob); GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true); YdmBaseClass.SetGridRowColor(ultraGrid1); YdmBaseClass.SetGridActivateOnly(ultraGrid1); YdmBaseClass.SetColAutoSizeExceptMemo(ultraGrid1); //gdRack.DisplayLayout.Bands[0].Columns["CREATE_TIME"].SortIndicator = SortIndicator.Ascending; } /// /// 更新数据 /// private void DoUpdate() { this.ultraGrid1.UpdateData(); UltraGridRow ugr = ultraGrid1.ActiveRow; if (ugr == null) { MessageBox.Show("请选择需要修改的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string rackNo = ugr.Cells["KEP_NO"].Text.ToString(); DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.coup.FrmBoxMainTenance.getReferRack", new object[] { rackNo }, this.ob); if (dt.Rows.Count > 0) { if (dt.Rows[0]["VALIDFLAG"].ToString() == "0") { MessageBox.Show("无效数据,无法修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (!GetData()) return; string newrackno = ""; if (list.Count > 0) { string rackno = ugr.Cells["KEP_NO"].Value.ToString(); newrackno = rackno.Replace(rackno.Substring(0, 1), cmbType1.Text.Trim()); list.RemoveAt(0); list.Add(newrackno); list.Add(rackno); } if (MessageBox.Show("是否确认修改该行数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int count = ServerHelper.SetData("com.steering.mes.mcp.coup.FrmBoxMainTenance.doUpdate", new Object[] { list }, this.ob); if (count > 0) { MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); DoQuery(); } } /// /// 行激活事件 /// /// /// private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { this.ultraGrid1.UpdateData(); UltraGridRow ugr = ultraGrid1.ActiveRow; if (ugr == null) { return; } string rackno = ugr.Cells["KEP_NO"].Value.ToString(); txtRacknoHead.Value = rackno.Substring(0, 1); txtRacknoTail.Value = rackno.Substring(1, 5); cmbType1.Text = ugr.Cells["KEP_TYPE"].Value.ToString(); this.cmbManage1.Text = ugr.Cells["HL_MANAGEMENT_NAME"].Text.ToString(); txtRackWidth.Value = ugr.Cells["KEP_WIDTH"].Value.ToString(); txtRackHeight.Value = ugr.Cells["KEP_HEIGHT"].Value.ToString(); txtRackLen.Value = ugr.Cells["KEP_LEN"].Value.ToString(); txtMemo.Value = ugr.Cells["MEMO"].Value.ToString(); } /// /// 作废或恢复数据 /// /// true 作废 false 恢复 private void DoDeleteOrResume(bool flag) { UltraGridRow ugr = ultraGrid1.ActiveRow; if (ugr == null) { MessageBox.Show("请选择你要操作的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (flag == false && ugr.Cells["VALIDFLAG"].Value.ToString().ToUpper() == "有效") { MessageBox.Show("有效数据,无法恢复!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (flag == true && ugr.Cells["VALIDFLAG"].Value.ToString().ToUpper() != "有效") { MessageBox.Show("无效数据,无法作废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (MessageBox.Show("是否确认" + (flag ? "作废" : "恢复") + "该行数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } string rackno = ugr.Cells["KEP_NO"].Value.ToString(); //DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.coup.FrmBoxMainTenance.getReferRack", new object[] { rackno }, this.ob); //if (dt.Rows.Count > 0) //{ // if (dt.Rows[0]["VALIDFLAG"].ToString() == "1") // { // MessageBox.Show("有效数据,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; // } //} string name = this.UserInfo.GetUserName(); int count = ServerHelper.SetData("com.steering.mes.mcp.coup.FrmBoxMainTenance.doDelete", new Object[] { rackno, name, flag }, this.ob); if (count > 0) { MessageBox.Show("数据" + (flag ? "作废" : "恢复") + "成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DoQuery(); } } private void chkValid_CheckedChanged(object sender, EventArgs e) { if (chkValid.Checked) { isValid = true; } else { isValid = false; } } private void ultraCheckEditor2_CheckedChanged(object sender, EventArgs e) { this.cmb_dw.Enabled = this.ultraCheckEditor2.Checked; } } }