using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Diagnostics; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using CoreFS.CA06; using System.Collections; using Core.Mes.Client.Common; using Infragistics.Win.UltraWinGrid; using Infragistics.Win; using System.Net; using System.Data.OleDb; namespace Core.LgMes.Client.LgIntegrationQuery { public partial class frmLiquidusTemp : Core.Mes.Client.Common.frmStyleBase { string strMess = ""; string username = ""; string strID = ""; string strSteelName = ""; string strLTemp = "", strMaxId = "", strBTemp = ""; int strTempId=0; private string _strWhere2 = ""; DataSet dsSteel = new DataSet(); public frmLiquidusTemp() { InitializeComponent(); } private void frmLiquidusTemp_Load(object sender, EventArgs e) { username = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID().Trim(); if (username == "jsk02") { this.button2.Visible = true; } InitSteel(); SetColumnSteel(); } /// /// 初始化钢种信息 /// private void InitSteel() { try { string strErr = ""; //获取钢种 ArrayList arrySteel = new ArrayList(); arrySteel.Add("GetSteelInfo.select"); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; 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(ultcboSteel, dsSteel); } } catch { } } /// /// 绑定列表牌号 /// private void SetColumnSteel() { JJBStaticFunction.SetGridDropDownListCell("STEELNAME", 0, "钢种", 135, urGridLTemp, dsSteel.Tables[0], "STEELCODE", "STEELNAME"); } /// /// 获取液相线最大ID值 /// public void GetMaxID() { string strErr = ""; string strNowTime = DateTime.Now.ToString("yyyyMM"); ArrayList arry = new ArrayList(); arry.Add("LTemp_MaxID.select"); 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) { strMaxId = (ds.Tables[0].Rows[0][0].ToString()).Substring(0,6); ; if (strNowTime == strMaxId) { strTempId = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString())+1; } else strTempId=Convert.ToInt32(strNowTime+"0001"); } } /// /// 保存液相线温度标准 /// private void SaveData() { try { urGridLTemp.UpdateData(); if (dataTable1.Rows.Count > 0) { string strErr = ""; ArrayList arry = new ArrayList(); if (strMess == "液相线温度标准保存成功!") { GetMaxID(); arry.Add("frmLTemp_Save.select"); strID = urGridLTemp.ActiveRow.Cells["ID"].Text; strSteelName = urGridLTemp.ActiveRow.Cells["STEELNAME"].Text; strLTemp = urGridLTemp.ActiveRow.Cells["LIQUIDUSTEMP"].Text; strBTemp = urGridLTemp.ActiveRow.Cells["BEYONDTEMPT"].Text; arry.Add(strTempId); arry.Add(strSteelName); arry.Add(strLTemp); arry.Add(strBTemp); } if (strMess == "液相线温度标准修改成功!") { arry.Add("frmLTemp_Update.select"); string strMCode = urGridLTemp.ActiveRow.Cells["ID"].Text.Trim(); string strMType = urGridLTemp.ActiveRow.Cells["STEELNAME"].Text.Trim(); string strMShort = urGridLTemp.ActiveRow.Cells["LIQUIDUSTEMP"].Value.ToString(); strBTemp = urGridLTemp.ActiveRow.Cells["BEYONDTEMPT"].Value.ToString(); arry.Add(strMShort); arry.Add(strBTemp); arry.Add(strMCode); } CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); if (strErr == "" && ds != null) { dataTable1.AcceptChanges(); JJBStaticFunction.SetRowEdit(urGridLTemp); if (!string.IsNullOrEmpty(strMess)) MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误"); } if (urGridLTemp.ActiveCell != null) urGridLTemp.ActiveCell.Activated = false; } } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } } /// /// 删除液相线温度标准 /// private void DelData(string strMCode) { string strErr = ""; if (dataTable1.GetChanges() != null) { ArrayList arry = new ArrayList(); // arry.Add("frmStoresProject_Del.select"); arry.Add("frmLTemp_Del.select"); arry.Add(strMCode); CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr); if (strErr != "" && ds != null) { MessageBox.Show(strErr); } else { MessageBox.Show("液相线温度标准删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } } public void TempValue() { //熔炼号从 if (this.txtTempStart.Text.Length == 0) { _strWhere2 = String.Format(" and t.liquidustemp = '{0}' ", this.txtTempEnd.Text.Trim()); } else { if (this.txtTempEnd.Text.Length == 0) { _strWhere2 = String.Format(" and t.liquidustemp = '{0}' ", this.txtTempStart.Text.Trim()); } else { _strWhere2 = String.Format(" and t.liquidustemp between '{0}' and '{1}' ", this.txtTempStart.Text.Trim(), this.txtTempEnd.Text.Trim()); } } } private void GetDataSource() { string strErr = ""; string strSteel = ""; DataSet ds = new DataSet(); if (this.txtTempStart.Text.Trim().Length > 0 || this.txtTempEnd.Text.Trim().Length > 0) TempValue(); else _strWhere2 = ""; if (chkSteel.Checked && ultcboSteel.SelectedIndex > -1) { strSteel = Convert.ToString(ultcboSteel.Text); } ArrayList arry = new ArrayList(); ArrayList sqlList = new ArrayList(); arry.Add("frmLTemp.select"); arry.Add(strSteel); arry.Add(strSteel); sqlList.Add(_strWhere2); //调用服务端方法 CoreClientParam CCP_LgEts = new CoreClientParam(); DataTable dt = new DataTable(); CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBQuery"; CCP_LgEts.MethodName = "doQuery"; CCP_LgEts.ServerParams = new object[] { arry, sqlList }; CCP_LgEts.SourceDataTable = dt; this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal); ds.Tables.Add(dt); dsLTemp.Clear(); if (strErr == "" && ds != null) { foreach (DataRow Dr in ds.Tables[0].Rows) { DataRow dr = dsLTemp.Tables[0].NewRow(); dr["ID"] = Dr["ID_"]; dr["STEELNAME"] = Dr["STEELNAME"]; dr["LIQUIDUSTEMP"] = Dr["LIQUIDUSTEMP"]; dr["BEYONDTEMPT"] = Dr["BEYONDTEMPT"]; dsLTemp.Tables[0].Rows.Add(dr); } urGridLTemp.UpdateData(); dataTable1.AcceptChanges(); } JJBStaticFunction.SetRowEdit(urGridLTemp); } /// /// 新增数据 /// /// public static void Add(Infragistics.Win.UltraWinGrid.UltraGridBase Grid, int strTempId) { Grid.UpdateData(); UltraGridRow ur = Grid.DisplayLayout.Bands[0].AddNew(); ur.Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit; ur.Cells["ID"].Value = strTempId; } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": GetDataSource(); break; case "Add": GetMaxID(); Add(urGridLTemp,strTempId); strMess = "液相线温度标准保存成功!"; break; case "Update": JJBStaticFunction.Update(urGridLTemp); strMess = "液相线温度标准修改成功!"; if (urGridLTemp.ActiveRow != null) { urGridLTemp.ActiveRow.Cells["ID"].Activation = Infragistics.Win.UltraWinGrid.Activation.NoEdit; urGridLTemp.ActiveRow.Cells["STEELNAME"].Activation = Infragistics.Win.UltraWinGrid.Activation.NoEdit; urGridLTemp.ActiveRow.Cells["LIQUIDUSTEMP"].Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit; } else MessageBox.Show("请选择需要修改的数据行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); break; case "Delete": if ("X01177".Equals(username)) { if (urGridLTemp.ActiveRow != null) { string strMCode = urGridLTemp.ActiveRow.Cells["ID"].Text.Trim(); JJBStaticFunction.Delete(urGridLTemp); DelData(strMCode); } else MessageBox.Show("请选择需要删除的数据行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { strMess = "您的权限不足!\r\n请联系技术科!"; MessageBox.Show(strMess); } break; case "Save": if ("X01177".Equals(username)) { urGridLTemp.UpdateData(); SaveData(); } else { strMess = "您的权限不足!\r\n请联系技术科!"; MessageBox.Show(strMess); } break; case "Rollback"://cancel JJBStaticFunction.dataCancel(urGridLTemp, dataTable1); break; case "Exit": this.Close(); break; default: break; } } private void chkSteel_CheckedChanged(object sender, EventArgs e) { ultcboSteel.Enabled = chkSteel.Checked; } private void button1_Click(object sender, EventArgs e) { this.doExport("液相线温度标准", urGridLTemp); } /// /// 导出EXCEL /// private void doExport(string fileName, UltraGrid grid) { if (grid.Rows.Count < 1) { MessageBox.Show("当前没有数据"); return; } try { Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ex = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter(); string strFileName = @"c:\" + fileName + System.DateTime.Today.ToString("yyMMdd") + ".xls"; if (CommonExportExcel(ref strFileName)) ex.Export(grid, strFileName); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private static bool CommonExportExcel(ref string strFileName) { System.Windows.Forms.SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Microsoft Office Excel 工作簿 (*.xls)|*.xls"; sfd.Title = "导出到Excel文件"; sfd.FileName = strFileName; if (sfd.ShowDialog() == DialogResult.OK) { strFileName = sfd.FileName; return sfd.FileName != ""; } return false; } private void button2_Click(object sender, EventArgs e) { excel(); } private void excel() { // GetDataFromExcelByConn(false); OpenFileDialog fileDialog = new OpenFileDialog(); //判断用户是否正确的选择了文件 if (fileDialog.ShowDialog() == DialogResult.OK) { //获取用户选择文件的后缀名 FileInfo fileInfo = new FileInfo(fileDialog.FileName); //全路径 if ((fileInfo.Extension == ".xls") || (fileInfo.Extension == ".xlsx")) { DataTable dt = LoadDataFromExcel(fileDialog.FileName); EcxelImport(dt); } else { MessageBox.Show("不能上传非Excel格式的文件,请检查!"); return; } } } public void EcxelImport(DataTable dt) { string strErr = ""; string bug=""; del(); string strNowTime = DateTime.Now.ToString("yyyyMM"); ArrayList arr = new ArrayList(); int ID =Convert.ToInt32(strNowTime+"0000"); for (int i = 0; i < dt.Rows.Count; i++) { ID = ID +1; strID = ID.ToString(); strSteelName = dt.Rows[i][0].ToString(); strLTemp = dt.Rows[i][1].ToString(); if (strSteelName=="" && strLTemp=="") { return; } arr.Add("frmLTemp_Save.select"); arr.Add(strID); arr.Add(strSteelName); arr.Add(strLTemp); try { CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; // DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arr, out strErr); } catch { bug += strSteelName + " ,"; } if (strErr != "") { bug += strSteelName + " ,"; } arr.Clear(); } if (bug != "") { MessageBox.Show(bug + "增加失败请检查!"); } } public DataTable LoadDataFromExcel(string Path) { string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + Path + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); string strExcel = ""; OleDbDataAdapter myCommand = null; DataTable dt = null; strExcel = "select * from [sheet1$]"; myCommand = new OleDbDataAdapter(strExcel, strConn); dt = new DataTable(); myCommand.Fill(dt); return dt; } private void del() { try { string strErr = ""; string sql = "delete SCM_LIQUIDUS_TEMP"; CommonClientToServer cctos = new CommonClientToServer(); cctos.ob = this.ob; // DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBExecute", "ExcuteNoParameter", sql, out strErr); } catch { } } } }