| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using Core.Mes.Client.Common;
- using Infragistics.Win.UltraWinGrid;
- using System.Collections;
- using CoreFS.CA06;
- using System.Diagnostics;
- using System.IO;
- namespace Core.LgMes.Client.lgIntegrationQuery
- {
- public partial class frmHLStandard : Core.Mes.Client.Common.frmStyleBase
- {
- string strMess = "";
- string username = "";
- DataSet ds = new DataSet();
- DataSet dsSteel = new DataSet();
- public frmHLStandard()
- {
- InitializeComponent();
- }
- private void frmHLStandard_Load(object sender, EventArgs e)
- {
- InitSteel();
- }
- public override void ToolBar_Click(object sender, string ToolbarKey)
- {
- switch (ToolbarKey)
- {
- case "Query":
- GetDataSource();
- break;
- case "Add":
- Add(urGridLTemp);
- strMess = "钢种恒拉范围标准保存成功!";
- //MessageBox.Show(strMess);
- break;
- case "Update":
- UpdateGrid();
- break;
- case "Delete":
- username = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID().Trim();
- if ("X01177".Equals(username))
- {
- DeleteGrid();
- }
- else
- {
- strMess = "您的权限不足!\r\n请联系技术科!";
- MessageBox.Show(strMess);
- }
- break;
- case "Save":
- username = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID().Trim();
- if ("X01177".Equals(username))
- {
- urGridLTemp.UpdateData();
- SaveData();
- }
- else
- {
- strMess = "您的权限不足!\r\n请联系技术科!";
- MessageBox.Show(strMess);
- }
- break;
-
- case "Export":
- if (urGridLTemp.Rows.Count > 0) ExportDataWithSaveDialog(ref this.urGridLTemp, "钢种恒拉范围标准");
- break;
- case "Rollback"://cancel
- JJBStaticFunction.dataCancel(urGridLTemp, dataTable1);
- break;
- case "Exit":
- this.Close();
- break;
- default:
- break;
- }
- }
- private void GetDataSource()
- {
- string strErr = "";
- string strSteel = "";
- string _strWhere2 = "";
- if (chkSteel.Checked && ultcboSteel.SelectedIndex > -1)
- {
- strSteel = Convert.ToString(ultcboSteel.Text);
- _strWhere2 = String.Format(" where t.steelname = '{0}'", strSteel);
- }
- else
- {
- _strWhere2 = "";
- }
- ArrayList arry = new ArrayList();
- ArrayList sqlList = new ArrayList();
- arry.Add("frmHLStandard.select");
- 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);
- dsSTemp.Clear();
- this.dataTable1.Rows.Clear();
- if (strErr == "" && ds != null)
- {
- DataRow dr;
- for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
- {
- dr = this.dataTable1.NewRow();
- for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
- {
- try
- {
- if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName))
- {
- dr[dt.Columns[jCol].ColumnName] = Convert.ToString(dt.Rows[iRow][jCol]);
- }
- }
- catch { }
- }
- this.dataTable1.Rows.Add(dr);
- }
- urGridLTemp.UpdateData();
- dataTable1.AcceptChanges();
- }
- JJBStaticFunction.SetRowEdit(urGridLTemp);//Grid可编辑性
- }
- /// <summary>
- /// 更新数据
- /// </summary>
- private void UpdateGrid()
- {
- JJBStaticFunction.Update(urGridLTemp);
- strMess = "钢种恒拉范围标准修改成功!";
- if (urGridLTemp.ActiveRow != null)
- {
- for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
- {
- if (ds.Tables[0].Columns[i].ColumnName == "STEELNAME")
- {
- urGridLTemp.ActiveRow.Cells["STEELNAME"].Activation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
- }
- else
- {
- urGridLTemp.ActiveRow.Cells[ds.Tables[0].Columns[i].ColumnName].Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
- }
- }
- }
- else
- MessageBox.Show("请选择需要修改的数据行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- private void DeleteGrid()
- {
- if (urGridLTemp.ActiveRow != null)
- {
- string strMCode = urGridLTemp.ActiveRow.Cells["STEELNAME"].Text.Trim();
- JJBStaticFunction.Delete(urGridLTemp);
- DelData(strMCode);
- }
- else
- MessageBox.Show("请选择需要删除的数据行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
- }
- /// <summary>
- /// 删除钢种恒拉范围标准标准
- /// </summary>
- private void DelData(string strMCode)
- {
- string strErr = "";
- if (dataTable1.GetChanges() != null)
- {
- ArrayList arry = new ArrayList();
- arry.Add("frmHLStandard_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);
- }
- }
- }
- /// <summary>
- /// 新增数据
- /// </summary>
- /// <param name="Grid"></param>
- public static void Add(Infragistics.Win.UltraWinGrid.UltraGridBase Grid)
- {
- Grid.UpdateData();
- UltraGridRow ur = Grid.DisplayLayout.Bands[0].AddNew();
- ur.Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
- }
- /// <summary>
- /// 保存钢种恒拉范围标准
- /// </summary>
- private void SaveData()
- {
- try
- {
- urGridLTemp.UpdateData();
- if (dataTable1.Rows.Count > 0)
- {
- string strErr = "";
- ArrayList arry = new ArrayList();
- string STEELNAME = urGridLTemp.ActiveRow.Cells["STEELNAME"].Text;
- string L1_230 = urGridLTemp.ActiveRow.Cells["L1_230"].Text;
- string L2_230 = urGridLTemp.ActiveRow.Cells["L2_230"].Text;
- string L3_230 = urGridLTemp.ActiveRow.Cells["L3_230"].Text;
- string L4_230 = urGridLTemp.ActiveRow.Cells["L4_230"].Text;
- string L5_230 = urGridLTemp.ActiveRow.Cells["L5_230"].Text;
- string L6_230 = urGridLTemp.ActiveRow.Cells["L6_230"].Text;
- string L1_300 = urGridLTemp.ActiveRow.Cells["L1_300"].Text;
- string L2_300 = urGridLTemp.ActiveRow.Cells["L2_300"].Text;
- string L3_300 = urGridLTemp.ActiveRow.Cells["L3_300"].Text;
- string L4_300 = urGridLTemp.ActiveRow.Cells["L4_300"].Text;
- string L1_360 = urGridLTemp.ActiveRow.Cells["L1_360"].Text;
- string L2_360 = urGridLTemp.ActiveRow.Cells["L2_360"].Text;
- string L3_360 = urGridLTemp.ActiveRow.Cells["L3_360"].Text;
- string L4_360 = urGridLTemp.ActiveRow.Cells["L4_360"].Text;
- string L1_420 = urGridLTemp.ActiveRow.Cells["L1_420"].Text;
- string L2_420 = urGridLTemp.ActiveRow.Cells["L2_420"].Text;
- string L3_420 = urGridLTemp.ActiveRow.Cells["L3_420"].Text;
- string L4_420 = urGridLTemp.ActiveRow.Cells["L4_420"].Text;
- if (strMess == "钢种恒拉范围标准保存成功!")
- {
- arry.Add("frmHLStandard_Save.select");
- arry.Add(STEELNAME);
- }
- if (strMess == "钢种恒拉范围标准修改成功!")
- {
- arry.Add("frmHLStandard_Update.select");
- }
- arry.Add(L1_230);
- arry.Add(L2_230);
- arry.Add(L3_230);
- arry.Add(L4_230);
- arry.Add(L5_230);
- arry.Add(L6_230);
- arry.Add(L1_300);
- arry.Add(L2_300);
- arry.Add(L3_300);
- arry.Add(L4_300);
- arry.Add(L1_360);
- arry.Add(L2_360);
- arry.Add(L3_360);
- arry.Add(L4_360);
- arry.Add(L1_420);
- arry.Add(L2_420);
- arry.Add(L3_420);
- arry.Add(L4_420);
- if (strMess == "钢种恒拉范围标准修改成功!")
- {
- arry.Add(STEELNAME);
- }
- 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 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);
- }
- }
- catch { }
- }
- private void chkSteel_CheckedChanged(object sender, EventArgs e)
- {
- ultcboSteel.Enabled = chkSteel.Checked;
- if (chkSteel.Checked == true)
- {
- InitSteel();
- }
- }
- public void ExportDataWithSaveDialog(ref UltraGrid ultGrid, string strFileName)
- {
- try
- {
- if (ultGrid.Rows.Count == 0) return;
- if (strFileName.Length == 0)
- strFileName = "未命名";
- 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(ultGrid, strFileName);
- if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- ultraGridExcelExporter1.Export(ultGrid, strFileName);
- ProcessStartInfo p = new ProcessStartInfo(strFileName);
- p.WorkingDirectory = Path.GetDirectoryName(strFileName);
- Process.Start(p);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
- }
|