基本信息
源码名称:ADO数据库NpgSql、调用DLL、调用CS6模板打印、登陆框等综合实例
源码大小:5.95M
文件格式:.rar
开发语言:C#
更新时间:2020-01-03
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 20 元 
   源码介绍
 ADO数据库NpgSql、调用DLL、调用CS6模板打印、登陆框、打开软件盘、程式版本管控、读写INI等综合实例

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;  //连接数据
using Npgsql;
using WinFrom_VersionCheckDLL;
using LabelManager2;         //引入命名空间
using System.Threading;
using System.Diagnostics;
using DateTime = System.DateTime;

namespace ALL_Carton_Lable_Print_WF
{
    public partial class ALL_Carton_Lable_Print_WF : Form
    {
        public string str = null;
        public string filePath = null;
        public string szSN;

        public string szCustomerCode;
        public string szTpye;
        public string szEUJAN;
        string labFile = "";
        LabelManager2.ApplicationClass labApp = null;
        LabelManager2.Document doc = null;
        public ALL_Carton_Lable_Print_WF()
        {
            InitializeComponent();

            DelBmp();  //初始化刪除BMP圖片

            //獲取時間顯示在標題欄上
            ucRtSystemTime.Text = "您好,歡印使用打印程式!"   "當前時間:"   DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            string CurrentTime = DateTime.Now.ToString("yyyy-MM-dd");

            //給程式自定義標題名、日期、獲取程式版本號
            this.Text = ("ALL_Carton_Lable_Print_WF")   "   "   System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

            WinFrom_VersionCheckDLL.versionDLL ip = new WinFrom_VersionCheckDLL.versionDLL(); //調用DLL函數 new一個實例
            txtpcip.Text = ip.GetInternalIP();  //獲取IP寫入TextBox中
            ip.VersionCheck(); //調用版本檢查
        }

