using System; using System.Collections.Generic; using System.Data.Entity.Infrastructure; using System.Linq; using System.Text; using System.Threading.Tasks; using CK.SCP.Models; using CK.SCP.Utils; namespace CK.SCP.Controller { public class SCP_BILLCODE_CONTROLLER { public static string MakeClaimCode() { return GetTablePK("M", "TM_HYANTOLIN_REVIEW", "ReviewBillNum", "yyMMdd", 4); } public static string MakePOCode() { return GetTablePK("P", "TB_PO", "PoBillNum", "yyMMdd", 4); } public static string MakeQualityCode() { return GetTablePK("Q", "TB_QUALITY", "QualityNo", "yyMMdd", 4); } public static string MakeASNCode() { return GetTablePK("N", "TB_ASN", "AsnBillNum", "yyMMdd", 4); } public static string MakePalletCode() { return GetTablePK("G", "TB_PALLET", "PalletNum", "yyMMdd", 4); } /// /// 生成托盘码(青岛) /// /// /// public static string MakePalletCode_QD(int num) { return GetTablePK_QD("G", "TB_PALLETS", "PalletNum", "yyMMdd", 4,num); } public static string MakeASKCode() { return GetTablePK("K", "TB_ASK", "AskBillNum", "yyMMdd", 4); } public static string MakePLAN_ASKCode() { return GetTablePK("E", "TB_ASK", "AskBillNum", "yyMMdd", 4); } public static string MakePLAN_EXTEND_ASKCode() { return GetTablePK("U", "TB_ASK", "AskBillNum", "yyMMdd", 4); } public static string MakeReviceCode() { return GetTablePK("R", "TB_RECEIVE", "RecvBillNum", "yyMMdd", 4); } public static string MakeRejectCode() { return GetTablePK("J", "TB_REJECT", "RjctBillNum", "yyMMdd", 4); } public static string MakeInvoiceCode() { return GetTablePK("F", "TB_INVOICE", "InvcBillNum", "yyMMdd", 4); } public static string MakeCode(string p_Header, string p_TableName,string p_ColumnName) { return GetTablePK(p_Header, p_TableName, p_ColumnName, "yyMMdd",4); } public static string GetTablePK(string Ext, string TableName, string ColName, string Format, int len) { var _result = string.Empty; try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string time = Ext + DateTime.Now.ToString(Format); string sql = "select max(right(" + ColName + "," + len.ToString() + ")+1) from " + TableName + " where " + ColName + " like '" + time + "%'"; DbRawSqlQuery result = db.Database.SqlQuery(sql); var obj = result.FirstOrDefault(); if (obj==null) { _result= time + "1".PadLeft(len, '0'); } else { _result= time + result.FirstOrDefault().ToString().PadLeft(len, '0'); } } } catch(Exception e) { LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BILLCODE_CONTROLLER), "GetTablePK", e.Message); } return _result; } public static string GetTablePK_QD(string Ext, string TableName, string ColName, string Format, int len,int num) { var _result = string.Empty; try { using (ScpEntities db = EntitiesFactory.CreateScpInstance()) { string time = Ext + DateTime.Now.ToString(Format); string sql = "select max(right(" + ColName + "," + len.ToString() + ")+1) from " + TableName + " where " + ColName + " like '" + time + "%'"; DbRawSqlQuery result = db.Database.SqlQuery(sql); var obj = result.FirstOrDefault(); if (obj == null) { _result = time + num.ToString().PadLeft(len, '0'); } else { _result = time + (result.FirstOrDefault()+num).ToString().PadLeft(len, '0'); } } } catch (Exception e) { LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_BILLCODE_CONTROLLER), "GetTablePK", e.Message); } return _result; } } }