using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using CoreFS.CA06; using PrintSolution.LabelPrinter; using INI; namespace Core.LZMes.Client.UIL { public partial class Form1 : FrmBase { public Form1() { InitializeComponent(); Init_WithConfig(); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": this.QUERYData(); break; } } private ZebraPrinter printer = new ZebraPrinter(); private string iniVersions = "5"; //初始化从配置文件中加载的打印版本号 System.Timers.Timer Weight_Time = new System.Timers.Timer(); System.Data.DataSet Weight_Data = new DataSet(); System.Data.DataSet Del_Weight_Data = new DataSet(); int num = 1; private void Init_WithConfig() { try { //Get Init Value from App.Config file //System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader(); // Weight_DBManager.SQConnStr = ((string)(configurationAppSettings.GetValue("SQConn", typeof(string)))); // Weight_DBManager.SQConnStr = "Provider=\"MSDAORA.1\";User ID=XG3Q;Data Source=XG3Q_8;Password=XG3Q123"; // Weight_DBManager.JLConnStr = ((string)(configurationAppSettings.GetValue("SZConn", typeof(string)))); // string interval = ((string)(configurationAppSettings.GetValue("Interval", typeof(string)))); string interval = "10000"; //Inter_H_WeightData(); //Init CoilWeight Server Time Weight_Time.Enabled = true; Weight_Time.Interval = Convert.ToDouble(interval); Weight_Time.Elapsed += new System.Timers.ElapsedEventHandler(Weight_Time_Elapsed); } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName, "酸轧二级接口服务初始化失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } } void Weight_Time_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Weight_Time.Enabled = false; try { //处理酸轧二级接口数据 Inter_H_WeightData(); num++; } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName, "酸轧二级接口服务定时器失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } Weight_Time.Enabled = true; } private void Inter_H_WeightData() { try { DataSetDispose(); GetWeightData(); AddWeightData(); DelWeightData(); } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName + "-热轧", "处理热轧计量数据失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } } private void DelWeightData() { try { if (Del_Weight_Data != null && Del_Weight_Data.Tables.Count == 1 && Del_Weight_Data.Tables[0].Rows.Count > 0) { for (int i = Del_Weight_Data.Tables[0].Rows.Count - 1; i >= 0; i--) { CoreClientParam ccp2 = new CoreClientParam(); ccp2.ServerName = "UIL.UIL01.UIL010010"; ccp2.MethodName = "updateprinter"; ccp2.ServerParams = new object[] { FixDBManager.CheckNullStr(Del_Weight_Data.Tables[0].Rows[i]["OLD_SAMPL_NO"]) }; ccp2 = this.ExecuteNonQuery(ccp2, CoreInvokeType.Internal); Del_Weight_Data.Tables[0].Rows.RemoveAt(i); Del_Weight_Data.AcceptChanges(); /*string exesql = "UPDATE L2_CALTHKDATA SET FLAG=1 WHERE convert(nvarchar(500),COILIDLZ)=N'" + FixDBManager.CheckNullStr(Del_Weight_Data.Tables[0].Rows[i]["COILIDLZ"]) + "'"; if (DBManager.ExecuteDB(Weight_DBManager.LogName + "-热轧", "更新酸轧二级接口数据失败:", exesql, Weight_DBManager.JLConn)) { Del_Weight_Data.Tables[0].Rows.RemoveAt(i); Del_Weight_Data.AcceptChanges(); }*/ } } // QUERYData(); } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName + "-热轧", "更新酸轧二级接口数据失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } } private void DataSetDispose() { try { Weight_Data = null; Del_Weight_Data = null; } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName, "释放资源失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } } private void GetWeightData() { try { this.dataSet1.Tables[0].Clear(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIL.UIL01.UIL010010"; ccp.MethodName = "queryprinter"; ccp.SourceDataTable = this.dataSet1.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); Weight_Data = this.dataSet1.Copy(); //string sql = "SELECT COILIDLZ,COILTHICK,COILSETTHICK,COILFLAT,INSERTDATE FROM L2_CALTHKDATA WHERE FLAG='4'"; //object obj = DBManager.GetDataSet(Weight_DBManager.LogName + "-酸轧", "获取酸轧二级接口数据失败:", sql, "L2_CALTHKDATA", Weight_DBManager.SQConn); //if (obj != null) //{ // Weight_Data = (obj as System.Data.DataSet).Copy(); //} } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName + "-热轧", "获取酸轧二级接口数据失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } } private void QUERYData() { try { this.dataSet2.Tables[0].Clear(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIL.UIL01.UIL010010"; ccp.MethodName = "queryprintING"; ccp.SourceDataTable = this.dataSet2.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName + "-热轧", "获取酸轧二级接口数据失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } } private void AddWeightData() { try { if (Weight_Data != null && Weight_Data.Tables.Count > 0 && Weight_Data.Tables[0].Rows.Count > 0) { Del_Weight_Data = Weight_Data;//Weight_Data.Clone(); foreach (System.Data.DataRow row in Weight_Data.Tables[0].Rows) { //string sql = "SELECT COILIDLZ FROM L2_CALTHKDATA WHERE COILIDLZ='" + FixDBManager.CheckNullStr(row["COILIDLZ"]) + "'"; // param = new Hashtable(); ColdCoilLable coilLabel = new ColdCoilLable(); coilLabel.rollNo = string.Empty; coilLabel.specification = FixDBManager.CheckNullStr(row["SPEC_ABBSYM"]); coilLabel.steelGrade = FixDBManager.CheckNullStr(row["STL_GRD"]); ;//SPEC_STL_GRD coilLabel.dimension = FixDBManager.CheckNullStr(row["T_K"]); coilLabel.coilNo = FixDBManager.CheckNullStr(row["OLD_SAMPL_NO"]); coilLabel.weight = FixDBManager.CheckNullStr(row["ACT_WGT"]); coilLabel.heatNo = FixDBManager.CheckNullStr(row["CHARGE_NO"]); coilLabel.prodDate = FixDBManager.CheckNullStr(row["MILL_DTIME"]); coilLabel.contractNo = FixDBManager.CheckNullStr(row["ORD_NO"]);//ORD coilLabel.prodName = FixDBManager.CheckNullStr(row["ORD_USE_TP"]); coilLabel.custName = FixDBManager.CheckNullStr(row["ORDCUST_CD"]); coilLabel.licenseNo = string.Empty; coilLabel.licenseMark = string.Empty; //coilLabel.checker = string.Empty; coilLabel.checker = FixDBManager.CheckNullStr(row["FAC_STL_GRD"]);//销售备注 coilLabel.barcode = coilLabel.coilNo; printer.printLable(coilLabel);//PRINTING printer.printLable(coilLabel);//PRINTING } } } catch (System.Exception ex) { System.Diagnostics.EventLog.WriteEntry(Weight_DBManager.LogName + "-热轧", "拷贝酸轧二级接口数据失败:" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error); } } protected void OnStart(string[] args) { try { Weight_Time.Enabled = true; Weight_Time.Start(); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } protected void OnStop() { try { Weight_Time.Stop(); Weight_Time.Close(); DataSetDispose(); /* Weight_DBManager.JLConn.Close(); Weight_DBManager.JLConn.Dispose(); Weight_DBManager.SQConn.Close(); Weight_DBManager.SQConn.Dispose();*/ } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } private void Form1_Load(object sender, EventArgs e) { /* printer.Addr = "172.16.50.210"; printer.LableVersion = 5;*/ string Current = System.IO.Directory.GetCurrentDirectory();//获取当前根目录 Ini ini = new Ini(Current + "/CoreFS.ini"); // 读取ini string labPrinterAddr = ini.ReadValue("LABPRINTERADDR", "6"); //labPrinterAddr = "172.16.50.200";//测试代码20161014 printer.Addr = labPrinterAddr; //string version = ini.ReadValue("LABPRINTERADDR", "Version"); string version = "5"; printer.LableVersion = int.Parse(version); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { OnStop(); } } }