        public void Clear()  //清空
        {
            this.lblMachineName.Text = "";  //機種名
            this.lblSN.Text = "";  //條碼
            this.lblTpye.Text = "";  //類型
            this.lblCustomerCode.Text = "";//客戶編碼
            this.lblEUJAN.Text = ""; //UPC EAN JAN碼  
        }
        private void tbSN_Click(object sender, EventArgs e)  //執行打印功能
        {
            Clear(); //初化清空
            WinFrom_VersionCheckDLL.versionDLL ip = new WinFrom_VersionCheckDLL.versionDLL();
            ip.VersionCheck(); //調用版本檢查
            szSN = tbSN.Text;
            if (szSN.Length != 14)
            {
                this.tbSN.Text = "";  //清空TextBox輸入框
                MessageBox.Show("輸入的條碼長度錯誤,請確認!");
                return;
            }
            DataFunction GetFunction = new DataFunction();  //調用Function 函數
            GetFunction.CheckSN(szSN);
            if (int.Parse(GetFunction.szCount) == 0)
            {
                string sResult;
                sResult = String.Format("\n當前條碼={0} 不存在,請確認!", szSN);
                MessageBox.Show(sResult);
                this.tbSN.Text = "";  //清空TextBox輸入框
                this.tbSN.Focus();  //鼠標焦點
                return;
            }
            lblSN.Text = GetFunction.GetSN(szSN); //將條碼顯示到文本框
            szSN = lblSN.Text.Substring(0, 10);

            GetFunction.GetLocationID();
            
            lblTpye.Text = GetFunction.GetCountriesType();   //將國別代碼顯示到文本框
            szTpye = lblTpye.Text;
            lblMachineName.Text = GetFunction.szModel;  ////將機種名稱顯示到文本框
            if (lblMachineName.Text == "Y")
            {
                string sType = GetFunction.szType;  //判斷是不是散貨
                if (sType == "001" || sType == "002")
                {
                    lblCustomerCode.Text = GetFunction.sCustomer1;  //散貨客戶編碼
                }
                else
                {
                    lblCustomerCode.Text = GetFunction.szProductNo;  //將客戶編碼顯示到文本框
                    szCustomerCode = lblCustomerCode.Text;
                    lblEUJAN.Text = GetFunction.szUpcCode;  //將UPC碼顯示到文本框
                    szEUJAN = lblEUJAN.Text;
                }

                GetFunction.GetLabFilePath(szSN);  //根據不同國別獲取Lab文件路徑
                OpenFileDialog ofd = new OpenFileDialog(); //选择要打印的Label档
                                                           //ofd.ShowDialog(); //彈出對話框選擇文件
                ofd.FileName = GetFunction.nPathINI;
                labFile = ofd.FileName;
                try
                {
                    labApp = new LabelManager2.ApplicationClass();
                    labApp.Documents.Open(labFile, false);
                    doc = labApp.ActiveDocument;
                    doc.Variables.FormVariables.Item("Var0").Value = szSN;//向Label档传入变量
                    doc.Variables.FormVariables.Item("Var1").Value = szCustomerCode;//向Label档传入变量
                    doc.Variables.FormVariables.Item("Var2").Value = szTpye;//向Label档传入变量
                    doc.Variables.FormVariables.Item("Var3").Value = szEUJAN.Substring(0, 11);//向Label档传入变量
                    doc.PrintDocument(1);
                    Thread.Sleep(1000);
                    doc.PrintLabel(1);

                    filePath = Path.Combine(System.Windows.Forms.Application.StartupPath, @""   DateTime.Now.Year   DateTime.Now.Month   DateTime.Now.Day   DateTime.Now.Hour   DateTime.Now.Minute   DateTime.Now.Second   ".bmp");//保存圖片當前路徑徑下 為後面預覽圖片做準備
                    string st = doc.CopyImageToFile(8, "BMP", 0, 100, filePath);
                    pictureBox1.Load(filePath);  //以图片的形式浏览打印的Label            
                }
                catch (Exception ex)
                {
                    MessageBox.Show("出錯了,原因"   ex.Message);
                }
                finally
                {
                    labApp.Documents.CloseAll(true);
                    labApp.Quit();
                    labApp = null;
                    doc = null;
                }
//=====================================================================================================================================================
            }
            else
            {
                MessageBox.Show("輸入的條碼錯誤,請重新輸入條碼!");
                Clear();
            }      
            this.tbSN.Text = "";  //清空TextBox輸入框
            this.tbSN.Focus();  //鼠標焦點
        }

        private void tbSN_KeyDown(object sender, KeyEventArgs e)  //回車功能
        {
            if (e.KeyCode == Keys.Enter)
            {
                e.Handled = true;   //将Handled设置为true,指示已经处理过KeyPress事件
                tbSN_Click(sender, e);
                this.tbSN.Focus();  //鼠標焦點
            }
        }
        private void ucBtnExtSetting_BtnClick(object sender, EventArgs e)  //點擊按扭彈密碼框
        {
            LoginFrm f2 = new LoginFrm();
            //f2.f_main = this;
            f2.ShowDialog();
        }

        private void DelBmp()  //刪除BMP圖片函數
        {
            string filePath = System.Environment.CurrentDirectory;           
            DirectoryInfo folder = new DirectoryInfo(filePath);
            //获取文件夹下所有的文件
            FileInfo[] fileList = folder.GetFiles();
            foreach (FileInfo file in fileList)
            {
                //判断文件的扩展名是否为 .bmp
                if (file.Extension == ".bmp")
                {
                    file.Delete();  // 删除
                }
            }
        }
        private void ucBtnExtDel_BtnClick(object sender, EventArgs e) //按件刪除BMP圖片
        {
            DelBmp();
        }

        private void ucBtnExtOSK_BtnClick(object sender, EventArgs e) //點擊按件叫開系統軟件盤
        {

            Process proc = new Process();
            proc.StartInfo.FileName = Environment.CurrentDirectory   @"\osk.exe";
            proc.StartInfo.UseShellExecute = true;
            proc.StartInfo.Verb = "runas";
            proc.Start();
        }
    }
}