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

条码打印基于:BarTender、ORM EF架构

UI展示:

主页代码:

using NPOI.OpenXmlFormats.Spreadsheet;
using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlantProcessControlSystem.BarCodePrint
{
    //tss_nowdate
    public partial class Main_BarCodePrint_Frm : Form
    {
        private System.Windows.Forms.Timer timer;
        //1.声明自适应类实例  
        private AutoSizeFormClass asc = null;
        private AutoSetControlSize ass = null;

        public Main_BarCodePrint_Frm()
        {
            InitializeComponent();
            ass = new AutoSetControlSize(this, this.Width, this.Height);
        }

        #region 窗体控件事件
        private void btn_Close_Click(object sender, EventArgs e)
        {
            if (((Button)sender).Name == "btn_Close")//窗体关闭
            {
                //DialogResult result = MessageBox.Show("是否确认退出??","提醒",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
                //if (result == DialogResult.Yes)
                //    Application.Exit();
                //else
                //    return;
                //this.Hide();//隐藏
                //tlrm_Show.Enabled = true;//控件可使用
                Environment.Exit(0);
                //Application.Exit();
            }
            else if (((Button)sender).Name == "btn_WinMinSize")//窗体最小化
            {
                this.WindowState = FormWindowState.Minimized;
            }
            else if (((Button)sender).Name == "btn_WinMaxSize")//窗体最大化
            {
                if (this.WindowState == FormWindowState.Normal)
                    this.WindowState = FormWindowState.Maximized;
                else
                    this.WindowState = FormWindowState.Normal;
            }
        }
        #endregion

        #region 时间同步
        private void Timer_Tick(object sender, EventArgs e)
        {
            tss_nowdate.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }
        #endregion

        #region 窗体加载
        private void Main_BarCodePrint_Frm_Load(object sender, EventArgs e)
        {
            timer = new System.Windows.Forms.Timer();
            timer.Interval = 1000;
            timer.Tick += Timer_Tick;
            timer.Enabled = true;
        }
        #endregion

        #region 窗体移动
        private Point mouseOff;//鼠标移动位置变量
        private bool leftFlag;//标签是否为左键

        private void Frm_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                leftFlag = true;                  //点击左键按下时标注为true;
            }
        }

        private void Frm_MouseMove(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                Location = mouseSet;
            }
        }

        private void Frm_MouseUp(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为false;
            }
        }
        #endregion

        #region 移动鼠标
        private void MainFrm_Move(object sender, EventArgs e)
        {
            // 获取当前鼠标的坐标
            Point cursorPosition = Cursor.Position;
            TS_X.Text = cursorPosition.X.ToString();
            TS_Y.Text = cursorPosition.Y.ToString();
            tss_State.Text = "当前状态:操作";
        }
        #endregion

        #region 装载窗体
        /// <summary>
        /// 装载窗体
        /// </summary>
        /// <param name="childFrom"></param>
        private void OpenForm(Form childFrom)
        {
            //首先判断容器中是否有其他的窗体
            foreach (Control item in this.Panel_Winfrm.Controls)
            {
                if (item is Form)
                {
                    ((Form)item).Close();
                }
            }
            //嵌入新的窗体
            childFrom.TopLevel = false;//将子窗体设置成非顶级控件
            // childFrom.FormBorderStyle = FormBorderStyle.None;//去掉窗体边框(目前不需要了)
            childFrom.Parent = this.Panel_Winfrm;//设置窗体的容器
            childFrom.Dock = DockStyle.Fill;//随着容器大小自动调整窗体大小(目前可能没有效果)
            childFrom.Show();
        }
        #endregion

        #region 窗体自适应
        private void MainFrm_SizeChanged(object sender, EventArgs e)
        {
            asc = new AutoSizeFormClass(this);
            asc.controlAutoSize(this);
        }

        private void MainFrm_Resize(object sender, EventArgs e)
        {
            ass.setControls((this.Width) / ass.X, (this.Height) / ass.Y, this);
        }
        #endregion

        #region 树形菜单单击事件
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Text == "配置.客户信息")
            {
                CfgClientInfoFrm cfgClientInfoFrm = new CfgClientInfoFrm();
                this.OpenForm(cfgClientInfoFrm);
            }
            else if (e.Node.Text == "配置.产品信息")
            {
                CfgProductInfoFrm cfgProductInfoFrm = new CfgProductInfoFrm();
                this.OpenForm(cfgProductInfoFrm);
            }
            else if (e.Node.Text == "配置.订单信息")
            {
                CfgOrderInfoFrm cfgOrderInfoFrm = new CfgOrderInfoFrm();
                this.OpenForm(cfgOrderInfoFrm);
            }
            else if (e.Node.Text == "配置.条码工序信息")
            {
                CfgBarCodeWkInfoFrm cfgBarCodeWkInfoFrm = new CfgBarCodeWkInfoFrm();
                this.OpenForm(cfgBarCodeWkInfoFrm);
            }
            else if ((e.Node.Text == "在线.条码打印"))
            {
                OnLineBarCodePrintFrm onLineBarCodePrintFrm = new OnLineBarCodePrintFrm();
                this.OpenForm(onLineBarCodePrintFrm);
            }
            else if (e.Node.Text == "配置.打印模板")
            {
                CfgBarCodePrintTemplateFrm cfgBarCodePrintTemplateFrm = new CfgBarCodePrintTemplateFrm();
                this.OpenForm(cfgBarCodePrintTemplateFrm);
            }
            else if (e.Node.Text == "配置.条码打印参数")
            {
                CfgBarCodePrintInfoFrm cfgBarCodePrintInfoFrm = new CfgBarCodePrintInfoFrm();
                cfgBarCodePrintInfoFrm.callBack += new Action<bool>((b) =>
                {
                    if (b == false) this.Hide();
                    else this.Show();

                });
                this.OpenForm((cfgBarCodePrintInfoFrm));
            }
            else if (e.Node.Text == "配置.动态字段")
            {
                CfgBarCodeInfoFrm cfgBarCodeInfoFrm = new CfgBarCodeInfoFrm();
                this.OpenForm(cfgBarCodeInfoFrm);
            }
        }
        #endregion
    }
}

