using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.DAL.Operation;
namespace QMAPP.FJC.TRACING.CodeGenerators
{
public class AssemblyCodeGenerator:DAInterface.ICodeGenerator
{
public string Generate(string materialcode, DateTime time, dynamic parameters)
{
DAL.Operation.MainDAL maindal = new DAL.Operation.MainDAL();
PrintCode printcode = maindal.GetMaxANDMinMainCode(materialcode);
string maxcode = maindal.GetMaxMainCode(printcode.MINVALUE, printcode.MAXVALUE);
string newcode = "1";
if (!string.IsNullOrEmpty(maxcode))
{
newcode = (Convert.ToInt32(maxcode) + 1) + "";
}
if (Convert.ToInt32(newcode) > printcode.MAXVALUE)
{
throw new Exception("该配置零件条码流水号溢出,请重新设置!");
}
newcode = "052 4XR" + newcode.PadLeft(7, '0');
string finalcode = newcode + CalculateChecksum(newcode);
printcode.MAINCODE = finalcode;
printcode.ISCOMPLETE = 0;
printcode.SERIAL_NUM = 0;
PrintCodeDAL dal = new PrintCodeDAL();
dal.Update(printcode);
return finalcode;
#region
//DAL.Operation.MainDAL maindal = new DAL.Operation.MainDAL();
//PrintCode condition = maindal.NewGetMaxMainCode(materialcode);
//string newcode = "1";
//if (!string.IsNullOrEmpty(condition.MAINCODE))
//{
// newcode = (Convert.ToInt32(condition.MAINCODE.Substring(1, 6)) + 1) + "";
//}
//newcode = "052 4XR" + condition.MAINCODE.Substring(0, 1) + newcode.PadLeft(6, '0');
//newcode = newcode + CalculateChecksum(newcode);
////更新T_AW_PRINTCODE表
//PrintCode pc = new PrintCode();
//pc.PID = condition.PID;
//pc.MAINCODE = newcode;
//pc.ISCOMPLETE = 0;
//pc.PRODUCTCODE = condition.PRODUCTCODE;
//pc.CREATETIME = System.DateTime.Now;
//PrintCodeDAL dal = new PrintCodeDAL();
//dal.Update(pc);
//return newcode;
#endregion
}
///
/// 计算验证码
///
///
public static string CalculateChecksum(string barcode)
{
string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
int sum = 0;
foreach (var c in barcode)
{
sum += chars.IndexOf(c);
}
int rem = sum % chars.Length;
return chars[rem].ToString();
}
}
}