Beispiel #1
0
        /// <summary>
        /// 获取新建单据号
        /// </summary>
        /// <returns>返回获取到的单据号</returns>
        public String GetNewBillNo(DepotManagementDataContext dataContxt)
        {
            string billNo = "";
            bool   bFind  = false;

            for (int i = 0; i < m_lstNewBillId.Count; i++)
            {
                if (!m_billServer.IsExist(dataContxt, m_lstNewBillId[i]))
                {
                    // 使用旧单据
                    bFind  = true;
                    billNo = m_lstNewBillId[i];
                }
                else
                {
                    m_lstNewBillId.RemoveAt(i);
                    i--;
                }
            }

            if (!bFind)
            {
                billNo = m_assignBill.AssignNewNo(dataContxt, m_billServer, m_billType.ToString());
                m_lstNewBillId.Add(billNo);
            }

            return(billNo);
        }
        /// <summary>
        /// 取消分配的单据号
        /// </summary>
        /// <param name="context">数据上下文</param>
        /// <param name="billTypeName">单据类型名称</param>
        /// <param name="billNo">单据号</param>
        /// <returns>成功则返回true, 失败返回false或抛出异常</returns>
        public bool CancelBillNo(DepotManagementDataContext context, string billTypeName, string billNo)
        {
            BASE_BillType billType = m_billTypeServer.GetBillTypeFromName(billTypeName);

            if (billType != null)
            {
                var result = from r in context.BASE_AssignBillNo
                             where r.Bill_TypeCode == billType.TypeCode && r.Bill_No == billNo
                             select r;

                if (result.Count() > 0)
                {
                    // 如果单据已经存在则不能取消单据号
                    if (m_billServer != null)
                    {
                        if (m_billServer.IsExist(billNo))
                        {
                            return(false);
                        }
                    }

                    // 由外部调用时需要强制性删除
                    if (result.Single().AlreadyUse)
                    {
                        throw new Exception(string.Format("{0}的编号为 [{1}] 的单据已经正式使用不能取消!", billTypeName, billNo));
                    }

                    result.Single().IsAbandoned = true;
                    result.Single().AlreadyUse  = false;

                    //删除CVT/TCU总成编号
                    var varData = from a in context.ProductsCodes
                                  where a.DJH == billNo
                                  select a;

                    context.ProductsCodes.DeleteAllOnSubmit(varData);

                    return(true);
                }
            }

            return(false);
        }
        /// <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);
        }