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 System.Collections; using Infragistics.Win.UltraWinGrid; using CoreFS.CA06; using Core.StlMes.Client.LgCommon; using Infragistics.Win.UltraWinEditors; namespace Core.StlMes.Client.LgIntegrationQuery { public partial class FrmShiftItems : Core.StlMes.Client.LgCommon.frmStyleBase { private bool ok_flag = false; private bool refreshflag = true; public FrmShiftItems(OpeBase oba) { InitializeComponent(); this.ob = oba; } private void FrmShiftItems_Load(object sender, EventArgs e) { shiftConfigQuery(); SetColumnModeClass(ugdShift); } // 查询班次配置的信息 /// /// 查询班次配置的信息 /// private void shiftConfigQuery() { try { string strErr = ""; ArrayList arry = new ArrayList(); CommonClientToServer ccTos = new CommonClientToServer(); ccTos.ob = this.ob; DataSet ds = ccTos.ExecuteQueryFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess", "QueryWithParameter", "STL_CON0002", 5, arry, out strErr); if (strErr == "" && ds != null) { udsConfig.Rows.Clear(); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { udsConfig.Rows.Add(new object[] { dr["ID"].ToString(), dr["SHIFTNAME"].ToString(), dr["SHIFTTYPE"].ToString(), dr["SHIFTTYPENAME"].ToString(), dr["CYCLES"].ToString(), dr["OPTPERSONNEL"].ToString(), dr["OPTPERDATE"].ToString() } ); } } PublicMethod.RefreshAndAutoSize(ugdConfig); } else MessageBox.Show("信息查询失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch { } } // 查询具体配置的信息 /// /// 查询具体配置的信息 /// private void DetailConfigQuery(String strID) { try { string strErr = ""; ArrayList arry = new ArrayList(); arry.Add(strID); CommonClientToServer ccTos = new CommonClientToServer(); ccTos.ob = this.ob; DataSet ds = ccTos.ExecuteQueryFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess", "QueryWithParameter", "STL_CON0003", 5, arry, out strErr); if (strErr == "" && ds != null) { udsShift.Rows.Clear(); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { udsShift.Rows.Add(new object[] { dr["CURDATE"].ToString(), dr["FUNC"].ToString(), dr["NO1"].ToString(), dr["NO2"].ToString(), dr["NO3"].ToString(), dr["NO4"].ToString() } ); } } // PublicMethod.RefreshAndAutoSize(ugdShift); } else MessageBox.Show("信息查询失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch { } } // 查询配置方案的最大id /// /// 查询配置方案的最大id /// private string MaxIDQuery() { try { string strInfo = ""; string strErr = ""; ArrayList arry = new ArrayList(); CommonClientToServer ccTos = new CommonClientToServer(); ccTos.ob = this.ob; DataSet ds = ccTos.ExecuteQueryFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess", "QueryWithParameter", "STL_CON0006", 5, arry, out strErr); if (strErr == "" && ds != null) { if (ds.Tables.Count > 0) { strInfo = ds.Tables[0].Rows[0]["MAXID"].ToString(); } } else MessageBox.Show("信息查询失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return strInfo; } catch { return ""; } } // 执行排班操作 /// /// 执行排班操作 /// private void proc_Exe() { try { if (textName.Text.Length == 0) { MessageBox.Show("方案名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); textName.Focus(); return; } if (cboShift1.SelectedIndex < 0 || cboShift2.SelectedIndex < 0) { MessageBox.Show("排班类型不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); cboShift1.Focus(); return; } if (udtBeginTime.Value == null) { MessageBox.Show("开始时间不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); udtBeginTime.Focus(); return; } if (cboJia.SelectedIndex < 0) { MessageBox.Show("甲班不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); cboJia.Focus(); return; } if (cboYi.SelectedIndex < 0) { MessageBox.Show("乙班不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); cboYi.Focus(); return; } if (cboBing.SelectedIndex < 0) { MessageBox.Show("丙班不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); cboBing.Focus(); return; } if (cboDing.SelectedIndex < 0) { MessageBox.Show("丁班不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); cboDing.Focus(); return; } int nJ = cboJia.SelectedIndex; //甲班 int nY = cboYi.SelectedIndex; //乙班 int nB = cboBing.SelectedIndex; //丙班 int nD = cboDing.SelectedIndex; //丁班 int nCount = 0; int nCount1 = 0; string strName = textName.Text.Trim(); int tBZ = Convert.ToInt16(cboShift1.Value.ToString()); //总共班组 int yBZ = Convert.ToInt16(cboShift2.Value.ToString()); //运转班组 int cycles = Convert.ToInt16(numericUpDown1.Value); //循环次数 DateTime dt = Convert.ToDateTime(udtBeginTime.Value); if (yBZ == 3) { if (nJ == 0) { nCount++; } else { nCount1++; } if (nY == 0) { nCount++; } else { nCount1++; } if (nB == 0) { nCount++; } else { nCount1++; } if (nD == 0) { nCount++; } else { nCount1++; } if (nCount > 1) { MessageBox.Show("你选择了三运转至少要选择三个班!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (nCount1 > 3) { MessageBox.Show("你选择了三运转最多只能选择三个班!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } } cboShift1.Value.ToString(); if (udsConfig.Rows.Count == 0) { udsConfig.Rows.Add(new object[] { "", strName, tBZ.ToString()+yBZ.ToString(), cboShift1.SelectedItem.DisplayText.ToString()+cboShift2.SelectedItem.DisplayText.ToString(), cycles.ToString(), "", ""}); } for (int i = 0; i < cycles; i++) { udsShift.Rows.Add(new object[] { dt.ToString("yyyy-MM-dd"), "", cboJia.Value.ToString(), cboYi.Value.ToString(), cboBing.Value.ToString(), cboDing.Value.ToString()}); dt = dt.AddDays(1); } udtBeginTime.Value = dt; cboJia.SelectedIndex = 0; cboYi.SelectedIndex = 0; cboBing.SelectedIndex = 0; cboDing.SelectedIndex = 0; } catch { } } // 新增配置方案 /// /// 新增配置方案 /// private void proc_Add() { try { if (ugdConfig.Rows.Count == 0) { MessageBox.Show("配置方案不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (ugdShift.Rows.Count == 0) { MessageBox.Show("具体方案不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } ArrayList listDate = new ArrayList(); ArrayList listNo1 = new ArrayList(); ArrayList listNo2 = new ArrayList(); ArrayList listNo3 = new ArrayList(); ArrayList listNo4 = new ArrayList(); string strName = ugdConfig.Rows[0].Cells["SHIFTNAME"].Value.ToString(); string vType = ugdConfig.Rows[0].Cells["SHIFTTYPE"].Value.ToString(); //运转班组 string vTypeName = ugdConfig.Rows[0].Cells["SHIFTTYPENAME"].Value.ToString(); //运转班组名称 string cycles = ugdConfig.Rows[0].Cells["CYCLES"].Value.ToString(); //循环次数 for (int i = 0; i < ugdShift.Rows.Count; i++) { listDate.Add(ugdShift.Rows[i].Cells["CURDATE"].Value.ToString()); listNo1.Add(ugdShift.Rows[i].Cells["NO1"].Value.ToString()); listNo2.Add(ugdShift.Rows[i].Cells["NO2"].Value.ToString()); listNo3.Add(ugdShift.Rows[i].Cells["NO3"].Value.ToString()); listNo4.Add(ugdShift.Rows[i].Cells["NO4"].Value.ToString()); } string strErr = ""; string strSqlID = "STL_CON0004"; //SQLID object[] sArgs = new object[11]; sArgs[0] = strName; //方案名称 sArgs[1] = vType; //运转班组 sArgs[2] = vTypeName; //运转班组名称 sArgs[3] = cycles; //循环次数 sArgs[4] = ugdShift.Rows.Count.ToString(); //配置总数 sArgs[5] = listDate; //班次日期 sArgs[6] = listNo1; //甲班 sArgs[7] = listNo2; //乙班 sArgs[8] = listNo3; //丙班 sArgs[9] = listNo4; //丁班 sArgs[10] = this.UserInfo.GetUserName(); //操作人 CommonClientToServer ccTs = new CommonClientToServer(); ccTs.ob = ob; CoreClientParam ccp = ccTs.ExecuteProcedureFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess", "ExecProcWithCollParam", strSqlID, 5, sArgs, out strErr); if (strErr == "") { ok_flag = true; shiftConfigQuery(); FrmShiftConfig frm = (FrmShiftConfig)this.Tag; frm.shiftConfigQuery(); MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else MessageBox.Show("保存失败!" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch { } } private void proc_Edit() { try { } catch { } } // 删除配置方案 /// /// 删除配置方案 /// private void proc_Delete() { try { if (ugdConfig.Rows.Count == 0) { MessageBox.Show("没有可以删除的配置方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (ugdConfig.ActiveRow == null) { MessageBox.Show("请选择要删除的配置方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } DialogResult dr = MessageBox.Show("是否确认删除名称为【" + ugdConfig.ActiveRow.Cells["SHIFTNAME"].Value.ToString() + "】的配置信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dr == DialogResult.No) return; string strErr = ""; string strSqlID = "STL_CON0005"; //SQLID object[] sArgs = new object[1]; sArgs[0] = ugdConfig.ActiveRow.Cells["ID"].Value.ToString(); //方案ID CommonClientToServer ccTs = new CommonClientToServer(); ccTs.ob = ob; CoreClientParam ccp = ccTs.ExecuteProcedureFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess", "ExecProcWithCollParam", strSqlID, 5, sArgs, out strErr); if (strErr == "") { shiftConfigQuery(); FrmShiftConfig frm = (FrmShiftConfig)this.Tag; frm.shiftConfigQuery(); MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else MessageBox.Show("删除失败!" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch { } } // 测试存储方案 /// /// 测试存储方案 /// private void pro_Test() { try { if (textTestName.Text.Length == 0) { MessageBox.Show("没有选择配置方案!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } DateTime dt = DateTime.Now; try { dt = Convert.ToDateTime(ute_TestTime.Text.ToString()); } catch { MessageBox.Show("日期格式不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } string strShift = ""; string strErr = ""; ArrayList arry = new ArrayList(); arry.Add(dt.ToString("yyyy-MM-dd HH:mm:ss")); //时间 arry.Add(ugdConfig.ActiveRow.Cells["ID"].Value.ToString()); //方案ID CommonClientToServer ccTos = new CommonClientToServer(); ccTos.ob = this.ob; DataSet ds = ccTos.ExecuteQueryFunctionsSqlID("Core.Mes.Server.Common.ComDataAccess", "QueryWithParameter", "STL_CON0010", 5, arry, out strErr); if (strErr == "" & ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { strShift = ds.Tables[0].Rows[0][0].ToString(); } if (strShift.Length == 2) { string strBC = ""; string strBZ = ""; switch (strShift.Substring(0, 1)) { case "1": strBC = "白班"; break; case "2": strBC = "小夜"; break; case "3": strBC = "大夜"; break; } switch (strShift.Substring(1, 1)) { case "1": strBZ = "甲班"; break; case "2": strBZ = "乙班"; break; case "3": strBZ = "丙班"; break; case "4": strBZ = "丁班"; break; } textTextValue.Text = strBC + "-" + strBZ; } else { textTextValue.Text = "测试失败"; } //string } catch { } } // 设置班组 /// /// 设置班组 /// /// private void SetColumnModeClass(Infragistics.Win.UltraWinGrid.UltraGridBase Grid) { DataTable dt = new DataTable(); dt.TableName = "CLASS"; DataColumn dc = new DataColumn("BCBM", Type.GetType("System.String")); dt.Columns.Add(dc); dc = new DataColumn("BCNA", Type.GetType("System.String")); dt.Columns.Add(dc); DataRow dr = dt.NewRow(); dr["BCBM"] = "0"; dr["BCNA"] = "无"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["BCBM"] = "1"; dr["BCNA"] = "白班"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["BCBM"] = "2"; dr["BCNA"] = "小夜"; dt.Rows.Add(dr); dr = dt.NewRow(); dr["BCBM"] = "3"; dr["BCNA"] = "大夜"; dt.Rows.Add(dr); ClsControlPack.SetGridDropDownListCell("NO1", 0, "甲班", 60, Grid, dt, "BCBM", "BCNA"); ClsControlPack.SetGridDropDownListCell("NO2", 0, "乙班", 60, Grid, dt, "BCBM", "BCNA"); ClsControlPack.SetGridDropDownListCell("NO3", 0, "丙班", 60, Grid, dt, "BCBM", "BCNA"); ClsControlPack.SetGridDropDownListCell("NO4", 0, "丁班", 60, Grid, dt, "BCBM", "BCNA"); } // 设置编辑区域是否可编辑 /// /// 设置编辑区域是否可编辑 /// /// private void setToolEnable(bool t_Enable) { try { textName.ReadOnly = t_Enable; cboShift1.ReadOnly = t_Enable; cboShift2.ReadOnly = t_Enable; numericUpDown1.ReadOnly = t_Enable; udtBeginTime.ReadOnly = t_Enable; cboJia.ReadOnly = t_Enable; cboYi.ReadOnly = t_Enable; cboBing.ReadOnly = t_Enable; cboDing.ReadOnly = t_Enable; butExe.Enabled = !t_Enable; textTestName.ReadOnly = t_Enable; ute_TestTime.ReadOnly = t_Enable; butTest.Enabled = t_Enable; } catch { } } // 清空编辑区域 /// /// 清空编辑区域 /// private void clearWidget() { textName.Text = "配置"+MaxIDQuery(); cboShift1.SelectedIndex = 0; cboShift2.SelectedIndex = 0; numericUpDown1.Value = 1; udtBeginTime.Value = DateTime.Now.ToString("yyyy-MM-dd"); cboJia.SelectedIndex = 0; cboYi.SelectedIndex = 0; cboBing.SelectedIndex = 0; cboDing.SelectedIndex = 0; } // 点击修改或删除时显示确认和取消按钮 /// /// 点击修改或删除时显示确认和取消按钮 /// /// private void SetDetailToolBarEnable(bool bEnable, string flag) { int count = this.uTbMTool.Tools.Count; for (int i = 0; i < count; i++) { this.uTbMTool.Tools[i].SharedProps.Enabled = !bEnable; } this.uTbMTool.Tools["ok"].SharedProps.Enabled = bEnable; this.uTbMTool.Tools["cancel"].SharedProps.Enabled = bEnable; this.uTbMTool.Tools["ok"].SharedProps.Visible = bEnable; this.uTbMTool.Tools["cancel"].SharedProps.Visible = bEnable; refreshflag = !bEnable; } private void ultraToolbarsManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { switch (e.Tool.Key) { case "Query": shiftConfigQuery(); break; case "add": SetDetailToolBarEnable(true, "add"); setToolEnable(false); this.uTbMTool.Tools["ok"].Tag = "add"; clearWidget(); ok_flag = false; udsConfig.Rows.Clear(); udsShift.Rows.Clear(); break; case "edit": if (ugdConfig.Rows.Count == 0) { MessageBox.Show("没有可修改的信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } if (ugdConfig.ActiveRow == null) { MessageBox.Show("请选择要修改的信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } SetDetailToolBarEnable(true, "edit"); setToolEnable(false); this.uTbMTool.Tools["ok"].Tag = "edit"; ok_flag = false; break; case "del": proc_Delete(); break; case "ok": string flag = this.uTbMTool.Tools["ok"].Tag.ToString(); if (flag == "edit") { proc_Edit(); } if (flag == "add") { proc_Add(); } if (ok_flag) { SetDetailToolBarEnable(false, ""); setToolEnable(true); } break; case "cancel": SetDetailToolBarEnable(false, ""); setToolEnable(true); ugdConfig_AfterRowActivate(null, null); shiftConfigQuery(); break; case "left": if (ugdConfig.Rows.Count == 0) return; //将位置移动到前一条记录 try { if (ugdConfig.ActiveRow == null) { ugdConfig.Rows[0].Activate(); } else { int nIndex = ugdConfig.ActiveRow.Index; nIndex = nIndex - 1; if (nIndex < 0) nIndex = ugdConfig.Rows.Count - 1; ugdConfig.Rows[nIndex].Activate(); } } catch { } break; case "right": if (ugdConfig.Rows.Count == 0) return; //将位置移动到后一条记录 try { if (ugdConfig.ActiveRow == null) { ugdConfig.Rows[0].Activate(); } else { int nIndex = ugdConfig.ActiveRow.Index; nIndex = nIndex + 1; if (nIndex >= ugdConfig.Rows.Count) nIndex = 0; ugdConfig.Rows[nIndex].Activate(); } } catch { } break; } } private void butExe_Click(object sender, EventArgs e) { proc_Exe(); } private void ugdConfig_AfterRowActivate(object sender, EventArgs e) { try { UltraGridRow row = ugdConfig.ActiveRow; try { textName.Text = row.Cells["SHIFTNAME"].Value.ToString(); textTestName.Text = row.Cells["SHIFTNAME"].Value.ToString(); cboShift1.Text = row.Cells["SHIFTTYPE"].Value.ToString().Substring(0, 1); cboShift2.Text = row.Cells["SHIFTTYPE"].Value.ToString().Substring(1, 1); } catch { } string ID = row.Cells["ID"].Value.ToString(); if (refreshflag) { DetailConfigQuery(ID); } } catch { } } private void cboBZ_ValueChanged(object sender, EventArgs e) { try { UltraComboEditor ucbo = (UltraComboEditor)sender; string strName = ucbo.Name; int nCbo = ucbo.SelectedIndex; int nJ = cboJia.SelectedIndex; //甲班 int nY = cboYi.SelectedIndex; //乙班 int nB = cboBing.SelectedIndex; //丙班 int nD = cboDing.SelectedIndex; //丁班 if(nCbo!=0) { if (strName == "cboJia") { if (nCbo == nY || nCbo == nB || nCbo == nD) { cboJia.SelectedIndex = 0; cboJia.Focus(); MessageBox.Show("班次重复请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } } if (strName == "cboYi") { if (nCbo == nJ || nCbo == nB || nCbo == nD) { cboYi.SelectedIndex = 0; cboYi.Focus(); MessageBox.Show("班次重复请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } } if (strName == "cboBing") { if (nCbo == nJ || nCbo == nY || nCbo == nD) { cboBing.SelectedIndex = 0; cboBing.Focus(); MessageBox.Show("班次重复请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } } if (strName == "cboDing") { if (nCbo == nY || nCbo == nB || nCbo == nJ) { cboDing.SelectedIndex = 0; cboDing.Focus(); MessageBox.Show("班次重复请重新选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } } } } catch { } } private void butTest_Click(object sender, EventArgs e) { pro_Test(); } private void ute_TestTime_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { try { frmSetTime frm = new frmSetTime(e.Context); //frm.Location = ClsControlPack.GetChildWindowLocation(frm.Size); frm.Location = new Point(300, 200);//ClsControlPack.GetChildWindowLocation(frm.Size); frm.AutoSize = true; if (frm.ShowDialog() == DialogResult.OK) { ute_TestTime.Text = (Convert.ToDateTime(frm.SelectDate.ToString())).ToString("yyyy-MM-dd HH:mm:ss"); ute_TestTime.Update(); } } catch { } } } }