From 5e610f4c9d9870b393720bc5fcc856e97bc2ea4b Mon Sep 17 00:00:00 2001 From: zongzhibin <zongzhibin@weben-smart.com> Date: 周三, 27 11月 2024 09:36:26 +0800 Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/LA24030-LuLI_PackageLine --- LA24030_LuLiPackageLine_Print/LA24030_LuLiPackageLine_PrintService/WindowsFormsApplication1/Form1.cs | 409 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 409 insertions(+), 0 deletions(-) diff --git a/LA24030_LuLiPackageLine_Print/LA24030_LuLiPackageLine_PrintService/WindowsFormsApplication1/Form1.cs b/LA24030_LuLiPackageLine_Print/LA24030_LuLiPackageLine_PrintService/WindowsFormsApplication1/Form1.cs new file mode 100644 index 0000000..90a1fcb --- /dev/null +++ b/LA24030_LuLiPackageLine_Print/LA24030_LuLiPackageLine_PrintService/WindowsFormsApplication1/Form1.cs @@ -0,0 +1,409 @@ +锘縰sing Admin.NET.Application; +using Admin.NET.Core.WareHouse.Enum; +using autuPrint.printService; +using Excel2SQL; +using iWareCommon; +using iWareCommon.Utils; +using iWareSql; +using iWareSql.DataAccess; +using iWareSql.MyDbContext; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Windows.Forms; +using WindowsFormsApplication1.Common; + +namespace WindowsFormsApplication1 +{ + public partial class Form1 : Form + { + //鑷姩鎵撳嵃绾跨▼ + Thread AutoPrint, Colors; + + public Form1() + { + InitializeComponent(); + } + + private void btn_SelectFile_Click(object sender, EventArgs e) + { + OpenFileDialog fileDialog = new OpenFileDialog(); + fileDialog.Multiselect = true; + fileDialog.Title = "璇烽�夋嫨鏂囦欢"; + fileDialog.Filter = "鎵�鏈夋枃浠�(*xls*)|*.xls*"; //璁剧疆瑕侀�夋嫨鐨勬枃浠剁殑绫诲瀷 + if (fileDialog.ShowDialog() == DialogResult.OK) + { + string file = fileDialog.FileName;//杩斿洖鏂囦欢鐨勫畬鏁磋矾寰� + this.tb_FilePath.Text = file; + } + } + + private void button2_Click(object sender, EventArgs e) + { + try + { + this.tb_Msg.Text = "鎵撳嵃:"; + string filePath = this.tb_FilePath.Text; + if (filePath == string.Empty) + { + MessageBox.Show("璇烽�夋嫨Excel!"); + return; + } + + + Dictionary<string, string> cellheader = new Dictionary<string, string> { + { "MaterialCode", "鐗╂枡鍙�" }, + { "MaterialName", "鐗╂枡鍚嶇О" }, + { "Vendor", "渚涘簲鍟�" }, + { "PO", "PO" }, + { "Qty", "鏁伴噺" } + }; + + // 1.2瑙f瀽鏂囦欢锛屽瓨鏀惧埌涓�涓狶ist闆嗗悎閲� + StringBuilder errorMsg = new StringBuilder(); // 閿欒淇℃伅 + string tableDesc = "", tableName = ""; + List<MaterialEntity> enlist = ExcelHelper.ExcelToEntityListForCreateTable<MaterialEntity>(cellheader, filePath, out tableDesc, out tableName, out errorMsg); + if (!string.IsNullOrEmpty(errorMsg.ToString())) + { + MessageBox.Show("閿欒:" + errorMsg.ToString()); + return; + } + + enlist = enlist.Where(x => !string.IsNullOrEmpty(x.MaterialCode)).ToList(); + this.tb_Msg.Text = "澶勭悊鏉℃暟:" + enlist.Count; + if (enlist != null && enlist.Count > 0) + { + foreach (var item in enlist) + { + if (string.IsNullOrEmpty(item.MaterialName)) + { + continue; + } + this.do_autoPrint(item); + + } + //MessageBox.Show("鎵归噺鎵撳嵃鎴愬姛鎴愬姛锛�"); + return; + } + MessageBox.Show("鏃犳墦鍗板唴瀹癸紒"); + } + catch (Exception ex) + { + MessageBox.Show("閿欒:" + ex.Message.ToString()); + this.tb_Msg.Text = "寮傚父:" + ex.Message; + } + } + + /// <summary> + /// 鑷姩鎵撳嵃-琛屽姩 + /// </summary> + public void do_autoPrint(MaterialEntity material) + { + + try + { + + #region 鍗曚釜澶勭悊鏍囩鎵撳嵃 + + string barCode = material.MaterialName;//鏍囩鏉$爜 + Image img = QrCodeAndBarCode.printQr(barCode); + var errMsg = ""; + ware_material_print_history ware_Material_Print_History = new ware_material_print_history() + { + Code = material.MaterialCode, + Name = material.MaterialName, + SupplierNo = material.Vendor, + PurchaseNo = material.PO, + Quantity = Convert.ToDecimal(material.Qty) + }; + bool saveSucceed = creatExcelPrint.creatEXcel(img, ware_Material_Print_History, ref errMsg); + + if (saveSucceed) + { + if (File.Exists(SystemConst.TEMPORARY_FILEPATH)) + { + bool printSucceed = true; + + + printSucceed = print.printExcel(SystemConst.TEMPORARY_FILEPATH, SystemConst.Default_LeftMargin, SystemConst.Default_TopMargin); + + if (printSucceed) + { + //鎵撳嵃鎴愬姛 鍒犻櫎涓存椂鏂囦欢,骞舵敼鐘舵�� + FileInfo myfile = new FileInfo(SystemConst.TEMPORARY_FILEPATH);//PartStatus + myfile.Delete(); + + int isSave = 1; + if (isSave < 1) + { + Log4NetHelper.WriteErrorLog(LogType.Print, "绫诲悕: Form1 鏂规硶鍚�: do_autoPrint 淇敼搴撳瓨鑷姩鎵撳嵃鐘舵�佸け璐�,淇敼鏉℃暟灏忎簬1 ", null); + } + } + //*/ + } + } + else + { + this.tb_Msg.Text = "澶辫触锛屽け璐ュ唴瀹癸細" + errMsg; + } + #endregion + + } + catch (Exception ex) + { + Log4NetHelper.WriteErrorLog(LogType.Print, "绫诲悕: Service1 鏂规硶鍚�: do_autoPrint 鑷姩鎵撳嵃鏂规硶鍙傛暟杞崲澶辫触 \r\n " + ex.ToString(), ex); + this.tb_Msg.Text = "澶辫触寮傚父 锛�" + ex.Message; + } + } + + private void Form1_Load(object sender, EventArgs e) + { + CheckForIllegalCrossThreadCalls = false; + + //妫�娴嬫槸鍚﹀凡缁忓紑鍚� + Process current = Process.GetCurrentProcess(); + Process[] processes = Process.GetProcessesByName(current.ProcessName); + foreach (Process process in processes) + { + if (process.Id != current.Id) + { + if (process.MainModule.FileName == current.MainModule.FileName) + { + Environment.Exit(0); + return; + } + } + } + + + + Colors = new Thread(changeColor); + Colors.Start(); + + AutoPrint = new Thread(DBAutoPrint); + AutoPrint.Start(); + + new Thread(DeleteData).Start(); + } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + Environment.Exit(0);//閫�鍑烘湰杩涚▼鎵�鏈夌嚎绋� + } + + public void changeColor() + { + bool isChange = true; + while (true) + { + Thread.Sleep(1000); + if (isChange) + { + label1.BackColor = Color.Yellow; + + } + else + { + label1.BackColor = Color.Pink; + } + isChange = !isChange; + } + + + } + + #region 鏁版嵁搴撴墦鍗� + + + public void DBAutoPrint() + { + var errMsg = ""; + while (true) + { + try + { + this.tb_Msg.Text = "寰幆寮�濮�..."; + + errMsg = "";//閲嶇疆 + try + { + Do(ref errMsg); + if (!string.IsNullOrEmpty(errMsg)) + { + this.tb_Msg.Text = errMsg; + } + } + catch (Exception ex) + { + Log4NetHelper.WriteErrorLog(LogType.Print, "鎵撳嵃澶勭悊鐨勭嚎绋�=>" + errMsg + ",寮傚父:" + ex.Message, ex); + this.tb_Msg.Text = "鎵撳嵃澶勭悊鐨勭嚎绋�=>" + errMsg + ",寮傚父:" + ex.Message; + } + + } + catch (Exception ex) + { + this.tb_Msg.Text = "鍑虹幇寮傚父:" + ex.Message; + Log4NetHelper.WriteErrorLog(LogType.Print, "Print 鍑虹幇寮傚父锛�" + ex.Message, ex); + } + Thread.Sleep(2 * 1000);//浼戠湢2绉� + } + } + + + /// <summary> + /// 鎵撳嵃 + /// </summary> + /// <param name="model"></param> + /// <param name="Lane"></param> + /// <param name="flag"></param> + /// <param name="errMsg"></param> + private void Do(ref string errMsg) + { + using (WmsDBModel mycontext = new WmsDBModel()) + { + var query_PrintStatuEnum = (int)PrintStatuEnum.鏈墦鍗�; + var list = mycontext.wms_record_print.Where(x => (x.IsDelete == false) && x.PrintStatus == query_PrintStatuEnum) + .OrderBy(x => x.Id).ToList(); + + + wms_config_print printConfig = null; + string _PrinterName = ""; + if (list.Count > 0) + { + + } + else + { + errMsg = $"娌℃湁鍙墦鍗扮殑鍐呭锛�"; + return; + } + + foreach (var item in list) + { + + + PrintClassifyEnum printClassifyEnum = PrintClassifyEnum.鍖呰鏉$爜; + + + printConfig = mycontext.wms_config_print.Where(x => x.PrintClassify == (int)printClassifyEnum).FirstOrDefault(); + if (printConfig == null) + { + errMsg = $"娌℃湁鎵惧埌{printClassifyEnum.ToString()}鐨勬墦鍗伴厤缃紒"; + return; + } + //璁剧疆鎵撳嵃鏈猴紝娉ㄦ剰锛氳繖閲屽彧鑾峰彇绗竴涓紝浠ュ悗鍙兘瑕佹敼锛� + _PrinterName = printConfig.PrinterList.Split(',')[0]; + //鏍规嵁閰嶇疆鍚嶅瓧鏌ヨ 鎵撳嵃鏈哄悕瀛� + //var printConfigData = mycontext.SysDictData.Where(x => x.Name == _PrinterName).FirstOrDefault(); + //if (printConfigData == null) + //{ + // errMsg = $"娌℃湁鎵惧埌{_PrinterName.ToString()}鐨勬墦鍗版満鍚嶅瓧锛�"; + // return; + //} + //_PrinterName = printConfigData.Value; + + Dictionary<string, object> data = new Dictionary<string, object>(); + if (printClassifyEnum == PrintClassifyEnum.鍖呰鏉$爜) + { + data.Add("Info4", item.Info4);//鍚堝悓鍗曞彿 + data.Add("Info5", item.Info5 ?? "");//鐢熶骇鍗曞彿 + data.Add("Info6", "绗�" + (item.Info6 ?? "") + "鍖�");//绗嚑鍖� + data.Add("bar", item.PackageCode);//浜岀淮鐮侊紙鍖呭彿锛� + data.Add("Info7", item.Info7 ?? "");//缁忛攢搴� + data.Add("Info8", item.Info8 ?? "");//浜у搧 + data.Add("Info9", item.PackageCode ?? "");//鍖呰缂栫爜 + data.Add("Info10", item.Info10 ?? "");//瀹㈡埛鍚嶇О + data.Add("Info11", item.Info11 ?? "");//鑷彁or鍙戣揣 + data.Add("Info12", "鍖呰鏄庣粏 閮ㄤ欢鎬绘暟" + item.Info12 ?? "");//閮ㄤ欢鏄庣粏 + data.Add("Info13", item.Info13 ?? "");//褰撳墠鍖呴潰绉� + data.Add("printTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + + //鏌ヨ涓� 鍖呮暟鎹� + var mylist = mycontext.mes_batchOrderUPI_new.Where(x => x.PackageCode == item.PackageCode).ToList(); + var gg = mylist.GroupBy(x => x.DetailName); + int i = 0; + foreach (var g in gg) + { + i++; + data.Add("detail_" + i, g.Key ?? "");//閮ㄤ欢鍚嶇О + data.Add("detail_" + i + "_length", g.ToList().First().Info16 ?? "");//閮ㄤ欢灏哄 + data.Add("detail_" + i + "_number", g.ToList().Count());//閮ㄤ欢鏁伴噺 + } + for (int p = (i + 1); p <= 6; p++) + { + data.Add("detail_" + p, "");//閮ㄤ欢鍚嶇О + data.Add("detail_" + p + "_length", "");//閮ㄤ欢灏哄 + data.Add("detail_" + p + "_number", "");//閮ㄤ欢鏁伴噺 + } + } + else + { + + } + + + //璋冪敤鎵撳嵃鎺ュ彛 + bool isSuccess = false; + using (iWarePrintService.PrintBaseService.PrintWcfServiceClient client = new iWarePrintService.PrintBaseService.PrintWcfServiceClient()) + { + //isSuccess = client.Print3(data, 1, @"D:\鎵撳嵃绋嬪簭\璺熻釜鐮佹墦鍗版ā鏉縗璺熻釜鐮佹墦鍗版ā鏉縚涓�缁寸爜.btw", "ZDesigner ZD888-203dpi ZPL", out errMsg); + //isSuccess = client.Print3(data, 1, @"D:\鎵撳嵃绋嬪簭\璺熻釜鐮佹墦鍗版ā鏉縗璺熻釜鐮佹墦鍗版ā鏉縚浜岀淮鐮�.btw", "ZDesigner ZD888-203dpi ZPL", out errMsg); + isSuccess = client.Print3(data, item.PrintSheetNum, printConfig.PrintTemplateAddr, _PrinterName, out errMsg); + } + if (isSuccess) + { + item.PrintStatus = 1;//鎵撳嵃鐘舵��(0锛氭湭鎵撳嵃 1锛氬凡鎵撳嵃) + item.PrintNum = (item.PrintNum) + 1; + + mycontext.SaveChanges(); + } + else + { + errMsg = $"鎵撳嵃閿欒 鎵撳嵃鏈哄悕绉皗_PrinterName},閿欒淇℃伅锛�(鎵撳嵃鏈嶅姟杩斿洖)" + errMsg; + Log4NetHelper.WriteErrorLog(LogType.Print, errMsg, null); + return; + } + + Thread.Sleep(2000); + } + + } + } + + #endregion + + #region 瀹氭椂鍒犻櫎鏁版嵁 + + /// <summary> + /// 瀹氭椂鍒犻櫎鏁版嵁 + /// </summary> + public void DeleteData() + { + while (true) + { + try + { + LogTextHelper.BatchDeleteLog(); + + Thread.Sleep(8 * 60 * 60 * 1000);//姣忓ぉ8灏忔椂涓�娆� + } + catch (Exception ex) + { + Log4NetHelper.WriteErrorLog(iWareCommon.Utils.LogType.Sys_DeleteLog, "瀹氭椂鍒犻櫎鏁版嵁 鍑虹幇寮傚父", ex); + } + finally + { + + } + } + } + + #endregion + } +} -- Gitblit v1.9.3