using LabelManager2; using System; using System.Linq; 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_SpecialReport : Form { DataHelper dh = SystemInf.dh; ApplicationClass lbl; Document doc; Thread InitPrint; public Query_SpecialReport() { InitializeComponent(); } private void Export_Click(object sender, EventArgs e) { ExcelExport(""); } //选择导出Excel时是选择导出数据的还是模板 private void ExcelExport(string DataOrTemplet) { for (int i = int.Parse(Rn.Text); i < int.Parse(Num.Text); i = i + 8) { int temp = i; for (int j = 0; j < doc.Variables.FormVariables.Count; j++) { switch (doc.Variables.FormVariables.Item(j + 1).Name) { case "RN1": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; case "RN2": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 1).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; case "RN3": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 2).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; case "RN4": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 3).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; case "RN5": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 4).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; case "RN6": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 5).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; case "RN7": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 6).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; case "RN8": doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 7).ToString())); Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value); break; default: break; } } doc.Printer.SwitchTo(Printer.Text); doc.PrintDocument(1); } } 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 lpad(int length, string number) { while (number.Length < length) { number = "0" + number; } number = number.Substring(number.Length - length, length); return number; } private void inoutno_TextChanged(object sender, EventArgs e) { } } }