Query_SpecialReport.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using LabelManager2;
  2. using System;
  3. using System.Linq;
  4. using System.Threading;
  5. using System.Windows.Forms;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.Entity;
  8. using UAS_MES_NEW.PublicForm;
  9. using UAS_MES_NEW.PublicMethod;
  10. namespace UAS_MES_NEW.Query
  11. {
  12. public partial class Query_SpecialReport : Form
  13. {
  14. DataHelper dh = SystemInf.dh;
  15. ApplicationClass lbl;
  16. Document doc;
  17. Thread InitPrint;
  18. public Query_SpecialReport()
  19. {
  20. InitializeComponent();
  21. }
  22. private void Export_Click(object sender, EventArgs e)
  23. {
  24. ExcelExport("");
  25. }
  26. //选择导出Excel时是选择导出数据的还是模板
  27. private void ExcelExport(string DataOrTemplet)
  28. {
  29. for (int i = int.Parse(Rn.Text); i < int.Parse(Num.Text); i = i + 8)
  30. {
  31. int temp = i;
  32. for (int j = 0; j < doc.Variables.FormVariables.Count; j++)
  33. {
  34. switch (doc.Variables.FormVariables.Item(j + 1).Name)
  35. {
  36. case "RN1":
  37. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp).ToString()));
  38. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  39. break;
  40. case "RN2":
  41. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 1).ToString()));
  42. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  43. break;
  44. case "RN3":
  45. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 2).ToString()));
  46. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  47. break;
  48. case "RN4":
  49. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 3).ToString()));
  50. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  51. break;
  52. case "RN5":
  53. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 4).ToString()));
  54. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  55. break;
  56. case "RN6":
  57. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 5).ToString()));
  58. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  59. break;
  60. case "RN7":
  61. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 6).ToString()));
  62. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  63. break;
  64. case "RN8":
  65. doc.Variables.FormVariables.Item(j + 1).Value = (Prefix.Text + Date.Value.ToString("yyMMdd") + lpad(4, (temp + 7).ToString()));
  66. Console.WriteLine(doc.Variables.FormVariables.Item(j + 1).Value);
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. doc.Printer.SwitchTo(Printer.Text);
  73. doc.PrintDocument(1);
  74. }
  75. }
  76. private void Query_SpecialReport_Load(object sender, EventArgs e)
  77. {
  78. InitPrint = new Thread(InPrint);
  79. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  80. BaseUtil.SetFormCenter(stw);
  81. stw.ShowDialog();
  82. doc = lbl.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\SN.lab");
  83. }
  84. private void InPrint()
  85. {
  86. try
  87. {
  88. lbl = new ApplicationClass();
  89. BaseUtil.WriteLbl();
  90. }
  91. catch (Exception)
  92. {
  93. MessageBox.Show("未正确安装CodeSoft软件");
  94. }
  95. }
  96. private static string lpad(int length, string number)
  97. {
  98. while (number.Length < length)
  99. {
  100. number = "0" + number;
  101. }
  102. number = number.Substring(number.Length - length, length);
  103. return number;
  104. }
  105. private void inoutno_TextChanged(object sender, EventArgs e)
  106. {
  107. }
  108. }
  109. }