using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using CoreFS.CA06; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using System.Collections; using Infragistics.Win.UltraWinGrid; namespace Core.StlMes.Client.YdmBase { public partial class frmRackDefine : FrmBase { public frmRackDefine() { InitializeComponent(); this.IsLoadUserView = true; } /// /// 重写基类方法 /// /// /// 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": ExportGridData(); break; case "Close": this.Close(); break; } } ArrayList list = new ArrayList(); bool isValid = false; private void frmRackDefine_Load(object sender, EventArgs e) { InitComBox(); // QueryTree(); getDepartMent(); getDepartMent1(); this.cmb_dw.Enabled = false; } /// /// 刷新 /// private void DoRefresh() { InitComBox(); //QueryTree(); getDepartMent(); getDepartMent1(); } private void getDepartMent() { DataTable dt = new DataTable(); string flag = "0"; dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.doQueryData", new object[] {"1" }, this.ob); if (dt.Rows.Count > 0) { cmb_dw.DataSource = dt; cmb_dw.DisplayMember = "DEPARTNAME"; cmb_dw.ValueMember = "DEPARTID"; this.cmb_dw.SelectedIndex = -1; } } private void getDepartMent1() { DataTable dt = new DataTable(); string flag = "0"; dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.doQueryData", new object[] { "1" }, this.ob); if (dt.Rows.Count > 0) { cmbManage1.DataSource = dt; cmbManage1.DisplayMember = "DEPARTNAME"; cmbManage1.ValueMember = "DEPARTID"; } } //刷新Tree public void QueryTree() { //this.cmbManage.Nodes.Clear(); DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.YdmBaseQuery.departQuery", null, this.ob); //树控件递归绑定方法。 //YdmBaseClass.MakeTree(dt, "PID", null, "DEPARTID", "DEPARTNAME", cmbManage.Nodes, -1); } /// /// 初始化下拉框 /// private void InitComBox() { YdmBaseClass.InitComboEditor(cmbRackType, "com.steering.pss.ydm.base.YdmBaseQuery.getRackType", "BASECODE", this.ob, true); YdmBaseClass.InitComboEditor(cmbType1, "com.steering.pss.ydm.base.YdmBaseQuery.getRackType", "BASECODE", this.ob, false); //YdmBaseClass.InitComboEditor(cmbManage1, "com.steering.pss.ydm.base.YdmBaseQuery.getManagement", "BASECODE", this.ob, false); YdmBaseClass.InitComboEditor(cmbSupportRoom, "com.steering.pss.ydm.base.YdmBaseQuery.getRackSp", "BASECODE", this.ob, false); } private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e) { if (ultraCheckEditor1.Checked) { cmbRackType.ReadOnly = false; } else { cmbRackType.ReadOnly = true; } } /// /// 导出数据 /// private void ExportGridData() { GridHelper.ulGridToExcel(gdRack,this.Text); } /// /// 获取编辑区的数据 /// 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; } if (txtBaseWidth.Value == null) { MessageBox.Show("请输入基座宽度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (txtBaseHeight == null) { MessageBox.Show("请输入基座高度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (Convert.ToInt32(txtRackWidth.Value) >Convert.ToInt32(txtBaseWidth.Value)) { MessageBox.Show("基座宽度不能小于料架宽度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (Convert.ToInt32(txtRackHeight.Value) >Convert.ToInt32(txtBaseHeight.Value)) { MessageBox.Show("基座高度不能小于料架高度", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (cmbSupportRoom.SelectedItem == null) { MessageBox.Show("请选择支持空间", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } list.Add(cmbType1.Text.Trim()); //用于编码类型 list.Add(cmbType1.Text.Trim()); //料架类型 list.Add(txtBaseWidth.Value.ToString()); list.Add(txtBaseHeight.Value.ToString()); list.Add(txtRackWidth.Value.ToString()); list.Add(txtRackHeight.Value.ToString()); list.Add(txtRackLen.Value.ToString()); list.Add(cmbSupportRoom.Text.Trim()); 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.pss.ydm.base.CoreRackDefine.doAdd", new Object[] { list }, this.ob); if (count > 0) { MessageBox.Show("数据新增成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); DoQuery(); DataRow[] dr = dataTable1.Select("", "CREATE_TIME DESC"); if (dr.Length > 0) YdmBaseClass.Postioning(gdRack,"RACK_NO",dr[0]["RACK_NO"].ToString()); } } /// /// 查询 /// 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.pss.ydm.base.CoreRackDefine.doQuery", new Object[] { manage, racktype, isValid }, this.ob); GridHelper.CopyDataToDatatable(ref dt, ref dataTable1, true); YdmBaseClass.SetGridRowColor(gdRack); YdmBaseClass.SetGridActivateOnly(gdRack); YdmBaseClass.SetColAutoSizeExceptMemo(gdRack); gdRack.DisplayLayout.Bands[0].Columns["CREATE_TIME"].SortIndicator = SortIndicator.Ascending; } /// /// 更新数据 /// private void DoUpdate() { this.gdRack.UpdateData(); UltraGridRow ugr = gdRack.ActiveRow; if (ugr == null) { MessageBox.Show("请选择需要修改的记录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string rackNo = ugr.Cells["RACK_NO"].Text.ToString(); DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.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 (dt.Rows[0]["USE_FLAG"].ToString() == "1") { MessageBox.Show("数据已被引用,无法修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if(!GetData())return; string newrackno=""; if (list.Count > 0) { string rackno = ugr.Cells["RACK_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.pss.ydm.base.CoreRackDefine.doUpdate", new Object[] { list }, this.ob); if (count > 0) { MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); DoQuery(); YdmBaseClass.Postioning(gdRack,"RACK_NO",newrackno); } } /// /// 行激活事件 /// /// /// private void gdRack_AfterRowActivate(object sender, EventArgs e) { this.gdRack.UpdateData(); UltraGridRow ugr = gdRack.ActiveRow; if (ugr == null) { return; } string rackno = ugr.Cells["RACK_NO"].Value.ToString(); txtRacknoHead.Value = rackno.Substring(0, 1); txtRacknoTail.Value = rackno.Substring(1, 5); cmbType1.Text= ugr.Cells["RACK_TYPE"].Value.ToString(); this.cmbManage1.Text = ugr.Cells["HL_MANAGEMENT_NAME"].Text.ToString(); txtRackWidth.Value = ugr.Cells["RACK_WIDTH"].Value.ToString(); txtRackHeight.Value = ugr.Cells["RACK_HEIGHT"].Value.ToString(); txtRackLen.Value = ugr.Cells["RACK_LEN"].Value.ToString(); txtBaseWidth.Value = ugr.Cells["BASE_WIDTH"].Value.ToString(); txtBaseHeight.Value = ugr.Cells["BASE_HEIGHT"].Value.ToString(); switch (ugr.Cells["RACK_RL"].Value.ToString()) { case"左侧": cmbSupportRoom.Text = "L"; break; case "右侧": cmbSupportRoom.Text = "R"; break; case "两侧": cmbSupportRoom.Text = "LR"; break; } txtMemo.Value = ugr.Cells["MEMO"].Value.ToString(); } /// /// 作废或恢复数据 /// /// true 作废 false 恢复 private void DoDeleteOrResume(bool flag) { UltraGridRow ugr = gdRack.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["RACK_NO"].Value.ToString(); DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.CoreRackDefine.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 (dt.Rows[0]["USE_FLAG"].ToString() == "1") { MessageBox.Show("数据已被引用,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } string name = this.UserInfo.GetUserName(); int count = ServerHelper.SetData("com.steering.pss.ydm.base.CoreRackDefine.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; } } }