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

news2025/1/18 7:33:19

条码打印基于: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.coloradmin.cn/o/1145607.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Android官方ShapeableImageView描边/圆形/圆角图,xml布局实现

Android官方ShapeableImageView描边/圆形/圆角图&#xff0c;xml布局实现 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.android.…

【PyQt学习篇 · ②】:QObject - 神奇的对象管理工具

文章目录 QObject介绍Object的继承结构测试QObject对象名称和属性QObject对象名称和属性的操作应用场景 QObject父子对象QObject父子对象的操作 QObject的信号与槽QObject的信号与槽的操作 QObject介绍 在PyQt中&#xff0c;QObject是Qt框架的核心对象之一。QObject是一个基类…

【C++】STL容器适配器入门:【堆】【栈】【队列】(16)

前言 大家好吖&#xff0c;欢迎来到 YY 滴C系列 &#xff0c;热烈欢迎&#xff01; 本章主要内容面向接触过C的老铁 主要内容含&#xff1a; 欢迎订阅 YY滴C专栏&#xff01;更多干货持续更新&#xff01;以下是传送门&#xff01; 目录 一.容器适配器的概念二.为什么stack和q…

Ubuntu Studio 23.10发布

导读Ubuntu Studio 是 Ubuntu 的多媒体社区版。该项目的 23.10 版本重点改进了 PipeWire 支持和音频配置。 PipeWire 已获得大量改进&#xff0c;包括针对专业音频和消费音频的修复。现在&#xff0c;JACK 兼容性可实时运行&#xff0c;一些 FireWire 功能也已实现。 我们还在…

Wpf 使用 Prism 实战开发Day01

一.开发环境准备 1. VisualStudio 2022 2. .NET SDK 7.0 3. Prism 版本 8.1.97 以上环境&#xff0c;如有新的版本&#xff0c;可自行选择安装新的版本为主 二.创建Wpf项目 1.项目的名称:MyToDo 项目名称:这里只是记录学习&#xff0c;所以随便命名都无所谓,只要觉得合理就…

sql-50练习题0-5

sql练习题0-5题 前言数据库表结构介绍学生表课程表成绩表教师表 0-1 查询"01"课程比"02"课程成绩高的学生的信息及课程分数0-2查询"01"课程比"02"课程成绩小的学生的信息及课程分数0-3查询平均成绩大于等于60分的同学的学生编号和学生…

2023年江西省“振兴杯”工业互联网安全技术技能大赛暨全国大赛江西选拔赛 Write UP

文章目录 一、协议分析 - modbus二、协议分析 - 异常的流量三、协议分析 - S7Error四、协议分析 - OmronAttack五、组态编程 - 工程的秘密六、组态编程 - 工程的秘密七、组态编程 - 简单的计算八、组态编程 - 交通灯九、组态编程 - 有趣的转盘十、应急处置 - 登录日志分析十一、…

DevOps与CI/CD的最佳实践

在当今的软件开发领域&#xff0c;DevOps&#xff08;开发与运维的结合&#xff09;和CI/CD&#xff08;持续集成/持续交付&#xff09;已经成为了不可或缺的一部分。它们不仅提高了软件开发的效率&#xff0c;还帮助团队更快地交付高质量的软件。本文将深入探讨DevOps文化和CI…

nodejs+vue+elementui+express外卖数据分析python

在上述需求分析的基础上&#xff0c;通过深入研究&#xff0c;将系统使用人员划分为信息采集编辑、信息维护编辑、信息发布编辑三个角色。 本论文的研究目的是为了给采编者提供一套完善、高效的智能信息收集解决方案&#xff0c;并利用一系列的程序设计与开发&#xff0c;为采…

Linux中shell脚本练习

目录 1.猜数字 2.批量创建用户 3.监控网卡Receive Transmit 数据的变化 4.部署Linux 5.系统性能检测脚本 6.分区脚本 7.数据库脚本 1.猜数字 随机数的生成 使用环境变量RANDOM&#xff0c;范围是0&#xff5e;32767 编写guest.sh&#xff0c;实现以下功能&#xff1…

