Query_SN.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using LabelManager2;
  2. using System;
  3. using System.Data;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using UAS_MES_NEW.DataOperate;
  9. using UAS_MES_NEW.Entity;
  10. using UAS_MES_NEW.PublicForm;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Query
  13. {
  14. public partial class Query_SN : Form
  15. {
  16. DataHelper dh = SystemInf.dh;
  17. ApplicationClass lbl;
  18. Thread InitPrint;
  19. Document doc;
  20. public Query_SN()
  21. {
  22. InitializeComponent();
  23. }
  24. private void Export_Click(object sender, EventArgs e)
  25. {
  26. ExcelExport("");
  27. }
  28. //选择导出Excel时是选择导出数据的还是模板
  29. private void ExcelExport(string DataOrTemplet)
  30. {
  31. //Data表示导出数据
  32. //Templet表示导出模板
  33. MD5 md5 = MD5.Create();
  34. folderBrowserDialog1.Description = "选择导出的路径";
  35. DialogResult result = folderBrowserDialog1.ShowDialog();
  36. if (result == DialogResult.OK)
  37. {
  38. string FolderPath = folderBrowserDialog1.SelectedPath;
  39. ExcelHandler eh = new ExcelHandler();
  40. DataTable dt = new DataTable();
  41. dt.Columns.Add("工单号");
  42. dt.Columns.Add("序列号");
  43. for (decimal i = currentSerial.Value; i < currentSerial.Value + int.Parse(num.Text); i++)
  44. {
  45. DataRow dr = dt.NewRow();
  46. dr["工单号"] = ma_code.Text;
  47. string serial = ma_code.Text
  48. + lpad(int.Parse(seriallength.Text), (i + 1).ToString());
  49. dr["序列号"] = serial;
  50. dt.Rows.Add(dr);
  51. }
  52. eh.ExportExcel(dt, FolderPath);
  53. }
  54. }
  55. private void Query_SpecialReport_Load(object sender, EventArgs e)
  56. {
  57. InitPrint = new Thread(InPrint);
  58. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  59. BaseUtil.SetFormCenter(stw);
  60. stw.ShowDialog();
  61. doc = lbl.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\SN.lab");
  62. }
  63. private void InPrint()
  64. {
  65. try
  66. {
  67. lbl = new ApplicationClass();
  68. BaseUtil.WriteLbl();
  69. }
  70. catch (Exception)
  71. {
  72. MessageBox.Show("未正确安装CodeSoft软件");
  73. }
  74. }
  75. private static string MD5Encoding(string rawPass)
  76. {
  77. // 创建MD5类的默认实例:MD5CryptoServiceProvider
  78. MD5 md5 = MD5.Create();
  79. byte[] bs = Encoding.UTF8.GetBytes(rawPass);
  80. byte[] hs = md5.ComputeHash(bs);
  81. StringBuilder stb = new StringBuilder();
  82. foreach (byte b in hs)
  83. {
  84. // 以十六进制格式格式化
  85. stb.Append(b.ToString("x2"));
  86. }
  87. return stb.ToString().ToUpper();
  88. }
  89. private static string lpad(int length, string number)
  90. {
  91. while (number.Length < length)
  92. {
  93. number = "0" + number;
  94. }
  95. number = number.Substring(number.Length - length, length);
  96. return number;
  97. }
  98. private void Print_Click(object sender, EventArgs e)
  99. {
  100. }
  101. }
  102. }