using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA06;
using Core.Mes.Client.Common;
namespace Core.LgMes.Client.LgDeviceManager
{
public partial class FrmCLBaseInfo : frmModelFormStyle
{
bool bOK = false; //是否响应结晶器号选择改变事件
public string strNo = "", strCCM = "";
OpeBase ob = null;
public FrmCLBaseInfo(OpeBase oba)
{
InitializeComponent();
ob = oba;
}
private void txtAge_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == '\b' || e.KeyChar == '.') || (((TextBox)(sender)).Text.Trim().Contains(".") && e.KeyChar == '.'))
{
e.Handled = true;
}
}
private void FrmCLBaseInfo_Load(object sender, EventArgs e)
{
if (strCCM.Length > 0)
{
ucmbCCM.Text = strCCM;
this.cbbCCM_SelectedIndexChanged(this, null);
if (strNo.Length > 0)
{
ucmbID.Text = strNo;
bOK = true;
this.cbbID_SelectedIndexChanged(this, null);
}
}
else
bOK = true;
}
private void proc_GetID(string strCCM)
{
try
{
if (strCCM.Length == 0)
return;
string strErr = "";
string strSql = "select CRYSTALLIZERID from DEV_JJQ_BASE_INFO where CCM_ID = '" + strCCM + "' order by length(CRYSTALLIZERID), CRYSTALLIZERID";
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp.MethodName = "QueryMethods";
ccp.ServerParams = new Object[] { strSql };
DataTable dt = new DataTable();
ccp.SourceDataTable = dt;
ob.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
if (strErr != "" || !(ds != null && ds.Tables.Count > 0))
{
MessageBox.Show("结晶器号加载失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (MessageBox.Show("是否重新加载结晶器号?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
proc_GetID(strCCM);
return;
}
ucmbID.Items.Clear();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ucmbID.Items.Add(ds.Tables[0].Rows[i][0]);
}
if (ds.Tables[0].Rows.Count == 0)
proc_ResetControl();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void proc_ResetControl()
{
try
{
ucmbID.Text = "";
txtType.Clear();
txtTgl.Clear();
txtTGBH.Clear();
txtTbcs.Clear();
txtStatus.Clear();
txtPos.Clear();
udtePTime.DateTime = DateTime.Now;
udteBuyTime.DateTime = DateTime.Now;
txtMemo.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
///
/// 新增
///
private void proc_Add()
{
try
{
string strCcm = ucmbCCM.Text.Trim();
string strID = ucmbID.Text.Trim();
if (strCcm.Length == 0)
{
MessageBox.Show("请选择铸机号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
ucmbCCM.Focus();
return;
}
if (strID.Length == 0)
{
MessageBox.Show("请输入结晶器编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
ucmbID.Focus();
return;
}
string strType = "2"; //方坯结晶器
string strErr = "";
string strSql = "select count(1) from DEV_JJQ_BASE_INFO where CCM_ID = '" + strCcm + "' and CRYSTALLIZERID = '" + strID + "'";
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp.MethodName = "QueryMethods";
ccp.ServerParams = new Object[] { strSql };
DataTable dt = new DataTable();
ccp.SourceDataTable = dt;
ob.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
{
MessageBox.Show("新增[" + strCcm + "]结晶器[" + strID + "]失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
if (iCnt > 0)
{
MessageBox.Show("[" + strCcm + "]已存在结晶器[" + strID + "],不能重复录入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
ucmbID.Focus();
return;
}
strErr = "";
string Sql = "insert into DEV_JJQ_BASE_INFO "
+ "(CRYSTALLIZERID, OUTERCOPPER, NOWSTATUS, TYPE, AGE, CUPRUMCANALTIME, CREATIVEDATE, BUYDATE, MEMO, CCM_ID, ID) "
+ "values "
+ "('" + strID + "',"
+ "'" + txtTGBH.Text.Trim() + "',"
+ "'3',"
+ "'" + strType + "',"
+ "'" + (txtTgl.Text.Trim() == "" ? "0" : txtTgl.Text.Trim()) + "',"
+ "'" + (txtTbcs.Text.Trim() == "" ? "0" : txtTbcs.Text.Trim()) + "',"
+ "to_date('" + udtePTime.DateTime.ToString("yyyy-MM-dd") + "','yyyy-MM-dd'),"
+ "to_date('" + udteBuyTime.DateTime.ToString("yyyy-MM-dd") + "','yyyy-MM-dd'),"
+ "'" + txtMemo.Text.Trim() + "',"
+ "'" + strCcm + "',"
+ "(select nvl(max(ID),0)+1 from DEV_JJQ_BASE_INFO))";
CoreClientParam ccp_add = new CoreClientParam();
ccp_add.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp_add.MethodName = "UpdateMethods";
ccp_add.ServerParams = new Object[] { Sql };
ob.ExecuteNonQuery(ccp_add, CoreInvokeType.Internal);
if (!(strErr == null || strErr == ""))
{
MessageBox.Show("新增[" + strCcm + "]结晶器[" + strID + "]失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
FrmCrystallizerManage frm = (FrmCrystallizerManage)this.Tag;
frm.proc_GetBaseInfo(strCcm, strID);
proc_GetID(strCcm);
MessageBox.Show("新增[" + strCcm + "]结晶器[" + strID + "]成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
///
/// 基本信息修改
///
private void proc_Edit()
{
try
{
if (ucmbID.Items.Count == 0)
return;
string strCcm = ucmbCCM.Text.Trim();
string strID = ucmbID.Text.Trim();
if (strID.Length == 0)
{
MessageBox.Show("请选择需要修改的结晶器编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
ucmbID.Focus();
return;
}
string strType = "2"; //方坯结晶器
if (MessageBox.Show("确定要修改[" + strCcm + "]的结晶器[" + strID + "]信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
string strErr = "";
string strSql = "select count(1) from DEV_JJQ_BASE_INFO where CCM_ID = '" + strCcm + "' and CRYSTALLIZERID = '" + strID + "'";
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp.MethodName = "QueryMethods";
ccp.ServerParams = new Object[] { strSql };
DataTable dt = new DataTable();
ccp.SourceDataTable = dt;
ob.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息修改失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
if (iCnt == 0)
{
MessageBox.Show("[" + strCcm + "]不存在结晶器[" + strID + "]信息,无法修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
ucmbID.Focus();
return;
}
strErr = "";
string Sql = "update DEV_JJQ_BASE_INFO set "
+ "TYPE = '" + strType + "',"
+ "OUTERCOPPER = '" + txtTGBH.Text.Trim() + "',"
+ "AGE = '" + (txtTgl.Text.Trim() == "" ? "0" : txtTgl.Text.Trim()) + "',"
+ "CUPRUMCANALTIME = '" + (txtTbcs.Text.Trim() == "" ? "0" : txtTbcs.Text.Trim()) + "',"
+ "CREATIVEDATE = to_date('" + udtePTime.DateTime.ToString("yyyy-MM-dd") + "','yyyy-MM-dd'),"
+ "BUYDATE = to_date('" + udteBuyTime.DateTime.ToString("yyyy-MM-dd") + "','yyyy-MM-dd'),"
+ "MEMO = '" + txtMemo.Text.Trim() + "' "
+ "where CCM_ID = '" + strCcm + "' and CRYSTALLIZERID = '" + strID + "'";
CoreClientParam ccp_up = new CoreClientParam();
ccp_up.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp_up.MethodName = "UpdateMethods";
ccp_up.ServerParams = new Object[] { Sql };
ob.ExecuteNonQuery(ccp_up, CoreInvokeType.Internal);
if (!(strErr == null || strErr == ""))
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息修改失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
FrmCrystallizerManage frm = (FrmCrystallizerManage)this.Tag;
frm.proc_GetBaseInfo(strCcm, strID);
proc_GetID(strCcm);
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
///
/// 基本信息删除
///
private void proc_Del()
{
try
{
if (ucmbID.Items.Count == 0)
return;
string strCcm = ucmbCCM.Text.Trim();
string strID = ucmbID.Text.Trim();
if (strID.Length == 0)
{
MessageBox.Show("请选择需要删除的结晶器编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
ucmbID.Focus();
return;
}
if (MessageBox.Show("确定要删除[" + strCcm + "]结晶器[" + strID + "]的信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
string strErr = "";
string strSql = "select count(1) from DEV_JJQ_BASE_INFO where CCM_ID = '" + strCcm + "' and CRYSTALLIZERID = '" + strID + "'";
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp.MethodName = "QueryMethods";
ccp.ServerParams = new Object[] { strSql };
DataTable dt = new DataTable();
ccp.SourceDataTable = dt;
ob.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息删除失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int iCnt = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
if (iCnt == 0)
{
MessageBox.Show("[" + strCcm + "]不存在结晶器[" + strID + "]信息,无法删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
ucmbID.Focus();
return;
}
iCnt = 0;
ds = null;
strErr = "";
string trSql = "select count(1) from DEV_JJQ_USE_DETAIL where CRYSTALLIZERID = (select ID from DEV_JJQ_BASE_INFO where CCM_ID = '" + strCcm + "' and CRYSTALLIZERID = '" + strID + "')";
CoreClientParam ccpselect = new CoreClientParam();
ccpselect.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccpselect.MethodName = "QueryMethods";
ccpselect.ServerParams = new Object[] { trSql };
DataTable dtt = new DataTable();
ccpselect.SourceDataTable = dtt;
ob.ExecuteQueryToDataTable(ccpselect, CoreInvokeType.Internal);
DataSet dss = new DataSet();
dss.Tables.Add(dtt);
if (strErr != "" || !(dss != null && dss.Tables.Count > 0 && dss.Tables[0].Rows.Count > 0))
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息删除失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
int Cnt = Convert.ToInt32(dss.Tables[0].Rows[0][0]);
if (Cnt > 0)
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]存在使用记录,不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
ucmbID.Focus();
return;
}
iCnt = 0;
ds = null;
strErr = "";
strSql = "select count(1) from DEV_TOOL_REPAIR where TOOLTYPEID = '2' and REPAIRTOOLID = (select ID from DEV_JJQ_BASE_INFO where CCM_ID = '" + strCcm + "' and CRYSTALLIZERID = '" + strID + "')";
CoreClientParam ccpsele = new CoreClientParam();
ccpsele.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccpsele.MethodName = "QueryMethods";
ccpsele.ServerParams = new Object[] { trSql };
DataTable dtl = new DataTable();
ccpsele.SourceDataTable = dtl;
ob.ExecuteQueryToDataTable(ccpsele, CoreInvokeType.Internal);
DataSet dst = new DataSet();
dst.Tables.Add(dtl);
if (strErr != "" || !(dst != null && dst.Tables.Count > 0 && dst.Tables[0].Rows.Count > 0))
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息删除失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
iCnt = Convert.ToInt32(dst.Tables[0].Rows[0][0]);
if (iCnt > 0)
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]存在维修记录,不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
ucmbID.Focus();
return;
}
strErr = "";
string Sql = "delete from DEV_JJQ_BASE_INFO where CCM_ID = '" + strCcm + "' and CRYSTALLIZERID = '" + strID + "'";
CoreClientParam ccp_del = new CoreClientParam();
ccp_del.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp_del.MethodName = "UpdateMethods";
ccp_del.ServerParams = new Object[] { Sql };
ob.ExecuteNonQuery(ccp_del, CoreInvokeType.Internal);
if (!(strErr == null || strErr == ""))
{
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息删除失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
FrmCrystallizerManage frm = (FrmCrystallizerManage)this.Tag;
frm.proc_GetBaseInfo(strCcm, "");
proc_GetID(strCcm);
MessageBox.Show("[" + strCcm + "]结晶器[" + strID + "]信息删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
switch (e.ClickedItem.Name)
{
case "ADD":
{
this.proc_Add();
break;
}
case "EDIT":
{
this.proc_Edit();
break;
}
case "DEL":
{
this.proc_Del();
break;
}
case "CLOSE":
{
this.Close();
break;
}
default:
break;
}
}
private void cbbCCM_SelectedIndexChanged(object sender, EventArgs e)
{
if (ucmbCCM.Text.Length > 0)
{
ucmbID.SelectedIndex = -1;
proc_GetID(ucmbCCM.Text);
}
}
private void cbbID_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (!bOK)
return;
string strCCM = ucmbCCM.Text.Trim();
string strID = ucmbID.Text.Trim();
if (strID.Length == 0)
return;
string strErr = "";
string strSql = "select case NOWSTATUS when '0' then '下线' when '1' then '上线' when '2' then '维修' when '3' then '备用' end NOWSTATUS,"
+ "AGE, CUPRUMCANALTIME, case TYPE when '1' then '板坯' when '2' then '方坯' end TYPE, case NOWSTATUS when '1' then CCM_S_ID end CCM_S_ID,"
+ "to_char(CREATIVEDATE,'yyyy-MM-dd') CREATIVEDATE, to_char(BUYDATE,'yyyy-MM-dd') BUYDATE, MEMO, OUTERCOPPER "
+ "from DEV_JJQ_BASE_INFO where CRYSTALLIZERID = '" + strID + "' and CCM_ID = '" + strCCM + "'";
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "Core.LgMes.Server.DEV.Methods.DEVPublicMethods";
ccp.MethodName = "QueryMethods";
ccp.ServerParams = new Object[] { strSql };
DataTable dt = new DataTable();
ccp.SourceDataTable = dt;
ob.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
if (strErr != "" || !(ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
{
MessageBox.Show("结晶器[" + strID + "]信息查询失败!\r\n" + strErr, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
txtType.Text = Convert.ToString(ds.Tables[0].Rows[0]["TYPE"]);
txtTgl.Text = Convert.ToString(ds.Tables[0].Rows[0]["AGE"]);
txtTGBH.Text = Convert.ToString(ds.Tables[0].Rows[0]["OUTERCOPPER"]);
txtTbcs.Text = Convert.ToString(ds.Tables[0].Rows[0]["CUPRUMCANALTIME"]);
txtStatus.Text = Convert.ToString(ds.Tables[0].Rows[0]["NOWSTATUS"]);
txtPos.Text = Convert.ToString(ds.Tables[0].Rows[0]["CCM_S_ID"]);
udtePTime.DateTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["CREATIVEDATE"]);
udteBuyTime.DateTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["BUYDATE"]);
txtMemo.Text = Convert.ToString(ds.Tables[0].Rows[0]["MEMO"]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示");
}
}
}
}