コード例 #1
0
        public bool DownOutBillMaster(string beginDate, string endDate, out string errorInfo)
        {
            errorInfo = string.Empty;
            bool   result           = false;
            string outBillStr       = "";
            string outBillMasterStr = "";

            try
            {
                var outBillNos = OutBillMasterRepository.GetQueryable().Where(i => i.BillNo == i.BillNo).Select(i => new { i.BillNo }).ToArray();

                for (int i = 0; i < outBillNos.Length; i++)
                {
                    outBillStr += outBillNos[i].BillNo + ",";
                }
                OutBillMaster[] outBillMasterList = OutBillMasterDownService.GetOutBillMaster(outBillStr);
                foreach (var master in outBillMasterList)
                {
                    var outBillMaster = new OutBillMaster();
                    outBillMaster.BillNo        = master.BillNo;
                    outBillMaster.BillDate      = master.BillDate;
                    outBillMaster.BillTypeCode  = master.BillTypeCode;
                    outBillMaster.WarehouseCode = master.WarehouseCode;
                    outBillMaster.Status        = "1";
                    outBillMaster.IsActive      = master.IsActive;
                    outBillMaster.UpdateTime    = DateTime.Now;
                    OutBillMasterRepository.Add(outBillMaster);
                    outBillMasterStr += master.BillNo + ",";
                }
                if (outBillMasterStr != string.Empty)
                {
                    OutBillDetail[] outBillDetailList = OutBillMasterDownService.GetOutBillDetail(outBillMasterStr);
                    foreach (var detail in outBillDetailList)
                    {
                        var outBillDetail = new OutBillDetail();
                        outBillDetail.BillNo        = detail.BillNo;
                        outBillDetail.ProductCode   = detail.ProductCode;
                        outBillDetail.UnitCode      = detail.UnitCode;
                        outBillDetail.Price         = detail.Price;
                        outBillDetail.BillQuantity  = detail.BillQuantity;
                        outBillDetail.AllotQuantity = detail.AllotQuantity;
                        outBillDetail.RealQuantity  = detail.RealQuantity;
                        outBillDetail.Description   = detail.Description;
                        OutBillDetailRepository.Add(outBillDetail);
                    }
                }
                OutBillMasterRepository.SaveChanges();
                result = true;
            }
            catch (Exception e)
            {
                errorInfo = "出错,原因:" + e.Message;
            }
            return(result);
        }
コード例 #2
0
        public bool Add(OutBillDetail outBillDetail, out string errorInfo)
        {
            errorInfo = string.Empty;
            bool result = false;
            IQueryable <OutBillDetail> outBillDetailQuery = OutBillDetailRepository.GetQueryable();
            var isExistProduct  = outBillDetailQuery.FirstOrDefault(i => i.BillNo == outBillDetail.BillNo && i.ProductCode == outBillDetail.ProductCode);
            var unit            = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == outBillDetail.UnitCode);
            var storage         = StorageRepository.GetQueryable().Where(s => s.ProductCode == outBillDetail.ProductCode);
            var storageQuantity = storage.Sum(s => (s.Quantity - s.OutFrozenQuantity));

            if (isExistProduct == null)
            {
                if (storageQuantity >= (outBillDetail.BillQuantity * unit.Count))
                {
                    var ibd = new OutBillDetail();
                    ibd.BillNo        = outBillDetail.BillNo;
                    ibd.ProductCode   = outBillDetail.ProductCode;
                    ibd.UnitCode      = outBillDetail.UnitCode;
                    ibd.Price         = outBillDetail.Price;
                    ibd.BillQuantity  = outBillDetail.BillQuantity * unit.Count;
                    ibd.AllotQuantity = 0;
                    ibd.RealQuantity  = 0;
                    ibd.Description   = outBillDetail.Description;

                    OutBillDetailRepository.Add(ibd);
                    OutBillDetailRepository.SaveChanges();
                    result = true;
                }
                else
                {
                    errorInfo = "当前库存小于您输入的数量!请从新输入!";
                }
            }
            else
            {
                if (storageQuantity >= isExistProduct.BillQuantity + (outBillDetail.BillQuantity * unit.Count))
                {
                    isExistProduct.BillQuantity = isExistProduct.BillQuantity + (outBillDetail.BillQuantity * unit.Count);
                    isExistProduct.UnitCode     = outBillDetail.UnitCode;
                    OutBillDetailRepository.SaveChanges();
                    result = true;
                }
                else
                {
                    errorInfo = "当前库存小于您输入的数量!请从新输入!";
                }
            }
            return(result);
        }