AS/400简介

AS400 AS400 简介AS/400操作系统演示 AS400 简介 在 AS400 中&#xff0c;AS代表“应用系统”。它是多用户、多任务和非常安全的系统&#xff0c;因此用于需要同时存储和处理敏感数据的行业。它最适合中级行业&#xff0c;因此用于制药行业、银行、商场、医院管理、制造业、分销…

栈队列OJ练习题(C语言版)

目录 一、括号匹配问题 思路&#xff1a; 完整版C语言代码&#xff1a; 讲解&#xff1a; 二、用队列实现栈 思路&#xff1a; 完整版C语言代码&#xff1a; 讲解&#xff1a; 三、用栈实现队列 思路&#xff1a; 完整版C语言代码&#xff1a; 讲解&#xff1a…

【C++】C++入门(下)--内联函数 auto关键字 nullptr

目录 一 内联函数 1 内联函数概念和定义 2 内联函数特性 二 auto关键字 1 auto概念 2 auto 的使用细则 (1) auto与指针和引用结合起来使用 (2) 在同一行定义多个变量 3 auto不能推导的场景 (1) auto不能作为函数的参数 (2) auto不能直接用来声明数组 4 基于范围的fo…

uniapp实现瀑布流

首先我们要先了解什么是瀑布流&#xff1a; 瀑布流&#xff08;Waterfall Flow&#xff09;是一种常见的网页布局方式&#xff0c;也被称为瀑布式布局或砌砖式布局。它通常用于展示图片、博客文章、商品等多个不同大小和高度的元素。 瀑布流布局的特点是每个元素按照从上到下…

椭圆曲线点加的推导公式

一、点加推导过程 1.1 背景 实数域上的椭圆曲线: y^2 =x^3+ax+b 假设P,Q,R三点的坐标分别为:P(x1,y1),Q(x2,y2),R(x3,-y3),我们这里求的是P+Q,即R的镜像点,因此R坐标为(x3,-y3)。 假设通过点P(x1,y1)点的直线方程L(x)可以表达为:y=k(x-x1)+y1 ,其中,k为直线L(x)的…

.NET CORE 3.1 集成JWT鉴权和授权2

JWT&#xff1a;全称是JSON Web Token是目前最流行的跨域身份验证、分布式登录、单点登录等解决方案。 通俗地来讲&#xff0c;JWT是能代表用户身份的令牌&#xff0c;可以使用JWT令牌在api接口中校验用户的身份以确认用户是否有访问api的权限。 授权&#xff1a;这是使用JWT的…

测绘屠夫报表系统V1.0.0-beta

1. 简介 测绘屠夫报表系统&#xff0c;能够根据变形监测数据&#xff1a;水准、平面、轴力、倾斜等数据&#xff0c;生成对应的报表&#xff0c;生成报表如下图。如需进一步了解&#xff0c;可以加QQ&#xff1a;3339745885。视频教程可以在bilibili观看。 2. 软件主界面 3. …

vue3+ts+threejs 1.创建场景

效果 创建画布容器元素 <script setup lang"ts"> ... // 画布容器 const canvasRef ref<HTMLElement>() const canvasSize ref<{ width: number, height: number }>({width: 0, height: 0})// 监控更新画布尺寸 function handleResize(entry: R…

云笔记一网打尽

二、云笔记产品 添加图片注释&#xff0c;不超过 140 字&#xff08;可选&#xff09; 这么多产品如何选择呢&#xff1f; 2.1、选择注重本地留存的产品 可以看到语雀出事后&#xff0c;网上的文章出场率比较高的有Obsidian和思源笔记。为什么呢&#xff1f;因为它们比较注意…

Go学习第十三章——Gin入门与路由

Go web框架——Gin入门与路由 1 Gin框架介绍1.1 基础介绍1.2 安装Gin1.3 快速使用 2 路由2.1 基本路由GET请求POST请求 2.2 路由参数2.3 路由分组基本分组带中间件的分组 2.4 重定向 1 Gin框架介绍 github链接&#xff1a;https://github.com/gin-gonic/gin 中文文档&#xf…