Query_SpecialReport.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }
  34. if (Num.Text == "")
  35. {
  36. MessageBox.Show("请输入数量");
  37. }
  38. if (BeginMac.Text == "")
  39. {
  40. MessageBox.Show("请输入起始地址号");
  41. }
  42. folderBrowserDialog1.Description = "选择导出的路径";
  43. DialogResult result = folderBrowserDialog1.ShowDialog();
  44. if (result == DialogResult.OK)
  45. {
  46. string FolderPath = folderBrowserDialog1.SelectedPath;
  47. ExcelHandler eh = new ExcelHandler();
  48. DataTable dt = new DataTable();
  49. dt.Columns.Add("工单号");
  50. dt.Columns.Add("MAC");
  51. dt.Columns.Add("BT");
  52. dt.Columns.Add("拓展栏位1");
  53. dt.Columns.Add("拓展栏位2");
  54. dt.Columns.Add("拓展栏位3");
  55. dt.Columns.Add("备注");
  56. string prefix = BeginMac.Text.Substring(0, 8);
  57. string suffix = BeginMac.Text.Substring(8, 4);
  58. int num = Int32.Parse(suffix, System.Globalization.NumberStyles.HexNumber);
  59. for (int i = 0; i < int.Parse(Num.Text); i++)
  60. {
  61. DataRow dr = dt.NewRow();
  62. dr["工单号"] = ma_code.Text;
  63. dr["MAC"] = prefix + num.ToString("X");
  64. num = num + 1;
  65. dr["BT"] = prefix + num.ToString("X");
  66. num = num + 1;
  67. dt.Rows.Add(dr);
  68. }
  69. eh.ExportExcel(dt, FolderPath);
  70. }
  71. }
  72. private void Query_SpecialReport_Load(object sender, EventArgs e)
  73. {
  74. }
  75. }
  76. }