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 Core.Mes.Client.Common; using Infragistics.Win.UltraWinGrid; using Infragistics.Win.UltraWinGrid.ExcelExport; using Infragistics.Win; using System.Collections; using CoreFS.CA06; using System.Diagnostics; using System.IO; namespace Core.LgMes.Client.lgIntegrationQuery { public partial class FrmTBCheckInfo : frmStyleBase { private bool bAddNow, bEditNow, bDelNow; private UltraGridRow currRow = null; public FrmTBCheckInfo() { InitializeComponent(); } private void FrmTBCheckInfo_Load(object sender, EventArgs e) { ultraDateTimeEditor1.DateTime = DateTime.Today; ultraDateTimeEditor2.DateTime = DateTime.Today; proc_SetToolbarButtons(); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": { if (bAddNow || bEditNow || bDelNow) return; proc_Query(); proc_SetToolbarButtons(); break; } case "Add": { if (bAddNow || bEditNow || bDelNow) return; currRow = this.ultraGrid1.DisplayLayout.Bands[0].AddNew(); this.proc_setCellReadOnly(currRow, false); bAddNow = true; this.proc_SetToolbarButtons(); break; } case "Edit": { if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow)) return; currRow = ultraGrid1.ActiveRow; this.proc_setCellReadOnly(currRow, false); bEditNow = true; this.proc_SetToolbarButtons(); break; } case "Save": { if (bAddNow) { proc_Add("Add"); } else if (bEditNow) { proc_Add("Edit"); } proc_Query(); break; } case "Delete": { if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow)) return; bDelNow = true; this.proc_SetToolbarButtons(); proc_Delete(); bDelNow = false; proc_Query(); this.proc_SetToolbarButtons(); break; } case "Export": { try { if (ultraGrid1.Rows.Count == 0) return; string strFileName = "铁包在线记录" + DateTime.Now.ToString("yyyyMMdd"); SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = "保存"; dlg.OverwritePrompt = true; dlg.Filter = "Excel文件(*.xls)|*.xls"; dlg.AddExtension = true; dlg.FileName = strFileName; if (dlg.ShowDialog() == DialogResult.OK) { strFileName = dlg.FileName; ultraGridExcelExporter1.Export(ultraGrid1, strFileName); if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ultraGridExcelExporter1.Export(ultraGrid1, strFileName); ProcessStartInfo p = new ProcessStartInfo(strFileName); p.WorkingDirectory = Path.GetDirectoryName(strFileName); Process.Start(p); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } break; } case "Cancel": { if (!(bAddNow || bEditNow)) return; string strOpt = " [" + (bAddNow ? "新增" : (bEditNow ? "修改" : "")) + "]"; if (MessageBox.Show("确定要取消" + strOpt + "操作吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; if (bAddNow) { currRow.Delete(false); currRow = null; if (ultraGrid1.Rows.Count > 0) { ultraGrid1.ActiveCell = ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STATIONCODE"]; ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STATIONCODE"].Selected = false; } bAddNow = false; } else if (bEditNow) { this.proc_setCellReadOnly(currRow, true); currRow = null; bEditNow = false; } this.proc_SetToolbarButtons(); break; } case "Close": { this.Close(); break; } } } public void proc_Query() { Cursor oldCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; try { this.dataTable1.Clear(); string sqlStr = @"SELECT * FROM DEV_IB_CHECK_INFO WHERE OPTDATE BETWEEN TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS') AND TO_DATE('{1}','YYYY-MM-DD HH24:MI:SS')"; if (ultraDateTimeEditor2.DateTime.Date.Subtract(ultraDateTimeEditor1.DateTime.Date).Days > 90) { MessageBox.Show("查询时间不可超过3个月。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (ultraDateTimeEditor1.DateTime.Date > ultraDateTimeEditor2.DateTime.Date) { MessageBox.Show("查询开始日期不能大于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string strFrom = ultraDateTimeEditor1.DateTime.ToString("yyyy-MM-dd") + " 00:00:00"; string strTo = ultraDateTimeEditor2.DateTime.ToString("yyyy-MM-dd") + " 23:59:59"; sqlStr = string.Format(sqlStr, strFrom, strTo); //调用服务端方法 CoreClientParam CCP_LgEts = new CoreClientParam(); DataTable dt = new DataTable(); CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBExecute"; CCP_LgEts.MethodName = "doSimpleQuery"; CCP_LgEts.ServerParams = new object[] { sqlStr }; CCP_LgEts.SourceDataTable = dt; this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal); DataSet ds = new DataSet(); if (dt != null && dt.Rows.Count > 0) { this.dataTable1.Rows.Clear(); DataRow dr; for (int iRow = 0; iRow < dt.Rows.Count; iRow++) { dr = this.dataTable1.NewRow(); for (int jCol = 0; jCol < dt.Columns.Count; jCol++) { if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName)) { dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol]; } } this.dataTable1.Rows.Add(dr); } } if (ultraGrid1.Rows.Count > 0) { ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["UUID_"]; ultraGrid1.Rows[0].Cells["UUID_"].Selected = false; } ultraGrid1.UpdateData(); this.proc_SetUltraGridReadOnly(ultraGrid1); } catch { } finally { this.Cursor = oldCursor; } } public void proc_Add(string flag) { try { this.ultraGrid1.UpdateData(); if (dataTable1.Rows.Count > 0) { string strErr = ""; string strMess = ""; if (flag == "Add") { ArrayList arry = new ArrayList(); arry.Add("frmTBCHECKInfo.Insert"); string str1 = ultraGrid1.ActiveRow.Cells["LADLEID"].Text; string str2 = ultraGrid1.ActiveRow.Cells["FACTORY"].Text; string str3 = ultraGrid1.ActiveRow.Cells["CHECK_DATE"].Text; string str4 = ultraGrid1.ActiveRow.Cells["LS"].Text; string str5 = ultraGrid1.ActiveRow.Cells["SHIFT_GROUP"].Text; string str6 = ultraGrid1.ActiveRow.Cells["SHIFT_CLASS"].Text; string str7 = ultraGrid1.ActiveRow.Cells["FJ"].Text; string str8 = ultraGrid1.ActiveRow.Cells["BZ"].Text; string str9 = ultraGrid1.ActiveRow.Cells["BDZ"].Text; string str10 = ultraGrid1.ActiveRow.Cells["RCZ"].Text; string str11 = ultraGrid1.ActiveRow.Cells["ZXZ"].Text; string str12 = ultraGrid1.ActiveRow.Cells["CHECK_MAN"].Text; string str13 = ultraGrid1.ActiveRow.Cells["REMARK"].Text; string str14 = this.UserInfo.GetUserName().Trim(); arry.Add(str1); arry.Add(str2); arry.Add(str3); arry.Add(str4); arry.Add(str5); arry.Add(str6); arry.Add(str7); arry.Add(str8); arry.Add(str9); arry.Add(str10); arry.Add(str11); arry.Add(str12); arry.Add(str13); arry.Add(str14); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); this.proc_setCellReadOnly(currRow, true); currRow = null; bAddNow = false; } else if (flag == "Edit") { ArrayList arry = new ArrayList(); arry.Add("frmTBCHECKInfo.Update"); string str1 = ultraGrid1.ActiveRow.Cells["LADLEID"].Text; string str2 = ultraGrid1.ActiveRow.Cells["FACTORY"].Text; string str3 = ultraGrid1.ActiveRow.Cells["CHECK_DATE"].Text; string str4 = ultraGrid1.ActiveRow.Cells["LS"].Text; string str5 = ultraGrid1.ActiveRow.Cells["SHIFT_GROUP"].Text; string str6 = ultraGrid1.ActiveRow.Cells["SHIFT_CLASS"].Text; string str7 = ultraGrid1.ActiveRow.Cells["FJ"].Text; string str8 = ultraGrid1.ActiveRow.Cells["BZ"].Text; string str9 = ultraGrid1.ActiveRow.Cells["BDZ"].Text; string str10 = ultraGrid1.ActiveRow.Cells["RCZ"].Text; string str11 = ultraGrid1.ActiveRow.Cells["ZXZ"].Text; string str12 = ultraGrid1.ActiveRow.Cells["CHECK_MAN"].Text; string str13 = ultraGrid1.ActiveRow.Cells["REMARK"].Text; string str14 = this.UserInfo.GetUserName().Trim(); string uuid = ultraGrid1.ActiveRow.Cells["UUID_"].Text; arry.Add(str1); arry.Add(str2); arry.Add(str3); arry.Add(str4); arry.Add(str5); arry.Add(str6); arry.Add(str7); arry.Add(str8); arry.Add(str9); arry.Add(str10); arry.Add(str11); arry.Add(str12); arry.Add(str13); arry.Add(str14); arry.Add(uuid); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); this.proc_setCellReadOnly(currRow, true); currRow = null; bEditNow = false; } if (strErr == "") { dataTable1.AcceptChanges(); //JJBStaticFunction.SetRowEdit(ultraGrid1); if (!string.IsNullOrEmpty(strMess)) MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误"); } if (ultraGrid1.ActiveCell != null) ultraGrid1.ActiveCell.Activated = false; this.proc_SetToolbarButtons(); } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } } public void proc_Delete() { try { string strErr = ""; ArrayList arry = new ArrayList(); if (this.ultraGrid1.ActiveRow == null) return; string uuid_ = ultraGrid1.ActiveRow.Cells["UUID_"].Text.Trim(); arry.Add("frmTBCHECKInfo.Delete"); arry.Add(uuid_); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); if (!string.IsNullOrEmpty(strErr)) { MessageBox.Show("删除错误:" + strErr); } else { MessageBox.Show("删除成功:" + strErr); } } catch { } } private void proc_SetToolbarButtons() { try { this.ToolBarItemEnable(this, "Query", !(bAddNow || bEditNow || bDelNow)); this.ToolBarItemEnable(this, "Add", !(bAddNow || bEditNow || bDelNow)); this.ToolBarItemEnable(this, "Edit", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null))); this.ToolBarItemEnable(this, "Delete", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null))); this.ToolBarItemEnable(this, "Export", (!(bAddNow || bEditNow || bDelNow) && ultraGrid1.Rows.Count > 0)); this.ToolBarItemEnable(this, "Save", (bAddNow || bEditNow)); this.ToolBarItemEnable(this, "Cancel", (bAddNow || bEditNow)); //this.ToolBarVisible(this, "Save"); //this.Toolbars[0].Tools["Save"].SharedProps.Visible = (bAddNow || bEditNow); //this.Toolbars[0].Tools["Cancel"].SharedProps.Visible = (bAddNow || bEditNow); } catch { } } private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly) { try { if (row == null) return; if (bReadOnly) { row.Activation = Activation.ActivateOnly; row.CellAppearance.BackColor = Color.White; foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells) { cell.CancelUpdate(); } } else { row.Activation = Activation.AllowEdit; row.CellAppearance.BackColor = Color.Khaki; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid) { foreach (UltraGridRow row in ultGrid.Rows) { row.Activation = Activation.ActivateOnly; } } } }