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可编辑性
}
///
/// 更新数据
///
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("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);
}
}
}
///
/// 新增数据
///
///
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 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);
}
}
}
}