首页

ADO数据库NpgSql、调用DLL、调用CS6模板打印、登陆框等综合实例

c#

2020-9-10

 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();
        }
    }
}

资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
ALL_Carton_Lable_Print_WF_20200103/.vs/ALL_Carton_Lable_Print_WF/v15/.suo , 29696
ALL_Carton_Lable_Print_WF_20200103/.vs/ALL_Carton_Lable_Print_WF/v15/Server/sqlite3/db.lock , 0
ALL_Carton_Lable_Print_WF_20200103/.vs/ALL_Carton_Lable_Print_WF/v15/Server/sqlite3/storage.ide , 4096
ALL_Carton_Lable_Print_WF_20200103/.vs/ALL_Carton_Lable_Print_WF/v15/Server/sqlite3/storage.ide-shm , 32768
ALL_Carton_Lable_Print_WF_20200103/.vs/ALL_Carton_Lable_Print_WF/v15/Server/sqlite3/storage.ide-wal , 1709832
ALL_Carton_Lable_Print_WF_20200103/.vs/config/applicationhost.config , 82986
ALL_Carton_Lable_Print_WF_20200103/.vs/Yosemite_Carton_Lable_Print_WF/v15/.suo , 34816
ALL_Carton_Lable_Print_WF_20200103/.vs/Yosemite_Carton_Lable_Print_WF/v15/Server/sqlite3/db.lock , 0
ALL_Carton_Lable_Print_WF_20200103/.vs/Yosemite_Carton_Lable_Print_WF/v15/Server/sqlite3/storage.ide , 987136
ALL_Carton_Lable_Print_WF_20200103/.vs/Yosemite_Carton_Lable_Print_WF/v15/Server/sqlite3/storage.ide-shm , 32768
ALL_Carton_Lable_Print_WF_20200103/.vs/Yosemite_Carton_Lable_Print_WF/v15/Server/sqlite3/storage.ide-wal , 4140632
ALL_Carton_Lable_Print_WF_20200103/ALL_Carton_Lable_Print_WF.cs , 8523
ALL_Carton_Lable_Print_WF_20200103/ALL_Carton_Lable_Print_WF.csproj , 6100
ALL_Carton_Lable_Print_WF_20200103/ALL_Carton_Lable_Print_WF.csproj.user , 245
ALL_Carton_Lable_Print_WF_20200103/ALL_Carton_Lable_Print_WF.Designer.cs , 24202
ALL_Carton_Lable_Print_WF_20200103/ALL_Carton_Lable_Print_WF.resx , 6011
ALL_Carton_Lable_Print_WF_20200103/ALL_Carton_Lable_Print_WF.sln , 1147
ALL_Carton_Lable_Print_WF_20200103/app.config , 161
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/20201312441.bmp , 92886
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/ALL_Carton_Lable_Print_WF.exe , 397824
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/HZH_Controls.dll , 12099072
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/Interop.LabelManager2.dll , 72192
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/LabFile/BGJ.Lab , 150528
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/Lppx2.tlb , 53940
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/Mono.Security.dll , 300544
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/Npgsql.dll , 180224
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/osk.exe , 233984
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/Setting.ini , 1043
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/SN.txt , 126
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/WinFrom_VersionCheckDLL.dll , 9216
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/ZebraPrintFunction.dll , 237568
ALL_Carton_Lable_Print_WF_20200103/bin/Debug/程式修改說明.txt , 89
ALL_Carton_Lable_Print_WF_20200103/DataFunction.cs , 11203
ALL_Carton_Lable_Print_WF_20200103/exetowinform.cs , 9090
ALL_Carton_Lable_Print_WF_20200103/Form1.cs , 1968
ALL_Carton_Lable_Print_WF_20200103/Form1.Designer.cs , 3978
ALL_Carton_Lable_Print_WF_20200103/Form1.resx , 5817
ALL_Carton_Lable_Print_WF_20200103/LoginFrm.cs , 10125
ALL_Carton_Lable_Print_WF_20200103/LoginFrm.Designer.cs , 15113
ALL_Carton_Lable_Print_WF_20200103/LoginFrm.resx , 6019
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.ALL_Carton_Lable_Print_WF.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.csproj.CopyComplete , 0
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.csproj.CoreCompileInputs.cache , 42
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.csproj.FileListAbsolute.txt , 1608
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.csproj.GenerateResource.cache , 1151
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.csproj.ResolveComReference.cache , 781
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.csprojAssemblyReference.cache , 39257
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.exe , 397824
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.Form1.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.LoginFrm.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.pdb , 77312
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/ALL_Carton_Lable_Print_WF.Properties.Resources.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/AssemblyReference.cache , 244344
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/DesignTimeResolveAssemblyReferences.cache , 21866
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 7278
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Interop.LabelManager2.dll , 72192
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll , 3584
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.csproj.CopyComplete , 0
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.csproj.CoreCompileInputs.cache , 42
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.csproj.FileListAbsolute.txt , 6450
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.csproj.GenerateResource.cache , 1156
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.csproj.ResolveComReference.cache , 813
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.csprojAssemblyReference.cache , 83360
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.Form1.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.LoginFrm.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Debug/Yosemite_Carton_Lable_Print_WF.Yosemite_Carton_Lable_Print_WF.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Release/DesignTimeResolveAssemblyReferences.cache , 8186
ALL_Carton_Lable_Print_WF_20200103/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache , 7343
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Interop.LabelManager2.dll , 72192
ALL_Carton_Lable_Print_WF_20200103/obj/Release/TempPE/Properties.Resources.Designer.cs.dll , 3584
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.csproj.CopyComplete , 0
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.csproj.CoreCompileInputs.cache , 42
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.csproj.FileListAbsolute.txt , 5143
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.csproj.GenerateResource.cache , 1156
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.csproj.ResolveComReference.cache , 761
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.csprojAssemblyReference.cache , 18274
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.exe , 395776
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.Form1.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.LoginFrm.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.pdb , 71168
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.Properties.Resources.resources , 180
ALL_Carton_Lable_Print_WF_20200103/obj/Release/Yosemite_Carton_Lable_Print_WF.Yosemite_Carton_Lable_Print_WF.resources , 180
ALL_Carton_Lable_Print_WF_20200103/Program.cs , 506
ALL_Carton_Lable_Print_WF_20200103/Properties/app.manifest , 3290
ALL_Carton_Lable_Print_WF_20200103/Properties/AssemblyInfo.cs , 1155
ALL_Carton_Lable_Print_WF_20200103/Properties/Resources.Designer.cs , 2885
ALL_Carton_Lable_Print_WF_20200103/Properties/Resources.resx , 5612
ALL_Carton_Lable_Print_WF_20200103/Properties/Settings.Designer.cs , 1125
ALL_Carton_Lable_Print_WF_20200103/Properties/Settings.settings , 249
ALL_Carton_Lable_Print_WF_20200103/SmartFolder.ico , 355574
没有账号? 忘记密码?

社交账号快速登录