Query_SpecialReport.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_MES_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Query
  13. {
  14. public partial class Query_SpecialReport : Form
  15. {
  16. DataHelper dh = SystemInf.dh;
  17. public Query_SpecialReport()
  18. {
  19. InitializeComponent();
  20. }
  21. private void Export_Click(object sender, EventArgs e)
  22. {
  23. ExcelExport("");
  24. }
  25. //选择导出Excel时是选择导出数据的还是模板
  26. private void ExcelExport(string DataOrTemplet)
  27. {
  28. //Data表示导出数据
  29. //Templet表示导出模板
  30. if (ma_code.Text == "")
  31. {
  32. MessageBox.Show("请输入工单号");
  33. return;
  34. }
  35. if (Num.Text == "")
  36. {
  37. MessageBox.Show("请输入数量");
  38. return;
  39. }
  40. if (BeginMac.Text == "" || BeginMac.TextLength != 12)
  41. {
  42. MessageBox.Show("请输入起始地址号或检查长度");
  43. return;
  44. }
  45. folderBrowserDialog1.Description = "选择导出的路径";
  46. DialogResult result = folderBrowserDialog1.ShowDialog();
  47. if (result == DialogResult.OK)
  48. {
  49. string FolderPath = folderBrowserDialog1.SelectedPath;
  50. ExcelHandler eh = new ExcelHandler();
  51. DataTable dt = new DataTable();
  52. dt.Columns.Add("工单号");
  53. dt.Columns.Add("MAC");
  54. dt.Columns.Add("BT");
  55. dt.Columns.Add("扩展栏位1");
  56. dt.Columns.Add("扩展栏位2");
  57. dt.Columns.Add("扩展栏位3");
  58. dt.Columns.Add("备注");
  59. string prefix = BeginMac.Text.Substring(0, 6);
  60. string suffix = BeginMac.Text.Substring(6, 6);
  61. int num = Int32.Parse(suffix, System.Globalization.NumberStyles.HexNumber);
  62. for (int i = 0; i < int.Parse(Num.Text); i++)
  63. {
  64. DataRow dr = dt.NewRow();
  65. dr["工单号"] = ma_code.Text;
  66. dr["MAC"] = prefix + lpad(6, num.ToString("X"));
  67. if (dr["MAC"].ToString().Length != 12)
  68. {
  69. MessageBox.Show("生成MAC地址错误");
  70. return;
  71. }
  72. num = num + 1;
  73. dr["BT"] = prefix + lpad(6, num.ToString("X"));
  74. if (dr["BT"].ToString().Length != 12)
  75. {
  76. MessageBox.Show("生成BT地址错误");
  77. return;
  78. }
  79. if (Serial.Checked)
  80. {
  81. num = num + 1;
  82. }
  83. else
  84. {
  85. num = num + int.Parse(numericUpDown1.Value.ToString());
  86. }
  87. dt.Rows.Add(dr);
  88. }
  89. eh.ExportExcel(dt, FolderPath);
  90. }
  91. }
  92. private static string lpad(int length, string number)
  93. {
  94. while (number.Length < length)
  95. {
  96. number = "0" + number;
  97. }
  98. number = number.Substring(number.Length - length, length);
  99. return number;
  100. }
  101. private void Query_SpecialReport_Load(object sender, EventArgs e)
  102. {
  103. }
  104. }
  105. }