/// <summary> /// 获取编号 /// </summary> /// <param name="clientCode"> /// </param> /// <returns></returns> public static string GetCodeByClientCode(string clientCode) { //长度 codeService = new CodeService(); List<Code> list = codeService.FindByUserCode(clientCode); if (list == null || list.Count == 0) return ""; Code code = list[0]; var sb = new StringBuilder(); sb.Append(GetSplitCode(code, code.Business)); //业务点标识 sb.Append(GetSplitCode(code, code.PrefixName)); //前缀 sb.Append(GetSplitCode(code, GetDateFormat(code))); //日期格式化 sb.Append(GetSplitCode(code, PreCreatTransactCode(code).ToString().PadLeft(code.TransactLength, '0'))); //自增 return sb.ToString().TrimEnd(code.CodeFormat.ToArray()); }
/// <summary> /// 校验C#生成编号和数据库中编吗的唯一性,当前生成系统中已作废 /// </summary> /// <param name="code">编码对象</param> /// <param name="iterator">C#自增变量</param> /// <returns></returns> private static int PreCheckCodeIsOnly(Code code, int iterator) { codeService = new CodeService(); int sourceCode = codeService.FindById(code.ID).Iterator; if (sourceCode >= iterator) { iterator++; PreCheckCodeIsOnly(code, iterator); } return sourceCode; }
/// <summary> /// 生成流水号,并检查是否有重复 /// </summary> /// <param name="code"></param> /// <returns></returns> private static int PreCreatTransactCode(Code code) { int result = 0; codeService = new CodeService(); lock (obj) { if (code.IsIterator) { //时间是否过期 if (PreCheckExpireTime(code)) { //先产生一个编号 code.Iterator++; code.Iterator = PreCheckCodeIsOnly(code, code.Iterator); //在取得数据库的值上再自加,跳号 code.Iterator++; //num++; //更新数据库 codeService.UpdateIterator(code.Iterator, code.ID); result = code.Iterator; } else { //时间过期 codeService.UpdateStartTime(DateTime.Now, code.ID, 1); result = 1; } } } return result; }
/// <summary> /// 获得最大订单编号 /// </summary> /// <returns></returns> private static Order_Code GetOrder() { codeService = new CodeService(); var _orderCode = codeService.GetOrderCount(); if (_orderCode != null) { return _orderCode; } return null; }