在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 条码打印程序(一维码和二维码)

C# 条码打印程序(一维码和二维码)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.93M
  • 下载次数:165
  • 浏览次数:716
  • 发布时间:2019-06-12
  • 实例类别:C#语言基础
  • 发 布 人:zhao_wb
  • 文件格式:.rar
  • 所需积分:2
 相关标签: 二维码 一维码 条码 打印 程序

实例介绍

【实例简介】

工厂收料或出货条码标签批量打印程序,可设置固定打印机和纸张格式及边距。

【实例截图】

from clipboard

【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.IO;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;
using ThoughtWorks.QRCode.Codec.Util;
using BarcodeLib;
using System.Configuration;

namespace MYQRCode
{    
    
    public partial class Form1 : Form
    {
        public static Form1 f1;
        Bitmap _NewBitmap = null;
        string d_File = System.IO.Directory.GetCurrentDirectory().ToString()   "\\Data_History\\"   DateTime.Now.ToString("s").Substring(0, 10)   ".txt";
        string h_File = System.IO.Directory.GetCurrentDirectory().ToString()   "\\Sysmanage\\条码程序使用说明.doc";
        string d_date = DateTime.Now.AddMonths(-2).ToString("yyMM");
        string m_Text = "";
        string Code_No_Count = "0";
        string data = "";
        Image Simage;
        public string m_psize = "";
        
        public Form1()
        {
            InitializeComponent();
            f1 = this;
        }
        #region 窗体启动
        private void FORM_LOAD(object sender, EventArgs e)
        {
                printDocument1.PrintPage  =
                new PrintPageEventHandler(printDocument1_PrintPage);
                textBox2.Enabled = false;
                txtSPk.Visible = false;
                txtEPK.Visible = false;
                txtSPk.Size = txtPNO.Size;
                txtSPk.Location = SPk.Location;
                txtEPK.Size = txtPNO.Size;
                txtEPK.Location = EPK.Location;
                //SPk.Text = DateTime.Now.ToString("s");
                EPK.Text = DateTime.Now.ToString("s");
                textBox1.Text = "1";
                txtGYS.Text = GetValue("Suppliers");

                SPk.Text = "2016-03-01";
                EPK.Text = "2016-05-01";
                txtPO.Text = "20160101001";
                txtPID.Text = "02001102";
                txtPNO.Text = "abcddeA";
                txtQTY.Text = "30000";
                txtBQTY.Text = "20KG/箱";
                txtPH.Text = "abcd123a";

                if (File.Exists(d_File) == false)//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory().ToString()   "\\Data_History");
                    File.Create(d_File).Close();
                }
                Add_log(d_File, DateTime.Now.ToString()   "  启动标签打印程序;");
                App_Del();  //清理配置文件中超出2月以上的节点内容
                
