UI展示:

ExcelHelper.cs:


using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace IMEIConvertPwdTools.V1._00
{public static class ExcelHelper{/// <summary>/// Excel导入成DataTable/// </summary>/// <param name="file">导入路径(包含文件名与扩展名)</param>/// <returns></returns>public static DataTable ExcelToTable(string file){if (file == "") return null;DataTable dt = new DataTable();IWorkbook workbook;//工作簿接口string fileExt = Path.GetExtension(file).ToLower();using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)){//XSSFWorkbook 适用XLSX格式,HSSFWorkbook 适用XLS格式if (fileExt == ".xlsx")//新版本excel2007{workbook = new XSSFWorkbook(fs);}else if (fileExt == ".xls")//早期版本excel2003{workbook = new HSSFWorkbook(fs);}else{workbook = null;}if (workbook == null) { return null; }ISheet sheet = workbook.GetSheetAt(0);//下标为零的工作簿//创建表头      FirstRowNum:获取第一个有数据的行好(默认0)IRow header = sheet.GetRow(sheet.FirstRowNum);//第一行是头部信息List<int> columns = new List<int>();for (int i = 0; i < header.LastCellNum; i++)//LastCellNum 获取列的条数{object obj = GetValueType(header.GetCell(i));if (obj == null || obj.ToString() == string.Empty){dt.Columns.Add(new DataColumn("Columns" + i.ToString()));//如果excel没有列头就自定义}elsedt.Columns.Add(new DataColumn(obj.ToString()));//获取excel列头columns.Add(i);}//构建数据   sheet.FirstRowNum + 1 表示去掉列头信息for (int i = sheet.FirstRowNum + 1; i <= sheet.LastRowNum; i++)//LastRowNum最后一条数据的行号{DataRow dr = dt.NewRow();//编号 名称 价格 描述bool hasValue = false;//判断是否有值foreach (int j in columns){//if (sheet.GetRow(i) == null) continue;//如果没数据dr[j] = GetValueType(sheet.GetRow(i).GetCell(j));if (dr[j] != null && dr[j].ToString() != string.Empty)//判断至少一列有值{hasValue = true;//不是空的}}if (hasValue){dt.Rows.Add(dr);}}}return dt;}/// <summary>/// Datable导出成Excel/// </summary>/// <param name="dt"></param>/// <param name="file">导出路径(包括文件名与扩展名)</param>public static void TableToExcel(DataTable dt, string file){IWorkbook workbook;string fileExt = Path.GetExtension(file).ToLower();if (fileExt == ".xlsx"){ workbook = new XSSFWorkbook(); }else if (fileExt == ".xls"){ workbook = new HSSFWorkbook(); }else { workbook = null; }if (workbook == null) { return; }ISheet sheet = string.IsNullOrEmpty(dt.TableName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(dt.TableName);#region 添加一行合并头部并居中显示的列//ICellStyle style = workbook.CreateCellStyle();//创建头部列样式单独合并头部列//IRow h_row = sheet.CreateRow(0);//ICell h_cell = h_row.CreateCell(0);//h_cell.SetCellValue("测试头部列");//设置单元格细信息//h_row.Height = 30 * 20;//sheet.SetColumnWidth(0, 30 * 256);//设置单元格的宽度//sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 10));//合并列//style.Alignment = HorizontalAlignment.Center;//居中显示新建一个字体样式对象//IFont font = workbook.CreateFont();//设置字体加粗样式//font.Boldweight = short.MaxValue;//使用SetFont方法将字体样式添加到单元格样式中 //style.SetFont(font);//将新的样式赋给单元格//h_cell.CellStyle = style;#endregion//表头  IRow row = sheet.CreateRow(0);//去头部修改for (int i = 0; i < dt.Columns.Count; i++){ICell cell = row.CreateCell(i);cell.SetCellValue(dt.Columns[i].ColumnName);}//数据  for (int i = 0; i < dt.Rows.Count; i++){IRow row1 = sheet.CreateRow(i + 1);//去头部修改for (int j = 0; j < dt.Columns.Count; j++){ICell cell = row1.CreateCell(j);cell.SetCellValue(dt.Rows[i][j].ToString());}}//转为字节数组  MemoryStream stream = new MemoryStream();//读写内存的对象workbook.Write(stream);var buf = stream.ToArray();//字节数组//保存为Excel文件  using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write)){fs.Write(buf, 0, buf.Length);//100.1MB  1MBfs.Flush();//缓冲区在内存中有个临时区域  盆 两个水缸 //缓冲区装满才会自动提交}}/// <summary>/// 获取单元格类型/// </summary>/// <param name="cell"></param>/// <returns></returns>private static object GetValueType(ICell cell){if (cell == null)return null;switch (cell.CellType){case CellType.Boolean: //BOOLEAN:  return cell.BooleanCellValue;case CellType.Numeric: //NUMERIC:  if (DateUtil.IsCellDateFormatted(cell))//判断是否日期 6位数字return cell.DateCellValue.ToString("yyyy/MM/dd");elsereturn cell.NumericCellValue;case CellType.Error: //ERROR:  return cell.ErrorCellValue;case CellType.String: //STRING:  default:return cell.StringCellValue;}}}
}

CsvHelper.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace IMEIConvertPwdTools.V1._00
{public class CSVFileHelper{/// <summary>/// 将DataTable中数据写入到CSV文件中/// </summary>/// <param name="dt">提供保存数据的DataTable</param>/// <param name="fileName">CSV的文件路径</param>public static void SaveCSV(DataTable dt, string fullPath){FileInfo fi = new FileInfo(fullPath);if (!fi.Directory.Exists){fi.Directory.Create();}FileStream fs = new FileStream(fullPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);//StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8);string data = "";//写出列名称for (int i = 0; i < dt.Columns.Count; i++){data += dt.Columns[i].ColumnName.ToString();if (i < dt.Columns.Count - 1){data += ",";}}sw.WriteLine(data);//写出各行数据for (int i = 0; i < dt.Rows.Count; i++){data = "";for (int j = 0; j < dt.Columns.Count; j++){string str = dt.Rows[i][j].ToString();str = str.Replace("\"", "\"\"");//替换英文冒号 英文冒号需要换成两个冒号if (str.Contains(',') || str.Contains('"')|| str.Contains('\r') || str.Contains('\n')) //含逗号 冒号 换行符的需要放到引号中{str = string.Format("\"{0}\"", str);}data += str;if (j < dt.Columns.Count - 1){data += ",";}}sw.WriteLine(data);}sw.Close();fs.Close();}/// <summary>/// 将CSV文件的数据读取到DataTable中/// </summary>/// <param name="fileName">CSV文件路径</param>/// <returns>返回读取了CSV数据的DataTable</returns>public static DataTable OpenCSV(string filePath){//Encoding encoding = Common.GetType(filePath); //Encoding.ASCII;//DataTable dt = new DataTable();FileStream fs = new FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);//StreamReader sr = new StreamReader(fs, Encoding.UTF8);StreamReader sr = new StreamReader(fs, Encoding.Default);//string fileContent = sr.ReadToEnd();//encoding = sr.CurrentEncoding;//记录每次读取的一行记录string strLine = "";//记录每行记录中的各字段内容string[] aryLine = null;string[] tableHead = null;//标示列数int columnCount = 0;//标示是否是读取的第一行bool IsFirst = true;//逐行读取CSV中的数据while ((strLine = sr.ReadLine()) != null){//strLine = Common.ConvertStringUTF8(strLine, encoding);//strLine = Common.ConvertStringUTF8(strLine);if (IsFirst == true){tableHead = strLine.Split(',');IsFirst = false;columnCount = tableHead.Length;//创建列for (int i = 0; i < columnCount; i++){DataColumn dc = new DataColumn(tableHead[i]);dt.Columns.Add(dc);}}else{aryLine = strLine.Split(',');DataRow dr = dt.NewRow();for (int j = 0; j < columnCount; j++){dr[j] = aryLine[j];}dt.Rows.Add(dr);}}if (aryLine != null && aryLine.Length > 0){dt.DefaultView.Sort = tableHead[0] + " " + "asc";}sr.Close();fs.Close();return dt;}}
}

IMEIConvertPwdEntity.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace IMEIConvertPwdTools.V1._00
{public class IMEIConvertPwdEntity{/// <summary>/// 序号/// </summary>public int NO { get; set; }/// <summary>/// 16位IMEI/// </summary>public string IMEI{ get; set; }/// <summary>/// 转换的密码/// </summary>public string Pwd { get; set; }}
}

AutoSizeFormClass.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;namespace IMEIConvertPwdTools.V1._00
{public class AutoSizeFormClass{//(1).声明结构,只记录窗体和其控件的初始位置和大小。  public struct controlRect{public int Left;public int Top;public int Width;public int Height;}//(2).声明 1个对象  //注意这里不能使用控件列表记录 List<Control> nCtrl;,因为控件的关联性,记录的始终是当前的大小。  public List<controlRect> oldCtrl;//int ctrl_first = 0;  //(3). 创建两个函数  //(3.1)记录窗体和其控件的初始位置和大小,  public AutoSizeFormClass(Form mForm){// if (ctrl_first == 0)  {//  ctrl_first = 1;  oldCtrl = new List<controlRect>();controlRect cR;cR.Left = mForm.Left; cR.Top = mForm.Top; cR.Width = mForm.Width; cR.Height = mForm.Height;oldCtrl.Add(cR);foreach (Control c in mForm.Controls){controlRect objCtrl;objCtrl.Left = c.Left; objCtrl.Top = c.Top; objCtrl.Width = c.Width; objCtrl.Height = c.Height;oldCtrl.Add(objCtrl);}}// this.WindowState = (System.Windows.Forms.FormWindowState)(2);//记录完控件的初始位置和大小后,再最大化  //0 - Normalize , 1 - Minimize,2- Maximize  }//(3.2)控件自适应大小,  public void controlAutoSize(Form mForm){//int wLeft0 = oldCtrl[0].Left; ;//窗体最初的位置  //int wTop0 = oldCtrl[0].Top;  int wLeft1 = this.Left;//窗体当前的位置  //int wTop1 = this.Top;  float wScale = (float)mForm.Width / (float)oldCtrl[0].Width;//新旧窗体之间的比例,与最早的旧窗体  float hScale = (float)mForm.Height / (float)oldCtrl[0].Height;//.Height;  int ctrLeft0, ctrTop0, ctrWidth0, ctrHeight0;int ctrlNo = 1;//第1个是窗体自身的 Left,Top,Width,Height,所以窗体控件从ctrlNo=1开始  foreach (Control c in mForm.Controls){ctrLeft0 = oldCtrl[ctrlNo].Left;ctrTop0 = oldCtrl[ctrlNo].Top;ctrWidth0 = oldCtrl[ctrlNo].Width;ctrHeight0 = oldCtrl[ctrlNo].Height;//c.Left = (int)((ctrLeft0 - wLeft0) * wScale) + wLeft1;//新旧控件之间的线性比例  //c.Top = (int)((ctrTop0 - wTop0) * h) + wTop1;  c.Left = (int)((ctrLeft0) * wScale);//新旧控件之间的线性比例。控件位置只相对于窗体,所以不能加 + wLeft1  c.Top = (int)((ctrTop0) * hScale);//  c.Width = (int)(ctrWidth0 * wScale);//只与最初的大小相关,所以不能与现在的宽度相乘 (int)(c.Width * w);  c.Height = (int)(ctrHeight0 * hScale);//  ctrlNo += 1;}}}
}

AutoSetControlSize.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace IMEIConvertPwdTools.V1._00
{public class AutoSetControlSize{#region 控件大小随窗体大小等比例缩放public float X { get; set; }//定义当前窗体的宽度public float Y { get; set; }//定义当前窗体的高度/// <summary>/// 原始X,Y的座标/// </summary>/// <param name="form"></param>/// <param name="x"></param>/// <param name="y"></param>public AutoSetControlSize(Form form,float x,float y){this.X = x;this.Y = y;setTag(form);}private void setTag(Control cons){foreach (Control con in cons.Controls){con.Tag = con.Width + ";" + con.Height + ";" + con.Left + ";" + con.Top + ";" + con.Font.Size;if (con.Controls.Count > 0){setTag(con);}}}public void setControls(float newx, float newy, Control cons){//遍历窗体中的控件,重新设置控件的值foreach (Control con in cons.Controls){//获取控件的Tag属性值,并分割后存储字符串数组if (con.Tag != null){string[] mytag = con.Tag.ToString().Split(new char[] { ';' });//根据窗体缩放的比例确定控件的值con.Width = Convert.ToInt32(System.Convert.ToSingle(mytag[0]) * newx);//宽度con.Height = Convert.ToInt32(System.Convert.ToSingle(mytag[1]) * newy);//高度con.Left = Convert.ToInt32(System.Convert.ToSingle(mytag[2]) * newx);//左边距con.Top = Convert.ToInt32(System.Convert.ToSingle(mytag[3]) * newy);//顶边距//Single currentSize = System.Convert.ToSingle(mytag[4]) * newy;//字体大小//con.Font = new Font(con.Font.Name, currentSize, con.Font.Style, con.Font.Unit);if (con.Controls.Count > 0){setControls(newx, newy, con);}}}}#endregion}
}

MainForm.cs


namespace IMEIConvertPwdTools.V1._00
{partial class MainForm{/// <summary>/// 必需的设计器变量。/// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// 清理所有正在使用的资源。/// </summary>/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// <summary>/// 设计器支持所需的方法 - 不要修改/// 使用代码编辑器修改此方法的内容。/// </summary>private void InitializeComponent(){this.components = new System.ComponentModel.Container();System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));this.splitContainer1 = new System.Windows.Forms.SplitContainer();this.panel1 = new System.Windows.Forms.Panel();this.btn_Close = new System.Windows.Forms.Button();this.imageList1 = new System.Windows.Forms.ImageList(this.components);this.label5 = new System.Windows.Forms.Label();this.label1 = new System.Windows.Forms.Label();this.statusStrip1 = new System.Windows.Forms.StatusStrip();this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();this.toolStripStatusLabel3 = new System.Windows.Forms.ToolStripStatusLabel();this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel();this.t_SystemDateTime = new System.Windows.Forms.ToolStripStatusLabel();this.toolStripStatusLabel5 = new System.Windows.Forms.ToolStripStatusLabel();this.toolStripStatusLabel6 = new System.Windows.Forms.ToolStripStatusLabel();this.t_DataCount = new System.Windows.Forms.ToolStripStatusLabel();this.btn_Import = new System.Windows.Forms.Button();this.txt_IEMIFilePath = new System.Windows.Forms.TextBox();this.label4 = new System.Windows.Forms.Label();this.label3 = new System.Windows.Forms.Label();this.dtgrive_ImeiData = new System.Windows.Forms.DataGridView();this.NO = new System.Windows.Forms.DataGridViewTextBoxColumn();this.IMEI_15Bit = new System.Windows.Forms.DataGridViewTextBoxColumn();this.PassWord_8Bit = new System.Windows.Forms.DataGridViewTextBoxColumn();this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);this.Men_txt = new System.Windows.Forms.ToolStripMenuItem();this.Men_csv = new System.Windows.Forms.ToolStripMenuItem();this.Men_xls = new System.Windows.Forms.ToolStripMenuItem();this.label2 = new System.Windows.Forms.Label();this.timer1 = new System.Windows.Forms.Timer(this.components);((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();this.splitContainer1.Panel1.SuspendLayout();this.splitContainer1.Panel2.SuspendLayout();this.splitContainer1.SuspendLayout();this.panel1.SuspendLayout();this.statusStrip1.SuspendLayout();((System.ComponentModel.ISupportInitialize)(this.dtgrive_ImeiData)).BeginInit();this.contextMenuStrip1.SuspendLayout();this.SuspendLayout();// // splitContainer1// this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;this.splitContainer1.Location = new System.Drawing.Point(0, 0);this.splitContainer1.Name = "splitContainer1";this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;// // splitContainer1.Panel1// this.splitContainer1.Panel1.Controls.Add(this.panel1);// // splitContainer1.Panel2// this.splitContainer1.Panel2.Controls.Add(this.statusStrip1);this.splitContainer1.Panel2.Controls.Add(this.btn_Import);this.splitContainer1.Panel2.Controls.Add(this.txt_IEMIFilePath);this.splitContainer1.Panel2.Controls.Add(this.label4);this.splitContainer1.Panel2.Controls.Add(this.label3);this.splitContainer1.Panel2.Controls.Add(this.dtgrive_ImeiData);this.splitContainer1.Panel2.Controls.Add(this.label2);this.splitContainer1.Size = new System.Drawing.Size(1037, 900);this.splitContainer1.SplitterDistance = 48;this.splitContainer1.SplitterWidth = 1;this.splitContainer1.TabIndex = 0;// // panel1// this.panel1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(161)))), ((int)(((byte)(188)))), ((int)(((byte)(219)))));this.panel1.Controls.Add(this.btn_Close);this.panel1.Controls.Add(this.label5);this.panel1.Controls.Add(this.label1);this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;this.panel1.Location = new System.Drawing.Point(0, 0);this.panel1.Name = "panel1";this.panel1.Size = new System.Drawing.Size(1037, 48);this.panel1.TabIndex = 0;this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Frm_MouseDown);this.panel1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Frm_MouseMove);this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Frm_MouseUp);// // btn_Close// this.btn_Close.FlatAppearance.BorderSize = 0;this.btn_Close.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.btn_Close.ImageIndex = 1;this.btn_Close.ImageList = this.imageList1;this.btn_Close.Location = new System.Drawing.Point(990, 11);this.btn_Close.Name = "btn_Close";this.btn_Close.Size = new System.Drawing.Size(28, 27);this.btn_Close.TabIndex = 2;this.btn_Close.UseVisualStyleBackColor = true;this.btn_Close.Click += new System.EventHandler(this.btn_Close_Click);// // imageList1// this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));this.imageList1.TransparentColor = System.Drawing.Color.Transparent;this.imageList1.Images.SetKeyName(0, "链接转换工具集.png");this.imageList1.Images.SetKeyName(1, "关闭.png");this.imageList1.Images.SetKeyName(2, "导入.png");this.imageList1.Images.SetKeyName(3, "导入项目_操作_jurassic.png");this.imageList1.Images.SetKeyName(4, "数据导入.png");// // label5// this.label5.ForeColor = System.Drawing.Color.White;this.label5.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;this.label5.ImageIndex = 0;this.label5.ImageList = this.imageList1;this.label5.Location = new System.Drawing.Point(383, 0);this.label5.Name = "label5";this.label5.Size = new System.Drawing.Size(40, 47);this.label5.TabIndex = 0;this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;// // label1// this.label1.ForeColor = System.Drawing.Color.White;this.label1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;this.label1.ImageList = this.imageList1;this.label1.Location = new System.Drawing.Point(418, 1);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(191, 47);this.label1.TabIndex = 0;this.label1.Text = "IMEI Convert Pwd Tools";this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;// // statusStrip1// this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.toolStripStatusLabel1,this.toolStripStatusLabel2,this.toolStripStatusLabel3,this.toolStripStatusLabel4,this.t_SystemDateTime,this.toolStripStatusLabel5,this.toolStripStatusLabel6,this.t_DataCount});this.statusStrip1.Location = new System.Drawing.Point(0, 829);this.statusStrip1.Name = "statusStrip1";this.statusStrip1.Size = new System.Drawing.Size(1037, 22);this.statusStrip1.TabIndex = 1;this.statusStrip1.Text = "statusStrip1";// // toolStripStatusLabel1// this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";this.toolStripStatusLabel1.Size = new System.Drawing.Size(110, 17);this.toolStripStatusLabel1.Text = "Software Version:";// // toolStripStatusLabel2// this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";this.toolStripStatusLabel2.Size = new System.Drawing.Size(40, 17);this.toolStripStatusLabel2.Text = "V1.00";// // toolStripStatusLabel3// this.toolStripStatusLabel3.Name = "toolStripStatusLabel3";this.toolStripStatusLabel3.Size = new System.Drawing.Size(296, 17);this.toolStripStatusLabel3.Text = "                                                                        ";// // toolStripStatusLabel4// this.toolStripStatusLabel4.Name = "toolStripStatusLabel4";this.toolStripStatusLabel4.Size = new System.Drawing.Size(111, 17);this.toolStripStatusLabel4.Text = "System DateTime:";// // t_SystemDateTime// this.t_SystemDateTime.Name = "t_SystemDateTime";this.t_SystemDateTime.Size = new System.Drawing.Size(32, 17);this.t_SystemDateTime.Text = "xxxx";// // toolStripStatusLabel5// this.toolStripStatusLabel5.Name = "toolStripStatusLabel5";this.toolStripStatusLabel5.Size = new System.Drawing.Size(208, 17);this.toolStripStatusLabel5.Text = "                                                  ";// // toolStripStatusLabel6// this.toolStripStatusLabel6.Name = "toolStripStatusLabel6";this.toolStripStatusLabel6.Size = new System.Drawing.Size(67, 17);this.toolStripStatusLabel6.Text = "DataTotal:";// // t_DataCount// this.t_DataCount.Name = "t_DataCount";this.t_DataCount.Size = new System.Drawing.Size(0, 17);// // btn_Import// this.btn_Import.FlatAppearance.BorderSize = 0;this.btn_Import.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.btn_Import.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;this.btn_Import.ImageIndex = 3;this.btn_Import.ImageList = this.imageList1;this.btn_Import.Location = new System.Drawing.Point(936, 23);this.btn_Import.Name = "btn_Import";this.btn_Import.Size = new System.Drawing.Size(82, 33);this.btn_Import.TabIndex = 1;this.btn_Import.Text = "....";this.btn_Import.TextAlign = System.Drawing.ContentAlignment.MiddleRight;this.btn_Import.UseVisualStyleBackColor = true;this.btn_Import.Click += new System.EventHandler(this.btn_Import_Click);// // txt_IEMIFilePath// this.txt_IEMIFilePath.BorderStyle = System.Windows.Forms.BorderStyle.None;this.txt_IEMIFilePath.Enabled = false;this.txt_IEMIFilePath.Location = new System.Drawing.Point(170, 36);this.txt_IEMIFilePath.Name = "txt_IEMIFilePath";this.txt_IEMIFilePath.ReadOnly = true;this.txt_IEMIFilePath.Size = new System.Drawing.Size(760, 19);this.txt_IEMIFilePath.TabIndex = 5;// // label4// this.label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;this.label4.Location = new System.Drawing.Point(170, 56);this.label4.Name = "label4";this.label4.Size = new System.Drawing.Size(760, 1);this.label4.TabIndex = 4;// // label3// this.label3.AutoSize = true;this.label3.Location = new System.Drawing.Point(5, 37);this.label3.Name = "label3";this.label3.Size = new System.Drawing.Size(168, 16);this.label3.TabIndex = 3;this.label3.Text = "Load IMEI File Path:";// // dtgrive_ImeiData// this.dtgrive_ImeiData.AllowUserToAddRows = false;this.dtgrive_ImeiData.AllowUserToDeleteRows = false;this.dtgrive_ImeiData.BackgroundColor = System.Drawing.Color.White;this.dtgrive_ImeiData.BorderStyle = System.Windows.Forms.BorderStyle.None;this.dtgrive_ImeiData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;this.dtgrive_ImeiData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {this.NO,this.IMEI_15Bit,this.PassWord_8Bit});this.dtgrive_ImeiData.ContextMenuStrip = this.contextMenuStrip1;this.dtgrive_ImeiData.Location = new System.Drawing.Point(33, 92);this.dtgrive_ImeiData.Name = "dtgrive_ImeiData";this.dtgrive_ImeiData.ReadOnly = true;this.dtgrive_ImeiData.RowTemplate.Height = 23;this.dtgrive_ImeiData.Size = new System.Drawing.Size(974, 734);this.dtgrive_ImeiData.TabIndex = 2;this.dtgrive_ImeiData.RowsAdded += new System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.dtgrive_ImeiData_RowsAdded);// // NO// this.NO.DataPropertyName = "NO";this.NO.HeaderText = "NO";this.NO.Name = "NO";this.NO.ReadOnly = true;this.NO.Width = 150;// // IMEI_15Bit// this.IMEI_15Bit.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;this.IMEI_15Bit.DataPropertyName = "IMEI";this.IMEI_15Bit.HeaderText = "IMEI_15Bit";this.IMEI_15Bit.Name = "IMEI_15Bit";this.IMEI_15Bit.ReadOnly = true;// // PassWord_8Bit// this.PassWord_8Bit.DataPropertyName = "Pwd";this.PassWord_8Bit.HeaderText = "PassWord_8Bit";this.PassWord_8Bit.Name = "PassWord_8Bit";this.PassWord_8Bit.ReadOnly = true;this.PassWord_8Bit.Width = 300;// // contextMenuStrip1// this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.Men_txt,this.Men_csv,this.Men_xls});this.contextMenuStrip1.Name = "contextMenuStrip1";this.contextMenuStrip1.Size = new System.Drawing.Size(181, 92);// // Men_txt// this.Men_txt.Enabled = false;this.Men_txt.Image = global::IMEIConvertPwdTools.V1._00.Properties.Resources.txt;this.Men_txt.Name = "Men_txt";this.Men_txt.Size = new System.Drawing.Size(180, 22);this.Men_txt.Text = "Export Data *.txt";this.Men_txt.Click += new System.EventHandler(this.Men_txt_Click);// // Men_csv// this.Men_csv.Enabled = false;this.Men_csv.Image = global::IMEIConvertPwdTools.V1._00.Properties.Resources.csv;this.Men_csv.Name = "Men_csv";this.Men_csv.Size = new System.Drawing.Size(180, 22);this.Men_csv.Text = "Export Data *.csv";this.Men_csv.Click += new System.EventHandler(this.Men_csv_Click);// // Men_xls// this.Men_xls.Enabled = false;this.Men_xls.Image = global::IMEIConvertPwdTools.V1._00.Properties.Resources.xls;this.Men_xls.Name = "Men_xls";this.Men_xls.Size = new System.Drawing.Size(180, 22);this.Men_xls.Text = "Export Data *.xlsx";this.Men_xls.Click += new System.EventHandler(this.Men_xls_Click);// // label2// this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;this.label2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.label2.Location = new System.Drawing.Point(3, 92);this.label2.Name = "label2";this.label2.Size = new System.Drawing.Size(1034, 1);this.label2.TabIndex = 0;// // timer1// this.timer1.Enabled = true;this.timer1.Tick += new System.EventHandler(this.timer1_Tick);// // MainForm// this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(1037, 900);this.Controls.Add(this.splitContainer1);this.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));this.Margin = new System.Windows.Forms.Padding(4);this.Name = "MainForm";this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;this.Text = "Form1";this.SizeChanged += new System.EventHandler(this.MainWinForm_SizeChanged);this.Resize += new System.EventHandler(this.MainWinForm_Resize);this.splitContainer1.Panel1.ResumeLayout(false);this.splitContainer1.Panel2.ResumeLayout(false);this.splitContainer1.Panel2.PerformLayout();((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();this.splitContainer1.ResumeLayout(false);this.panel1.ResumeLayout(false);this.statusStrip1.ResumeLayout(false);this.statusStrip1.PerformLayout();((System.ComponentModel.ISupportInitialize)(this.dtgrive_ImeiData)).EndInit();this.contextMenuStrip1.ResumeLayout(false);this.ResumeLayout(false);}#endregionprivate System.Windows.Forms.SplitContainer splitContainer1;private System.Windows.Forms.Panel panel1;private System.Windows.Forms.Label label1;private System.Windows.Forms.ImageList imageList1;private System.Windows.Forms.Button btn_Close;private System.Windows.Forms.StatusStrip statusStrip1;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel3;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4;private System.Windows.Forms.ToolStripStatusLabel t_SystemDateTime;private System.Windows.Forms.Label label2;private System.Windows.Forms.Timer timer1;private System.Windows.Forms.DataGridView dtgrive_ImeiData;private System.Windows.Forms.Label label4;private System.Windows.Forms.Label label3;private System.Windows.Forms.TextBox txt_IEMIFilePath;private System.Windows.Forms.Button btn_Import;private System.Windows.Forms.DataGridViewTextBoxColumn NO;private System.Windows.Forms.DataGridViewTextBoxColumn IMEI_15Bit;private System.Windows.Forms.DataGridViewTextBoxColumn PassWord_8Bit;private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;private System.Windows.Forms.ToolStripMenuItem Men_txt;private System.Windows.Forms.ToolStripMenuItem Men_csv;private System.Windows.Forms.ToolStripMenuItem Men_xls;private System.Windows.Forms.Label label5;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel5;private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel6;private System.Windows.Forms.ToolStripStatusLabel t_DataCount;}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace IMEIConvertPwdTools.V1._00
{public partial class MainForm : Form{private AutoSizeFormClass asc = null;private AutoSetControlSize ass = null;private List<string> iMEIdata;private List<IMEIConvertPwdEntity> iMEIConvertPwdEntities;public MainForm(){InitializeComponent();ass = new AutoSetControlSize(this, this.Width, this.Height);}#region 窗体自适应private void MainWinForm_SizeChanged(object sender, EventArgs e){asc = new AutoSizeFormClass(this);asc.controlAutoSize(this);}private void MainWinForm_Resize(object sender, EventArgs e){ass.setControls((this.Width) / ass.X, (this.Height) / ass.Y, this);}#endregion#region 窗体移动private Point mouseOff;//鼠标移动位置变量private bool leftFlag;//标签是否为左键private void Frm_MouseDown(object sender, MouseEventArgs e){if (e.Button == MouseButtons.Left){mouseOff = new Point(-e.X, -e.Y); //得到变量的值leftFlag = true;                  //点击左键按下时标注为true;}}private void Frm_MouseMove(object sender, MouseEventArgs e){if (leftFlag){Point mouseSet = Control.MousePosition;mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置Location = mouseSet;}}private void Frm_MouseUp(object sender, MouseEventArgs e){if (leftFlag){leftFlag = false;//释放鼠标后标注为false;}}#endregion#region 同步系统时间private void timer1_Tick(object sender, EventArgs e){t_SystemDateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");}#endregion#region 关闭窗体private void btn_Close_Click(object sender, EventArgs e){DialogResult dialogResult = MessageBox.Show("Confirm Exit!!", "Remind",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);if (dialogResult==DialogResult.Yes)Application.Exit();}#endregion#region 导入数据private void btn_Import_Click(object sender, EventArgs e){OpenFileDialog dialog = new OpenFileDialog();dialog.Multiselect = false;//该值确定是滞可以选择多个文件dialog.Title = "Please select file";dialog.Filter = "(*.txt)|*.txt";if (dialog.ShowDialog() == DialogResult.OK){txt_IEMIFilePath.Text = dialog.FileName;if (this.ReadImeiFileData(txt_IEMIFilePath.Text)){if (this.BatchImeiConvertPwsData(iMEIdata)){dtgrive_ImeiData.DataSource = new List<IMEIConvertPwdEntity>();dtgrive_ImeiData.DataSource = iMEIConvertPwdEntities;}}}}#endregion#region 批量转换ImeiDataprivate bool BatchImeiConvertPwsData(List<string> data){iMEIConvertPwdEntities = new List<IMEIConvertPwdEntity>();for (int i = 0; i < data.Count; i++){if (this.ImeiConvertPwsData(data[i])){iMEIConvertPwdEntities.Add(new IMEIConvertPwdEntity(){NO = i + 1,IMEI = data[i],Pwd = temp});}elsereturn false;}if (iMEIConvertPwdEntities.Count > 0)return true;return false;}#endregion#region 单项转换Imei 数据private string temp;private bool ImeiConvertPwsData(string strdata){temp = string.Empty;for (int i = 0; i < strdata.Length - 1; i += 2){try{temp += ((Convert.ToInt32(strdata[i].ToString()) + Convert.ToInt32(strdata[i + 1].ToString())) % 10).ToString();}catch (Exception ex){MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);return false;}}temp += strdata[0].ToString();if (temp != string.Empty)return true;return false;}#endregion#region 读取IMEI文件数据private bool ReadImeiFileData(string fileName){using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)){using (StreamReader sr = new StreamReader(fs, Encoding.Default)){string temp = string.Empty;iMEIdata = new List<string>();while ((temp = sr.ReadLine()) != null){if (temp.Length != 15){MessageBox.Show($"IMEI:{temp}Format error!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);return false;}else{iMEIdata.Add(temp.Trim());}}return true;}}return false;}#endregion#region 表格内容更新事件private void dtgrive_ImeiData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e){t_DataCount.Text = iMEIConvertPwdEntities.Count.ToString() + "Pcs";Men_csv.Enabled = iMEIConvertPwdEntities.Count > 0 ? true : false;Men_txt.Enabled = iMEIConvertPwdEntities.Count > 0 ? true : false;Men_xls.Enabled = iMEIConvertPwdEntities.Count > 0 ? true : false;}#endregion#region 导出txtprivate void Men_txt_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog = new SaveFileDialog();saveFileDialog.InitialDirectory = Application.StartupPath;// @"C:\Users\Administrator\Desktop";saveFileDialog.Filter = @"*.txt|*.txt";if (saveFileDialog.ShowDialog() == DialogResult.OK){using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.Write)){using (StreamWriter sw = new StreamWriter(fs)){sw.WriteLine("NO|IMEI_15Bit|Pws_8Bit");iMEIConvertPwdEntities.ForEach((i) => { sw.WriteLine(i.NO + "|" + i.IMEI + "|" + i.Pwd); });}MessageBox.Show("Export the complete!!", "Remind",MessageBoxButtons.OK,MessageBoxIcon.Information);}}}#endregion#region 导出xlsprivate void Men_xls_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog = new SaveFileDialog();saveFileDialog.InitialDirectory = Application.StartupPath;// @"C:\Users\Administrator\Desktop";saveFileDialog.Filter = @"*.xlsx|*.xlsx";if (saveFileDialog.ShowDialog() == DialogResult.OK){DataTable dt = new DataTable();dt.Columns.Add("NO", typeof(Int32));dt.Columns.Add("IMEI_15Bit", typeof(string));dt.Columns.Add("Pws_8Bit", typeof(string));iMEIConvertPwdEntities.ForEach((i) => {DataRow dr = dt.NewRow();dr[0] = i.NO;dr[1] = i.IMEI;dr[2] = i.Pwd;dt.Rows.Add(dr);});ExcelHelper.TableToExcel(dt, saveFileDialog.FileName);MessageBox.Show("Export the complete!!", "Remind", MessageBoxButtons.OK, MessageBoxIcon.Information);}}#endregion#region 导出csvprivate void Men_csv_Click(object sender, EventArgs e){SaveFileDialog saveFileDialog = new SaveFileDialog();saveFileDialog.InitialDirectory = Application.StartupPath;// @"C:\Users\Administrator\Desktop";saveFileDialog.Filter = @"*.csv|*.csv";if (saveFileDialog.ShowDialog() == DialogResult.OK){DataTable dt = new DataTable();dt.Columns.Add("NO", typeof(Int32));dt.Columns.Add("IMEI_15Bit", typeof(string));dt.Columns.Add("Pws_8Bit", typeof(string));iMEIConvertPwdEntities.ForEach((i) => {DataRow dr = dt.NewRow();dr[0] = i.NO;dr[1] = i.IMEI;dr[2] = i.Pwd;dt.Rows.Add(dr);});CSVFileHelper.SaveCSV(dt, saveFileDialog.FileName);MessageBox.Show("Export the complete!!", "Remind", MessageBoxButtons.OK, MessageBoxIcon.Information);}}#endregion}
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;namespace IMEIConvertPwdTools.V1._00
{static class Program{/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(new MainForm());}}
}

C# IMEI15位转换成8位密码相关推荐

  1. nodejs将图片的像素值提取出来将RGBA转换成16位彩色

    nodejs将图片的像素值提取出来将RGBA转换成16位彩色 RGBA转16位彩色的原理 RGBA由4*8bit组成(255, 255, 255,255),16位彩色为2*8bit组成.16位彩色需要 ...

  2. 16Aspx.com-将15位身份证转换成18位

    16Aspx.com-将15位身份证转换成18位 //************************************************************************* ...

  3. IEEE754:将单精度浮点数的IEEE754格式转换成32位整型

    ieee754,要求如下, 定义函数 int my_int_float() 从键盘输入一个单精度浮点数的字符串,然后自己解析该字符串,并用位操作把对应的值按754格式保存到4字节里,最后返回该四字节对 ...

  4. 怎么把JAVA32位改成64位_win732位改成64位教程

    win732位改成64位要怎么做呢?2位win7改成64位win7的原因,想必大家都知道了,回归正题,我们来说说32位win7改成64位的,这里就给大家说一下操作的方法. 用户想要把win732位改成 ...

  5. JAVA32位的如何换成64位的_教你怎么把win732位换成64位

    近来,小编在网上看到一些网友在寻求windows732位怎么换成64位的方法,所以急人之所需,小编就如何windows732位怎么换成64位,做出以下解答. 一些朋友在网站上想要知道怎么把win732 ...

  6. python日期格式转换成13位时间戳_python生成13位或16位时间戳以及反向解析时间戳的实例...

    我就废话不多说了,直接上代码吧! import datetime import time def get_float_time_stamp(): datetime_now = datetime.dat ...

  7. 32位指针强制转换成64位数据

    代码如下: void        *paddr = dma buffer physical address; pkt->vp_pkt.paddr       = (uint64_t)paddr ...

  8. 32位颜色 转换成16位颜色

    向别人学习而来:分享.. 1.颜色值有32位存储和16位存储实现呼唤. 2.原理new Color(97,100,255);这个是32位存储 参数依次是 r.g.b.省略了a,alpha通道的值 rg ...

  9. eclipse 32位换成64位 maven tomcat svn 集成

    搞了这么多年的java一直使用eclipse32位的,一直就想换成64位的,涉及的东西太多了,一直没成功! 通过好几天的努力!哎...不容易! 1..eclipseproduct中版本version= ...

  10. wav文件的采样位数从16位转换到8位的C语言实现

    目录 前言 程序解析及源码 函数学习 malloc与free函数 memcpy函数 feof函数 源码解析 前言 今天来对自己找到的一份网上的有关将wav文件的采样位数从16位转化成8位的程序进行解析 ...

最新文章

  1. Android stadio 调试太掉了
  2. 白话Elasticsearch29-IK中文分词之IK分词器配置文件+自定义词库
  3. anaconda3环境整体打包放在Spark集群上运行
  4. 苹果mac视频和字幕下载软件:Downie
  5. C++ 不能在类体外指定关键字static
  6. 微信小程序map组件拖拽地图获取经纬度,地址,带定位点范围(中心点固定)
  7. excel2007加载宏的两种方法
  8. OtherSoftwares
  9. 超详细的Django面试题
  10. C语言strrchr()函数
  11. 在excel筛选出某一列多个重复值
  12. 台式电脑c语言如何安装,台式电脑怎么安装电源 组装机正确安装电源的方法
  13. 一文读懂十大数据存储加密技术
  14. T级攻防:大规模DDOS防御架构
  15. 入门科普|Python和C/C++等有何区别?
  16. 一行代码得到全学科的北大核心期刊投稿方式
  17. 安装RapidDesign_v1.3.0.Cracked.DX10.3.Rio
  18. 微信和淘宝最赤裸的分析 转载
  19. 雪晴数据网 - 在线学习数据科学技术
  20. [绍棠] iOS开发经验总结

热门文章

  1. linux命令备忘录
  2. (matlab代码)绘制地震记录的F-K谱
  3. 证据理论(2)—— 多种合成公式
  4. 学完python可以当黑客吗_想当黑客吗?我教你啊!精心整理最简单的黑客入门——PYTHON教程,免费系统又经典...
  5. 多年iOS开发经验总结
  6. MATLAB实现自编码器(五)——变分自编码器(VAE)实现图像生成的帮助函数
  7. (强烈推荐)无线网络密码破解方法
  8. Kali Linux学习之arp地址欺骗
  9. Linux LAMP架构介绍及配置
  10. php中的递归调用函数返回值,深入理解php递归函数返回值的正确用法