using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using CoreFS.CA06;
using Core.Mes.Client.Common;
namespace Core.LgMes.Client.LgDeviceManager
{
public partial class FrmIronLadleManage : frmStyleBase
{
public FrmIronLadleManage()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
private string strCurrID = "";
private bool bSelected = false;
private bool bRefreshNow = false;
private Thread _refreshThread;
private bool _bStop = false;
public bool _bAutoRefresh = false;
private delegate void RefreshDataHandler();
private RefreshDataHandler refreshDataHandler;
private void FrmIronLadleManage_Load(object sender, EventArgs e)
{
GetID();
chkAutoRefresh.Checked = true;
refreshDataHandler = new RefreshDataHandler(GetAndSetData);
StartupThread();
GetAndSetData();
}
private void StartupThread()
{
try
{
_refreshThread = new Thread(new ThreadStart(refreshData));
_refreshThread.IsBackground = true;
_refreshThread.Start();
}
catch { }
}
private void refreshData()
{
There:
while (!_bStop)
{
if (!this.On_Off_Thread || !_bAutoRefresh)
{
Thread.Sleep(500);
continue;
}
try
{
if (refreshDataHandler != null)
{
this.Invoke(refreshDataHandler);
}
Thread.Sleep(1000 * 5);
}
catch { }
}
goto There;
}
///
/// 铁包信息查询
///
public void GetAndSetData()
{
bRefreshNow = true;
try
{
string strErr = "", strWhere = "";
if (!chkShowBF.Checked)
{
strWhere = " and t.STATUS <> '报废'";
}
if (chkID.Checked && ucmeID.SelectedIndex > -1)
{
strWhere += " and t.LADLEID = '" + ucmeID.Text.Trim() + "'";
}
if (chkStatus.Checked && cmbStatus.SelectedIndex > -1)
{
strWhere += " and t.STATUS = '" + cmbStatus.Text.Trim() + "'";
}
ArrayList arry = new ArrayList();
ArrayList sqlList = new ArrayList();
arry.Add("FrmIronLadleManage_Query1");
sqlList.Add(strWhere);
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);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
strErr = CCP_LgEts.ReturnInfo;
if (strErr == "" && ds != null && ds.Tables.Count > 0)
{
ugrdTBinfo.BeginUpdate();
dataTable1.Rows.Clear();
DataRow row;
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
row = dataTable1.NewRow();
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
if (dataTable1.Columns.Contains(ds.Tables[0].Columns[j].ColumnName))
row[ds.Tables[0].Columns[j].ColumnName] = ds.Tables[0].Rows[i][j];
}
dataTable1.Rows.Add(row);
}
ugrdTBinfo.EndUpdate();
}
if (ugrdTBinfo.Rows.Count > 0)
{
SetGridBackColor();
if (strCurrID.Length > 0)
LocateRecord(strCurrID, bSelected);
}
else
strCurrID = "";
}
catch
{ }
finally
{
bRefreshNow = false;
}
}
///
/// 颜色显示
///
private void SetGridBackColor()
{
try
{
Hashtable htOperate = new Hashtable();
htOperate.Add("备用", Color.GhostWhite);
htOperate.Add("使用", Color.LightGreen);
htOperate.Add("维修", Color.LightBlue);
htOperate.Add("烘烤", Color.Yellow);
htOperate.Add("报废", Color.Red);
LadleCommonClass.SetGridBackColor(ugrdTBinfo, htOperate, "当前状态", true);
}
catch { }
}
private void LocateRecord(string strID, bool bSelect)
{
try
{
for (int i = 0; i < ugrdTBinfo.Rows.Count; i++)
{
if (Convert.ToString(ugrdTBinfo.Rows[i].Cells["铁包编号"].Value) == strID)
{
ugrdTBinfo.ActiveRow = ugrdTBinfo.Rows[i];
ugrdTBinfo.Rows[i].Selected = bSelect;
return;
}
}
}
catch { }
}
///
/// 加载铁包号
///
public void GetID()
{
try
{
string strID = "";
if (ucmeID.SelectedIndex >= 0)
strID = ucmeID.Text;
string strErr = "";
ArrayList arry = new ArrayList();
arry.Add("FrmIronLadleManage_Query2");
CommonClientToServer ccs = new CommonClientToServer();
ccs.ob = this.ob;
DataSet ds = ccs.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery", "doSimpleQuery", arry, out strErr);
if (strErr == "" && ds != null && ds.Tables.Count > 0)
{
this.ucmeID.Items.Clear();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ucmeID.Items.Add(ds.Tables[0].Rows[i]["铁包编号"]);
}
}
if (ucmeID.Items.Count > 0 )
{
if (strID.Length > 0)
ucmeID.Text = strID;
else
ucmeID.SelectedIndex = -1;
}
}
catch { }
}
private void cbxID_CheckedChanged(object sender, EventArgs e)
{
ucmeID.Enabled = chkID.Checked;
}
private void cbxStatus_CheckedChanged(object sender, EventArgs e)
{
cmbStatus.Enabled = chkStatus.Checked;
}
private void ulgrid_AfterRowActivate(object sender, EventArgs e)
{
try
{
if (bRefreshNow) return;
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
{
strCurrID = Convert.ToString(row.Cells["铁包编号"].Value);
bSelected = ugrdTBinfo.ActiveRow.Selected;
}
}
catch
{
strCurrID = "";
}
}
private void cbxAutoRefresh_CheckedChanged(object sender, EventArgs e)
{
_bAutoRefresh = chkAutoRefresh.Checked;
}
///
/// 铁包报废
///
///
private void proc_RejectTB(string strID)
{
try
{
string strErr = "";
ArrayList arry = new ArrayList();
arry.Add("FrmIronLadleManage_Query3");
arry.Add(strID);
CommonClientToServer ccs = new CommonClientToServer();
ccs.ob = this.ob;
DataSet ds = ccs.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery", "doSimpleQuery", arry, out strErr);
if (!(strErr == "" && ds != null && ds.Tables.Count > 0))
{
MessageBox.Show("铁包[" + strID + "]报废操作失败,请重试!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("铁包编号[" + strID + "]不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
string strCurrStatus = Convert.ToString(ds.Tables[0].Rows[0]["当前状态"]);
if (strCurrStatus == "报废")
{
MessageBox.Show("铁包[" + strID + "]已经报废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
if (strCurrStatus != "备用")
{
MessageBox.Show("铁包[" + strID + "]当前状态为[" + strCurrStatus + "],不能执行报废操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
for (int i = 0; i < 3; i++)
{
string strTimes = (i == 0 ? "一" : (i == 1 ? "二" : (i == 2 ? "三" : "")));
if (MessageBox.Show("第[" + strTimes + "]次确认\r\n\r\n"
+ "铁包号:[" + strID + "]\r\n"
+ "报废操作不能撤销\r\n"
+ "确认要报废吗?",
"报废",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.No)
return;
}
string strReturn = "";
strErr = "";
arry.Clear();
arry.Add("FrmIronLadleManage_Edit");
arry.Add(strID);
strReturn = ccs.NoQueryFunctions("Core.LgMes.Server.Common.ComDBSave", "doSimpleSave", arry, out strErr);
if (strErr != "")
{
MessageBox.Show("铁包[" + strID + "]报废操作失败!\n" + strErr, "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!chkAutoRefresh.Checked)
{
GetID();
GetAndSetData();
}
GetAndSetData();
MessageBox.Show("铁包[" + strID + "]报废操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
catch (Exception ex)
{
MessageBox.Show("铁包报废操作失败!\r\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
{
GetAndSetData();
break;
}
case "BaseInfo": //基础信息
{
string strInitID = "";
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
strInitID = Convert.ToString(row.Cells["铁包编号"].Value);
FrmILBaseInfo frm = new FrmILBaseInfo(ob);
frm.Tag = this;
frm.strInitiD = strInitID;
frm.ShowDialog();
break;
}
case "Repair": //维修
{
string strInitID = "";
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
strInitID = Convert.ToString(row.Cells["铁包编号"].Value);
FrmILRepair frm = new FrmILRepair(strInitID,ob);
frm.Tag = this;
//frm.strInitiD = strInitID;
frm.ShowDialog();
break;
}
case "TBBake"://铁包烘烤
{
string strInitID = "";
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
strInitID = Convert.ToString(row.Cells["铁包编号"].Value);
FrmILFire frm = new FrmILFire(strInitID,ob);
frm.Tag = this;
frm.ShowDialog();
break;
}
case "Reject": //报废
{
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
{
proc_RejectTB(Convert.ToString(row.Cells["铁包编号"].Value));
}
break;
}
case "UseDetail": //使用信息
{
string strInitID = "";
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
strInitID = Convert.ToString(row.Cells["铁包编号"].Value);
FrmILHistory frm = new FrmILHistory(ToolsName.铁包, strInitID, RecordsName.使用记录,ob);
frm.Tag = this;
frm.ShowDialog();
break;
}
case "RepairDetail": //维修记录
{
string strInitID = "";
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
strInitID = Convert.ToString(row.Cells["铁包编号"].Value);
FrmILHistory frm = new FrmILHistory(ToolsName.铁包, strInitID, RecordsName.维修记录,ob);
frm.Tag = this;
frm.ShowDialog();
break;
}
case "烘烤记录":
{
string strInitID = "";
UltraGridRow row = ugrdTBinfo.ActiveRow;
if (row != null)
strInitID = Convert.ToString(row.Cells["铁包编号"].Value);
FrmILHistory frm = new FrmILHistory(ToolsName.铁包, strInitID, RecordsName.烘烤记录, ob);
frm.Tag = this;
frm.ShowDialog();
break;
}
case "ILSend":
frmILSend frmIL = new frmILSend(ob);
frmIL._ds = dStTBinfo.Copy();
frmIL.ShowDialog();
break;
case "Cance":
CancelIronUserInfo();
break;
case "Exit":
{
this.Close();
break;
}
}
}
///
/// 是否显示废钢信息
///
///
///
private void cbxShowBF_CheckedChanged(object sender, EventArgs e)
{
//GetAndSetData();
}
///
/// 取消铁水使用信息
///
private void CancelIronUserInfo()
{
string strSqlID = ""; //sqlId
string strErr = ""; //错误信息
if (ugrdTBinfo.ActiveRow == null)
{
MessageBox.Show("没有选择要取消使用信息的铁包,请选择!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
if (MessageBox.Show("是否确认取消【铁包号:" + ugrdTBinfo.ActiveRow.Cells["铁包编号"].Value.ToString() +
"】铁水使用信息!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
{
strSqlID = "CancelIronUserInfo.Cancel"; //SQLID
Hashtable ht = new Hashtable();
ht.Add("I1", ugrdTBinfo.ActiveRow.Cells["铁包编号"].Value.ToString()); //铁水罐号
ht.Add("O1", "");
ht.Add("O2", "");
CommonClientToServer ccTs = new CommonClientToServer();
ccTs.ob = ob;
string strRCode = ccTs.ExecuteProcedureFunctions("Core.LgMes.Server.LgDeviceManager.LadleManager",
"CancelIronUserInfo", strSqlID, ht, out strErr);
if (strErr == "")
{
MessageBox.Show("铁水使用信息取消成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
GetAndSetData();
}
else
MessageBox.Show("铁水使用信息取消失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
///
/// 工器具名称
///
public enum ToolsName
{
钢包, 铁包, 中包, 氧枪, 结晶器, 出钢口
}
///
/// 工器具记录类别
///
public enum RecordsName
{
使用记录, 维修记录, 烘烤记录
}
}