Query_SpecialReport.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 + 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 + num.ToString("X");
  74. num = num + 1;
  75. dt.Rows.Add(dr);
  76. }
  77. eh.ExportExcel(dt, FolderPath);
  78. }
  79. }
  80. private void Query_SpecialReport_Load(object sender, EventArgs e)
  81. {
  82. }
  83. }
  84. }