| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Query
- {
- public partial class Query_SpecialReport : Form
- {
- DataHelper dh = SystemInf.dh;
- public Query_SpecialReport()
- {
- InitializeComponent();
- }
- private void Export_Click(object sender, EventArgs e)
- {
- ExcelExport("");
- }
- //选择导出Excel时是选择导出数据的还是模板
- private void ExcelExport(string DataOrTemplet)
- {
- //Data表示导出数据
- //Templet表示导出模板
- if (ma_code.Text == "")
- {
- MessageBox.Show("请输入工单号");
- return;
- }
- if (Num.Text == "")
- {
- MessageBox.Show("请输入数量");
- return;
- }
- if (BeginMac.Text ==""|| BeginMac.TextLength != 12)
- {
- MessageBox.Show("请输入起始地址号或检查长度");
- return;
- }
- folderBrowserDialog1.Description = "选择导出的路径";
- DialogResult result = folderBrowserDialog1.ShowDialog();
- if (result == DialogResult.OK)
- {
- string FolderPath = folderBrowserDialog1.SelectedPath;
- ExcelHandler eh = new ExcelHandler();
- DataTable dt = new DataTable();
- dt.Columns.Add("工单号");
- dt.Columns.Add("MAC");
- dt.Columns.Add("BT");
- dt.Columns.Add("扩展栏位1");
- dt.Columns.Add("扩展栏位2");
- dt.Columns.Add("扩展栏位3");
- dt.Columns.Add("备注");
- string prefix = BeginMac.Text.Substring(0, 6);
- string suffix = BeginMac.Text.Substring(6, 6);
- int num = Int32.Parse(suffix, System.Globalization.NumberStyles.HexNumber);
- for (int i = 0; i < int.Parse(Num.Text); i++)
- {
- DataRow dr = dt.NewRow();
- dr["工单号"] = ma_code.Text;
- dr["MAC"] = prefix + num.ToString("X");
- if (dr["MAC"].ToString().Length != 12)
- {
- MessageBox.Show("生成MAC地址错误");
- return;
- }
- num = num + 1;
- dr["BT"] = prefix + num.ToString("X");
- num = num + 1;
- dt.Rows.Add(dr);
- }
- eh.ExportExcel(dt, FolderPath);
- }
- }
- private void Query_SpecialReport_Load(object sender, EventArgs e)
- {
- }
- }
- }
|