using ServerSide.DAL;
using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlantProcessControlSystem.BarCodePrint
{
    public partial class CfgBarCodeWkInfoFrm : Form
    {
        private List<Processinformation> processinformations;//工序信息
        private Processinformation oldProcessinformation;//旧的工序信息
        public string errInfo;//错误信息
        public CfgBarCodeWkInfoFrm()
        {
            InitializeComponent();
        }

        #region 初始化界面
        private void InitWinFrmTable()
        {
            using (EFContext db = new EFContext())
            {
                this.processinformations = new List<Processinformation>();
                this.processinformations = db!.Processinformation!.ToList();
                this.dataSource.DataSource = processinformations;

                txt_Process.Text = "";
                txt_Process.Enabled = false;
            }
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.dataSource.ClearSelection();
        }
        #endregion

        #region 返回
        private void btn_Result_Click(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
            this.pe_Processinfo.Visible = false;
        }
        #endregion

        #region 添加
        private void btn_Add_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "添加";
            this.pe_Processinfo.Visible = true;
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.txt_Process.Text = "";
            this.oldProcessinformation = null;
            this.txt_Process.Enabled = true;
        }
        #endregion

        #region 删除
        private void btn_Del_Click(object sender, EventArgs e)
        {
            this.pe_Processinfo.Visible = true;
            this.lbl_ItemName.Text = "删除";
            this.txt_Process.Enabled = false;
            this.btn_Save.Focus();
        }
        #endregion

        #region 修改
        private void btn_Rework_Click(object sender, EventArgs e)
        {
            this.pe_Processinfo.Visible = true;
            this.lbl_ItemName.Text = "修改";
            this.txt_Process.Enabled = true;
            this.txt_Process.SelectAll();
            this.txt_Process.Focus();
        }
        #endregion

        #region 保存
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (txt_Process.Text != string.Empty && txt_Process.Text.Length > 0)
            {
                using (EFContext db = new EFContext())
                {
                    if (lbl_ItemName.Text == "添加")
                    {
                        Processinformation processinformation = new Processinformation
                        {
                            PrsName = txt_Process.Text
                        };
                        db?.Processinformation?.Add(processinformation);
                    }
                    else if (lbl_ItemName.Text == "修改")
                    {
                        db!.Processinformation!.ToList().ForEach((p) =>
                        {
                            if (p.PrsInfoID == oldProcessinformation.PrsInfoID)
                                p.PrsName = txt_Process.Text;
                        });
                    }
                    else if (lbl_ItemName.Text == "删除")
                    {
                        db?.Processinformation?.Remove(oldProcessinformation);
                    }
                    int result = db!.SaveChanges();
                    if (result <= 0)
                        MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.pe_Processinfo.Visible = false;
                this.InitWinFrmTable();
            }
        }
        #endregion

        #region 窗体加载
        private void CfgBarCodeWkInfoFrm_Load(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
            this.dataSource.ClearSelection();
        }
        #endregion

        #region 点击选择
        private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    if (processinformations[e.RowIndex] != null)
                    {
                        this.oldProcessinformation = new Processinformation();
                        this.oldProcessinformation = processinformations[e.RowIndex];
                        this.btn_Del.Enabled = true;
                        this.btn_Rework.Enabled = true;

                        this.txt_Process.Text = processinformations[e.RowIndex].PrsName;
                    }
                    else
                    {
                        this.btn_Del.Enabled = false;
                        this.btn_Rework.Enabled = false;
                    }
                }
                this.pe_Processinfo.Visible = false;
            }
            catch (Exception ex)
            {
                this.errInfo = string.Empty;
                MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        #endregion
    }
}

using ServerSide.DAL;
using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlantProcessControlSystem.BarCodePrint
{
    public partial class CfgProductInfoFrm : Form
    {
        private List<ProductNames> productNames;//产品名称
        private ProductNames oldproductName;
        private string ErrInfo;//错误信息
        public CfgProductInfoFrm()
        {
            InitializeComponent();
        }

        #region 初始化界面
        private void InitWinFrmTable()
        {
            using (EFContext db = new EFContext())
            {
                productNames = new List<ProductNames>();
                productNames = db!.ProductNames!.ToList();
                this.dataSource.DataSource = productNames;

                cmb_Client.Items.Clear();
                db!.ClientInfo!.ToList().ForEach((c) => cmb_Client.Items.Add(c.ClientName));

                txt_ProductName.Text = "";
                txt_ProductName.Enabled = false;
                cmb_Client.Enabled = true;

            }
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.dataSource.ClearSelection();
        }
        #endregion

        #region 窗体加载
        private void CfgProductInfoFrm_Load(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
        }
        #endregion

        #region 修改
        private void btn_Rework_Click(object sender, EventArgs e)
        {
            this.pe_ProductInfo.Visible = true;
            this.lbl_ItemName.Text = "修改";
            this.txt_ProductName.SelectAll();
            this.txt_ProductName.Focus();
        }
        #endregion

        #region 册除
        private void btn_Del_Click(object sender, EventArgs e)
        {
            this.pe_ProductInfo.Visible = true;
            this.lbl_ItemName.Text = "删除";
            this.txt_ProductName.Enabled = false;
            this.cmb_Client.Enabled = false;

        }
        #endregion

        #region 添加
        private void btn_Add_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "添加";
            this.pe_ProductInfo.Visible = true;
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.txt_ProductName.Text = "";
            this.oldproductName = null;
        }
        #endregion

        #region 返回
        private void btn_Result_Click(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
            this.pe_ProductInfo.Visible = false;
        }
        #endregion

        #region 保存
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (txt_ProductName.Text != string.Empty && txt_ProductName.Text.Length > 0)
            {
                using (EFContext db = new EFContext())
                {
                    if (lbl_ItemName.Text == "添加")
                    {
                        ProductNames productNames = new ProductNames
                        {
                            ClientId = db?.ClientInfo?.ToList()?.Where(c => c.ClientName == cmb_Client.Text)?.FirstOrDefault()?.ClientId,
                            ProductName = txt_ProductName.Text
                        };
                        db?.ProductNames?.Add(productNames);
                    }
                    else if (lbl_ItemName.Text == "修改")
                    {
                        oldproductName.ProductName = txt_ProductName.Text;
                        db?.ProductNames?.ToList().ForEach(p =>
                        {
                            if (p.ProductId == oldproductName.ProductId)
                                p.ProductName = txt_ProductName.Text;
                        });
                    }
                    else if (lbl_ItemName.Text == "删除")
                    {
                        db?.ProductNames?.Remove(oldproductName);
                    }
                    int result = db.SaveChanges();
                    if (result <= 0) MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            this.pe_ProductInfo.Visible = false;
            this.InitWinFrmTable();

        }
        #endregion

        #region 选择客户名称
        private void cmb_Client_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmb_Client.Text != string.Empty)
            {
                txt_ProductName.Enabled = true;
                txt_ProductName.Focus();
            }
        }
        #endregion

        #region 点击选择
        private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    if (productNames[e.RowIndex] != null)
                    {
                        //txt_UserName.Text = allAuthorizedUsers[e.RowIndex].UserName;
                        //txt_NickName.Text = allAuthorizedUsers[e.RowIndex].NickName;
                        //pte_Image.Image = ImageHelper.ByteToImage(allAuthorizedUsers[e.RowIndex].Picture);
                        //pnl_Edit.Visible = true;
                        using (EFContext db = new EFContext())
                        {
                            this.cmb_Client.Text = db?.ClientInfo?.ToList()?.Where(c => c?.ClientId == productNames[e.RowIndex]?.ClientId)?.FirstOrDefault()?.ClientName;
                        }
                        this.oldproductName = new ProductNames();
                        this.oldproductName = productNames[e.RowIndex];
                        this.btn_Del.Enabled = true;
                        this.btn_Rework.Enabled = true;

                        this.txt_ProductName.Text = productNames[e.RowIndex].ProductName;
                        //this.btn_Query.Enabled = true;
                    }
                    else
                    {
                        this.btn_Del.Enabled = false;
                        this.btn_Rework.Enabled = false;
                    }
                }
                this.pe_ProductInfo.Visible = false;
            }
            catch (Exception ex)
            {
                //LogHelper.Error("授权信息", ex);
                this.ErrInfo = string.Empty;
                MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //WMessageBox wMessageBox = new WMessageBox(ex.Message, Color.Red);
            }
        }
        #endregion
    }
}