                //MessageBox.Show(d_date);
                txtPO.Focus();                
        }
        #endregion
        #region 生成按钮
        private void button1_Click(object sender, EventArgs e)
        {
           
            if (string.IsNullOrEmpty(txtGYS.Text))
                {
                    MessageBox.Show("供应商代码不能为空,请输入数据哦!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtGYS.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtPO.Text))
                {
                    MessageBox.Show("订单编号不能为空,请输入数据哦!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtPO.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtPID.Text))
                {
                    MessageBox.Show("物料编码不能为空,请输入数据哦!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtPID.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtPNO.Text))
                {
                    MessageBox.Show("物料名称不能为空,请输入数据哦!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtPNO.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtQTY.Text))
                {
                    MessageBox.Show("批次数量不能为空,请输入数据哦!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtQTY.Focus();
                    return;
                }
                float num;
                if (!float.TryParse(txtQTY.Text, out num))
                {
                    MessageBox.Show("数量格式错误,请输入数据哦!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtQTY.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(txtBQTY.Text))
                {
                    MessageBox.Show("包装数量不能为空(最小包装单位数量)!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtBQTY.Focus();
                    return;
                }
                int i = DateTime.Compare(SPk.Value, EPK.Value);
                if (i >= 0)
                {
                    MessageBox.Show("保质日期必须大于生产日期,请重新选择日期!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    picEncode.Image = null;
                    sicEncode.Image = null;
                    EPK.Focus();
                    return;
                }

                if (checkBox1.CheckState != CheckState.Checked)
                {
                    m_Text = GetCode_No("Code_No", txtGYS.Text);

                }
                else
                {
                    string[] sArray = textBox2.Text.ToString().Split('.');
                    m_Text = sArray[0];
                }

                if (m_Text == "")
                {
                    MessageBox.Show("一维码内容为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    picEncode.Image = null;
                    sicEncode.Image = null;
                    EPK.Focus();
                    return;
                }
                //MessageBox.Show(d_File);
                //return;                              

                data = txtPID.Text.ToString()   ";"   txtPO.Text.ToString()   ";"   txtGYS.Text.ToString()   ";"   txtPH.Text.ToString()   ";"   txtQTY.Text.ToString()   ";"   SPk.Text.ToString().Replace("-", "")   ";"   EPK.Text.ToString().Replace("-", "");
                if (ReadTXT_Value(d_File, data) == true)
                {
                    MessageBox.Show("当天此信息已生成和打印,如需继续请选择补印!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                data = txtPID.Text.ToString()   ";"   txtPO.Text.ToString()   ";"   txtGYS.Text.ToString()   ";"   txtPH.Text.ToString()   ";"   txtQTY.Text.ToString()   ";"   SPk.Text.ToString().Replace("-", "")   ";"   EPK.Text.ToString().Replace("-", "")   ";"   m_Text;

                //MessageBox.Show(data);
                //return;
               
                    GetBarcode_T(data);
                    GetBarcode(sicEncode.Size.Width, sicEncode.Size.Height, TYPE.CODE128, m_Text, out Simage);
                    sicEncode.Image = Simage;
                    EditZt(true);
                    button2.Enabled = true;
                    
               
           
                      
        }
        #endregion
        #region 修改功能按钮
        private void button4_Click(object sender, EventArgs e)
        {
            if (picEncode.Image == null || sicEncode.Image == null)
            {
                txtPO.Focus();
                return;
            }
            EditZt(false);
            Add_log(d_File, DateTime.Now.ToString()   "  修改已生成标签的内容;");
            txtPO.Focus();
        }
        #endregion
        #region 打印按钮功能
        private void button2_Click(object sender, EventArgs e)
        {
            #region 判断内容齐整
            if (picEncode.Image == null||sicEncode.Image == null)
            {
                MessageBox.Show("无条码信息,请点击生成按钮!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                return;
            }
                     
            try
            {
                int ac = int.Parse(textBox1.Text);
            }
            catch
            {
                MessageBox.Show("输入的类型有误,请输入整型数.", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Focus();
                return;
            }
            #endregion
            PrintDialog MySettings = new PrintDialog();
            MySettings.Document = this.printDocument1;
            #region 指定打印机, 根据指定打印机名称参数判断当前打印机是否存在且指定打印,如网络路径错误或未共享但名称能匹配也会出现异常;
            string p_Pt = GetValue("Printer");      //获取打印机设置参数     
            bool p_Check = false;                   //判断参数,默认为假,如存在当前打印机列表则为真
            int ii = 0;            
            foreach (String fPrinterName in PrinterSettings.InstalledPrinters)
            {
                ii  ;
                if (fPrinterName.IndexOf(p_Pt) >= 0 && p_Pt!="")  //根据名称内容进行匹配
                {
                    p_Pt = fPrinterName;     //将变量开始获取的值转换为当前打印机列表中的描述,因有些是网络打印机,在设置参数时可能没有维护齐全,以名称内容与打印机列表匹配,不排队名称一样,但网络不通产生异常
                    p_Check = true;           //转换判断参数
                    MySettings.PrinterSettings.PrinterName = p_Pt;   //指定打印机名称
                    break;  //如有匹配值则退出循环;
                }
            }
            if (ii == 0)   //循环后为0则无安装打印机
            {
                MessageBox.Show("本机未安装打印机!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (p_Check == false)
            {
                MessageBox.Show("指定打印机不存在,请重新设置打印机参数!", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                return;
                //DialogResult dt = MessageBox.Show("指定打印机不存在或未设置打印机参数,是否使用默认打印机操作?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                //if (dt == DialogResult.Cancel)
                //{
                //    return;
                //}
                //else
                //{
                //    SetValue("Printer", MySettings.PrinterSettings.PrinterName);
                //    MySettings.PrinterSettings.PrinterName = MySettings.PrinterSettings.PrinterName;
                //}
            }
            //MessageBox.Show(MySettings.PrinterSettings.PrinterName.ToString());
            #endregion 
            #region 设置纸张大小
            PaperSize p = null;
            

            foreach (PaperSize ps in MySettings.PrinterSettings.PaperSizes)
            {                
                if (ps.PaperName.Equals(GetValue("PaperSize")))  //这里设置纸张大小,但必须是定义好的,注意维护纸张格式,有时打印机上显示的格式带有空格(测试时用B5取不到值,用B5 加个空格就可以取到值)  
                    p = ps;
                //f.add_List(ps.PaperName.ToString());
            }
            if (p == null)
            {
                MessageBox.Show("打印机纸张类型不匹配,请选择纸张样式.", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //f.add_Label(MySettings.PrinterSettings.PrinterName.ToString());
                //f.GetForm(this);
                //f.ShowDialog();                
                //f.Dispose();
                //foreach (PaperSize ps in MySettings.PrinterSettings.PaperSizes)
                //{
                //    if (ps.PaperName.Equals(m_psize))  //这里设置纸张大小,但必须是定义好的,注意维护纸张格式,有时打印机上显示的格式带有空格(测试时用B5取不到值,用B5 加个空格就可以取到值)  
                //        p = ps;                   
                //}
                //MessageBox.Show(m_psize, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //if (p == null)
            //{
            //    MessageBox.Show("未选择纸张样式.", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
           
            MySettings.Document.DefaultPageSettings.PaperSize = p;       //纸张规格
            //SetValue("PaperSize", p.PaperName.ToString());
            #endregion
            #region 设置打印方向
            if (GetValue("Landscape") == "横向")
            {
                MySettings.Document.DefaultPageSettings.Landscape = true;   //如TRUE则为横向;反之为纵向
            }
            else
            {
                MySettings.Document.DefaultPageSettings.Landscape = false;   //如TRUE则为横向;反之为纵向
            }
            #endregion
            #region 设置打印边距毫米为单位设置值时只能为整数;
            PageSetupDialog psd = new PageSetupDialog();
            psd.Document = printDocument1;
            psd.EnableMetric = true;
            int p_Top = 10;
            int p_Left = 12;
            if (GetValue("Top")!= "")
            {
                p_Top = Convert.ToInt32(Convert.ToDouble(GetValue("Top")));
            }
            if (GetValue("Left") != "")
            {
                p_Left = Convert.ToInt32(Convert.ToDouble(GetValue("Left")));
            }
            MySettings.Document.DefaultPageSettings.Margins.Top = p_Top;
            MySettings.Document.DefaultPageSettings.Margins.Left = p_Left;
            #endregion
            DialogResult dr= MessageBox.Show("请确认是否打印: " textBox1.Text " 份标签?","对话框标题", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.Cancel)
            {
                textBox1.Focus();
                return;
            }

            foreach (Control c in groupBox2.Controls)
            {
                if (c is System.Windows.Forms.TextBox || c is System.Windows.Forms.DateTimePicker)  // 当前控件是文本框控件
                {
                    c.Enabled = true;
                }
            }
                       
                Image Simage;
                StandardPrintController spc = new StandardPrintController();
                this.printDocument1.PrintController = spc;
                //button2.Enabled = false;
                txtSPk.Visible = false;
                txtEPK.Visible = false;
                SPk.Visible = true;
                EPK.Visible = true;
                //EditZt(true);
                string m_Text_q = "";
                int acount = int.Parse(textBox1.Text);
                for (int i = 0; i < acount; i  )
                {
                                 
                    m_Text_q = m_Text   "."   (i   1   Convert.ToInt32(Code_No_Count)).ToString("00000");
                    GetBarcode(sicEncode.Size.Width, sicEncode.Size.Height, TYPE.CODE128, m_Text_q, out Simage);
                    sicEncode.Image = Simage;
                    InitPrint();
                    this.printPreviewDialog1.ShowDialog();
                    //this.printDocument1.Print();  
                }
                Add_log(d_File, DateTime.Now.ToString()   "  生成标签内容:"   data);
                Add_log(d_File, DateTime.Now.ToString()   "  标签打印内容:"   m_Text   ";共"   textBox1.Text   "张;起始计数为:"   Code_No_Count);
                SetValue("Suppliers", txtGYS.Text);
                SetValue("Code_No", m_Text);
                data = data   ";"   txtPNO.Text   ";"   txtBQTY.Text   ";"   (Convert.ToInt32(textBox1.Text)   Convert.ToInt32(Code_No_Count)).ToString();
                SetValue(m_Text, data);
                button2.Enabled = false;
           
        }              
        #endregion
        #region 退出程序按钮
        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您将退出系统?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Add_log(d_File, DateTime.Now.ToString()   "  退出标签打印程序;");
                System.Environment.Exit(0);
            }
        }
        #endregion
        #region 关闭窗体即程序
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("您将退出系统?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                e.Cancel=true;
            }
            Add_log(d_File, DateTime.Now.ToString()   "  退出标签打印程序;");
        }
        #endregion
        #region 生成groupBox截图
        public void InitPrint()
        {

                txtSPk.Text = SPk.Text;
                txtEPK.Text = EPK.Text;
                txtSPk.Visible = true;
                txtEPK.Visible = true;
                SPk.Visible = false;
                EPK.Visible = false;               
                _NewBitmap = new Bitmap(groupBox2.Width, groupBox2.Height);
                groupBox2.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
           
        }
        #endregion
        #region 打印当前页
        private void printDocument1_PrintPage(System.Object sender,System.Drawing.Printing.PrintPageEventArgs e)
        {
           e.Graphics.DrawImage(_NewBitmap, 0, 0, _NewBitmap.Width, _NewBitmap.Height);           
        }
        #endregion
        #region 生成条码后信息输入失效,反之生效
        public void EditZt(bool keyData)
        {
            foreach (Control c in groupBox2.Controls)
            {
                if (c is System.Windows.Forms.TextBox || c is System.Windows.Forms.DateTimePicker)  // 当前控件是文本框控件
                {
                    if (keyData == true)
                    {
                        c.Enabled = false;
                    }
                    else
                    {
                        c.Enabled = true;
                        sicEncode.Image = null;
                        picEncode.Image = null;
                        txtEPK.Visible = false;
                        txtSPk.Visible = false;
                        SPk.Visible = true;
                        EPK.Visible = true;
                    }
                }
            }
            if (keyData == true)
            {
                button1.Enabled = false;
            }
            else
            {
                button1.Enabled = true;
            }
        }
        #endregion
        #region 根据内容生成二维码
        private void GetBarcode_T(string lr)
        {
            QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();//创建一个对象         
            qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;
            //设置编码测量度
            qrCodeEncoder.QRCodeScale = 3;  //大小(值越大生成的二维码图片像素越高)
            //设置编码版本
            qrCodeEncoder.QRCodeVersion = 0; //版本(注意:设置为0主要是防止编码的字符串太长时发生错误)  

            qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;
            //qrCodeEncoder.QRCodeForegroundColor = btnQRCodeForegroundColor.BackColor;//设置二维码前景色
            //qrCodeEncoder.QRCodeBackgroundColor = btnQRCodeBackgroundColor.BackColor;//设置二维码背景色
            Image image = qrCodeEncoder.Encode(lr, Encoding.UTF8);//生成二维码图片                       
            picEncode.Image = image;
        }
        #endregion
        #region 生成条形码
        /// <summary>
        /// 生成条形码
        /// </summary>
        static byte[] GetBarcode(int width, int height, TYPE type, string code, out Image image)
        {
            Barcode b = new Barcode
                {
                    //BackColor = Color.White, //图片背景颜色
                    //ForeColor = Color.Black, //条码颜色
                    IncludeLabel = true,
                    Alignment = AlignmentPositions.CENTER,
                    LabelPosition = LabelPositions.BOTTOMCENTER,
                    ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg, //图片格式
                    LabelFont = new Font("verdana", 10f), //字体设置
                    Height = height, //图片高度
                    Width = width //图片宽度
                };
 
            image = b.Encode(type, code);//生成图片
            byte[] buffer = b.GetImageData(SaveTypes.GIF);//转换byte格式
            return buffer;
        }
        #endregion        
        #region 回车键切换焦点
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if ((ActiveControl is TextBox || ActiveControl is DateTimePicker) &&
                keyData == Keys.Enter)
            {
                keyData = Keys.Tab;
            }
            return base.ProcessDialogKey(keyData);
        }
        #endregion
        #region 参数文件写入
        /// <summary>  
        /// 写入值  
        /// </summary>  
        /// <param name="key"></param>  
        /// <param name="value"></param>  
        public void SetValue(string key, string value)
        {
            //增加的内容写在appSettings段下 <add key="RegCode" value="0"/>  
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (config.AppSettings.Settings[key] == null)
            {
                config.AppSettings.Settings.Add(key, value);
            }
            else
            {
                config.AppSettings.Settings[key].Value = value;
            }
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件   
            
        }
        #endregion
        #region 参数文件读取
        /// <summary>  
        /// 读取指定key的值  
        /// </summary>  
        /// <param name="key"></param>  
        /// <returns></returns>  
        public  string GetValue(string key)
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (config.AppSettings.Settings[key] == null)
                return "";
            else
                return config.AppSettings.Settings[key].Value;
        }
        #endregion
        #region 获取一维码序号内容
        public  string GetCode_No(string key,string gys)
        {
            if (GetValue(key) == "")
            {
                return gys   DateTime.Now.ToString("yyMMdd")   "001";
            }
            else if (GetValue(key).Contains(gys   DateTime.Now.ToString("yyMMdd")))
            {
                return GetStringOrder_No(GetValue(key));
            }
            else
            {
                return gys   DateTime.Now.ToString("yyMMdd")   "001";
            }
               
        }
        #endregion
        #region 根据序号累加,为GetCode_No服务
        public static string GetStringOrder_No(string key)
        {           
            if (key == "" || key.Substring(key.Length - 3)=="999")
            {
                return "";
            }
            else 
            {
                string headStr = key.Substring(0, key.Length - 3);
                string subStr = key.Substring(key.Length - 3);
                int value = Convert.ToInt32(subStr);
                value  ;
                subStr = value.ToString();
                //新的尾如果不足3位则补0
                subStr = subStr.PadLeft(3, '0');
                //得到新的字符串
                return headStr   subStr;                
            }
           
        }
        #endregion
        #region 选择是否补印
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            m_Clear();
            if (checkBox1.CheckState ==CheckState.Checked )
            {
                textBox2.Enabled = true;
                button4.Enabled = false;
                button1.Enabled = false;
                textBox2.Focus();
            }
            else
            {
                textBox2.Text = "";
                textBox2.Enabled = false;
                button4.Enabled = true;
                button1.Enabled = true;
                EditZt(false);
                txtPO.Focus();
            }
            
        }
        #endregion
        #region 判断输入补印条码是否存在
        private void textBox2_Leave(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
                {
                    return;
                }
                           
                string s_Code_No = "";
                if (textBox2.Text.LastIndexOf(".") < 0)
                {
                    s_Code_No = textBox2.Text;
                }
                else
                {
                    s_Code_No = textBox2.Text.Replace(textBox2.Text.Substring(textBox2.Text.LastIndexOf(".")), "");
                }
                string b_Code_No = GetValue(s_Code_No);
                if (b_Code_No == "")
                {
                    MessageBox.Show("补印条码号不存在,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBox2.Focus();
                    return;
                }
               
                string[] sArray = b_Code_No.Split(';');
                txtPID.Text = sArray[0];
                txtPO.Text = sArray[1];
                txtGYS.Text = sArray[2];
                txtPH.Text = sArray[3];
                txtQTY.Text = sArray[4];
                SPk.Text = DateTime.ParseExact(sArray[5], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).ToString();
                EPK.Text = DateTime.ParseExact(sArray[6], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture).ToString();
                m_Text = sArray[7];
                txtPNO.Text = sArray[8];
                txtBQTY.Text = sArray[9];
                Code_No_Count = sArray[10];
                data = txtPID.Text.ToString()   ";"   txtPO.Text.ToString()   ";"   txtGYS.Text.ToString()   ";"   txtPH.Text.ToString()   ";"   txtQTY.Text.ToString()   ";"   SPk.Text.ToString().Replace("-", "")   ";"   EPK.Text.ToString().Replace("-", "")   ";"   m_Text;
                GetBarcode_T(data);
                GetBarcode(sicEncode.Size.Width, sicEncode.Size.Height, TYPE.CODE128, m_Text, out Simage);
                sicEncode.Image = Simage;
                EditZt(true);
                button2.Enabled = true;
        }
        #endregion
        #region 清空当前窗体信息
        private void m_Clear()
        {
            picEncode.Image = null;
            sicEncode.Image = null;
            SPk.Text = DateTime.Now.ToString("s");
            EPK.Text = DateTime.Now.ToString("s");
            textBox1.Text = "1";                          
            txtPO.Text = "";
            txtPID.Text = "";
            txtPNO.Text = "";
            txtQTY.Text = "";
            txtBQTY.Text = "";
            txtPH.Text = "";
        }
        #endregion
        #region 添加日志记录
        public void Add_log(string m_file, string m_lr)
        {
            FileStream fs = new FileStream(m_file, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);
            sw.BaseStream.Seek(0, SeekOrigin.End);
            sw.WriteLine("{0}", m_lr);
            sw.Flush();
            sw.Close();
            fs.Close();
        }
        #endregion
        #region 判断在日期日志文件当前信息是否已存在
        public static bool ReadTXT_Value(string r_file, string key_value)
        {
            bool zt = false;
            StreamReader sr = new StreamReader(r_file, Encoding.UTF8);
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                //MessageBox.Show(line.ToString());
                if (line.ToString().LastIndexOf(key_value) > 0)
                {
                    zt = true;
                    break;
                }
            }
            sr.Close();
            sr.Dispose();
            return zt;
        }
        #endregion
        #region 删除配置文件中2月以上记录
        public void App_Del()
        {
            System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            foreach (string m_key in ConfigurationManager.AppSettings.Keys )
            {
                if (m_key.ToString().LastIndexOf(d_date) > 0)
                {
                    //MessageBox.Show(m_key);              
                    config.AppSettings.Settings.Remove(m_key);
                }
            }
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件               
        }
        #endregion
        #region 快捷键打开帮助文件
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F1)
            {
                if(File.Exists(h_File))
                {
                  System.Diagnostics.Process.Start(h_File);
                }
                else
                {
                    MessageBox.Show("说明文档未找到!","系统提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    return ;
                }
            }
        }
        #endregion

        private void button5_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form2 f = new Form2();
            f.ShowDialog();
            f.Dispose();
           
        }
    }   
}

实例下载地址

C# 条码打印程序(一维码和二维码)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警