/// <summary> /// 更新单据编号信息 /// </summary> /// <param name="billNoInfo">更新后的信息</param> /// <returns>操作成功返回true</returns> private bool Update(BASE_AssignBillNo billNoInfo) { DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext; var result = from r in dataContxt.BASE_AssignBillNo where r.Bill_TypeCode == billNoInfo.Bill_TypeCode && r.Bill_No == billNoInfo.Bill_No select r; if (result.Count() == 0) { return(false); } BASE_AssignBillNo data = result.Single(); data.AlreadyUse = billNoInfo.AlreadyUse; data.AssignedDate = ServerModule.ServerTime.Time; data.IsAbandoned = billNoInfo.IsAbandoned; dataContxt.SubmitChanges(); return(true); }
/// <summary> /// 为指定类别的单据分配新号 /// </summary> /// <param name="dataContxt">数据上下文</param> /// <param name="billServer">单据服务</param> /// <param name="billTypeName">单据类别名称, 如:领料单</param> /// <returns>返回获取到的新单据号</returns> public string AssignNewNo(DepotManagementDataContext dataContxt, IBasicBillServer billServer, string billTypeName) { BASE_BillType billType = m_billTypeServer.GetBillTypeFromName(billTypeName); string billNo = null; if (billType == null) { throw new Exception("不存在的单据类型名称:" + billTypeName); } m_billServer = billServer; BASE_AssignBillNo billInfo = null; #region 检查是否有放弃的编号 var result = from r in dataContxt.BASE_AssignBillNo where r.Bill_TypeCode == billType.TypeCode && r.AlreadyUse == false && r.IsAbandoned == true && r.AssignedDate.Year == ServerTime.Time.Year select r; if (result.Count() > 0) { // 是否发现异常单据 bool findExceptionBill = false; foreach (var item in result) { if (!billServer.IsExist(dataContxt, item.Bill_No)) { billInfo = item; break; } else { findExceptionBill = true; item.IsAbandoned = false; } } if (findExceptionBill) { dataContxt.SubmitChanges(); } if (billInfo != null) { Console.WriteLine("使用放弃的单据号:{0}", billInfo.Bill_No); billInfo.IsAbandoned = false; billInfo.AssignedDate = ServerModule.ServerTime.Time; dataContxt.SubmitChanges(); return(billInfo.Bill_No); } } #endregion // 生成新编号 int maxValue = 1; result = from r in dataContxt.BASE_AssignBillNo where r.Bill_TypeCode == billType.TypeCode && r.AssignedDate.Year == ServerTime.Time.Year select r; if (result.Count() > 0) { maxValue += (from c in dataContxt.BASE_AssignBillNo where c.Bill_TypeCode == billType.TypeCode && c.AssignedDate.Year == ServerTime.Time.Year select Convert.ToInt32(c.Bill_No.Substring(billType.TypeCode.Length + 6))).Max(); } //string prefix = GlobalObject.PinYin.GetFirstPYLetter(billTypeName).Substring(0, 3).ToUpper(); DateTime dt = ServerTime.Time; billNo = string.Format("{0}{1:D4}{2:D2}{3:D6}", billType.TypeCode, dt.Year, dt.Month, maxValue); Console.WriteLine("使用新分配的单据号:{0}", billNo); billInfo = new BASE_AssignBillNo(); billInfo.AlreadyUse = false; billInfo.AssignedDate = ServerModule.ServerTime.Time; billInfo.Bill_No = billNo; billInfo.Bill_TypeCode = billType.TypeCode; billInfo.IsAbandoned = false; dataContxt.BASE_AssignBillNo.InsertOnSubmit(billInfo); dataContxt.SubmitChanges(); return(billNo); }