using NPOI.OpenXmlFormats.Spreadsheet;
using ServerSide.DAL;
using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlantProcessControlSystem.BarCodePrint
{
    public partial class CfgOrderInfoFrm : Form
    {
        private List<ConfigBarCodeOrderInfoEntity> configBarCodeOrderInfoEntities;//配置订单信息
        private ConfigBarCodeOrderInfoEntity oldconfigBarCodeOrderInfoEntity;//
        public string ErrInfo;//错误日志
        public CfgOrderInfoFrm()
        {
            InitializeComponent();
            this.InitWinFrmTable();
        }

        #region 初始化界面
        private void InitWinFrmTable()
        {
            using (EFContext db = new EFContext())
            {
                configBarCodeOrderInfoEntities = new List<ConfigBarCodeOrderInfoEntity>();
                db?.ConfigBarCodeOrderInfoEntity?.ToList().ForEach(c => configBarCodeOrderInfoEntities.Add(c));
                dtgv_dataSource.DataSource = configBarCodeOrderInfoEntities;//数据源

                cmb_ProductName.Text = "";//产品名称
                cmb_ProductName.Items.Clear();
                db?.ProductNames?.ToList().ForEach(p => cmb_ProductName.Items.Add(p.ProductName));
                txt_OrderNum.Text = "";//订单号

                txt_BoxNum.Text = "";//外箱序号
                txt_OrderTotal.Text = "";//订单总数

                cmb_Binding_Nbr.Text = "";//绑码数
                cmb_Binding_Nbr.Items.Clear();
                for (int i = 1; i <= 60; i++)
                    cmb_Binding_Nbr.Items.Add(i.ToString());
            }

            btn_Del.Enabled = false;//删除
            btn_Rework.Enabled = false;//修改
            btn_Query.Enabled = false;//查询

            this.txt_OrderNum.Enabled = true;
            this.cmb_ProductName.Enabled = true;
            this.txt_BoxNum.Enabled = true;
            this.txt_OrderTotal.Enabled = true;
            this.cmb_Binding_Nbr.Enabled = true;
            pe_OrderInfo.Visible = false;

        }
        #endregion

        #region 添加
        private void btn_Add_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "添加";
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            oldconfigBarCodeOrderInfoEntity = null;
            this.InitWinFrmTable();
            this.pe_OrderInfo.Visible = true;
        }
        #endregion

        #region 删除
        private void btn_Del_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "删除";
            this.pe_OrderInfo.Visible = true;
            this.txt_OrderNum.Enabled = false;
            this.cmb_ProductName.Enabled = false;
            this.txt_BoxNum.Enabled = false;
            this.txt_OrderTotal.Enabled = false;
            this.cmb_Binding_Nbr.Enabled = false;
        }
        #endregion

        #region 修改
        private void btn_Rework_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "修改";
            this.txt_OrderNum.Enabled = true;
            this.cmb_ProductName.Enabled = true;
            this.txt_BoxNum.Enabled = true;
            this.txt_OrderTotal.Enabled = true;
            this.cmb_Binding_Nbr.Enabled = true;
            this.pe_OrderInfo.Visible = true;
        }
        #endregion

        #region 保存
        private void btn_Save_Click(object sender, EventArgs e)
        {
            using (EFContext db = new EFContext())
            {
                if (txt_BoxNum.Text != string.Empty &&
                    txt_OrderNum.Text != string.Empty &&
                    txt_OrderTotal.Text != string.Empty &&
                    cmb_Binding_Nbr.Text != string.Empty &&
                    cmb_ProductName.Text != string.Empty)
                {
                    if (this.lbl_ItemName.Text == "添加")
                    {
                        oldconfigBarCodeOrderInfoEntity = new ConfigBarCodeOrderInfoEntity
                        {
                            OrderInfo = txt_OrderNum.Text.Trim(),
                            ProductId = db?.ProductNames?.ToList()?.Where(p => p.ProductName == cmb_ProductName.Text)?.FirstOrDefault()?.ProductId,
                            OrderCount = Convert.ToInt32(txt_OrderTotal.Text.Trim()),
                            CartonSerialNumber = txt_BoxNum?.Text.Trim(),
                            PackingBindingCode = Convert.ToInt32(cmb_Binding_Nbr.Text.Trim()),
                            FuselageScanCount = 0,
                            GiftBoxScanCount = 0,
                            MasterCartonScanCount = 0
                        };
                        db?.ConfigBarCodeOrderInfoEntity?.Add(oldconfigBarCodeOrderInfoEntity);
                    }
                    else if (this.lbl_ItemName.Text == "修改")
                    {
                        db?.ConfigBarCodeOrderInfoEntity?.ToList().ForEach((c) =>
                        {
                            if (c.WorkOrderId == oldconfigBarCodeOrderInfoEntity.WorkOrderId)
                            {
                                c.OrderInfo = txt_OrderNum.Text.Trim();
                                c.ProductId = db?.ProductNames?.ToList()?.Where(p => p?.ProductName?.Trim() == cmb_ProductName.Text.Trim())?.FirstOrDefault()?.ProductId;
                                c.OrderCount = Convert.ToInt32(txt_OrderTotal.Text.Trim());
                                c.CartonSerialNumber = txt_BoxNum?.Text.Trim();
                                c.PackingBindingCode = Convert.ToInt32(cmb_Binding_Nbr?.Text.Trim());
                            }
                        });
                    }
                    else if (this.lbl_ItemName.Text == "删除")
                    {
                        db?.ConfigBarCodeOrderInfoEntity?.Remove(oldconfigBarCodeOrderInfoEntity);
                    }
                    int result = db!.SaveChanges();
                    if (result <= 0) MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.pe_OrderInfo.Visible = false;
                    this.InitWinFrmTable();//初始化界面
                }
            }
        }
        #endregion

        #region 表单选择
        private void dtgv_dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    if (configBarCodeOrderInfoEntities[e.RowIndex] != null)
                    {
                        this.oldconfigBarCodeOrderInfoEntity = new ConfigBarCodeOrderInfoEntity();
                        this.oldconfigBarCodeOrderInfoEntity.WorkOrderId = configBarCodeOrderInfoEntities[e.RowIndex].WorkOrderId;
                        this.oldconfigBarCodeOrderInfoEntity.ProductId = configBarCodeOrderInfoEntities[e.RowIndex].ProductId;
                        this.oldconfigBarCodeOrderInfoEntity.OrderInfo = configBarCodeOrderInfoEntities[e.RowIndex].OrderInfo;
                        this.oldconfigBarCodeOrderInfoEntity.CartonSerialNumber = configBarCodeOrderInfoEntities[e.RowIndex].CartonSerialNumber;
                        this.oldconfigBarCodeOrderInfoEntity.OrderCount = configBarCodeOrderInfoEntities[e.RowIndex].OrderCount;
                        this.oldconfigBarCodeOrderInfoEntity.FuselageScanCount = configBarCodeOrderInfoEntities[e.RowIndex].FuselageScanCount;
                        this.oldconfigBarCodeOrderInfoEntity.GiftBoxScanCount = configBarCodeOrderInfoEntities[e.RowIndex].GiftBoxScanCount;
                        this.oldconfigBarCodeOrderInfoEntity.MasterCartonScanCount = configBarCodeOrderInfoEntities[e.RowIndex].MasterCartonScanCount;
                        this.oldconfigBarCodeOrderInfoEntity.PackingBindingCode = configBarCodeOrderInfoEntities[e.RowIndex].PackingBindingCode;

                        this.txt_OrderNum.Text = configBarCodeOrderInfoEntities[e.RowIndex].OrderInfo;//订单数
                        this.txt_OrderTotal.Text = configBarCodeOrderInfoEntities[e.RowIndex].OrderCount.ToString();//订单总数
                        using (EFContext db = new EFContext())
                        {
                            this.cmb_ProductName.Text = db?.ProductNames?.ToList()?.Where(p => p.ProductId == configBarCodeOrderInfoEntities[e.RowIndex].ProductId)?.FirstOrDefault()?.ProductName;//产品名称
                        }
                        this.txt_BoxNum.Text = configBarCodeOrderInfoEntities[e.RowIndex].CartonSerialNumber;//外箱
                        //this.txt_OrderTotal.Text = configBarCodeOrderInfoEntities[e.RowIndex].OrderCount.ToString();//订单总数
                        this.cmb_Binding_Nbr.Text = configBarCodeOrderInfoEntities[e.RowIndex].PackingBindingCode.ToString();//绑码数
                    }
                }
                this.pe_OrderInfo.Visible = false;
                btn_Del.Enabled = e.RowIndex >= 0 ? true : false;
                btn_Rework.Enabled = e.RowIndex >= 0 ? true : false;

            }
            catch (Exception ex)
            {
                this.ErrInfo = $@"{ex.Message}";

                MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        #endregion

        #region 返回
        private void btn_Result_Click(object sender, EventArgs e)
        {
            this.pe_OrderInfo.Visible = false;
            this.InitWinFrmTable();
        }
        #endregion
    }
}

