using Panuon.WPF.UI;
|
using Plugin.SNGenerateTool.Entity;
|
using System;
|
using System.Collections.ObjectModel;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Globalization;
|
using System.IO;
|
using System.Linq;
|
using System.Runtime.CompilerServices;
|
using System.Runtime.InteropServices;
|
using System.Text;
|
using System.Windows;
|
using System.Windows.Controls;
|
|
namespace Plugin.SNGenerateTool
|
{
|
/// <summary>
|
/// UserControl1.xaml 的交互逻辑
|
/// </summary>
|
public partial class UserControl1 : UserControl, INotifyPropertyChanged
|
{
|
#region ...
|
public virtual event PropertyChangedEventHandler PropertyChanged;
|
|
protected virtual void Set(string name)
|
{
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
|
}
|
|
protected void Set<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
|
{
|
old = @new;
|
if (propertyName != null)
|
{
|
Set(propertyName);
|
}
|
}
|
#endregion
|
|
private string iniFile = Path.Combine(Environment.CurrentDirectory, "Config", "UserSettings.ini");
|
|
private string[] years = new string[30]
|
{
|
"1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
|
"B", "C", "D", "E", "F", "G", "H", "J", "K", "L",
|
"M", "N", "P", "R", "S", "T", "V", "W", "X", "Y"
|
};
|
|
private string[] months = new string[12]
|
{
|
"1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
|
"B", "C"
|
};
|
|
private string[] days = new string[31]
|
{
|
"1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
|
"B", "C", "D", "E", "F", "G", "H", "J", "K", "L",
|
"M", "N", "P", "R", "S", "T", "V", "W", "X", "Y",
|
"Z"
|
};
|
|
private string[] F18CY = new string[10] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
|
private ObservableCollection<DataInfo> datasource = new ObservableCollection<DataInfo>();
|
public ObservableCollection<DataInfo> Datasource
|
{
|
get => datasource;
|
set
|
{
|
Set(ref datasource, value);
|
}
|
}
|
|
|
public UserControl1()
|
{
|
this.DataContext = this;
|
InitializeComponent();
|
}
|
|
[DllImport("kernel32")]
|
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
|
[DllImport("kernel32")]
|
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
|
|
|
private void SaveSettings(string section, string file)
|
{
|
if (!File.Exists(file))
|
{
|
MessageBox.Show("配置文件不存在,保存失败", "错误提示", MessageBoxButton.OK, MessageBoxImage.Hand);
|
return;
|
}
|
WritePrivateProfileString(section, "OrderId", tbx_OrderID.Text, file);
|
WritePrivateProfileString(section, "SNPrefix", txt_SNPrefix.Text, file);
|
WritePrivateProfileString(section, "MESStartSN", txt_StartSN.Text, file);
|
WritePrivateProfileString(section, "MESEndSN", txt_EndSN.Text, file);
|
WritePrivateProfileString(section, "XDSNDate", txt_Date1.Text, file);
|
WritePrivateProfileString(section, "XDSNDaySN", txt_StartDaySN.Text, file);
|
WritePrivateProfileString(section, "XDSNSpecialSN", txt_MinSpecialSN.Text, file);
|
WritePrivateProfileString(section, "PartNo", txt_PN.Text, file);
|
WritePrivateProfileString(section, "HW", txt_HW.Text, file);
|
WritePrivateProfileString(section, "SW", txt_SW.Text, file);
|
WritePrivateProfileString(section, "GeelyDU", txt_GeelyDU.Text, file);
|
WritePrivateProfileString(section, "GeelyHWSD", txt_GeelyHWSD.Text, file);
|
WritePrivateProfileString(section, "SXBL", txt_SXBL.Text, file);
|
WritePrivateProfileString(section, "SXDISXBL", txt_SXDISXBL.Text, file);
|
WritePrivateProfileString(section, "VolvoDU", txt_VolvoDU.Text, file);
|
WritePrivateProfileString(section, "VolvoHWSD", txt_VolvoHWSD.Text, file);
|
}
|
|
public void CreateSN()
|
{
|
Datasource.Clear();
|
|
try
|
{
|
int num = Convert.ToInt32(txt_StartSN.Text);
|
int num2 = Convert.ToInt32(txt_EndSN.Text);
|
int num3 = Convert.ToInt32(txt_StartDaySN.Text);
|
int num4 = Convert.ToInt32(txt_MinSpecialSN.Text);
|
int num5 = Convert.ToInt32(txt_StartDHUIDSN.Text);
|
int num6 = Convert.ToInt32(txt_Date1.Text.Substring(0, 4)) % 2001;
|
int num7 = Convert.ToInt32(txt_Date1.Text.Substring(4, 2)) - 1;
|
int num8 = Convert.ToInt32(txt_Date1.Text.Substring(6, 2)) - 1;
|
if (Convert.ToInt32(txt_Date1.Text.Substring(0, 4)) < 2020)
|
{
|
MessageBox.Show("生产日期中的年份早于当前年份!", "错误提示", MessageBoxButton.OK, MessageBoxImage.Hand);
|
return;
|
}
|
int num9 = Convert.ToInt32(txt_Date1.Text.Substring(0, 4)) % 2020;
|
GregorianCalendar gregorianCalendar = new GregorianCalendar();
|
DateTime time = DateTime.ParseExact(txt_Date1.Text, "yyyyMMdd", CultureInfo.CurrentCulture);
|
int weekOfYear = gregorianCalendar.GetWeekOfYear(time, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
|
int num10 = 0;
|
switch (time.DayOfWeek.ToString())
|
{
|
case "Monday":
|
num10 = 1;
|
break;
|
case "Tuesday":
|
num10 = 2;
|
break;
|
case "Wednesday":
|
num10 = 3;
|
break;
|
case "Thursday":
|
num10 = 4;
|
break;
|
case "Friday":
|
num10 = 5;
|
break;
|
case "Saturday":
|
num10 = 6;
|
break;
|
case "Sunday":
|
num10 = 7;
|
break;
|
}
|
if (txt_StartSN.Text != null && txt_EndSN.Text != null && num <= num2 && txt_EndSN.Text.Length < 5)
|
{
|
int num11 = num;
|
int num12 = num3;
|
int num13 = num4;
|
int num14 = num5;
|
while (num11 <= num2)
|
{
|
DataInfo di = new DataInfo();
|
if (num12.ToString().Length < 5 && num13.ToString().Length < 8 && num14.ToString().Length < 5)
|
{
|
string text = txt_PCODE.Text.Trim() + years[num6] + num13.ToString().PadLeft(7, '0');
|
string text2 = HashPlus.GetHashMD5(text).ToUpper();
|
text2 = text2.Substring(0, 8) + "-" + text2.Substring(8, 4) + "-" + text2.Substring(12, 4) + "-" + text2.Substring(16, 4) + "-" + text2.Substring(20, 12);
|
string text3 = txt_SNPrefix.Text + num11.ToString().PadLeft(4, '0');
|
string text4 = txt_PCODE.Text + txt_MachineCode.Text + txt_FactoryCode.Text + txt_LineNo1.Text + years[num6] + months[num7] + days[num8] + num12.ToString().PadLeft(4, '0') + num13.ToString().PadLeft(7, '0');
|
string text5 = txt_VendorCode.Text + txt_PN.Text + years[num6] + months[num7] + days[num8] + txt_ShiftsNo.Text + num14.ToString().PadLeft(4, '0');
|
string empty = string.Empty;
|
empty = F18CY[num9] + weekOfYear.ToString().PadLeft(2, '0') + num10 + num12.ToString().PadLeft(4, '0');
|
if (text3.Length != 14 && text4.Length != 24 && text5.Length != 24)
|
{
|
MessageBox.Show("MESSN / XDSN / DHUID长度有误,请检查输入的数据是否有误!", "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
|
return;
|
}
|
//dataRow["GUID"] = text2;
|
//dataRow["Orderid"] = tbx_OrderID.Text.Trim();
|
//dataRow["Model"] = cbox_Model.Text.Trim();
|
//dataRow["MESSN"] = text3.Trim();
|
//dataRow["XDSN"] = text4.Trim();
|
//dataRow["DHUID"] = text5.Trim();
|
//dataRow["ProductSN"] = empty.Trim();
|
//dataRow["HW"] = txt_HW.Text.PadRight(16, '0').Trim();
|
//dataRow["SW"] = txt_SW.Text.Trim();
|
//dataRow["SXBL"] = txt_SXBL.Text.Trim();
|
//dataRow["SXDI_SXBL"] = txt_SXDISXBL.Text.Trim();
|
//dataRow["GeelyDU"] = txt_GeelyDU.Text.Trim();
|
//dataRow["GeelyHWSD"] = txt_GeelyHWSD.Text.Trim();
|
//dataRow["ECUDAPN"] = txt_VolvoDU.Text.Trim();
|
//dataRow["ECUCAPN"] = txt_VolvoHWSD.Text.Trim();
|
//dataRow["Status"] = 0;
|
//dataRow["CreateTime"] = Convert.ToDateTime(DateTime.Now.ToString("G"));
|
|
di.GUID = text2;
|
di.OrderID = tbx_OrderID.Text.Trim();
|
di.Model = cbox_Model.Text.Trim();
|
di.MESSN = text3.Trim();
|
di.XDSN = text4.Trim();
|
di.DHUID = text5.Trim();
|
di.ProductSN = empty.Trim();
|
di.HW = txt_HW.Text.PadRight(16, '0').Trim();
|
di.SW = txt_SW.Text.Trim();
|
di.SXBL = txt_SXBL.Text.Trim();
|
di.SXDI_SXBL = txt_SXDISXBL.Text.Trim();
|
di.GeelyDU = txt_GeelyDU.Text.Trim();
|
di.GeelyHWSD = txt_GeelyHWSD.Text.Trim();
|
di.ECUDAPN = txt_VolvoDU.Text.Trim();
|
di.ECUCAPN = txt_VolvoHWSD.Text.Trim();
|
di.Status = 0;
|
di.CreateTime = Convert.ToDateTime(DateTime.Now.ToString("G"));
|
Datasource.Add(di);
|
num11++;
|
num12++;
|
num13++;
|
num14++;
|
continue;
|
}
|
MessageBox.Show("日流水号或连续号位数超出范围", "错误提示", MessageBoxButton.OK, MessageBoxImage.Hand);
|
break;
|
}
|
//toolStripStatusLabel8.Text = $"{table.Rows.Count}行";
|
}
|
else
|
{
|
MessageBox.Show("请检查所有文本框是否有填写,并确认SN的流水号及位数是否有误", "错误提示", MessageBoxButton.OK, MessageBoxImage.Hand);
|
}
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show(ex.Message, "错误提示", MessageBoxButton.OK, MessageBoxImage.Hand);
|
}
|
}
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
{
|
SaveSettings(cbox_Model.Text, iniFile);
|
CreateSN();
|
}
|
}
|
}
|