实例介绍
【实例简介】 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(); } } }
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论