using ServerSide.DAL;
using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlantProcessControlSystem.BarCodePrint
{
    public partial class CfgBarCodeWkInfoFrm : Form
    {
        private List<Processinformation> processinformations;//工序信息
        private Processinformation oldProcessinformation;//旧的工序信息
        public string errInfo;//错误信息
        public CfgBarCodeWkInfoFrm()
        {
            InitializeComponent();
        }

        #region 初始化界面
        private void InitWinFrmTable()
        {
            using (EFContext db = new EFContext())
            {
                this.processinformations = new List<Processinformation>();
                this.processinformations = db!.Processinformation!.ToList();
                this.dataSource.DataSource = processinformations;

                txt_Process.Text = "";
                txt_Process.Enabled = false;
            }
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.dataSource.ClearSelection();
        }
        #endregion

        #region 返回
        private void btn_Result_Click(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
            this.pe_Processinfo.Visible = false;
        }
        #endregion

        #region 添加
        private void btn_Add_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "添加";
            this.pe_Processinfo.Visible = true;
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.txt_Process.Text = "";
            this.oldProcessinformation = null;
            this.txt_Process.Enabled = true;
        }
        #endregion

        #region 删除
        private void btn_Del_Click(object sender, EventArgs e)
        {
            this.pe_Processinfo.Visible = true;
            this.lbl_ItemName.Text = "删除";
            this.txt_Process.Enabled = false;
            this.btn_Save.Focus();
        }
        #endregion

        #region 修改
        private void btn_Rework_Click(object sender, EventArgs e)
        {
            this.pe_Processinfo.Visible = true;
            this.lbl_ItemName.Text = "修改";
            this.txt_Process.Enabled = true;
            this.txt_Process.SelectAll();
            this.txt_Process.Focus();
        }
        #endregion

        #region 保存
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (txt_Process.Text != string.Empty && txt_Process.Text.Length > 0)
            {
                using (EFContext db = new EFContext())
                {
                    if (lbl_ItemName.Text == "添加")
                    {
                        Processinformation processinformation = new Processinformation
                        {
                            PrsName = txt_Process.Text
                        };
                        db?.Processinformation?.Add(processinformation);
                    }
                    else if (lbl_ItemName.Text == "修改")
                    {
                        db!.Processinformation!.ToList().ForEach((p) =>
                        {
                            if (p.PrsInfoID == oldProcessinformation.PrsInfoID)
                                p.PrsName = txt_Process.Text;
                        });
                    }
                    else if (lbl_ItemName.Text == "删除")
                    {
                        db?.Processinformation?.Remove(oldProcessinformation);
                    }
                    int result = db!.SaveChanges();
                    if (result <= 0)
                        MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.pe_Processinfo.Visible = false;
                this.InitWinFrmTable();
            }
        }
        #endregion

        #region 窗体加载
        private void CfgBarCodeWkInfoFrm_Load(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
            this.dataSource.ClearSelection();
        }
        #endregion

        #region 点击选择
        private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    if (processinformations[e.RowIndex] != null)
                    {
                        this.oldProcessinformation = new Processinformation();
                        this.oldProcessinformation = processinformations[e.RowIndex];
                        this.btn_Del.Enabled = true;
                        this.btn_Rework.Enabled = true;

                        this.txt_Process.Text = processinformations[e.RowIndex].PrsName;
                    }
                    else
                    {
                        this.btn_Del.Enabled = false;
                        this.btn_Rework.Enabled = false;
                    }
                }
                this.pe_Processinfo.Visible = false;
            }
            catch (Exception ex)
            {
                this.errInfo = string.Empty;
                MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        #endregion
    }
}

using ServerSide.DAL;
using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlantProcessControlSystem.BarCodePrint
{
    public partial class CfgBarCodeInfoFrm : Form
    {
        private List<ConfigBarCodeInfoEntity> configBarCodeInfoEntitys;//配置动态字段信息
        private ConfigBarCodeInfoEntity oldConfigBarCodeInfoEntity;//旧的配置动态字段信息
        public string errInfo;//错误信息
        public CfgBarCodeInfoFrm()
        {
            InitializeComponent();
        }

        #region 初始化界面
        private void InitWinFrmTable()
        {
            using (EFContext db = new EFContext())
            {
                this.configBarCodeInfoEntitys = new List<ConfigBarCodeInfoEntity>();
                this.configBarCodeInfoEntitys = db!.ConfigBarCodeInfoEntity!.ToList();
                this.dataSource.DataSource = this.configBarCodeInfoEntitys;

                txt_Process.Text = "";
                txt_Process.Enabled = false;

                txt_Description.Text = "";
                txt_Description.Enabled = false;
            }
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.dataSource.ClearSelection();
        }
        #endregion

        #region 返回
        private void btn_Result_Click(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
            this.pe_Processinfo.Visible = false;
        }
        #endregion

        #region 添加
        private void btn_Add_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "添加";
            this.pe_Processinfo.Visible = true;
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.txt_Process.Text = "";
            this.oldConfigBarCodeInfoEntity = null;
            this.txt_Process.Enabled = true;
            this.txt_Description.Enabled = true;
        }
        #endregion

        #region 删除
        private void btn_Del_Click(object sender, EventArgs e)
        {
            this.pe_Processinfo.Visible = true;
            this.lbl_ItemName.Text = "删除";
            this.txt_Process.Enabled = false;
            this.txt_Description.Enabled = false;
            this.btn_Save.Focus();
        }
        #endregion

        #region 修改
        private void btn_Rework_Click(object sender, EventArgs e)
        {
            this.pe_Processinfo.Visible = true;
            this.lbl_ItemName.Text = "修改";
            this.txt_Process.Enabled = true;
            this.txt_Description.Enabled = true;
            this.txt_Process.SelectAll();
            this.txt_Process.Focus();
        }
        #endregion

        #region 保存
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if ((txt_Process.Text != string.Empty && txt_Process.Text.Length > 0)&&
                (txt_Description.Text!=string.Empty&&txt_Description.Text.Length>0))
            {
                using (EFContext db = new EFContext())
                {
                    if (lbl_ItemName.Text == "添加")
                    {
                        ConfigBarCodeInfoEntity configBarCodeInfoEntity = new ConfigBarCodeInfoEntity
                        {
                            ConfigBarCodeName = txt_Process.Text,
                            ConfigDescription=txt_Description.Text
                        };
                        db?.ConfigBarCodeInfoEntity?.Add(configBarCodeInfoEntity);
                    }
                    else if (lbl_ItemName.Text == "修改")
                    {
                        db!.ConfigBarCodeInfoEntity!.ToList().ForEach((p) =>
                        {
                            if (p.cfBarCodeID == oldConfigBarCodeInfoEntity.cfBarCodeID)
                            {
                                p.ConfigBarCodeName = txt_Process.Text;
                                p.ConfigDescription=txt_Description.Text;
                            }  
                        });
                    }
                    else if (lbl_ItemName.Text == "删除")
                    {
                        db?.ConfigBarCodeInfoEntity?.Remove(oldConfigBarCodeInfoEntity);
                    }
                    int result = db!.SaveChanges();
                    if (result <= 0)
                        MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.pe_Processinfo.Visible = false;
                this.InitWinFrmTable();
            }
        }
        #endregion

        #region 窗体加载
        private void CfgBarCodeWkInfoFrm_Load(object sender, EventArgs e)
        {
            this.InitWinFrmTable();
            this.dataSource.ClearSelection();
        }
        #endregion

        #region 点击选择
        private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    if (configBarCodeInfoEntitys[e.RowIndex] != null)
                    {
                        this.oldConfigBarCodeInfoEntity = new ConfigBarCodeInfoEntity();
                        this.oldConfigBarCodeInfoEntity = configBarCodeInfoEntitys[e.RowIndex];
                        this.btn_Del.Enabled = true;
                        this.btn_Rework.Enabled = true;

                        this.txt_Process.Text = configBarCodeInfoEntitys[e.RowIndex].ConfigBarCodeName;
                        this.txt_Description.Text = configBarCodeInfoEntitys[e.RowIndex].ConfigDescription;
                    }
                    else
                    {
                        this.btn_Del.Enabled = false;
                        this.btn_Rework.Enabled = false;
                    }
                }
                this.pe_Processinfo.Visible = false;
            }
            catch (Exception ex)
            {
                this.errInfo = string.Empty;
                MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        #endregion
    }
}

