using LabelManager2; using System; using System.Data; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Windows.Forms; using UAS_MES_NEW.DataOperate; using UAS_MES_NEW.Entity; using UAS_MES_NEW.PublicForm; using UAS_MES_NEW.PublicMethod; namespace UAS_MES_NEW.Query { public partial class Query_SN : Form { DataHelper dh = SystemInf.dh; ApplicationClass lbl; Thread InitPrint; Document doc; public Query_SN() { InitializeComponent(); } private void Export_Click(object sender, EventArgs e) { ExcelExport(""); } //选择导出Excel时是选择导出数据的还是模板 private void ExcelExport(string DataOrTemplet) { //Data表示导出数据 //Templet表示导出模板 MD5 md5 = MD5.Create(); folderBrowserDialog1.Description = "选择导出的路径"; DialogResult result = folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { string FolderPath = folderBrowserDialog1.SelectedPath; ExcelHandler eh = new ExcelHandler(); DataTable dt = new DataTable(); dt.Columns.Add("工单号"); dt.Columns.Add("序列号"); for (decimal i = currentSerial.Value; i < currentSerial.Value + int.Parse(num.Text); i++) { DataRow dr = dt.NewRow(); dr["工单号"] = ma_code.Text; string serial = ma_code.Text + lpad(int.Parse(seriallength.Text), (i + 1).ToString()); dr["序列号"] = serial; dt.Rows.Add(dr); } eh.ExportExcel(dt, FolderPath); } } private void Query_SpecialReport_Load(object sender, EventArgs e) { InitPrint = new Thread(InPrint); SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序"); BaseUtil.SetFormCenter(stw); stw.ShowDialog(); doc = lbl.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\SN.lab"); } private void InPrint() { try { lbl = new ApplicationClass(); BaseUtil.WriteLbl(); } catch (Exception) { MessageBox.Show("未正确安装CodeSoft软件"); } } private static string MD5Encoding(string rawPass) { // 创建MD5类的默认实例:MD5CryptoServiceProvider MD5 md5 = MD5.Create(); byte[] bs = Encoding.UTF8.GetBytes(rawPass); byte[] hs = md5.ComputeHash(bs); StringBuilder stb = new StringBuilder(); foreach (byte b in hs) { // 以十六进制格式格式化 stb.Append(b.ToString("x2")); } return stb.ToString().ToUpper(); } private static string lpad(int length, string number) { while (number.Length < length) { number = "0" + number; } number = number.Substring(number.Length - length, length); return number; } private void Print_Click(object sender, EventArgs e) { } } }