• c# .net6 在线条码打印基于


    条码打印基于:BarTenderORM EF架构

    UI展示:

    主页代码:

    1. using NPOI.OpenXmlFormats.Spreadsheet;
    2. using ServerSide.Models;
    3. using System;
    4. using System.Collections.Generic;
    5. using System.ComponentModel;
    6. using System.Data;
    7. using System.Drawing;
    8. using System.Linq;
    9. using System.Text;
    10. using System.Threading.Tasks;
    11. using System.Windows.Forms;
    12. namespace PlantProcessControlSystem.BarCodePrint
    13. {
    14. //tss_nowdate
    15. public partial class Main_BarCodePrint_Frm : Form
    16. {
    17. private System.Windows.Forms.Timer timer;
    18. //1.声明自适应类实例
    19. private AutoSizeFormClass asc = null;
    20. private AutoSetControlSize ass = null;
    21. public Main_BarCodePrint_Frm()
    22. {
    23. InitializeComponent();
    24. ass = new AutoSetControlSize(this, this.Width, this.Height);
    25. }
    26. #region 窗体控件事件
    27. private void btn_Close_Click(object sender, EventArgs e)
    28. {
    29. if (((Button)sender).Name == "btn_Close")//窗体关闭
    30. {
    31. //DialogResult result = MessageBox.Show("是否确认退出??","提醒",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
    32. //if (result == DialogResult.Yes)
    33. // Application.Exit();
    34. //else
    35. // return;
    36. //this.Hide();//隐藏
    37. //tlrm_Show.Enabled = true;//控件可使用
    38. Environment.Exit(0);
    39. //Application.Exit();
    40. }
    41. else if (((Button)sender).Name == "btn_WinMinSize")//窗体最小化
    42. {
    43. this.WindowState = FormWindowState.Minimized;
    44. }
    45. else if (((Button)sender).Name == "btn_WinMaxSize")//窗体最大化
    46. {
    47. if (this.WindowState == FormWindowState.Normal)
    48. this.WindowState = FormWindowState.Maximized;
    49. else
    50. this.WindowState = FormWindowState.Normal;
    51. }
    52. }
    53. #endregion
    54. #region 时间同步
    55. private void Timer_Tick(object sender, EventArgs e)
    56. {
    57. tss_nowdate.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
    58. }
    59. #endregion
    60. #region 窗体加载
    61. private void Main_BarCodePrint_Frm_Load(object sender, EventArgs e)
    62. {
    63. timer = new System.Windows.Forms.Timer();
    64. timer.Interval = 1000;
    65. timer.Tick += Timer_Tick;
    66. timer.Enabled = true;
    67. }
    68. #endregion
    69. #region 窗体移动
    70. private Point mouseOff;//鼠标移动位置变量
    71. private bool leftFlag;//标签是否为左键
    72. private void Frm_MouseDown(object sender, MouseEventArgs e)
    73. {
    74. if (e.Button == MouseButtons.Left)
    75. {
    76. mouseOff = new Point(-e.X, -e.Y); //得到变量的值
    77. leftFlag = true; //点击左键按下时标注为true;
    78. }
    79. }
    80. private void Frm_MouseMove(object sender, MouseEventArgs e)
    81. {
    82. if (leftFlag)
    83. {
    84. Point mouseSet = Control.MousePosition;
    85. mouseSet.Offset(mouseOff.X, mouseOff.Y); //设置移动后的位置
    86. Location = mouseSet;
    87. }
    88. }
    89. private void Frm_MouseUp(object sender, MouseEventArgs e)
    90. {
    91. if (leftFlag)
    92. {
    93. leftFlag = false;//释放鼠标后标注为false;
    94. }
    95. }
    96. #endregion
    97. #region 移动鼠标
    98. private void MainFrm_Move(object sender, EventArgs e)
    99. {
    100. // 获取当前鼠标的坐标
    101. Point cursorPosition = Cursor.Position;
    102. TS_X.Text = cursorPosition.X.ToString();
    103. TS_Y.Text = cursorPosition.Y.ToString();
    104. tss_State.Text = "当前状态:操作";
    105. }
    106. #endregion
    107. #region 装载窗体
    108. ///
    109. /// 装载窗体
    110. ///
    111. ///
    112. private void OpenForm(Form childFrom)
    113. {
    114. //首先判断容器中是否有其他的窗体
    115. foreach (Control item in this.Panel_Winfrm.Controls)
    116. {
    117. if (item is Form)
    118. {
    119. ((Form)item).Close();
    120. }
    121. }
    122. //嵌入新的窗体
    123. childFrom.TopLevel = false;//将子窗体设置成非顶级控件
    124. // childFrom.FormBorderStyle = FormBorderStyle.None;//去掉窗体边框(目前不需要了)
    125. childFrom.Parent = this.Panel_Winfrm;//设置窗体的容器
    126. childFrom.Dock = DockStyle.Fill;//随着容器大小自动调整窗体大小(目前可能没有效果)
    127. childFrom.Show();
    128. }
    129. #endregion
    130. #region 窗体自适应
    131. private void MainFrm_SizeChanged(object sender, EventArgs e)
    132. {
    133. asc = new AutoSizeFormClass(this);
    134. asc.controlAutoSize(this);
    135. }
    136. private void MainFrm_Resize(object sender, EventArgs e)
    137. {
    138. ass.setControls((this.Width) / ass.X, (this.Height) / ass.Y, this);
    139. }
    140. #endregion
    141. #region 树形菜单单击事件
    142. private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
    143. {
    144. if (e.Node.Text == "配置.客户信息")
    145. {
    146. CfgClientInfoFrm cfgClientInfoFrm = new CfgClientInfoFrm();
    147. this.OpenForm(cfgClientInfoFrm);
    148. }
    149. else if (e.Node.Text == "配置.产品信息")
    150. {
    151. CfgProductInfoFrm cfgProductInfoFrm = new CfgProductInfoFrm();
    152. this.OpenForm(cfgProductInfoFrm);
    153. }
    154. else if (e.Node.Text == "配置.订单信息")
    155. {
    156. CfgOrderInfoFrm cfgOrderInfoFrm = new CfgOrderInfoFrm();
    157. this.OpenForm(cfgOrderInfoFrm);
    158. }
    159. else if (e.Node.Text == "配置.条码工序信息")
    160. {
    161. CfgBarCodeWkInfoFrm cfgBarCodeWkInfoFrm = new CfgBarCodeWkInfoFrm();
    162. this.OpenForm(cfgBarCodeWkInfoFrm);
    163. }
    164. else if ((e.Node.Text == "在线.条码打印"))
    165. {
    166. OnLineBarCodePrintFrm onLineBarCodePrintFrm = new OnLineBarCodePrintFrm();
    167. this.OpenForm(onLineBarCodePrintFrm);
    168. }
    169. else if (e.Node.Text == "配置.打印模板")
    170. {
    171. CfgBarCodePrintTemplateFrm cfgBarCodePrintTemplateFrm = new CfgBarCodePrintTemplateFrm();
    172. this.OpenForm(cfgBarCodePrintTemplateFrm);
    173. }
    174. else if (e.Node.Text == "配置.条码打印参数")
    175. {
    176. CfgBarCodePrintInfoFrm cfgBarCodePrintInfoFrm = new CfgBarCodePrintInfoFrm();
    177. cfgBarCodePrintInfoFrm.callBack += new Action<bool>((b) =>
    178. {
    179. if (b == false) this.Hide();
    180. else this.Show();
    181. });
    182. this.OpenForm((cfgBarCodePrintInfoFrm));
    183. }
    184. else if (e.Node.Text == "配置.动态字段")
    185. {
    186. CfgBarCodeInfoFrm cfgBarCodeInfoFrm = new CfgBarCodeInfoFrm();
    187. this.OpenForm(cfgBarCodeInfoFrm);
    188. }
    189. }
    190. #endregion
    191. }
    192. }

    1. using ServerSide.DAL;
    2. using ServerSide.Models;
    3. using System;
    4. using System.Collections.Generic;
    5. using System.ComponentModel;
    6. using System.Data;
    7. using System.Drawing;
    8. using System.Linq;
    9. using System.Text;
    10. using System.Threading.Tasks;
    11. using System.Windows.Forms;
    12. namespace PlantProcessControlSystem.BarCodePrint
    13. {
    14. public partial class CfgBarCodeWkInfoFrm : Form
    15. {
    16. private List processinformations;//工序信息
    17. private Processinformation oldProcessinformation;//旧的工序信息
    18. public string errInfo;//错误信息
    19. public CfgBarCodeWkInfoFrm()
    20. {
    21. InitializeComponent();
    22. }
    23. #region 初始化界面
    24. private void InitWinFrmTable()
    25. {
    26. using (EFContext db = new EFContext())
    27. {
    28. this.processinformations = new List();
    29. this.processinformations = db!.Processinformation!.ToList();
    30. this.dataSource.DataSource = processinformations;
    31. txt_Process.Text = "";
    32. txt_Process.Enabled = false;
    33. }
    34. this.btn_Del.Enabled = false;
    35. this.btn_Rework.Enabled = false;
    36. this.dataSource.ClearSelection();
    37. }
    38. #endregion
    39. #region 返回
    40. private void btn_Result_Click(object sender, EventArgs e)
    41. {
    42. this.InitWinFrmTable();
    43. this.pe_Processinfo.Visible = false;
    44. }
    45. #endregion
    46. #region 添加
    47. private void btn_Add_Click(object sender, EventArgs e)
    48. {
    49. this.lbl_ItemName.Text = "添加";
    50. this.pe_Processinfo.Visible = true;
    51. this.btn_Del.Enabled = false;
    52. this.btn_Rework.Enabled = false;
    53. this.txt_Process.Text = "";
    54. this.oldProcessinformation = null;
    55. this.txt_Process.Enabled = true;
    56. }
    57. #endregion
    58. #region 删除
    59. private void btn_Del_Click(object sender, EventArgs e)
    60. {
    61. this.pe_Processinfo.Visible = true;
    62. this.lbl_ItemName.Text = "删除";
    63. this.txt_Process.Enabled = false;
    64. this.btn_Save.Focus();
    65. }
    66. #endregion
    67. #region 修改
    68. private void btn_Rework_Click(object sender, EventArgs e)
    69. {
    70. this.pe_Processinfo.Visible = true;
    71. this.lbl_ItemName.Text = "修改";
    72. this.txt_Process.Enabled = true;
    73. this.txt_Process.SelectAll();
    74. this.txt_Process.Focus();
    75. }
    76. #endregion
    77. #region 保存
    78. private void btn_Save_Click(object sender, EventArgs e)
    79. {
    80. if (txt_Process.Text != string.Empty && txt_Process.Text.Length > 0)
    81. {
    82. using (EFContext db = new EFContext())
    83. {
    84. if (lbl_ItemName.Text == "添加")
    85. {
    86. Processinformation processinformation = new Processinformation
    87. {
    88. PrsName = txt_Process.Text
    89. };
    90. db?.Processinformation?.Add(processinformation);
    91. }
    92. else if (lbl_ItemName.Text == "修改")
    93. {
    94. db!.Processinformation!.ToList().ForEach((p) =>
    95. {
    96. if (p.PrsInfoID == oldProcessinformation.PrsInfoID)
    97. p.PrsName = txt_Process.Text;
    98. });
    99. }
    100. else if (lbl_ItemName.Text == "删除")
    101. {
    102. db?.Processinformation?.Remove(oldProcessinformation);
    103. }
    104. int result = db!.SaveChanges();
    105. if (result <= 0)
    106. MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    107. }
    108. this.pe_Processinfo.Visible = false;
    109. this.InitWinFrmTable();
    110. }
    111. }
    112. #endregion
    113. #region 窗体加载
    114. private void CfgBarCodeWkInfoFrm_Load(object sender, EventArgs e)
    115. {
    116. this.InitWinFrmTable();
    117. this.dataSource.ClearSelection();
    118. }
    119. #endregion
    120. #region 点击选择
    121. private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
    122. {
    123. try
    124. {
    125. if (e.RowIndex >= 0)
    126. {
    127. if (processinformations[e.RowIndex] != null)
    128. {
    129. this.oldProcessinformation = new Processinformation();
    130. this.oldProcessinformation = processinformations[e.RowIndex];
    131. this.btn_Del.Enabled = true;
    132. this.btn_Rework.Enabled = true;
    133. this.txt_Process.Text = processinformations[e.RowIndex].PrsName;
    134. }
    135. else
    136. {
    137. this.btn_Del.Enabled = false;
    138. this.btn_Rework.Enabled = false;
    139. }
    140. }
    141. this.pe_Processinfo.Visible = false;
    142. }
    143. catch (Exception ex)
    144. {
    145. this.errInfo = string.Empty;
    146. MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    147. }
    148. }
    149. #endregion
    150. }
    151. }

    1. using ServerSide.DAL;
    2. using ServerSide.Models;
    3. using System;
    4. using System.Collections.Generic;
    5. using System.ComponentModel;
    6. using System.Data;
    7. using System.Drawing;
    8. using System.Linq;
    9. using System.Text;
    10. using System.Threading.Tasks;
    11. using System.Windows.Forms;
    12. namespace PlantProcessControlSystem.BarCodePrint
    13. {
    14. public partial class CfgProductInfoFrm : Form
    15. {
    16. private List productNames;//产品名称
    17. private ProductNames oldproductName;
    18. private string ErrInfo;//错误信息
    19. public CfgProductInfoFrm()
    20. {
    21. InitializeComponent();
    22. }
    23. #region 初始化界面
    24. private void InitWinFrmTable()
    25. {
    26. using (EFContext db = new EFContext())
    27. {
    28. productNames = new List();
    29. productNames = db!.ProductNames!.ToList();
    30. this.dataSource.DataSource = productNames;
    31. cmb_Client.Items.Clear();
    32. db!.ClientInfo!.ToList().ForEach((c) => cmb_Client.Items.Add(c.ClientName));
    33. txt_ProductName.Text = "";
    34. txt_ProductName.Enabled = false;
    35. cmb_Client.Enabled = true;
    36. }
    37. this.btn_Del.Enabled = false;
    38. this.btn_Rework.Enabled = false;
    39. this.dataSource.ClearSelection();
    40. }
    41. #endregion
    42. #region 窗体加载
    43. private void CfgProductInfoFrm_Load(object sender, EventArgs e)
    44. {
    45. this.InitWinFrmTable();
    46. }
    47. #endregion
    48. #region 修改
    49. private void btn_Rework_Click(object sender, EventArgs e)
    50. {
    51. this.pe_ProductInfo.Visible = true;
    52. this.lbl_ItemName.Text = "修改";
    53. this.txt_ProductName.SelectAll();
    54. this.txt_ProductName.Focus();
    55. }
    56. #endregion
    57. #region 册除
    58. private void btn_Del_Click(object sender, EventArgs e)
    59. {
    60. this.pe_ProductInfo.Visible = true;
    61. this.lbl_ItemName.Text = "删除";
    62. this.txt_ProductName.Enabled = false;
    63. this.cmb_Client.Enabled = false;
    64. }
    65. #endregion
    66. #region 添加
    67. private void btn_Add_Click(object sender, EventArgs e)
    68. {
    69. this.lbl_ItemName.Text = "添加";
    70. this.pe_ProductInfo.Visible = true;
    71. this.btn_Del.Enabled = false;
    72. this.btn_Rework.Enabled = false;
    73. this.txt_ProductName.Text = "";
    74. this.oldproductName = null;
    75. }
    76. #endregion
    77. #region 返回
    78. private void btn_Result_Click(object sender, EventArgs e)
    79. {
    80. this.InitWinFrmTable();
    81. this.pe_ProductInfo.Visible = false;
    82. }
    83. #endregion
    84. #region 保存
    85. private void btn_Save_Click(object sender, EventArgs e)
    86. {
    87. if (txt_ProductName.Text != string.Empty && txt_ProductName.Text.Length > 0)
    88. {
    89. using (EFContext db = new EFContext())
    90. {
    91. if (lbl_ItemName.Text == "添加")
    92. {
    93. ProductNames productNames = new ProductNames
    94. {
    95. ClientId = db?.ClientInfo?.ToList()?.Where(c => c.ClientName == cmb_Client.Text)?.FirstOrDefault()?.ClientId,
    96. ProductName = txt_ProductName.Text
    97. };
    98. db?.ProductNames?.Add(productNames);
    99. }
    100. else if (lbl_ItemName.Text == "修改")
    101. {
    102. oldproductName.ProductName = txt_ProductName.Text;
    103. db?.ProductNames?.ToList().ForEach(p =>
    104. {
    105. if (p.ProductId == oldproductName.ProductId)
    106. p.ProductName = txt_ProductName.Text;
    107. });
    108. }
    109. else if (lbl_ItemName.Text == "删除")
    110. {
    111. db?.ProductNames?.Remove(oldproductName);
    112. }
    113. int result = db.SaveChanges();
    114. if (result <= 0) MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    115. }
    116. }
    117. this.pe_ProductInfo.Visible = false;
    118. this.InitWinFrmTable();
    119. }
    120. #endregion
    121. #region 选择客户名称
    122. private void cmb_Client_SelectedIndexChanged(object sender, EventArgs e)
    123. {
    124. if (cmb_Client.Text != string.Empty)
    125. {
    126. txt_ProductName.Enabled = true;
    127. txt_ProductName.Focus();
    128. }
    129. }
    130. #endregion
    131. #region 点击选择
    132. private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
    133. {
    134. try
    135. {
    136. if (e.RowIndex >= 0)
    137. {
    138. if (productNames[e.RowIndex] != null)
    139. {
    140. //txt_UserName.Text = allAuthorizedUsers[e.RowIndex].UserName;
    141. //txt_NickName.Text = allAuthorizedUsers[e.RowIndex].NickName;
    142. //pte_Image.Image = ImageHelper.ByteToImage(allAuthorizedUsers[e.RowIndex].Picture);
    143. //pnl_Edit.Visible = true;
    144. using (EFContext db = new EFContext())
    145. {
    146. this.cmb_Client.Text = db?.ClientInfo?.ToList()?.Where(c => c?.ClientId == productNames[e.RowIndex]?.ClientId)?.FirstOrDefault()?.ClientName;
    147. }
    148. this.oldproductName = new ProductNames();
    149. this.oldproductName = productNames[e.RowIndex];
    150. this.btn_Del.Enabled = true;
    151. this.btn_Rework.Enabled = true;
    152. this.txt_ProductName.Text = productNames[e.RowIndex].ProductName;
    153. //this.btn_Query.Enabled = true;
    154. }
    155. else
    156. {
    157. this.btn_Del.Enabled = false;
    158. this.btn_Rework.Enabled = false;
    159. }
    160. }
    161. this.pe_ProductInfo.Visible = false;
    162. }
    163. catch (Exception ex)
    164. {
    165. //LogHelper.Error("授权信息", ex);
    166. this.ErrInfo = string.Empty;
    167. MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    168. //WMessageBox wMessageBox = new WMessageBox(ex.Message, Color.Red);
    169. }
    170. }
    171. #endregion
    172. }
    173. }

    1. using NPOI.OpenXmlFormats.Spreadsheet;
    2. using ServerSide.DAL;
    3. using ServerSide.Models;
    4. using System;
    5. using System.Collections.Generic;
    6. using System.ComponentModel;
    7. using System.Data;
    8. using System.Drawing;
    9. using System.Linq;
    10. using System.Text;
    11. using System.Threading.Tasks;
    12. using System.Windows.Forms;
    13. namespace PlantProcessControlSystem.BarCodePrint
    14. {
    15. public partial class CfgOrderInfoFrm : Form
    16. {
    17. private List configBarCodeOrderInfoEntities;//配置订单信息
    18. private ConfigBarCodeOrderInfoEntity oldconfigBarCodeOrderInfoEntity;//
    19. public string ErrInfo;//错误日志
    20. public CfgOrderInfoFrm()
    21. {
    22. InitializeComponent();
    23. this.InitWinFrmTable();
    24. }
    25. #region 初始化界面
    26. private void InitWinFrmTable()
    27. {
    28. using (EFContext db = new EFContext())
    29. {
    30. configBarCodeOrderInfoEntities = new List();
    31. db?.ConfigBarCodeOrderInfoEntity?.ToList().ForEach(c => configBarCodeOrderInfoEntities.Add(c));
    32. dtgv_dataSource.DataSource = configBarCodeOrderInfoEntities;//数据源
    33. cmb_ProductName.Text = "";//产品名称
    34. cmb_ProductName.Items.Clear();
    35. db?.ProductNames?.ToList().ForEach(p => cmb_ProductName.Items.Add(p.ProductName));
    36. txt_OrderNum.Text = "";//订单号
    37. txt_BoxNum.Text = "";//外箱序号
    38. txt_OrderTotal.Text = "";//订单总数
    39. cmb_Binding_Nbr.Text = "";//绑码数
    40. cmb_Binding_Nbr.Items.Clear();
    41. for (int i = 1; i <= 60; i++)
    42. cmb_Binding_Nbr.Items.Add(i.ToString());
    43. }
    44. btn_Del.Enabled = false;//删除
    45. btn_Rework.Enabled = false;//修改
    46. btn_Query.Enabled = false;//查询
    47. this.txt_OrderNum.Enabled = true;
    48. this.cmb_ProductName.Enabled = true;
    49. this.txt_BoxNum.Enabled = true;
    50. this.txt_OrderTotal.Enabled = true;
    51. this.cmb_Binding_Nbr.Enabled = true;
    52. pe_OrderInfo.Visible = false;
    53. }
    54. #endregion
    55. #region 添加
    56. private void btn_Add_Click(object sender, EventArgs e)
    57. {
    58. this.lbl_ItemName.Text = "添加";
    59. this.btn_Del.Enabled = false;
    60. this.btn_Rework.Enabled = false;
    61. oldconfigBarCodeOrderInfoEntity = null;
    62. this.InitWinFrmTable();
    63. this.pe_OrderInfo.Visible = true;
    64. }
    65. #endregion
    66. #region 删除
    67. private void btn_Del_Click(object sender, EventArgs e)
    68. {
    69. this.lbl_ItemName.Text = "删除";
    70. this.pe_OrderInfo.Visible = true;
    71. this.txt_OrderNum.Enabled = false;
    72. this.cmb_ProductName.Enabled = false;
    73. this.txt_BoxNum.Enabled = false;
    74. this.txt_OrderTotal.Enabled = false;
    75. this.cmb_Binding_Nbr.Enabled = false;
    76. }
    77. #endregion
    78. #region 修改
    79. private void btn_Rework_Click(object sender, EventArgs e)
    80. {
    81. this.lbl_ItemName.Text = "修改";
    82. this.txt_OrderNum.Enabled = true;
    83. this.cmb_ProductName.Enabled = true;
    84. this.txt_BoxNum.Enabled = true;
    85. this.txt_OrderTotal.Enabled = true;
    86. this.cmb_Binding_Nbr.Enabled = true;
    87. this.pe_OrderInfo.Visible = true;
    88. }
    89. #endregion
    90. #region 保存
    91. private void btn_Save_Click(object sender, EventArgs e)
    92. {
    93. using (EFContext db = new EFContext())
    94. {
    95. if (txt_BoxNum.Text != string.Empty &&
    96. txt_OrderNum.Text != string.Empty &&
    97. txt_OrderTotal.Text != string.Empty &&
    98. cmb_Binding_Nbr.Text != string.Empty &&
    99. cmb_ProductName.Text != string.Empty)
    100. {
    101. if (this.lbl_ItemName.Text == "添加")
    102. {
    103. oldconfigBarCodeOrderInfoEntity = new ConfigBarCodeOrderInfoEntity
    104. {
    105. OrderInfo = txt_OrderNum.Text.Trim(),
    106. ProductId = db?.ProductNames?.ToList()?.Where(p => p.ProductName == cmb_ProductName.Text)?.FirstOrDefault()?.ProductId,
    107. OrderCount = Convert.ToInt32(txt_OrderTotal.Text.Trim()),
    108. CartonSerialNumber = txt_BoxNum?.Text.Trim(),
    109. PackingBindingCode = Convert.ToInt32(cmb_Binding_Nbr.Text.Trim()),
    110. FuselageScanCount = 0,
    111. GiftBoxScanCount = 0,
    112. MasterCartonScanCount = 0
    113. };
    114. db?.ConfigBarCodeOrderInfoEntity?.Add(oldconfigBarCodeOrderInfoEntity);
    115. }
    116. else if (this.lbl_ItemName.Text == "修改")
    117. {
    118. db?.ConfigBarCodeOrderInfoEntity?.ToList().ForEach((c) =>
    119. {
    120. if (c.WorkOrderId == oldconfigBarCodeOrderInfoEntity.WorkOrderId)
    121. {
    122. c.OrderInfo = txt_OrderNum.Text.Trim();
    123. c.ProductId = db?.ProductNames?.ToList()?.Where(p => p?.ProductName?.Trim() == cmb_ProductName.Text.Trim())?.FirstOrDefault()?.ProductId;
    124. c.OrderCount = Convert.ToInt32(txt_OrderTotal.Text.Trim());
    125. c.CartonSerialNumber = txt_BoxNum?.Text.Trim();
    126. c.PackingBindingCode = Convert.ToInt32(cmb_Binding_Nbr?.Text.Trim());
    127. }
    128. });
    129. }
    130. else if (this.lbl_ItemName.Text == "删除")
    131. {
    132. db?.ConfigBarCodeOrderInfoEntity?.Remove(oldconfigBarCodeOrderInfoEntity);
    133. }
    134. int result = db!.SaveChanges();
    135. if (result <= 0) MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    136. this.pe_OrderInfo.Visible = false;
    137. this.InitWinFrmTable();//初始化界面
    138. }
    139. }
    140. }
    141. #endregion
    142. #region 表单选择
    143. private void dtgv_dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
    144. {
    145. try
    146. {
    147. if (e.RowIndex >= 0)
    148. {
    149. if (configBarCodeOrderInfoEntities[e.RowIndex] != null)
    150. {
    151. this.oldconfigBarCodeOrderInfoEntity = new ConfigBarCodeOrderInfoEntity();
    152. this.oldconfigBarCodeOrderInfoEntity.WorkOrderId = configBarCodeOrderInfoEntities[e.RowIndex].WorkOrderId;
    153. this.oldconfigBarCodeOrderInfoEntity.ProductId = configBarCodeOrderInfoEntities[e.RowIndex].ProductId;
    154. this.oldconfigBarCodeOrderInfoEntity.OrderInfo = configBarCodeOrderInfoEntities[e.RowIndex].OrderInfo;
    155. this.oldconfigBarCodeOrderInfoEntity.CartonSerialNumber = configBarCodeOrderInfoEntities[e.RowIndex].CartonSerialNumber;
    156. this.oldconfigBarCodeOrderInfoEntity.OrderCount = configBarCodeOrderInfoEntities[e.RowIndex].OrderCount;
    157. this.oldconfigBarCodeOrderInfoEntity.FuselageScanCount = configBarCodeOrderInfoEntities[e.RowIndex].FuselageScanCount;
    158. this.oldconfigBarCodeOrderInfoEntity.GiftBoxScanCount = configBarCodeOrderInfoEntities[e.RowIndex].GiftBoxScanCount;
    159. this.oldconfigBarCodeOrderInfoEntity.MasterCartonScanCount = configBarCodeOrderInfoEntities[e.RowIndex].MasterCartonScanCount;
    160. this.oldconfigBarCodeOrderInfoEntity.PackingBindingCode = configBarCodeOrderInfoEntities[e.RowIndex].PackingBindingCode;
    161. this.txt_OrderNum.Text = configBarCodeOrderInfoEntities[e.RowIndex].OrderInfo;//订单数
    162. this.txt_OrderTotal.Text = configBarCodeOrderInfoEntities[e.RowIndex].OrderCount.ToString();//订单总数
    163. using (EFContext db = new EFContext())
    164. {
    165. this.cmb_ProductName.Text = db?.ProductNames?.ToList()?.Where(p => p.ProductId == configBarCodeOrderInfoEntities[e.RowIndex].ProductId)?.FirstOrDefault()?.ProductName;//产品名称
    166. }
    167. this.txt_BoxNum.Text = configBarCodeOrderInfoEntities[e.RowIndex].CartonSerialNumber;//外箱
    168. //this.txt_OrderTotal.Text = configBarCodeOrderInfoEntities[e.RowIndex].OrderCount.ToString();//订单总数
    169. this.cmb_Binding_Nbr.Text = configBarCodeOrderInfoEntities[e.RowIndex].PackingBindingCode.ToString();//绑码数
    170. }
    171. }
    172. this.pe_OrderInfo.Visible = false;
    173. btn_Del.Enabled = e.RowIndex >= 0 ? true : false;
    174. btn_Rework.Enabled = e.RowIndex >= 0 ? true : false;
    175. }
    176. catch (Exception ex)
    177. {
    178. this.ErrInfo = $@"{ex.Message}";
    179. MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    180. }
    181. }
    182. #endregion
    183. #region 返回
    184. private void btn_Result_Click(object sender, EventArgs e)
    185. {
    186. this.pe_OrderInfo.Visible = false;
    187. this.InitWinFrmTable();
    188. }
    189. #endregion
    190. }
    191. }

    1. using ServerSide.DAL;
    2. using ServerSide.Models;
    3. using System;
    4. using System.Collections.Generic;
    5. using System.ComponentModel;
    6. using System.Data;
    7. using System.Drawing;
    8. using System.Linq;
    9. using System.Text;
    10. using System.Threading.Tasks;
    11. using System.Windows.Forms;
    12. namespace PlantProcessControlSystem.BarCodePrint
    13. {
    14. public partial class CfgBarCodeWkInfoFrm : Form
    15. {
    16. private List processinformations;//工序信息
    17. private Processinformation oldProcessinformation;//旧的工序信息
    18. public string errInfo;//错误信息
    19. public CfgBarCodeWkInfoFrm()
    20. {
    21. InitializeComponent();
    22. }
    23. #region 初始化界面
    24. private void InitWinFrmTable()
    25. {
    26. using (EFContext db = new EFContext())
    27. {
    28. this.processinformations = new List();
    29. this.processinformations = db!.Processinformation!.ToList();
    30. this.dataSource.DataSource = processinformations;
    31. txt_Process.Text = "";
    32. txt_Process.Enabled = false;
    33. }
    34. this.btn_Del.Enabled = false;
    35. this.btn_Rework.Enabled = false;
    36. this.dataSource.ClearSelection();
    37. }
    38. #endregion
    39. #region 返回
    40. private void btn_Result_Click(object sender, EventArgs e)
    41. {
    42. this.InitWinFrmTable();
    43. this.pe_Processinfo.Visible = false;
    44. }
    45. #endregion
    46. #region 添加
    47. private void btn_Add_Click(object sender, EventArgs e)
    48. {
    49. this.lbl_ItemName.Text = "添加";
    50. this.pe_Processinfo.Visible = true;
    51. this.btn_Del.Enabled = false;
    52. this.btn_Rework.Enabled = false;
    53. this.txt_Process.Text = "";
    54. this.oldProcessinformation = null;
    55. this.txt_Process.Enabled = true;
    56. }
    57. #endregion
    58. #region 删除
    59. private void btn_Del_Click(object sender, EventArgs e)
    60. {
    61. this.pe_Processinfo.Visible = true;
    62. this.lbl_ItemName.Text = "删除";
    63. this.txt_Process.Enabled = false;
    64. this.btn_Save.Focus();
    65. }
    66. #endregion
    67. #region 修改
    68. private void btn_Rework_Click(object sender, EventArgs e)
    69. {
    70. this.pe_Processinfo.Visible = true;
    71. this.lbl_ItemName.Text = "修改";
    72. this.txt_Process.Enabled = true;
    73. this.txt_Process.SelectAll();
    74. this.txt_Process.Focus();
    75. }
    76. #endregion
    77. #region 保存
    78. private void btn_Save_Click(object sender, EventArgs e)
    79. {
    80. if (txt_Process.Text != string.Empty && txt_Process.Text.Length > 0)
    81. {
    82. using (EFContext db = new EFContext())
    83. {
    84. if (lbl_ItemName.Text == "添加")
    85. {
    86. Processinformation processinformation = new Processinformation
    87. {
    88. PrsName = txt_Process.Text
    89. };
    90. db?.Processinformation?.Add(processinformation);
    91. }
    92. else if (lbl_ItemName.Text == "修改")
    93. {
    94. db!.Processinformation!.ToList().ForEach((p) =>
    95. {
    96. if (p.PrsInfoID == oldProcessinformation.PrsInfoID)
    97. p.PrsName = txt_Process.Text;
    98. });
    99. }
    100. else if (lbl_ItemName.Text == "删除")
    101. {
    102. db?.Processinformation?.Remove(oldProcessinformation);
    103. }
    104. int result = db!.SaveChanges();
    105. if (result <= 0)
    106. MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    107. }
    108. this.pe_Processinfo.Visible = false;
    109. this.InitWinFrmTable();
    110. }
    111. }
    112. #endregion
    113. #region 窗体加载
    114. private void CfgBarCodeWkInfoFrm_Load(object sender, EventArgs e)
    115. {
    116. this.InitWinFrmTable();
    117. this.dataSource.ClearSelection();
    118. }
    119. #endregion
    120. #region 点击选择
    121. private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
    122. {
    123. try
    124. {
    125. if (e.RowIndex >= 0)
    126. {
    127. if (processinformations[e.RowIndex] != null)
    128. {
    129. this.oldProcessinformation = new Processinformation();
    130. this.oldProcessinformation = processinformations[e.RowIndex];
    131. this.btn_Del.Enabled = true;
    132. this.btn_Rework.Enabled = true;
    133. this.txt_Process.Text = processinformations[e.RowIndex].PrsName;
    134. }
    135. else
    136. {
    137. this.btn_Del.Enabled = false;
    138. this.btn_Rework.Enabled = false;
    139. }
    140. }
    141. this.pe_Processinfo.Visible = false;
    142. }
    143. catch (Exception ex)
    144. {
    145. this.errInfo = string.Empty;
    146. MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    147. }
    148. }
    149. #endregion
    150. }
    151. }

    1. using ServerSide.DAL;
    2. using ServerSide.Models;
    3. using System;
    4. using System.Collections.Generic;
    5. using System.ComponentModel;
    6. using System.Data;
    7. using System.Drawing;
    8. using System.Linq;
    9. using System.Text;
    10. using System.Threading.Tasks;
    11. using System.Windows.Forms;
    12. namespace PlantProcessControlSystem.BarCodePrint
    13. {
    14. public partial class CfgBarCodeInfoFrm : Form
    15. {
    16. private List configBarCodeInfoEntitys;//配置动态字段信息
    17. private ConfigBarCodeInfoEntity oldConfigBarCodeInfoEntity;//旧的配置动态字段信息
    18. public string errInfo;//错误信息
    19. public CfgBarCodeInfoFrm()
    20. {
    21. InitializeComponent();
    22. }
    23. #region 初始化界面
    24. private void InitWinFrmTable()
    25. {
    26. using (EFContext db = new EFContext())
    27. {
    28. this.configBarCodeInfoEntitys = new List();
    29. this.configBarCodeInfoEntitys = db!.ConfigBarCodeInfoEntity!.ToList();
    30. this.dataSource.DataSource = this.configBarCodeInfoEntitys;
    31. txt_Process.Text = "";
    32. txt_Process.Enabled = false;
    33. txt_Description.Text = "";
    34. txt_Description.Enabled = false;
    35. }
    36. this.btn_Del.Enabled = false;
    37. this.btn_Rework.Enabled = false;
    38. this.dataSource.ClearSelection();
    39. }
    40. #endregion
    41. #region 返回
    42. private void btn_Result_Click(object sender, EventArgs e)
    43. {
    44. this.InitWinFrmTable();
    45. this.pe_Processinfo.Visible = false;
    46. }
    47. #endregion
    48. #region 添加
    49. private void btn_Add_Click(object sender, EventArgs e)
    50. {
    51. this.lbl_ItemName.Text = "添加";
    52. this.pe_Processinfo.Visible = true;
    53. this.btn_Del.Enabled = false;
    54. this.btn_Rework.Enabled = false;
    55. this.txt_Process.Text = "";
    56. this.oldConfigBarCodeInfoEntity = null;
    57. this.txt_Process.Enabled = true;
    58. this.txt_Description.Enabled = true;
    59. }
    60. #endregion
    61. #region 删除
    62. private void btn_Del_Click(object sender, EventArgs e)
    63. {
    64. this.pe_Processinfo.Visible = true;
    65. this.lbl_ItemName.Text = "删除";
    66. this.txt_Process.Enabled = false;
    67. this.txt_Description.Enabled = false;
    68. this.btn_Save.Focus();
    69. }
    70. #endregion
    71. #region 修改
    72. private void btn_Rework_Click(object sender, EventArgs e)
    73. {
    74. this.pe_Processinfo.Visible = true;
    75. this.lbl_ItemName.Text = "修改";
    76. this.txt_Process.Enabled = true;
    77. this.txt_Description.Enabled = true;
    78. this.txt_Process.SelectAll();
    79. this.txt_Process.Focus();
    80. }
    81. #endregion
    82. #region 保存
    83. private void btn_Save_Click(object sender, EventArgs e)
    84. {
    85. if ((txt_Process.Text != string.Empty && txt_Process.Text.Length > 0)&&
    86. (txt_Description.Text!=string.Empty&&txt_Description.Text.Length>0))
    87. {
    88. using (EFContext db = new EFContext())
    89. {
    90. if (lbl_ItemName.Text == "添加")
    91. {
    92. ConfigBarCodeInfoEntity configBarCodeInfoEntity = new ConfigBarCodeInfoEntity
    93. {
    94. ConfigBarCodeName = txt_Process.Text,
    95. ConfigDescription=txt_Description.Text
    96. };
    97. db?.ConfigBarCodeInfoEntity?.Add(configBarCodeInfoEntity);
    98. }
    99. else if (lbl_ItemName.Text == "修改")
    100. {
    101. db!.ConfigBarCodeInfoEntity!.ToList().ForEach((p) =>
    102. {
    103. if (p.cfBarCodeID == oldConfigBarCodeInfoEntity.cfBarCodeID)
    104. {
    105. p.ConfigBarCodeName = txt_Process.Text;
    106. p.ConfigDescription=txt_Description.Text;
    107. }
    108. });
    109. }
    110. else if (lbl_ItemName.Text == "删除")
    111. {
    112. db?.ConfigBarCodeInfoEntity?.Remove(oldConfigBarCodeInfoEntity);
    113. }
    114. int result = db!.SaveChanges();
    115. if (result <= 0)
    116. MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    117. }
    118. this.pe_Processinfo.Visible = false;
    119. this.InitWinFrmTable();
    120. }
    121. }
    122. #endregion
    123. #region 窗体加载
    124. private void CfgBarCodeWkInfoFrm_Load(object sender, EventArgs e)
    125. {
    126. this.InitWinFrmTable();
    127. this.dataSource.ClearSelection();
    128. }
    129. #endregion
    130. #region 点击选择
    131. private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
    132. {
    133. try
    134. {
    135. if (e.RowIndex >= 0)
    136. {
    137. if (configBarCodeInfoEntitys[e.RowIndex] != null)
    138. {
    139. this.oldConfigBarCodeInfoEntity = new ConfigBarCodeInfoEntity();
    140. this.oldConfigBarCodeInfoEntity = configBarCodeInfoEntitys[e.RowIndex];
    141. this.btn_Del.Enabled = true;
    142. this.btn_Rework.Enabled = true;
    143. this.txt_Process.Text = configBarCodeInfoEntitys[e.RowIndex].ConfigBarCodeName;
    144. this.txt_Description.Text = configBarCodeInfoEntitys[e.RowIndex].ConfigDescription;
    145. }
    146. else
    147. {
    148. this.btn_Del.Enabled = false;
    149. this.btn_Rework.Enabled = false;
    150. }
    151. }
    152. this.pe_Processinfo.Visible = false;
    153. }
    154. catch (Exception ex)
    155. {
    156. this.errInfo = string.Empty;
    157. MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    158. }
    159. }
    160. #endregion
    161. }
    162. }

    1. using NPOI.SS.Formula.Functions;
    2. using Org.BouncyCastle.Tls.Crypto;
    3. using ServerSide.Common;
    4. using ServerSide.DAL;
    5. using ServerSide.Models;
    6. using System;
    7. using System.Collections.Generic;
    8. using System.ComponentModel;
    9. using System.Data;
    10. using System.Drawing;
    11. using System.Linq;
    12. using System.Text;
    13. using System.Threading.Tasks;
    14. using System.Windows.Forms;
    15. namespace PlantProcessControlSystem
    16. {
    17. public partial class CfgBarCodePrintTemplateFrm : Form
    18. {
    19. private List configBarCodePrintTemplates;//斑码打印模板配置
    20. private ConfigBarCodePrintTemplate oldconfigBarCodePrintTemplate;//旧的模板配置信息
    21. public string errInfo;//错误日志
    22. public CfgBarCodePrintTemplateFrm()
    23. {
    24. InitializeComponent();
    25. this.InitWinFrmTable();
    26. }
    27. #region 初始化界面
    28. private void InitWinFrmTable()
    29. {
    30. using (EFContext db = new EFContext())
    31. {
    32. configBarCodePrintTemplates = new List();
    33. configBarCodePrintTemplates = db!.ConfigBarCodePrintTemplate!.ToList();
    34. this.dataSource.DataSource = configBarCodePrintTemplates;
    35. //客户信息
    36. this.cmb_Client.Items.Clear();
    37. db!.ClientInfo!.ToList()!.ForEach((c) =>
    38. {
    39. cmb_Client.Items.Add(c.ClientName);
    40. });
    41. this.cmb_Client.Text = "";
    42. this.cmb_Client.Enabled = true;
    43. //工序信息
    44. this.cmb_Processinformation.Items.Clear();
    45. db!.Processinformation!.ToList()!.ForEach(p =>
    46. {
    47. this.cmb_Processinformation.Items.Add(p.PrsName);
    48. });
    49. this.cmb_Processinformation.Text = "";
    50. this.cmb_Processinformation.Enabled = true;
    51. }
    52. //this.gb_PrintModel.Visible = false;
    53. this.txt_PrintTemplateDownPath.Text = "";
    54. this.txt_TemplateName.Text = "";
    55. this.btn_Del.Enabled = false;
    56. this.btn_Rework.Enabled = false;
    57. this.dataSource.ClearSelection();
    58. this.panel_Edit.Visible = false;
    59. templateName = string.Empty;
    60. }
    61. #endregion
    62. #region 选择文档
    63. //private List fileServiceModels;
    64. private FileProcesService fProcesService;
    65. private string selectFileName;//选择文件名称
    66. private void btn_Example_Click(object sender, EventArgs e)
    67. {
    68. selectFileName = string.Empty;
    69. this.txt_PrintTemplateDownPath.Text = "";
    70. fProcesService = new FileProcesService();
    71. fProcesService.SelectFile(out selectFileName, "所有文件(*.btw) | *.btw");
    72. string[] arrayStr = selectFileName.Split('\\');
    73. if (this.UploadFile(selectFileName, arrayStr[arrayStr.Length - 1]))//上传模板
    74. {
    75. txt_PrintTemplateDownPath.Text = templateName;//上传模板文件全路径
    76. txt_TemplateName.Text = arrayStr[arrayStr.Length - 1];//上传模板名称
    77. }
    78. }
    79. #endregion
    80. #region 返回
    81. private void btn_Result_Click(object sender, EventArgs e)
    82. {
    83. this.panel_Edit.Visible = false;
    84. this.InitWinFrmTable();
    85. }
    86. #endregion
    87. #region 添加
    88. private void btn_Add_Click(object sender, EventArgs e)
    89. {
    90. this.lbl_ItemName.Text = "添加";
    91. this.btn_Del.Enabled = false;
    92. this.btn_Rework.Enabled = false;
    93. this.InitWinFrmTable();
    94. this.panel_Edit.Visible = true;
    95. }
    96. #endregion
    97. #region 删除
    98. private void btn_Del_Click(object sender, EventArgs e)
    99. {
    100. this.lbl_ItemName.Text = "删除";
    101. this.panel_Edit.Visible = true;
    102. this.cmb_Client.Enabled = false;
    103. this.txt_PrintTemplateDownPath.Enabled = false;
    104. this.txt_TemplateName.Enabled = false;
    105. this.cmb_Processinformation.Enabled = false;
    106. }
    107. #endregion
    108. #region 修改
    109. private void btn_Rework_Click(object sender, EventArgs e)
    110. {
    111. this.lbl_ItemName.Text = "修改";
    112. //this.txt_TemplateName.Enabled = true;
    113. //this.txt_PrintTemplateDownPath.Enabled = true;
    114. this.cmb_Client.Enabled = true;
    115. //this.InitWinFrmTable();
    116. this.panel_Edit.Visible = true;
    117. }
    118. #endregion
    119. #region 表单点击事件
    120. private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
    121. {
    122. try
    123. {
    124. if (e.RowIndex >= 0)
    125. {
    126. if (configBarCodePrintTemplates[e.RowIndex] != null)
    127. {
    128. this.oldconfigBarCodePrintTemplate = new ConfigBarCodePrintTemplate();
    129. this.oldconfigBarCodePrintTemplate = configBarCodePrintTemplates[e.RowIndex];
    130. this.btn_Del.Enabled = true;
    131. this.btn_Rework.Enabled = true;
    132. using (EFContext db = new EFContext())
    133. {
    134. this.cmb_Client.Text = db?.ClientInfo?.ToList()?.Where(c => c.ClientId == configBarCodePrintTemplates[e.RowIndex].ClientId)?.FirstOrDefault()?.ClientName;
    135. this.cmb_Processinformation.Text = db?.Processinformation?.ToList()?.Where(p => p.PrsInfoID == this.oldconfigBarCodePrintTemplate.PrsInfoID)?.FirstOrDefault()?.PrsName;
    136. }
    137. this.txt_TemplateName.Text = this.oldconfigBarCodePrintTemplate.TempateName;//打印模板名称
    138. this.txt_PrintTemplateDownPath.Text = this.oldconfigBarCodePrintTemplate.TempateDownPath;//打印模板下载路径
    139. }
    140. else
    141. {
    142. this.btn_Del.Enabled = false;
    143. this.btn_Rework.Enabled = false;
    144. }
    145. }
    146. }
    147. catch (Exception ex)
    148. {
    149. this.errInfo = string.Empty;
    150. MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    151. }
    152. }
    153. #endregion
    154. #region 保存
    155. private void btn_Save_Click(object sender, EventArgs e)
    156. {
    157. if (cmb_Client.Text != string.Empty &&
    158. txt_TemplateName.Text != string.Empty &&
    159. txt_PrintTemplateDownPath.Text != string.Empty &&
    160. cmb_Processinformation.Text != string.Empty)
    161. {
    162. using (EFContext db = new EFContext())
    163. {
    164. if (lbl_ItemName.Text == "添加")
    165. {
    166. ConfigBarCodePrintTemplate cfgbptemplate = new ConfigBarCodePrintTemplate
    167. {
    168. ClientId = db?.ClientInfo?.ToList().Where(c => c.ClientName == cmb_Client.Text)?.FirstOrDefault()?.ClientId,
    169. PrsInfoID = db?.Processinformation?.ToList().Where(p => p.PrsName == cmb_Processinformation.Text.Trim())?.FirstOrDefault()?.PrsInfoID,
    170. TempateDownPath = txt_PrintTemplateDownPath.Text.Trim(),
    171. TempateName = txt_TemplateName.Text.Trim()
    172. };
    173. db?.ConfigBarCodePrintTemplate?.Add(cfgbptemplate);
    174. }
    175. else if (lbl_ItemName.Text == "修改")
    176. {
    177. db?.ConfigBarCodePrintTemplate?.ToList().ForEach(c =>
    178. {
    179. if (c.BarCodePrintId == oldconfigBarCodePrintTemplate.BarCodePrintId)
    180. {
    181. c.ClientId = db?.ClientInfo?.ToList()?.Where(c => c.ClientName == cmb_Client.Text)?.FirstOrDefault()?.ClientId;//客户
    182. c.TempateDownPath = txt_PrintTemplateDownPath.Text.Trim();
    183. c.TempateName = txt_TemplateName.Text.Trim();
    184. }
    185. });
    186. }
    187. else if (lbl_ItemName.Text == "删除")
    188. {
    189. db?.ConfigBarCodePrintTemplate?.Remove(oldconfigBarCodePrintTemplate);
    190. }
    191. int result = db!.SaveChanges();
    192. if (result <= 0)
    193. MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    194. }
    195. this.panel_Edit.Visible = false;
    196. this.InitWinFrmTable();//初始化界面
    197. }
    198. }
    199. #endregion
    200. #region 上传日志
    201. ///
    202. /// 上传日志信息
    203. ///
    204. ///
    205. /// 上传文件路径
    206. /// 上传文件名及路径
    207. ///
    208. public bool UploadLog(string uploadFilePath, string fileName, string processFile,bool isLogPass=false)
    209. {
    210. try
    211. {
    212. if(uploadFilePath!=string.Empty&&fileName!=string.Empty)
    213. {
    214. string networkPath = string.Empty;
    215. if (!File.Exists(@"\\10.2.2.163\Data\PASS.OK"))
    216. {
    217. NetworkShareConnect mess = new NetworkShareConnect();
    218. if (mess.connectToShare(networkPath, "test", "Admin123") != "OK")
    219. {
    220. MessageBox.Show($@"{networkPath}:服务器连接失败", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    221. return false;
    222. }
    223. }
    224. if (isLogPass)//是PASS
    225. {
    226. if (!Directory.Exists($@"\\10.2.2.163\data\LOG\PASS\{processFile}\{DateTime.Now.ToString("yyyyMMdd")}"))
    227. Directory.CreateDirectory($@"\\10.2.2.163\data\LOG\{processFile}\PASS\{DateTime.Now.ToString("yyyyMMdd")}");//创建文件夹
    228. System.IO.File.Copy(uploadFilePath, $@"\\10.2.2.163\data\LOG\{processFile}\PASS\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.log");
    229. if (System.IO.File.Exists($@"\\10.2.2.163\data\LOG\{processFile}\PASS\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.log"))
    230. return true;
    231. }
    232. else if (!isLogPass)//是FAIL
    233. {
    234. if (!Directory.Exists($@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}"))
    235. Directory.CreateDirectory($@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}");//创建文件夹
    236. System.IO.File.Copy(uploadFilePath, $@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.FA");
    237. if (System.IO.File.Exists($@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.FA"))
    238. return true;
    239. }
    240. }
    241. }
    242. catch(Exception ex)
    243. {
    244. MessageBox.Show(ex.Message, "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    245. return false;
    246. }
    247. return false;
    248. }
    249. #endregion
    250. #region 上传模板
    251. private string templateName = string.Empty;
    252. private bool UploadFile(string uploadFilePath, string fileName)
    253. {
    254. try
    255. {
    256. if (uploadFilePath != string.Empty)
    257. {
    258. string networkPath = string.Empty;
    259. //networkPath = $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}";
    260. networkPath = $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}";
    261. if (!File.Exists(@"\\10.2.2.163\Data\PASS.OK"))
    262. {
    263. NetworkShareConnect mess = new NetworkShareConnect();
    264. if (mess.connectToShare(networkPath, "test", "Admin123") != "OK")
    265. {
    266. MessageBox.Show($@"{networkPath}:服务器连接失败", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    267. return false;
    268. }
    269. }
    270. if (System.IO.File.Exists($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}"))
    271. System.IO.File.Delete($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}");
    272. if (System.IO.File.Exists($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}"))
    273. {
    274. MessageBox.Show($"打印模板:{fileName}名称在服务器中已存在", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    275. return false;
    276. }
    277. else
    278. {
    279. //MessageBox.Show(txt_PrintModelSample.Text);
    280. //MessageBox.Show(networkPath);
    281. System.IO.File.Copy(uploadFilePath, $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}");
    282. if (System.IO.File.Exists($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}") == true)
    283. {
    284. templateName = $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}";
    285. return true;
    286. }
    287. else
    288. {
    289. MessageBox.Show($"打印模板:{fileName}上传服务器失败", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    290. return false;
    291. }
    292. }
    293. }
    294. }
    295. catch (Exception ex)
    296. {
    297. MessageBox.Show(ex.Message, "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
    298. return false;
    299. }
    300. return false;
    301. }
    302. #endregion
    303. }
    304. }

    1.条码打印实现类

    1. using ServerSide.Models;
    2. using System;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5. using System.Text;
    6. using System.Threading.Tasks;
    7. namespace ServerSide.Common
    8. {
    9. public class BarTenderHelper
    10. {
    11. public event Action<string> callBack;
    12. private PrintConfigEntity pcEntity;
    13. private BarTender.Application btapp;//引用方法1
    14. private BarTender.Format btformat;//引用方法2
    15. public BarTenderHelper(PrintConfigEntity pcfEntity)
    16. {
    17. this.pcEntity= pcfEntity;
    18. }
    19. #region 条码打印
    20. public Boolean BarTenderPrint()
    21. {
    22. try
    23. {
    24. this.btapp = new BarTender.Application();
    25. this.btformat = this.btapp.Formats.Open(this.pcEntity.PTemplate, false, "");//设置模板文件
    26. this.btformat.PrintSetup.NumberSerializedLabels = Convert.ToInt32(this.pcEntity.PCount);//设置打印份数
    27. this.pcEntity.ScanDt.ForEach((d) => {
    28. this.btformat.SetNamedSubStringValue(d.BarCodeName, d.BarCodeString);
    29. });
    30. this.btformat.PrintOut(true,Convert.ToBoolean(this.pcEntity.IsShowPrint));//打印提示
    31. this.btapp.Quit(BarTender.BtSaveOptions.btPromptSave);//退出并改变BarTender模板
    32. return true;
    33. }
    34. catch (Exception ex)
    35. {
    36. this.callBack(ex.Message);
    37. return false;
    38. }
    39. }
    40. #endregion
    41. }
    42. }

    实体类

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel.DataAnnotations;
    4. using System.ComponentModel.DataAnnotations.Schema;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. namespace ServerSide.Models
    9. {
    10. #region 配置动态字段信息
    11. public class ConfigBarCodeInfoEntity
    12. {
    13. ///
    14. /// 配置动态条码ID
    15. ///
    16. [Key]
    17. [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
    18. public int ?cfBarCodeID { get; set; }
    19. ///
    20. /// 动态字段名称
    21. ///
    22. [Required]//不允许为空
    23. [StringLength(50)]
    24. public string? ConfigBarCodeName { get; set; }
    25. ///
    26. /// 项目描述
    27. ///
    28. [Required]
    29. [StringLength(80)]
    30. public string? ConfigDescription { get; set; }
    31. public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间
    32. }
    33. #endregion
    34. }
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel.DataAnnotations;
    4. using System.ComponentModel.DataAnnotations.Schema;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. namespace ServerSide.Models
    9. {
    10. ///
    11. /// 条码配置
    12. ///
    13. public class BarCodeCfig
    14. {
    15. ///
    16. /// 配置ID
    17. ///
    18. [Key]
    19. [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
    20. public int ?CfigId { get; set; }
    21. ///
    22. /// 客户ID
    23. ///
    24. [ForeignKey("ClientId")]//设置导航属性
    25. //public ClientInfo? ClientInfo { get; set; }
    26. public int? ClientId { get; set; }//外键
    27. ///
    28. /// 产品ID
    29. ///
    30. [ForeignKey("ProductId")]//设置导航属性
    31. //public ProductNames? ProductNames { get; set; }
    32. public int? ProductId { get; set; }//外键
    33. ///
    34. /// 订单ID
    35. ///
    36. [ForeignKey("WorkOrderId")]//设置导航属性
    37. //public ProductNames? ProductNames { get; set; }
    38. public int? WorkOrderId { get; set; }//外键
    39. ///
    40. /// 工序ID
    41. ///
    42. [ForeignKey("PrsInfoID")]//设置导航属性
    43. //public Processinformation? Processinformation { get; set; }
    44. public int? PrsInfoID { get; set; }//外键
    45. ///
    46. /// 配置打印模板ID
    47. ///
    48. [Required]//不允许为空
    49. [ForeignKey("BarCodePrintId")]//打印模板ID
    50. //public ConfigBarCodeInfoEntity? ConfigBarCodeInfoEntity { get; set; }
    51. public int? BarCodePrintId { get; set; }//外键
    52. ///
    53. /// 配置参数值
    54. ///
    55. [StringLength(255)]
    56. public string? CfgArgsValue { get; set; }
    57. public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间
    58. }
    59. }
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel.DataAnnotations.Schema;
    4. using System.ComponentModel.DataAnnotations;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. namespace ServerSide.Models
    9. {
    10. ///
    11. /// 配置打印模板
    12. ///
    13. public class ConfigBarCodePrintTemplate
    14. {
    15. ///
    16. /// 打印模板ID
    17. ///
    18. [Key]
    19. [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
    20. public int BarCodePrintId { get; set; }
    21. ///
    22. /// 客户ID
    23. ///
    24. [ForeignKey("ClientId")]//设置导航属性
    25. //public ClientInfo? ClientInfo { get; set; }
    26. public int? ClientId { get; set; }//外键
    27. ///
    28. /// 工序ID
    29. ///
    30. [ForeignKey("PrsInfoID")]//设置导航属性
    31. //public Processinformation? Processinformation { get; set; }
    32. public int? PrsInfoID { get; set; }//外键
    33. ///
    34. /// 模板名称
    35. ///
    36. [Required]
    37. [StringLength(100)]
    38. public string? TempateName { get; set; }
    39. ///
    40. /// 模板下载路径
    41. ///
    42. [Required]
    43. [StringLength(255)]
    44. public string? TempateDownPath { get; set; }
    45. }
    46. }
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel.DataAnnotations.Schema;
    4. using System.ComponentModel.DataAnnotations;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. namespace ServerSide.Models
    9. {
    10. ///
    11. /// 配置打印模板
    12. ///
    13. public class ConfigBarCodePrintTemplate
    14. {
    15. ///
    16. /// 打印模板ID
    17. ///
    18. [Key]
    19. [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
    20. public int BarCodePrintId { get; set; }
    21. ///
    22. /// 客户ID
    23. ///
    24. [ForeignKey("ClientId")]//设置导航属性
    25. //public ClientInfo? ClientInfo { get; set; }
    26. public int? ClientId { get; set; }//外键
    27. ///
    28. /// 工序ID
    29. ///
    30. [ForeignKey("PrsInfoID")]//设置导航属性
    31. //public Processinformation? Processinformation { get; set; }
    32. public int? PrsInfoID { get; set; }//外键
    33. ///
    34. /// 模板名称
    35. ///
    36. [Required]
    37. [StringLength(100)]
    38. public string? TempateName { get; set; }
    39. ///
    40. /// 模板下载路径
    41. ///
    42. [Required]
    43. [StringLength(255)]
    44. public string? TempateDownPath { get; set; }
    45. }
    46. }
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel.DataAnnotations.Schema;
    4. using System.ComponentModel.DataAnnotations;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. namespace ServerSide.Models
    9. {
    10. ///
    11. /// 配置打印模板
    12. ///
    13. public class ConfigBarCodePrintTemplate
    14. {
    15. ///
    16. /// 打印模板ID
    17. ///
    18. [Key]
    19. [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
    20. public int BarCodePrintId { get; set; }
    21. ///
    22. /// 客户ID
    23. ///
    24. [ForeignKey("ClientId")]//设置导航属性
    25. //public ClientInfo? ClientInfo { get; set; }
    26. public int? ClientId { get; set; }//外键
    27. ///
    28. /// 工序ID
    29. ///
    30. [ForeignKey("PrsInfoID")]//设置导航属性
    31. //public Processinformation? Processinformation { get; set; }
    32. public int? PrsInfoID { get; set; }//外键
    33. ///
    34. /// 模板名称
    35. ///
    36. [Required]
    37. [StringLength(100)]
    38. public string? TempateName { get; set; }
    39. ///
    40. /// 模板下载路径
    41. ///
    42. [Required]
    43. [StringLength(255)]
    44. public string? TempateDownPath { get; set; }
    45. }
    46. }
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel.DataAnnotations;
    4. using System.ComponentModel.DataAnnotations.Schema;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. namespace ServerSide.Models
    9. {
    10. #region 配置打印的订单信息
    11. public class ConfigBarCodeOrderInfoEntity
    12. {
    13. ///
    14. /// 订单ID
    15. ///
    16. [Key]
    17. [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
    18. public int WorkOrderId { get; set; }
    19. ///
    20. /// 产品ID
    21. ///
    22. [ForeignKey("ProductId")]//设置导航属性
    23. //public ProductNames? ProductNames { get; set; }
    24. public int? ProductId { get; set; }//外键
    25. ///
    26. /// 订单号
    27. ///
    28. [Required]
    29. [StringLength(150)]
    30. public string ?OrderInfo { get; set; }
    31. ///
    32. /// 订单总数
    33. ///
    34. [Required]
    35. public int? OrderCount { get; set; }
    36. ///
    37. /// 外箱序号
    38. ///
    39. [Required]
    40. [StringLength(100)]
    41. public string ?CartonSerialNumber { get; set; }
    42. ///
    43. /// 机身扫描总数
    44. ///
    45. [Required]
    46. public int? FuselageScanCount { get; set; } = 0;
    47. ///
    48. /// 彩盒扫描总数
    49. ///
    50. [Required]
    51. public int? GiftBoxScanCount { get; set; } = 0;
    52. ///
    53. /// 外箱扫描总数
    54. ///
    55. [Required]
    56. public int? MasterCartonScanCount { get; set; } = 0;
    57. ///
    58. /// 装箱绑码数
    59. ///
    60. [Required]
    61. public int PackingBindingCode { get; set; } = 1;
    62. public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间
    63. }
    64. #endregion
    65. }
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel.DataAnnotations;
    4. using System.ComponentModel.DataAnnotations.Schema;
    5. using System.Linq;
    6. using System.Text;
    7. using System.Threading.Tasks;
    8. namespace ServerSide.Models
    9. {
    10. ///
    11. /// 产品名称
    12. ///
    13. public class ProductNames
    14. {
    15. ///
    16. /// 产品ID
    17. ///
    18. [Key]
    19. [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
    20. public int? ProductId { get; set; }
    21. ///
    22. /// 客户ID
    23. ///
    24. [ForeignKey("ClientId")]//设置导航属性
    25. //public ClientInfo? ClientInfo { get; set; }
    26. public int? ClientId { get; set; }//外键
    27. ///
    28. /// 产品名称
    29. ///
    30. [Required]
    31. [StringLength(100)]
    32. public string? ProductName { get; set; }
    33. public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间
    34. }
    35. }

  • 相关阅读:
    《低代码指南》——维格云和Airtable的比较
    “2024杭州国际物联网展览会”定于4月份在杭州国际博览中心召开
    网络安全(黑客)自学
    RPA在票据处理中的应用
    微信小程序报request:fail url not in domain list的解决方法
    Maven dependency 详解
    栈和队列1——栈的实现及其oj(括号匹配问题)
    JVM 双亲委派模型
    【网络服务&数据库教程】09 Rsync 实操
    【Visual Leak Detector】核心源码剖析(VLD 2.5.1)
  • 原文地址:https://blog.csdn.net/u013934107/article/details/134097988