using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Tls.Crypto;
using ServerSide.Common;
using ServerSide.DAL;
using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PlantProcessControlSystem
{
    public partial class CfgBarCodePrintTemplateFrm : Form
    {
        private List<ConfigBarCodePrintTemplate> configBarCodePrintTemplates;//斑码打印模板配置
        private ConfigBarCodePrintTemplate oldconfigBarCodePrintTemplate;//旧的模板配置信息
        public string errInfo;//错误日志
        public CfgBarCodePrintTemplateFrm()
        {
            InitializeComponent();
            this.InitWinFrmTable();
        }

        #region 初始化界面
        private void InitWinFrmTable()
        {
            using (EFContext db = new EFContext())
            {
                configBarCodePrintTemplates = new List<ConfigBarCodePrintTemplate>();
                configBarCodePrintTemplates = db!.ConfigBarCodePrintTemplate!.ToList();
                this.dataSource.DataSource = configBarCodePrintTemplates;

                //客户信息
                this.cmb_Client.Items.Clear();
                db!.ClientInfo!.ToList()!.ForEach((c) =>
                {
                    cmb_Client.Items.Add(c.ClientName);
                });
                this.cmb_Client.Text = "";
                this.cmb_Client.Enabled = true;

                //工序信息
                this.cmb_Processinformation.Items.Clear();
                db!.Processinformation!.ToList()!.ForEach(p =>
                {
                    this.cmb_Processinformation.Items.Add(p.PrsName);
                });
                this.cmb_Processinformation.Text = "";
                this.cmb_Processinformation.Enabled = true;
            }
            //this.gb_PrintModel.Visible = false;
            this.txt_PrintTemplateDownPath.Text = "";
            this.txt_TemplateName.Text = "";
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.dataSource.ClearSelection();
            this.panel_Edit.Visible = false;
            templateName = string.Empty;
        }
        #endregion

        #region 选择文档
        //private List<FileServiceEntity> fileServiceModels;
        private FileProcesService fProcesService;
        private string selectFileName;//选择文件名称
        private void btn_Example_Click(object sender, EventArgs e)
        {
            selectFileName = string.Empty;
            this.txt_PrintTemplateDownPath.Text = "";
            fProcesService = new FileProcesService();
            fProcesService.SelectFile(out selectFileName, "所有文件(*.btw) | *.btw");
            string[] arrayStr = selectFileName.Split('\\');
            if (this.UploadFile(selectFileName, arrayStr[arrayStr.Length - 1]))//上传模板
            {
                txt_PrintTemplateDownPath.Text = templateName;//上传模板文件全路径
                txt_TemplateName.Text = arrayStr[arrayStr.Length - 1];//上传模板名称
            }
        }
        #endregion

        #region 返回
        private void btn_Result_Click(object sender, EventArgs e)
        {
            this.panel_Edit.Visible = false;
            this.InitWinFrmTable();
        }
        #endregion

        #region 添加
        private void btn_Add_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "添加";
            this.btn_Del.Enabled = false;
            this.btn_Rework.Enabled = false;
            this.InitWinFrmTable();
            this.panel_Edit.Visible = true;

        }
        #endregion

        #region 删除
        private void btn_Del_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "删除";
            this.panel_Edit.Visible = true;
            this.cmb_Client.Enabled = false;
            this.txt_PrintTemplateDownPath.Enabled = false;
            this.txt_TemplateName.Enabled = false;
            this.cmb_Processinformation.Enabled = false;
        }
        #endregion

        #region 修改
        private void btn_Rework_Click(object sender, EventArgs e)
        {
            this.lbl_ItemName.Text = "修改";
            //this.txt_TemplateName.Enabled = true;
            //this.txt_PrintTemplateDownPath.Enabled = true;
            this.cmb_Client.Enabled = true;
            //this.InitWinFrmTable();
            this.panel_Edit.Visible = true;
        }
        #endregion

        #region 表单点击事件
        private void dataSource_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex >= 0)
                {
                    if (configBarCodePrintTemplates[e.RowIndex] != null)
                    {
                        this.oldconfigBarCodePrintTemplate = new ConfigBarCodePrintTemplate();
                        this.oldconfigBarCodePrintTemplate = configBarCodePrintTemplates[e.RowIndex];
                        this.btn_Del.Enabled = true;
                        this.btn_Rework.Enabled = true;

                        using (EFContext db = new EFContext())
                        {
                            this.cmb_Client.Text = db?.ClientInfo?.ToList()?.Where(c => c.ClientId == configBarCodePrintTemplates[e.RowIndex].ClientId)?.FirstOrDefault()?.ClientName;
                            this.cmb_Processinformation.Text = db?.Processinformation?.ToList()?.Where(p => p.PrsInfoID == this.oldconfigBarCodePrintTemplate.PrsInfoID)?.FirstOrDefault()?.PrsName;
                        }
                        this.txt_TemplateName.Text = this.oldconfigBarCodePrintTemplate.TempateName;//打印模板名称
                        this.txt_PrintTemplateDownPath.Text = this.oldconfigBarCodePrintTemplate.TempateDownPath;//打印模板下载路径
                    }
                    else
                    {
                        this.btn_Del.Enabled = false;
                        this.btn_Rework.Enabled = false;
                    }
                }
            }
            catch (Exception ex)
            {
                this.errInfo = string.Empty;
                MessageBox.Show($@"{ex.Message}", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        #endregion

        #region 保存
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (cmb_Client.Text != string.Empty &&
                txt_TemplateName.Text != string.Empty &&
                txt_PrintTemplateDownPath.Text != string.Empty &&
                cmb_Processinformation.Text != string.Empty)
            {
                using (EFContext db = new EFContext())
                {
                    if (lbl_ItemName.Text == "添加")
                    {
                        ConfigBarCodePrintTemplate cfgbptemplate = new ConfigBarCodePrintTemplate
                        {
                            ClientId = db?.ClientInfo?.ToList().Where(c => c.ClientName == cmb_Client.Text)?.FirstOrDefault()?.ClientId,
                            PrsInfoID = db?.Processinformation?.ToList().Where(p => p.PrsName == cmb_Processinformation.Text.Trim())?.FirstOrDefault()?.PrsInfoID,
                            TempateDownPath = txt_PrintTemplateDownPath.Text.Trim(),
                            TempateName = txt_TemplateName.Text.Trim()
                        };
                        db?.ConfigBarCodePrintTemplate?.Add(cfgbptemplate);
                    }
                    else if (lbl_ItemName.Text == "修改")
                    {
                        db?.ConfigBarCodePrintTemplate?.ToList().ForEach(c =>
                        {
                            if (c.BarCodePrintId == oldconfigBarCodePrintTemplate.BarCodePrintId)
                            {
                                c.ClientId = db?.ClientInfo?.ToList()?.Where(c => c.ClientName == cmb_Client.Text)?.FirstOrDefault()?.ClientId;//客户
                                c.TempateDownPath = txt_PrintTemplateDownPath.Text.Trim();
                                c.TempateName = txt_TemplateName.Text.Trim();
                            }
                        });
                    }
                    else if (lbl_ItemName.Text == "删除")
                    {
                        db?.ConfigBarCodePrintTemplate?.Remove(oldconfigBarCodePrintTemplate);
                    }
                    int result = db!.SaveChanges();
                    if (result <= 0)
                        MessageBox.Show("数据保存失败!!", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                this.panel_Edit.Visible = false;
                this.InitWinFrmTable();//初始化界面
            }
        }
        #endregion

        #region 上传日志
        /// <summary>
        /// 上传日志信息
        /// </summary>
        /// <param name=""></param>
        /// <param name="uploadFilePath">上传文件路径</param>
        /// <param name="fileName">上传文件名及路径</param>
        /// <returns></returns>
        public bool UploadLog(string uploadFilePath, string fileName, string processFile,bool isLogPass=false)
        {
            try
            {
                if(uploadFilePath!=string.Empty&&fileName!=string.Empty)
                {
                    string networkPath = string.Empty;
                    if (!File.Exists(@"\\10.2.2.163\Data\PASS.OK"))
                    {
                        NetworkShareConnect mess = new NetworkShareConnect();
                        if (mess.connectToShare(networkPath, "test", "Admin123") != "OK")
                        {
                            MessageBox.Show($@"{networkPath}:服务器连接失败", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    if (isLogPass)//是PASS
                    {
                        if (!Directory.Exists($@"\\10.2.2.163\data\LOG\PASS\{processFile}\{DateTime.Now.ToString("yyyyMMdd")}"))
                            Directory.CreateDirectory($@"\\10.2.2.163\data\LOG\{processFile}\PASS\{DateTime.Now.ToString("yyyyMMdd")}");//创建文件夹
                        System.IO.File.Copy(uploadFilePath, $@"\\10.2.2.163\data\LOG\{processFile}\PASS\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.log");
                        if (System.IO.File.Exists($@"\\10.2.2.163\data\LOG\{processFile}\PASS\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.log"))
                            return true;
                    }
                    else if (!isLogPass)//是FAIL
                    {
                        if (!Directory.Exists($@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}"))
                            Directory.CreateDirectory($@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}");//创建文件夹
                        System.IO.File.Copy(uploadFilePath, $@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.FA");
                        if (System.IO.File.Exists($@"\\10.2.2.163\data\LOG\{processFile}\FAIL\{DateTime.Now.ToString("yyyyMMdd")}\{fileName}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.FA"))
                            return true;
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return false;
        }
        #endregion

        #region 上传模板
        private string templateName = string.Empty;
        private bool UploadFile(string uploadFilePath, string fileName)
        {
            try
            {
                if (uploadFilePath != string.Empty)
                {
                    string networkPath = string.Empty;
                    //networkPath = $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}";
                    networkPath = $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}";
                    if (!File.Exists(@"\\10.2.2.163\Data\PASS.OK"))
                    {
                        NetworkShareConnect mess = new NetworkShareConnect();
                        if (mess.connectToShare(networkPath, "test", "Admin123") != "OK")
                        {
                            MessageBox.Show($@"{networkPath}:服务器连接失败", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                    if (System.IO.File.Exists($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}"))
                        System.IO.File.Delete($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}");

                    if (System.IO.File.Exists($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}"))
                    {
                        MessageBox.Show($"打印模板:{fileName}名称在服务器中已存在", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return false;
                    }
                    else
                    {
                        //MessageBox.Show(txt_PrintModelSample.Text);
                        //MessageBox.Show(networkPath);
                        System.IO.File.Copy(uploadFilePath, $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}");
                        if (System.IO.File.Exists($@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}") == true)
                        {
                            templateName = $@"\\10.2.2.163\BarCode\{cmb_Processinformation.Text}\{fileName}";
                            return true;
                        }
                        else
                        {
                            MessageBox.Show($"打印模板:{fileName}上传服务器失败", "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return false;
        }
        #endregion

    }
}

1.条码打印实现类

using ServerSide.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Common
{
    public class BarTenderHelper
    {
        public event Action<string> callBack;
        private PrintConfigEntity pcEntity;
        private BarTender.Application btapp;//引用方法1
        private BarTender.Format btformat;//引用方法2
        public BarTenderHelper(PrintConfigEntity pcfEntity)
        {
            this.pcEntity= pcfEntity;
        }

        #region 条码打印
        public Boolean BarTenderPrint()
        {
            try
            {
                this.btapp = new BarTender.Application();
                this.btformat = this.btapp.Formats.Open(this.pcEntity.PTemplate, false, "");//设置模板文件
                this.btformat.PrintSetup.NumberSerializedLabels = Convert.ToInt32(this.pcEntity.PCount);//设置打印份数
                this.pcEntity.ScanDt.ForEach((d) => {
                    this.btformat.SetNamedSubStringValue(d.BarCodeName, d.BarCodeString);
                });
                this.btformat.PrintOut(true,Convert.ToBoolean(this.pcEntity.IsShowPrint));//打印提示
                this.btapp.Quit(BarTender.BtSaveOptions.btPromptSave);//退出并改变BarTender模板
                return true;
            }
            catch (Exception ex)
            {
                this.callBack(ex.Message);
                return false;
            }
        }
        #endregion
    }
}

实体类:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Models
{
    #region 配置动态字段信息
    public class ConfigBarCodeInfoEntity
    {

        /// <summary>
        /// 配置动态条码ID
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
        public int ?cfBarCodeID { get; set; }


        /// <summary>
        /// 动态字段名称
        /// </summary>
        [Required]//不允许为空
        [StringLength(50)]
        public string? ConfigBarCodeName { get; set; }


        /// <summary>
        /// 项目描述
        /// </summary>
        [Required]
        [StringLength(80)]
        public string? ConfigDescription { get; set; }

        public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间     
    }
    #endregion
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Models
{
    /// <summary>
    /// 条码配置
    /// </summary>
    public class BarCodeCfig
    {
        /// <summary>
        /// 配置ID
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
        public int ?CfigId { get; set; }

        /// <summary>
        /// 客户ID
        /// </summary>
        [ForeignKey("ClientId")]//设置导航属性
        //public ClientInfo? ClientInfo { get; set; }
        public int? ClientId { get; set; }//外键

        /// <summary>
        /// 产品ID
        /// </summary>
        [ForeignKey("ProductId")]//设置导航属性
        //public ProductNames? ProductNames { get; set; }
        public int? ProductId { get; set; }//外键


        /// <summary>
        /// 订单ID
        /// </summary>
        [ForeignKey("WorkOrderId")]//设置导航属性
        //public ProductNames? ProductNames { get; set; }
        public int? WorkOrderId { get; set; }//外键

        /// <summary>
        /// 工序ID
        /// </summary>
        [ForeignKey("PrsInfoID")]//设置导航属性
        //public Processinformation? Processinformation { get; set; }
        public int? PrsInfoID { get; set; }//外键

        /// <summary>
        /// 配置打印模板ID
        /// </summary>
        [Required]//不允许为空
        [ForeignKey("BarCodePrintId")]//打印模板ID
        //public ConfigBarCodeInfoEntity? ConfigBarCodeInfoEntity { get; set; }
        public int? BarCodePrintId { get; set; }//外键

        /// <summary>
        /// 配置参数值
        /// </summary>
        [StringLength(255)]
        public string? CfgArgsValue { get; set; }

        public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间

    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Models
{
    /// <summary>
    /// 配置打印模板
    /// </summary>
    public class ConfigBarCodePrintTemplate
    {
        /// <summary>
        /// 打印模板ID
        /// </summary>

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
        public int BarCodePrintId { get; set; }


        /// <summary>
        /// 客户ID
        /// </summary>
        [ForeignKey("ClientId")]//设置导航属性
        //public ClientInfo? ClientInfo { get; set; }
        public int? ClientId { get; set; }//外键

        /// <summary>
        /// 工序ID
        /// </summary>
        [ForeignKey("PrsInfoID")]//设置导航属性
        //public Processinformation? Processinformation { get; set; }
        public int? PrsInfoID { get; set; }//外键


        /// <summary>
        /// 模板名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public string? TempateName { get; set; }


        /// <summary>
        /// 模板下载路径
        /// </summary>
        [Required]
        [StringLength(255)]
        public string? TempateDownPath { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Models
{
    /// <summary>
    /// 配置打印模板
    /// </summary>
    public class ConfigBarCodePrintTemplate
    {
        /// <summary>
        /// 打印模板ID
        /// </summary>

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
        public int BarCodePrintId { get; set; }


        /// <summary>
        /// 客户ID
        /// </summary>
        [ForeignKey("ClientId")]//设置导航属性
        //public ClientInfo? ClientInfo { get; set; }
        public int? ClientId { get; set; }//外键

        /// <summary>
        /// 工序ID
        /// </summary>
        [ForeignKey("PrsInfoID")]//设置导航属性
        //public Processinformation? Processinformation { get; set; }
        public int? PrsInfoID { get; set; }//外键


        /// <summary>
        /// 模板名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public string? TempateName { get; set; }


        /// <summary>
        /// 模板下载路径
        /// </summary>
        [Required]
        [StringLength(255)]
        public string? TempateDownPath { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Models
{
    /// <summary>
    /// 配置打印模板
    /// </summary>
    public class ConfigBarCodePrintTemplate
    {
        /// <summary>
        /// 打印模板ID
        /// </summary>

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
        public int BarCodePrintId { get; set; }


        /// <summary>
        /// 客户ID
        /// </summary>
        [ForeignKey("ClientId")]//设置导航属性
        //public ClientInfo? ClientInfo { get; set; }
        public int? ClientId { get; set; }//外键

        /// <summary>
        /// 工序ID
        /// </summary>
        [ForeignKey("PrsInfoID")]//设置导航属性
        //public Processinformation? Processinformation { get; set; }
        public int? PrsInfoID { get; set; }//外键


        /// <summary>
        /// 模板名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public string? TempateName { get; set; }


        /// <summary>
        /// 模板下载路径
        /// </summary>
        [Required]
        [StringLength(255)]
        public string? TempateDownPath { get; set; }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Models
{
    #region 配置打印的订单信息
    public class ConfigBarCodeOrderInfoEntity
    {
        /// <summary>
        /// 订单ID
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
        public int WorkOrderId { get; set; }

        /// <summary>
        /// 产品ID
        /// </summary>
        [ForeignKey("ProductId")]//设置导航属性
        //public ProductNames? ProductNames { get; set; }
        public int? ProductId { get; set; }//外键

        /// <summary>
        /// 订单号
        /// </summary>
        [Required]
        [StringLength(150)]
        public string ?OrderInfo { get; set; }

        /// <summary>
        /// 订单总数
        /// </summary>
        [Required]
        public int? OrderCount { get; set; }

        /// <summary>
        /// 外箱序号
        /// </summary>
        [Required]
        [StringLength(100)]
        public string ?CartonSerialNumber { get; set; }

        /// <summary>
        /// 机身扫描总数
        /// </summary>
        [Required]
        public int? FuselageScanCount { get; set; } = 0;

        /// <summary>
        /// 彩盒扫描总数
        /// </summary>
        [Required]
        public int? GiftBoxScanCount { get; set; } = 0;

        /// <summary>
        /// 外箱扫描总数
        /// </summary>
        [Required]
        public int? MasterCartonScanCount { get; set; } = 0;

        /// <summary>
        /// 装箱绑码数
        /// </summary>
        [Required]
        public int PackingBindingCode { get; set; } = 1;

        public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间
    }
    #endregion
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSide.Models
{
    /// <summary>
    /// 产品名称
    /// </summary>
    public class ProductNames
    {

        /// <summary>
        /// 产品ID
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)] //自增
        public int? ProductId { get; set; }

        /// <summary>
        /// 客户ID
        /// </summary>
        [ForeignKey("ClientId")]//设置导航属性
        //public ClientInfo? ClientInfo { get; set; }
        public int? ClientId { get; set; }//外键

        /// <summary>
        /// 产品名称
        /// </summary>
        [Required]
        [StringLength(100)]
        public string? ProductName { get; set; }

        public DateTime? CreateTim { get; set; } = DateTime.Now;//创建时间

    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/112033.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

web:[GYCTF2020]Blacklist

题目 点开靶机&#xff0c;页面显示为 查看源码 没有其他线索 先提交1试一下 猜测是sql注入&#xff0c;先测试 同时注意到url 提交为3-1&#xff0c;发现页面回显为空白 可以判断为字符型注入 输入select&#xff0c;看是否存在回显 回显了黑名单限制的关键字 但是发现没有…

用rust写web服务器笔记(11/1)

文章目录 一、创建一个具有监听链接功能web服务器二、读取请求内容三、编写web服务器返回网页(编写响应)四、编写web服务器有条件的返回网页五、编写多线程的web服务器六、用线程池实现web服务器七、实现线程池清除的web服务器八、读取文件 rust官网文档地址&#xff1a;https:…

QMI8658A_QMC5883L(9轴)-EVB 评估板——索引博文

0.前言 【初见姿态传感器】 在做一个4轴飞行器的时候了解到有这样一个可以控制飞行器姿态的传感器&#xff0c;而后在哔哩哔哩看到利用姿态传感做很多很好玩的作品。目前在自己的本职工作中广泛会用姿态传感器IMU的应用。 1.博文索引 【基础内容】 【QMI8658 - 姿态传感器学习…

基于图神经网络的联邦学习跨企业推荐

Federated Learning-Based Cross-Enterprise Recommendation With Graph Neural Networks 论文试图解决什么问题 该论文试图解决跨企业推荐系统中存在的数据共享和用户隐私保护的问题。在许多小型和中型企业中&#xff0c;由于资源有限&#xff0c;无法提供足够的数据来进行大…

java基础之IO操作

用户进程发起请求&#xff0c;内核接收到请求后&#xff0c;从I/O设备中获取数据到buffer中&#xff0c;再将buffer中的数据copy到用户进程的地址空间&#xff0c;该用户进程获取到数据后再响应客户端。 数据输入到buffer需要时间&#xff0c;从buffer复制数据至进程也需要时间…

服务器遭受攻击如何处理(记录排查)

本文的重点是介绍如何鉴别安全事件以及保护现场的方法&#xff0c;以确保服务器负责人能够在第一时间对安全攻击做出反应&#xff0c;并在最短时间内抵御攻击或减少攻击所带来的影响。 在服务器遭遇疑似安全事件时&#xff0c;通常可以从账号、进程、网络和日志四个主要方面进…

onlyoffice 二次开发 连接器(connector) 表单填(Filling out the form) jsApi级别操作文档

阅读须知&#xff1a;本文针对有对word/excel进行js操作的需求 本次改造基于V7.3.3进行&#xff0c;已经更新进入docker。 小伙伴们须知&#xff1a;改造后的office docker需要付费&#xff08;875元&#xff09;&#xff0c;等于wps一个月费用 欢迎大家一起交流&#xff1a;V&…

面经(面试经验)第一步,从自我介绍开始说起

看到一位同学讲自己的面试步骤和过程&#xff0c;我心有所感&#xff0c;故此想整理下面试的准备工作。以便大家能顺利应对面试&#xff0c;通过面试... 求职应聘找工作&#xff0c;面试是必然的关卡&#xff0c;如今竞争激烈呀&#xff0c;想要得到自己喜欢的工作&#xff0c…

基于springboot实现学生考勤管理系统【项目源码+论文说明】

基于springboot实现学生考勤管理系统演示 摘要 随着信息技术和网络技术的飞速发展&#xff0c;人类已进入全新信息化时代&#xff0c;传统管理技术已无法高效&#xff0c;便捷地管理信息。为了迎合时代需求&#xff0c;优化管理效率&#xff0c;各种各样的管理系统应运而生&am…

敲敲云零代码平台超实用表单设计技巧推荐,分分钟玩转零代码

敲敲云是一个APaaS零代码云平台&#xff0c;帮助企业快速搭建个性化业务应用。用户不需要编码就能够搭建出用户体验上佳的销售、运营、人事、采购等核心业务应用&#xff0c;打通企业内部数据。平台拥有完善的表单引擎、流程引擎、仪表盘等。 有时我们在添加明细表时&#xff0…

瑞数专题五

今日文案&#xff1a;焦虑&#xff0c;想象力过度发酵的产物。 网址&#xff1a;https://www.iyiou.com/ 专题五主要是分享瑞数6代。6代很少见&#xff0c;所以找理想哥要的&#xff0c;感谢感谢。 关于瑞数作者之前已经分享过4篇文章&#xff0c;全都收录在瑞数专栏中了&am…

LED显示屏的4种连接方式

全彩LED显示屏是由多块LED模组拼接起来的LED大屏幕&#xff0c;而显示屏模组是由许多的LED灯珠组装起来的。LED显示屏效果好不好&#xff0c;和LED显示屏组装有很大的关系。而显示屏的组装关键在连接方式上&#xff0c;如果连接不好将影响LED显示屏的画面质量&#xff0c;甚至会…

Rust-错误处理魔法

这篇文章收录于Rust 实战专栏。这个专栏中的相关代码来自于我开发的笔记系统。它启动于是2023年的9月14日。相关技术栈目前包括&#xff1a;Rust&#xff0c;Javascript。关注我&#xff0c;我会通过这个项目的开发给大家带来相关实战技术的分享。 我们写的代码主要有两部分&am…

linux 安装 elasticsearch 全教程

一、去 elasticsearch官网找到Linux版本的下载链接 地址https://www.elastic.co/cn/downloads/elasticsearch 二、在linux 中用wget下载 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.4-linux-x86_64.tar.gz三、下载成功后解压文件 tar -x…

Windows 开启 Kerberos 的火狐 Firefox 浏览器访问yarn、hdfs

背景&#xff1a;类型为IPA或者MIT KDC&#xff0c;windows目前只支持 firefoxMIT Kerberos客户端的形式&#xff0c;其他windows端浏览器IE、chrome、edge&#xff0c;没有办法去调用MIT Kerberos Windows客户端的GSSAPI验证方式&#xff0c;所以均无法使用 Windows 开启 Kerb…

驱动开发11-2 编写SPI驱动程序-点亮数码管

驱动程序 #include <linux/init.h> #include <linux/module.h> #include <linux/spi/spi.h>int m74hc595_probe(struct spi_device *spi) {printk("%s:%d\n",__FILE__,__LINE__);char buf[]{0XF,0X6D};spi_write(spi,buf,sizeof(buf));return 0; …

基于51单片机的智能手机充电器设计

**单片机设计介绍&#xff0c;1660【毕设课设】基于51单片机和MAX1898的智能手机充电器设计 文章目录 一 概要二、功能设计设计思路 三、 软件设计原理图 五、 程序六、 文章目录 一 概要 51单片机智能手机充电器设计介绍 51单片机智能手机充电器是一种可以实现智能快速充电的…

OpenAI将推出ChatGPT Plus会员新功能,有用户反馈将支持上传文件和多模态

&#x1f989; AI新闻 &#x1f680; OpenAI将推出ChatGPT Plus会员新功能&#xff0c;有用户反馈将支持上传文件和多模态 摘要&#xff1a;OpenAI为ChatGPT Plus会员推出了一些新功能&#xff0c;包括上传文件、处理文件和多模态支持。用户不再需要手动选择模式&#xff0c;…

自动化测试mock模块使用详解介绍

mock简介 py3已将mock集成到unittest库中为的就是更好的进行单元测试简单理解&#xff0c;模拟接口返回参数通俗易懂&#xff0c;直接修改接口返回参数的值官方文档&#xff1a;unittest.mock --- 模拟对象库 — Python 3.11.3 文档 mock作用 解决依赖问题&#xff0c;达到解…

Mac/Linux类虚拟机_CrossOver虚拟机CrossOver 23.6正式发布2024全新功能解析

CodeWeivers 公司于今年 10 月发布了 CrossOver 23.6 测试版&#xff0c;重点添加了对 DirectX 12 支持&#xff0c;从而在 Mac 上更好地模拟运行 Windows 游戏。 该公司今天发布新闻稿&#xff0c;表示正式发布 CrossOver 23 稳定版&#xff0c;在诸多新增功能中&#xff0c;最…
最新文章