123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- 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 + lpad(6, num.ToString("X"));
- if (dr["MAC"].ToString().Length != 12)
- {
- MessageBox.Show("生成MAC地址错误");
- return;
- }
- num = num + 1;
- dr["BT"] = prefix + lpad(6, num.ToString("X"));
- if (dr["BT"].ToString().Length != 12)
- {
- MessageBox.Show("生成BT地址错误");
- return;
- }
- if (Serial.Checked)
- {
- num = num + 1;
- }
- else
- {
- num = num + int.Parse(numericUpDown1.Value.ToString());
- }
- dt.Rows.Add(dr);
- }
- eh.ExportExcel(dt, FolderPath);
- }
- }
- private static string lpad(int length, string number)
- {
- while (number.Length < length)
- {
- number = "0" + number;
- }
- number = number.Substring(number.Length - length, length);
- return number;
- }
- private void Query_SpecialReport_Load(object sender, EventArgs e)
- {
- }
- }
- }
|