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 frmSteelTemp : Core.Mes.Client.Common.frmStyleBase
{
string strMess = "";
string username = "";
DataSet ds = new DataSet();
DataSet dsSteel = new DataSet();
public frmSteelTemp()
{
InitializeComponent();
}
private void frmSteelTemp_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 = "钢水温度范围标准保存成功!";
break;
case "Update":
UpdateGrid();
break;
case "Delete":
username = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID().Trim();
if ("jsk02".Equals(username))
{
DeleteGrid();
}
else
{
strMess = "您的权限不足!\r\n请联系技术科!";
MessageBox.Show(strMess);
}
break;
case "Save":
username = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID().Trim();
if ("jsk02".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("frmSTemp.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可编辑性
}
///
/// 更新数据
///
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);
}
///
/// 删除钢水温度范围标准标准
///
private void DelData(string strMCode)
{
string strErr = "";
if (dataTable1.GetChanges() != null)
{
ArrayList arry = new ArrayList();
arry.Add("frmSTemp_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 static void Add(Infragistics.Win.UltraWinGrid.UltraGridBase Grid)
{
Grid.UpdateData();
UltraGridRow ur = Grid.DisplayLayout.Bands[0].AddNew();
ur.Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
}
///
/// 保存钢水温度范围标准
///
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 LEAVETEMPTC_D = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_D"].Text;
string ARRIVETEMPTD_D = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_D"].Text;
string LEAVETEMPTD_D = urGridLTemp.ActiveRow.Cells["LEAVETEMPTD_D"].Text;
string ARRIVETEMPTG_D = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_D"].Text;
string LEAVETEMPTC_E = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_E"].Text;
string ARRIVETEMPTD_E = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_E"].Text;
string LEAVETEMPTE_E = urGridLTemp.ActiveRow.Cells["LEAVETEMPTE_E"].Text;
string ARRIVETEMPTG_E = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_E"].Text;
string LEAVETEMPTC_F = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_F"].Text;
string ARRIVETEMPTD_F = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_F"].Text;
string ARRIVETEMPTF_F = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTF_F"].Text;
string LEAVETEMPTF_F = urGridLTemp.ActiveRow.Cells["LEAVETEMPTF_F"].Text;
string ARRIVETEMPTG_F = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_F"].Text;
string LEAVETEMPTC_EF = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_EF"].Text;
string ARRIVETEMPTD_EF = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_EF"].Text;
string LEAVETEMPTE_EF = urGridLTemp.ActiveRow.Cells["LEAVETEMPTE_EF"].Text;
string LEAVETEMPTF_EF = urGridLTemp.ActiveRow.Cells["LEAVETEMPTF_EF"].Text;
string ARRIVETEMPTG_EF = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_EF"].Text;
string LEAVETEMPTC_EI = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_EI"].Text;
string ARRIVETEMPTD_EI = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_EI"].Text;
string LEAVETEMPTE_EI = urGridLTemp.ActiveRow.Cells["LEAVETEMPTE_EI"].Text;
string LEAVETEMPTI_EI = urGridLTemp.ActiveRow.Cells["LEAVETEMPTI_EI"].Text;
string ARRIVETEMPTG_EI = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_EI"].Text;
if (strMess == "钢水温度范围标准保存成功!")
{
arry.Add("frmSTemp_Save.select");
arry.Add(STEELNAME);
}
if (strMess == "钢水温度范围标准修改成功!")
{
arry.Add("frmSTemp_Update.select");
}
arry.Add(LEAVETEMPTC_D);
arry.Add(ARRIVETEMPTD_D);
arry.Add(LEAVETEMPTD_D);
arry.Add(ARRIVETEMPTG_D);
arry.Add(LEAVETEMPTC_E);
arry.Add(ARRIVETEMPTD_E);
arry.Add(LEAVETEMPTE_E);
arry.Add(ARRIVETEMPTG_E);
arry.Add(LEAVETEMPTC_F);
arry.Add(ARRIVETEMPTD_F);
arry.Add(ARRIVETEMPTF_F);
arry.Add(LEAVETEMPTF_F);
arry.Add(ARRIVETEMPTG_F);
arry.Add(LEAVETEMPTC_EF);
arry.Add(ARRIVETEMPTD_EF);
arry.Add(LEAVETEMPTE_EF);
arry.Add(LEAVETEMPTF_EF);
arry.Add(ARRIVETEMPTG_EF);
arry.Add(LEAVETEMPTC_EI);
arry.Add(ARRIVETEMPTD_EI);
arry.Add(LEAVETEMPTE_EI);
arry.Add(LEAVETEMPTI_EI);
arry.Add(ARRIVETEMPTG_EI);
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);
}
}
}
}