using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System.Collections; using System.Diagnostics; using System.IO; using Core.Mes.Client.Common; namespace Core.LgMes.Client.LgIntegrationQuery { public partial class frmElementsCriterion : Core.Mes.Client.Common.frmStyleBase { UltraGridRow currentRow = null; public frmElementsCriterion() { InitializeComponent(); } private void frmElementsCriterion_Load(object sender, EventArgs e) { Init(); doQuery(); activeUlGridRow(this.ultGridLeft, ""); } /// /// 初始化 /// private void Init() { try { string strErr = ""; //获取钢种 ArrayList arrySteel = new ArrayList(); arrySteel.Add("GetSteelInfo.select"); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; DataSet dsSteel = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery", "doSimpleQuery", arrySteel, out strErr); if (strErr == "" && dsSteel != null) { Core.Mes.Client.Common.Globals.FillUltraComboItems(ultcboSteel, dsSteel); Core.Mes.Client.Common.Globals.FillUltraComboItems(ultcboSteelSee, dsSteel); } } catch { } } /// /// 获取标准主表 /// void doQuery() { try { string[] sArgs = new string[1]; string txtSteel = ""; string txtStdstyle = ""; string GWName = ""; string strErr = "",strHeaNo=""; if (chkSteel.Checked && ultcboSteelSee.Text.Trim().Length > 0) { if (ultcboSteelSee.SelectedItem != null) txtSteel = this.ultcboSteelSee.Text; else { MessageBox.Show("请重新输入牌号!", "提示"); ultcboSteelSee.Focus(); return; } } if (chkGWName.Checked && ultcboGWName.Text.Trim().Length > 0) { if (ultcboGWName.SelectedItem != null) GWName = ultcboGWName.SelectedItem.DataValue.ToString(); else { MessageBox.Show("请重新输入标准!", "提示"); ultcboGWName.Focus(); return; } } if (rboAll.Checked == false) { if (rdoInner.Checked) { txtStdstyle = "1"; } else if (rdoFx.Checked) { txtStdstyle = "2"; } } if(chkheano.Checked) { strHeaNo = this.txtheano.Text; } ArrayList arry = new ArrayList(); arry.Add("getChemOrdMianData.select"); arry.Add(txtSteel); arry.Add(txtSteel); arry.Add(txtStdstyle); arry.Add(txtStdstyle); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery", "doSimpleQuery", arry, out strErr); if (strErr == "" && ds != null) { if (ds.Tables[0].Rows.Count != 0) { dataSet1.Tables[0].Clear(); dataSet1.Tables[0].Merge(ds.Tables[0]); } else { dataSet1.Clear(); } } else { MessageBox.Show("查询失败!!!", "提示"); dataSet1.Clear(); ultGridLeft.Rows.CollapseAll(true); } this.ultGridLeft.DisplayLayout.Bands[0].Columns["GYCODE"].Hidden = true; if (chkheano.Checked) { if (strHeaNo != "" && strHeaNo !=null) { this.ultGridLeft.DisplayLayout.Bands[0].Columns["GYCODE"].Hidden = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示"); } } private void chkSteel_CheckedChanged(object sender, EventArgs e) { ultcboSteelSee.Enabled = chkSteel.Checked; if (chkSteel.Checked) { this.chkheano.Enabled = false; this.txtheano.Enabled = false; this.ultcboSteelSee.Enabled = true; } else { this.chkheano.Enabled = true; this.txtheano.Enabled = false; this.ultcboSteelSee.Enabled = false; } } private void chkGWName_CheckedChanged(object sender, EventArgs e) { ultcboGWName.Enabled = chkGWName.Checked; } private void ultGridLeft_AfterRowActivate(object sender, EventArgs e) { UltraGridRow activeRow = ultGridLeft.ActiveRow; if (activeRow != null) { UltraGridRow parentRow = activeRow.ParentRow; UltraGridRow row = activeRow; UltraGridRow ulRow = null; if (parentRow != null) ulRow = parentRow; else ulRow = row; if (parentRow != null) row = parentRow; if (row != currentRow) { currentRow = row; ultGridRight.UpdateData(); if (ultGridRight.DataSource != null && ultGridRight.DataSource is DataSet) { DataTable dt = ((DataSet)(ultGridRight.DataSource)).Tables[0]; if (dt.GetChanges() != null) { if (MessageBox.Show("您已经作了修改,是否要保存本次编辑的结果?", "提示选择", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { SaveItemChange(); } else { dt.RejectChanges(); } } } } //if (row.Cells["STDSTYLE"].Text == "放行") rdoFx.Checked = true; //if (row.Cells["STDSTYLE"].Text == "内控") rdoInnerEdit.Checked = true; //if (row.Cells["STDSTYLE"].Text == "放行") rdoFxEdit.Checked = true; this.ultcboSteel.Text = row.Cells["STEEL"].Text; ultcboGWNameEdit.Text = row.Cells["STATIONCODE"].Text; txtMemo.Text = row.Cells["MEMO"].Text; string[] sArgs = new string[2]; //sArgs[0] = row.Cells["CIC"].Text; if (row.Cells["STATIONCODE"].Text.Trim().Length > 1) sArgs[1] = row.Cells["STATIONCODE"].Text.Substring(0, 1); string strErr = ""; int stdstype = (row.Cells["STDSTYLE"].Text == "内控" ? 1 : 2); ArrayList arry = new ArrayList(); arry.Add("getSubChem.select"); arry.Add(row.Cells["STEEL"].Text); arry.Add(stdstype); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery", "doSimpleQuery", arry, out strErr); if (strErr == "" && ds.Tables[0].Rows.Count >0) { ultGridRight.DataSource = ds; ultGridRight.DataBind(); foreach (UltraGridRow colorRow in ultGridRight.Rows) { //if (colorRow.Cells["CIC"].Text != "" && colorRow.Cells["STDSIGN"].Text != "") //{ // applyCellChange(colorRow.Cells["STDSIGN"]); // colorRow.Appearance.BackColor = Color.MistyRose; //} //else //{ // colorRow.Appearance.BackColor = Color.White; //} } ultGridRight.UpdateData(); ((DataSet)ultGridRight.DataSource).Tables[0].AcceptChanges(); } } } /// /// 保存化学成分标准 /// void SaveItemChange() { ultGridRight.UpdateData(); if (ultGridRight.DataSource != null) { DataTable dtDown = ((DataSet)ultGridRight.DataSource).Tables[0]; if (dtDown.GetChanges(DataRowState.Modified) != null) { DataTable dt = dtDown.GetChanges(DataRowState.Modified); UltraGridRow activeRow = ultGridLeft.ActiveRow; if (activeRow != null) { UltraGridRow parentRow = activeRow.ParentRow; UltraGridRow row = activeRow; ArrayList alItem = new ArrayList(); ArrayList alSign = new ArrayList(); ArrayList alMin = new ArrayList(); ArrayList alMax = new ArrayList(); ArrayList alFormula = new ArrayList(); string strCIC = ""; string strStationCode = ""; foreach (DataRow drow in dt.Rows) { if (drow["STDSIGN"].ToString().Trim() != "") { string sign = drow["STDSIGN"].ToString().Trim(); if (sign == "~") { if (drow["STDMIN"].ToString().Trim() == "") { MessageBox.Show("请输入正确的下限范围!"); UltraGridRow currentRow = findDownRow(drow["ITEMCODE"].ToString()); if (currentRow != null) { currentRow.Cells["STDMIN"].Activated = true; currentRow.Cells["STDMIN"].Selected = true; } return; } if (drow["STDMAX"].ToString().Trim() == "") { MessageBox.Show("请输入正确的上限范围!"); UltraGridRow currentRow = findDownRow(drow["ITEMCODE"].ToString()); if (currentRow != null) { currentRow.Cells["STDMAX"].Activated = true; currentRow.Cells["STDMAX"].Selected = true; } return; } if (decimal.Parse(drow["STDMIN"].ToString()) > decimal.Parse(drow["STDMAX"].ToString())) { MessageBox.Show("请输入正确的上下限范围!"); UltraGridRow currentRow = findDownRow(drow["ITEMCODE"].ToString()); if (currentRow != null) { currentRow.Cells["STDMIN"].Activated = true; currentRow.Cells["STDMIN"].Selected = true; } return; } } if (sign == ">" || sign == ">=" || sign == "=") { if (drow["STDMIN"].ToString().Trim() == "") { MessageBox.Show("请输入正确的下限范围!"); UltraGridRow currentRow = findDownRow(drow["ITEMCODE"].ToString()); if (currentRow != null) { currentRow.Cells["STDMIN"].Activated = true; currentRow.Cells["STDMIN"].Selected = true; } return; } } if (sign == "<" || sign == "<=") { if (drow["STDMAX"].ToString().Trim() == "") { MessageBox.Show("请输入正确的上限范围!"); UltraGridRow currentRow = findDownRow(drow["ITEMCODE"].ToString()); if (currentRow != null) { currentRow.Cells["STDMAX"].Activated = true; currentRow.Cells["STDMAX"].Selected = true; } return; } } } else { if (drow["STDMIN"].ToString().Trim() != "" || drow["STDMAX"].ToString().Trim() != "") { MessageBox.Show("请选择范围符号!"); UltraGridRow currentRow = findDownRow(drow["ITEMCODE"].ToString()); if (currentRow != null) { currentRow.Cells["STDSIGN"].Activated = true; currentRow.Cells["STDSIGN"].Selected = true; } return; } } alItem.Add(drow["UCCODE"].ToString()); alSign.Add((drow["STDSIGN"].ToString().Trim().Length > 0) ? drow["STDSIGN"].ToString() : "Empty"); alMin.Add((drow["STDMIN"].ToString().Trim().Length > 0) ? drow["STDMIN"].ToString() : "Empty"); alMax.Add((drow["STDMAX"].ToString().Trim().Length > 0) ? drow["STDMAX"].ToString() : "Empty"); alFormula.Add((drow["FORMULA"].ToString().Trim())); strCIC = drow["CIC"].ToString(); strStationCode = drow["StationCode"].ToString(); } if (string.IsNullOrEmpty(strStationCode) && ultcboGWNameEdit.Text.Trim().Length > 1) strStationCode = ultcboGWNameEdit.Text.Trim().Substring(0, 1); object[] sArgs = new object[8]; sArgs[0] = strCIC; sArgs[1] = alItem; sArgs[2] = alSign; sArgs[3] = alMin; sArgs[4] = alMax; sArgs[5] = alFormula; sArgs[6] = this.UserInfo.GetUserName(); sArgs[7] = strStationCode; string err = ""; object obj = null; if ((int)obj > 0) { activeRow.Activated = false; activeRow.Selected = false; if (parentRow != null) row = parentRow; row.Selected = true; row.Activated = true; } else { MessageBox.Show(err); } } else { MessageBox.Show("请选择一行数据!"); } } } } /// /// 根据所选符号控制样式 /// /// void applyCellChange(UltraGridCell cell) { if (cell.Text == "~" || cell.Text.Trim() == "") { cell.Row.Cells["STDMIN"].Activation = Activation.AllowEdit; cell.Row.Cells["STDMIN"].Appearance.BackColor = cell.Row.Appearance.BackColor; cell.Row.Cells["STDMAX"].Activation = Activation.AllowEdit; cell.Row.Cells["STDMAX"].Appearance.BackColor = cell.Row.Appearance.BackColor; } if (cell.Text == ">" || cell.Text == ">=" || cell.Text == "=") { cell.Row.Cells["STDMIN"].Activation = Activation.AllowEdit; cell.Row.Cells["STDMIN"].Appearance.BackColor = cell.Row.Appearance.BackColor; cell.Row.Cells["STDMAX"].Value = DBNull.Value; cell.Row.Cells["STDMAX"].Activation = Activation.Disabled; cell.Row.Cells["STDMAX"].Appearance.BackColor = Color.Gray; } if (cell.Text == "<" || cell.Text == "<=") { cell.Row.Cells["STDMIN"].Value = DBNull.Value; cell.Row.Cells["STDMIN"].Activation = Activation.Disabled; cell.Row.Cells["STDMIN"].Appearance.BackColor = Color.Gray; cell.Row.Cells["STDMAX"].Activation = Activation.AllowEdit; cell.Row.Cells["STDMAX"].Appearance.BackColor = cell.Row.Appearance.BackColor; } } UltraGridRow findDownRow(string code) { UltraGridRow currentRow = null; foreach (UltraGridRow row in ultGridRight.Rows) { if (row.Cells["ITEMCODE"].Value.ToString() == code) currentRow = row; row.Selected = false; row.Activated = false; } if (currentRow != null) return currentRow; return null; } private void activeUlGridRow(UltraGrid ulGrid, string strCIC) { try { if (ulGrid.Rows.VisibleRowCount > 0) { this.ultraToolbarsManager1.Tools["bt_Edit"].SharedProps.Enabled = true; this.ultraToolbarsManager1.Tools["bt_delete"].SharedProps.Enabled = true; this.ultraToolbarsManager1.Tools["OutEXcel"].SharedProps.Enabled = true; this.ultraToolbarsManager1.Tools["bt_Updata"].SharedProps.Enabled = true; //for (int i = 0; i < ulGrid.Rows.Count; i++) //{ // if (ulGrid.Rows[i].Cells["CIC"].Text == strCIC) // { // ulGrid.ActiveRow = ulGrid.Rows[i]; // ulGrid.Rows[i].Selected = true; // return; // } //} } else { ultcboSteel.SelectedIndex = -1; txtMemo.Text = ""; if (ultGridLeft.ActiveRow != null) { ultGridLeft.ActiveRow.Activated = false; ultGridLeft.ActiveRow.Selected = false; } if (ultGridRight.DataSource is DataSet) ((DataSet)(this.ultGridRight.DataSource)).Tables[0].Rows.Clear(); this.ultraToolbarsManager1.Tools["bt_Edit"].SharedProps.Enabled = false; this.ultraToolbarsManager1.Tools["bt_delete"].SharedProps.Enabled = false; this.ultraToolbarsManager1.Tools["OutEXcel"].SharedProps.Enabled = false; this.ultraToolbarsManager1.Tools["bt_Updata"].SharedProps.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void ultGridRight_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.Key == "STDSIGN") { applyCellChange(e.Cell); } } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": doQuery(); activeUlGridRow(ultGridLeft, ""); break; case "bt_ad": doAdd(); break; case "bt_Edit": doEdit(); break; case "bt_Delete": doDel(); break; case "bt_Updata": doUpdate(); break; case "OutEXcel": doExport(); break; case "Exit": Close(); break; default: break; } } /// /// 增加成分标准主表内容 /// void doAdd() { if (this.ultcboSteel.Text == "") { MessageBox.Show("请选择牌号"); ultcboSteel.Focus(); return; } if (this.ultcboGWNameEdit.Text == "") { MessageBox.Show("请选择岗位"); ultcboGWNameEdit.Focus(); return; } if (this.rdoNationEdit.Checked == false && this.rdoInnerEdit.Checked == false) { MessageBox.Show("请选择标准类型[国标/内控]"); return; } string err = ""; string[] sArgs = new string[10]; if (rdoNationEdit.Checked == true) sArgs[0] = "1"; else sArgs[0] = "2"; sArgs[1] = ultcboSteel.Text.ToString();//牌号 sArgs[2] = ""; sArgs[3] = ""; sArgs[4] = ""; sArgs[5] = "";//交货状态 sArgs[6] = "1"; sArgs[7] = txtMemo.Text; sArgs[8] = this.UserInfo.GetUserName(); sArgs[9] = this.ultcboGWNameEdit.SelectedItem.DataValue.ToString(); object obj = null; if ((int)obj > 0) { doQuery(); activeUlGridRow(ultGridLeft, err); } else { MessageBox.Show(err); } } /// /// 修改成分标准主表内容 /// void doEdit() { Infragistics.Win.UltraWinGrid.UltraGridRow row = this.ultGridLeft.ActiveRow; if (row != null && !row.IsFilteredOut) { if (row.ParentRow != null) row = row.ParentRow; if (this.ultcboSteel.Text == "") { MessageBox.Show("请选择牌号"); ultcboSteel.Focus(); return; } if (this.ultcboGWNameEdit.Text == "") { MessageBox.Show("请选择岗位"); ultcboGWNameEdit.Focus(); return; } string err = ""; string[] sArgs = new string[11]; //标准(1国标2内控) if (rdoNationEdit.Checked == true) sArgs[0] = "1"; else sArgs[0] = "2"; sArgs[1] = ultcboSteel.Text.ToString();//牌号 sArgs[2] = ""; sArgs[3] = ""; sArgs[4] = ""; sArgs[5] = "";//交货状态 sArgs[6] = "1"; sArgs[7] = txtMemo.Text; sArgs[8] = this.UserInfo.GetUserName(); sArgs[9] = row.Cells[0].Value.ToString(); sArgs[10] = this.ultcboGWNameEdit.SelectedItem.DataValue.ToString(); object obj = null; if ((int)obj > 0) { doQuery(); activeUlGridRow(ultGridLeft, err); } else { MessageBox.Show(err); } } else { MessageBox.Show("请选择一行数据!"); } } /// /// 删除成分标准主表内容 /// void doDel() { Infragistics.Win.UltraWinGrid.UltraGridRow row = this.ultGridLeft.ActiveRow; if (row != null && !row.IsFilteredOut) { if (row.ParentRow != null) row = row.ParentRow; if (MessageBox.Show("你确定要删除此行数据吗?", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string err = ""; string[] sArgs = new string[3]; sArgs[0] = row.Cells[0].Text; sArgs[1] = this.UserInfo.GetUserName(); if (row.Cells["STATIONCODE"].Text.Trim().Length > 1) sArgs[2] = row.Cells["STATIONCODE"].Text.Substring(0, 1); object obj = null; if ((int)obj > 0) { doQuery(); } else { MessageBox.Show(err); } } } else { MessageBox.Show("请选择一行数据!"); } } /// /// 保存成分标准值 /// void doUpdate() { SaveItemChange(); } /// /// 导出数据 /// void doExport() { if (ultGridRight.Rows.Count < 1) { MessageBox.Show("当前没有数据"); return; } try { string StrfileName = string.Format(System.Windows.Forms.Application.StartupPath + "\\{0}{1}.xls", "成分标准信息导出记录", DateTime.Now.ToString("yyyy年MM月dd日")); this.ultraGridExcelExporter1.Export(this.ultGridRight, StrfileName); ProcessStartInfo p = new ProcessStartInfo(StrfileName); p.WorkingDirectory = Path.GetDirectoryName(StrfileName); Process.Start(p); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void chkstand_CheckedChanged(object sender, EventArgs e) { txtstand.Enabled = chkstand.Checked; if (!chkstand.Checked) { txtstand.BackColor = Color.WhiteSmoke;//(224, 224, 224); } } private void chkGyCode_CheckedChanged(object sender, EventArgs e) { txtGyCode.Enabled = chkGyCode.Checked; } private void chkheano_CheckedChanged(object sender, EventArgs e) { txtheano.Enabled = chkheano.Checked; if (chkheano.Checked) { this.chkSteel.Enabled = false; this.ultcboSteelSee.Enabled = false; this.txtheano.Enabled = true; } else { txtheano.BackColor = Color.WhiteSmoke; this.chkSteel.Enabled = true; this.ultcboSteelSee.Enabled = false; this.ultcboSteelSee.Enabled = false; } } } }