Esempio n. 1
0
        public JsonResult LoadCustomerByName(string strName)
        {
            string         strErrText;
            CustomerSystem customer = new CustomerSystem();
            Customer       data     = customer.LoadCustomerByName(strName, LoginAccountId, LoginStaffName, out strErrText);

            if (data == null)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            else
            {
                decimal decLoadingForceFeePrice   = 0;
                decimal decUnloadingForceFeePrice = 0;
                CustomerForceFeePrice data1       = customer.LoadCustomerForceFeePrice(data.Id, DateTime.Now, LoginAccountId, LoginStaffName, out strErrText);
                if (data1 != null)
                {
                    decLoadingForceFeePrice   = data1.LoadingForceFeePrice;
                    decUnloadingForceFeePrice = data1.UnloadingForceFeePrice;
                }

                decimal decStorageFeePrice    = 0;
                CustomerStorageFeePrice data2 = customer.LoadCustomerStorageFeePrice(data.Id, DateTime.Now, LoginAccountId, LoginStaffName, out strErrText);
                if (data2 != null)
                {
                    decStorageFeePrice = data2.StorageFeePrice;
                }

                var ret = new
                {
                    Id   = data.Id,
                    Name = data.Name,
                    LoadingForceFeePrice   = decLoadingForceFeePrice,
                    UnloadingForceFeePrice = decUnloadingForceFeePrice,
                    StorageFeePrice        = decStorageFeePrice,
                    OwnOrganId             = data.OwnOrganId
                };

                return(Json(ret, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 新增客户力支费价格数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool InsertCustomerForceFeePrice(CustomerForceFeePrice data, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            //创建存储过程参数
            SqlParameter[] Params =
            {
                MakeParam(CUSTOMERID_PARAM,             SqlDbType.BigInt,    8, ParameterDirection.Input, (object)data.CustomerId),
                MakeParam(STARTTIME_PARAM,              SqlDbType.DateTime,  8, ParameterDirection.Input, (object)data.StartTime),
                MakeParam(ENDTIME_PARAM,                SqlDbType.DateTime,  8, ParameterDirection.Input, (object)data.EndTime),
                MakeParam(LOADINGFORCEFEEPRICE_PARAM,   SqlDbType.Decimal,  13, ParameterDirection.Input, (object)data.LoadingForceFeePrice),
                MakeParam(UNLOADINGFORCEFEEPRICE_PARAM, SqlDbType.Decimal,  13, ParameterDirection.Input, (object)data.UnloadingForceFeePrice),
                MakeParam(OPSTAFFID_PARAM,              SqlDbType.BigInt,    8, ParameterDirection.Input, (object)nOpStaffId),
                MakeParam(OPSTAFFNAME_PARAM,            SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)strOpStaffName),
            };

            if (Execute("InsertCustomerForceFeePrice", Params, out strErrText) >= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 读取指定客户和时间的力支费价格数据
        /// </summary>
        /// <param name="nCustomerId"></param>
        /// <param name="dtStartTime"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public CustomerForceFeePrice LoadCustomerForceFeePrice(long nCustomerId, DateTime dtStartTime, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            try
            {
                CustomerForceFeePrice dataResult = null;
                strErrText = String.Empty;

                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (CustomerDAO dao = new CustomerDAO())
                    {
                        dataResult = dao.LoadCustomerForceFeePrice(nCustomerId, dtStartTime, nOpStaffId, strOpStaffName, out strErrText);
                    }
                    transScope.Complete();
                }
                return(dataResult);
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 修改出库单数据
        /// </summary>
        /// <param name="bill"></param>
        /// <param name="listGoods"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool UpdateOutWarehouseBill(OutWarehouseBill bill, List <OutWarehouseBillGoods> listGoods, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (StockDAO dao = new StockDAO())
                    {
                        //修改出库单数据
                        if (!dao.UpdateOutWarehouseBill(bill, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(false);
                        }

                        //修改出库货物数据
                        foreach (OutWarehouseBillGoods goods in listGoods)
                        {
                            if (!dao.UpdateOutWarehouseBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(false);
                            }
                        }
                    }

                    using (CustomerDAO dao = new CustomerDAO())
                    {
                        //修改上力支费价格数据
                        List <CustomerForceFeePrice> listForceFeePrice = dao.LoadCustomerForceFeePricesByCustomerId(bill.CustomerId, nOpStaffId, strOpStaffName, out strErrText);
                        if (listForceFeePrice.Count == 0)
                        {
                            //新增力支费价格数据
                            CustomerForceFeePrice data = new CustomerForceFeePrice();
                            data.CustomerId             = bill.CustomerId;
                            data.StartTime              = bill.CreateTime;
                            data.EndTime                = DateTime.Parse("9999-12-31");
                            data.LoadingForceFeePrice   = bill.LoadingForceFeePrice;
                            data.UnloadingForceFeePrice = 0;

                            if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            int i = 0;
                            while (i < listForceFeePrice.Count)
                            {
                                if (bill.CreateTime.Date >= listForceFeePrice[i].StartTime.Date && bill.CreateTime.Date <= listForceFeePrice[i].EndTime.Date)
                                {
                                    break;
                                }
                                i++;
                            }
                            if (i < listForceFeePrice.Count)
                            {
                                //修改力支费价格数据
                                listForceFeePrice[i].LoadingForceFeePrice = bill.LoadingForceFeePrice;

                                if (!dao.UpdateCustomerForceFeePrice(listForceFeePrice[i], nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                //新增力支费价格数据
                                CustomerForceFeePrice data = new CustomerForceFeePrice();
                                data.CustomerId             = bill.CustomerId;
                                data.StartTime              = bill.CreateTime;
                                data.LoadingForceFeePrice   = bill.LoadingForceFeePrice;
                                data.UnloadingForceFeePrice = 0;

                                //计算截止时间
                                i = 0;
                                while (i < listForceFeePrice.Count)
                                {
                                    if (bill.CreateTime.Date < listForceFeePrice[i].StartTime.Date)
                                    {
                                        break;
                                    }
                                    i++;
                                }
                                if (i < listForceFeePrice.Count)
                                {
                                    data.EndTime = listForceFeePrice[i].StartTime.Date.AddDays(-1);
                                }
                                else
                                {
                                    data.EndTime = DateTime.Parse("9999-12-31");
                                }

                                if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    transScope.Complete();
                }
                return(true);
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return(false);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 修改入库单数据
        /// </summary>
        /// <param name="bill"></param>
        /// <param name="listGoods"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool UpdateEnterWarehouseBill(EnterWarehouseBill bill, List <EnterWarehouseBillGoods> listGoods, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (StockDAO dao = new StockDAO())
                    {
                        //读取原入库单货物数据
                        List <EnterWarehouseBillGoods> listOldGoods = dao.LoadEnterWarehouseBillAllGoods(bill.Id, nOpStaffId, strOpStaffName, out strErrText);
                        if (listOldGoods == null)
                        {
                            return(false);
                        }

                        //如果划拨计划所产生的入库单,则修改前必须检查新旧货物的数量
                        if (bill.PlanId > 0)
                        {
                            //检查每个品种数据
                            var grpOldGoods = listOldGoods.GroupBy(g => new { g.GoodsNo, g.BatchNo, g.Packing, g.ProductionDate, g.EnterWarehouseBillId });
                            foreach (var grpOld in grpOldGoods)
                            {
                                string  strGoodsNo            = grpOld.Key.GoodsNo;
                                string  strBatchNo            = grpOld.Key.BatchNo;
                                string  strPacking            = grpOld.Key.Packing;
                                string  strProductionDate     = grpOld.Key.ProductionDate;
                                long    nEnterWarehouseBillId = grpOld.Key.EnterWarehouseBillId;
                                int     nOldTotalPackages     = grpOld.Sum(s => s.Packages);
                                decimal decOldTotalTunnages   = grpOld.Sum(s => s.Tunnages);

                                List <EnterWarehouseBillGoods> listNew = listGoods.Where(g => g.GoodsNo == strGoodsNo && g.BatchNo == strBatchNo && (g.Packing ?? string.Empty) == strPacking && g.ProductionDate == strProductionDate && g.EnterWarehouseBillId == nEnterWarehouseBillId).ToList();
                                if (nOldTotalPackages != listNew.Sum(g => g.Packages) || decOldTotalTunnages != listNew.Sum(g => g.Tunnages))
                                {
                                    strErrText = string.Format(InnoSoft.LS.Resources.Strings.GoodsModifyBeforeAndAfterPackagesOrTunnagesNotEqual, strGoodsNo, strBatchNo, strPacking, strProductionDate);
                                    return(false);
                                }
                            }

                            //检查总数量
                            if (listGoods.Sum(g => g.Packages) != listOldGoods.Sum(g => g.Packages) || listGoods.Sum(g => g.Tunnages) != listOldGoods.Sum(g => g.Tunnages))
                            {
                                strErrText = InnoSoft.LS.Resources.Strings.GoodsModifyBeforeAndAfterTotalPackagesOrTotalTunnagesNotEqual;
                                return(false);
                            }
                        }

                        //新增入库货物数据
                        foreach (EnterWarehouseBillGoods goods in listGoods)
                        {
                            if (goods.Id == 0)
                            {
                                if (!dao.InsertEnterWarehouseBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                        }

                        //修改入库货物数据
                        foreach (EnterWarehouseBillGoods goods in listGoods)
                        {
                            if (goods.Id > 0)
                            {
                                if (!dao.UpdateEnterWarehouseBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                        }

                        //删除入库单货物数据
                        foreach (EnterWarehouseBillGoods o in listOldGoods)
                        {
                            if (listGoods.FindAll(delegate(EnterWarehouseBillGoods g) { return(g.Id == o.Id); }).Count == 0)
                            {
                                if (!dao.DeleteEnterWarehouseBillGoods(o.Id, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                        }

                        //修改入库单数据
                        if (!dao.UpdateEnterWarehouseBill(bill, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return(false);
                        }
                    }

                    using (CustomerDAO dao = new CustomerDAO())
                    {
                        //修改下力支费价格数据
                        List <CustomerForceFeePrice> listForceFeePrice = dao.LoadCustomerForceFeePricesByCustomerId(bill.CustomerId, nOpStaffId, strOpStaffName, out strErrText);
                        if (listForceFeePrice.Count == 0)
                        {
                            //新增力支费价格数据
                            CustomerForceFeePrice data = new CustomerForceFeePrice();
                            data.CustomerId             = bill.CustomerId;
                            data.StartTime              = bill.CreateTime;
                            data.EndTime                = DateTime.Parse("9999-12-31");
                            data.LoadingForceFeePrice   = 0;
                            data.UnloadingForceFeePrice = bill.UnloadingForceFeePrice;

                            if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            int i = 0;
                            while (i < listForceFeePrice.Count)
                            {
                                if (bill.CreateTime.Date >= listForceFeePrice[i].StartTime.Date && bill.CreateTime.Date <= listForceFeePrice[i].EndTime.Date)
                                {
                                    break;
                                }
                                i++;
                            }
                            if (i < listForceFeePrice.Count)
                            {
                                //修改力支费价格数据
                                listForceFeePrice[i].UnloadingForceFeePrice = bill.UnloadingForceFeePrice;

                                if (!dao.UpdateCustomerForceFeePrice(listForceFeePrice[i], nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                //新增力支费价格数据
                                CustomerForceFeePrice data = new CustomerForceFeePrice();
                                data.CustomerId             = bill.CustomerId;
                                data.StartTime              = bill.CreateTime;
                                data.LoadingForceFeePrice   = 0;
                                data.UnloadingForceFeePrice = bill.UnloadingForceFeePrice;

                                //计算截止时间
                                i = 0;
                                while (i < listForceFeePrice.Count)
                                {
                                    if (bill.CreateTime.Date < listForceFeePrice[i].StartTime.Date)
                                    {
                                        break;
                                    }
                                    i++;
                                }
                                if (i < listForceFeePrice.Count)
                                {
                                    data.EndTime = listForceFeePrice[i].StartTime.Date.AddDays(-1);
                                }
                                else
                                {
                                    data.EndTime = DateTime.Parse("9999-12-31");
                                }

                                if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                        }

                        //修改仓储费价格数据
                        List <CustomerStorageFeePrice> listStorageFeePrice = dao.LoadCustomerStorageFeePricesByCustomerId(bill.CustomerId, nOpStaffId, strOpStaffName, out strErrText);
                        if (listStorageFeePrice.Count == 0)
                        {
                            //新增仓储费价格数据
                            CustomerStorageFeePrice data = new CustomerStorageFeePrice();
                            data.CustomerId      = bill.CustomerId;
                            data.StartTime       = bill.CreateTime;
                            data.EndTime         = DateTime.Parse("9999-12-31");
                            data.StorageFeePrice = bill.StorageFeePrice;

                            if (!dao.InsertCustomerStorageFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            int i = 0;
                            while (i < listStorageFeePrice.Count)
                            {
                                if (bill.CreateTime.Date >= listStorageFeePrice[i].StartTime.Date && bill.CreateTime.Date <= listStorageFeePrice[i].EndTime.Date)
                                {
                                    break;
                                }
                                i++;
                            }
                            if (i < listStorageFeePrice.Count)
                            {
                                //修改仓储费价格数据
                                listStorageFeePrice[i].StorageFeePrice = bill.StorageFeePrice;

                                if (!dao.UpdateCustomerStorageFeePrice(listStorageFeePrice[i], nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                //新增仓储费价格数据
                                CustomerStorageFeePrice data = new CustomerStorageFeePrice();
                                data.CustomerId      = bill.CustomerId;
                                data.StartTime       = bill.CreateTime;
                                data.StorageFeePrice = bill.StorageFeePrice;

                                //计算截止时间
                                i = 0;
                                while (i < listStorageFeePrice.Count)
                                {
                                    if (bill.CreateTime.Date < listStorageFeePrice[i].StartTime.Date)
                                    {
                                        break;
                                    }
                                    i++;
                                }
                                if (i < listStorageFeePrice.Count)
                                {
                                    data.EndTime = listStorageFeePrice[i].StartTime.Date.AddDays(-1);
                                }
                                else
                                {
                                    data.EndTime = DateTime.Parse("9999-12-31");
                                }

                                if (!dao.InsertCustomerStorageFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    transScope.Complete();
                }
                return(true);
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return(false);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 修改客户力支费价格数据
        /// </summary>
        /// <param name="data"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool UpdateCustomerForceFeePrice(CustomerForceFeePrice data, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            //创建存储过程参数
            SqlParameter[] Params =
                {
                    MakeParam(ID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.Id),
                    MakeParam(CUSTOMERID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)data.CustomerId),
                    MakeParam(STARTTIME_PARAM, SqlDbType.DateTime, 8, ParameterDirection.Input, (object)data.StartTime),
                    MakeParam(ENDTIME_PARAM, SqlDbType.DateTime, 8, ParameterDirection.Input, (object)data.EndTime),
                    MakeParam(LOADINGFORCEFEEPRICE_PARAM, SqlDbType.Decimal, 13, ParameterDirection.Input, (object)data.LoadingForceFeePrice),
                    MakeParam(UNLOADINGFORCEFEEPRICE_PARAM, SqlDbType.Decimal, 13, ParameterDirection.Input, (object)data.UnloadingForceFeePrice),
                    MakeParam(OPSTAFFID_PARAM, SqlDbType.BigInt, 8, ParameterDirection.Input, (object)nOpStaffId),
                    MakeParam(OPSTAFFNAME_PARAM, SqlDbType.NVarChar, 50, ParameterDirection.Input, (object)strOpStaffName),
                };

            if (Execute("UpdateCustomerForceFeePrice", Params, out strErrText) >= 0)
                return true;
            else
                return false;
        }
Esempio n. 7
0
        public ActionResult NewCustomer(CustomerViewModel model)
        {
            if (ModelState.IsValid)
            {
                //创建数据
                Customer data = new Customer();
                data.Name = model.Name;
                data.FullName = model.FullName;
                data.WarningStock = model.WarningStock;
                data.StopStock = model.StopStock;
                data.SettlementExpression = model.SettlementExpression;
                data.ValuationMode = model.ValuationMode;
                data.GrossWeightRate = decimal.Parse(model.GrossWeightRate);
                data.OwnOrganId = model.OwnOrganId;
                data.Remark = model.Remark ?? string.Empty;

                List<CustomerTransportPrice> listTransportPrice = new List<CustomerTransportPrice>();
                if (model.TransportPrices != null)
                {
                    foreach (CustomerTransportPriceViewModel m in model.TransportPrices)
                    {
                        CustomerTransportPrice p = new CustomerTransportPrice();
                        p.CustomerId = m.CustomerId;
                        p.StartCountry = m.StartCountry;
                        p.StartProvince = m.StartProvince;
                        p.StartCity = m.StartCity;
                        p.DestCountry = m.DestCountry;
                        p.DestProvince = m.DestProvince;
                        p.DestCity = m.DestCity;
                        p.MinTunnagesOrPiles = m.MinTunnagesOrPiles;
                        p.MaxTunnagesOrPiles = m.MaxTunnagesOrPiles;
                        p.StartTime = DateTime.Parse(m.StartTime);
                        p.EndTime = DateTime.Parse(m.EndTime);
                        p.CarType = m.CarType;
                        p.TransportPrice = m.TransportPrice;
                        p.RiverCrossingCharges = m.RiverCrossingCharges;
                        listTransportPrice.Add(p);
                    }
                }

                List<CustomerForceFeePrice> listForceFeePrice = new List<CustomerForceFeePrice>();
                if (model.ForceFeePrices != null)
                {
                    foreach (CustomerForceFeePriceViewModel m in model.ForceFeePrices)
                    {
                        CustomerForceFeePrice p = new CustomerForceFeePrice();
                        p.CustomerId = m.CustomerId;
                        p.StartTime = DateTime.Parse(m.ForceFeePriceStartTime);
                        p.EndTime = DateTime.Parse(m.ForceFeePriceEndTime);
                        p.LoadingForceFeePrice = m.LoadingForceFeePrice;
                        p.UnloadingForceFeePrice = m.UnloadingForceFeePrice;
                        listForceFeePrice.Add(p);
                    }
                }

                List<CustomerStorageFeePrice> listStorageFeePrice = new List<CustomerStorageFeePrice>();
                if (model.StorageFeePrices != null)
                {
                    foreach (CustomerStorageFeePriceViewModel m in model.StorageFeePrices)
                    {
                        CustomerStorageFeePrice p = new CustomerStorageFeePrice();
                        p.CustomerId = m.CustomerId;
                        p.StartTime = DateTime.Parse(m.StorageFeePriceStartTime);
                        p.EndTime = DateTime.Parse(m.StorageFeePriceEndTime);
                        p.StorageFeePrice = m.StorageFeePrice;
                        listStorageFeePrice.Add(p);
                    }
                }

                //保存数据
                string strErrText;
                CustomerSystem customer = new CustomerSystem();
                if (customer.InsertCustomer(data, listTransportPrice, listForceFeePrice, listStorageFeePrice, LoginAccountId, LoginStaffName, out strErrText) > 0)
                {
                    return Json(string.Empty);
                }
                else
                {
                    return Json(strErrText);
                }
            }
            return View(model);
        }
Esempio n. 8
0
        /// <summary>
        /// 修改出库单数据
        /// </summary>
        /// <param name="bill"></param>
        /// <param name="listGoods"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool UpdateOutWarehouseBill(OutWarehouseBill bill, List<OutWarehouseBillGoods> listGoods, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (StockDAO dao = new StockDAO())
                    {
                        //修改出库单数据
                        if (!dao.UpdateOutWarehouseBill(bill, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return false;
                        }

                        //修改出库货物数据
                        foreach (OutWarehouseBillGoods goods in listGoods)
                        {
                            if (!dao.UpdateOutWarehouseBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return false;
                            }
                        }
                    }

                    using (CustomerDAO dao = new CustomerDAO())
                    {
                        //修改上力支费价格数据
                        List<CustomerForceFeePrice> listForceFeePrice = dao.LoadCustomerForceFeePricesByCustomerId(bill.CustomerId, nOpStaffId, strOpStaffName, out strErrText);
                        if (listForceFeePrice.Count == 0)
                        {
                            //新增力支费价格数据
                            CustomerForceFeePrice data = new CustomerForceFeePrice();
                            data.CustomerId = bill.CustomerId;
                            data.StartTime = bill.CreateTime;
                            data.EndTime = DateTime.Parse("9999-12-31");
                            data.LoadingForceFeePrice = bill.LoadingForceFeePrice;
                            data.UnloadingForceFeePrice = 0;

                            if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return false;
                            }
                        }
                        else
                        {
                            int i = 0;
                            while (i < listForceFeePrice.Count)
                            {
                                if (bill.CreateTime.Date >= listForceFeePrice[i].StartTime.Date && bill.CreateTime.Date <= listForceFeePrice[i].EndTime.Date)
                                {
                                    break;
                                }
                                i++;
                            }
                            if (i < listForceFeePrice.Count)
                            {
                                //修改力支费价格数据
                                listForceFeePrice[i].LoadingForceFeePrice = bill.LoadingForceFeePrice;

                                if (!dao.UpdateCustomerForceFeePrice(listForceFeePrice[i], nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                //新增力支费价格数据
                                CustomerForceFeePrice data = new CustomerForceFeePrice();
                                data.CustomerId = bill.CustomerId;
                                data.StartTime = bill.CreateTime;
                                data.LoadingForceFeePrice = bill.LoadingForceFeePrice;
                                data.UnloadingForceFeePrice = 0;

                                //计算截止时间
                                i = 0;
                                while (i < listForceFeePrice.Count)
                                {
                                    if (bill.CreateTime.Date < listForceFeePrice[i].StartTime.Date)
                                    {
                                        break;
                                    }
                                    i++;
                                }
                                if (i < listForceFeePrice.Count)
                                {
                                    data.EndTime = listForceFeePrice[i].StartTime.Date.AddDays(-1);
                                }
                                else
                                {
                                    data.EndTime = DateTime.Parse("9999-12-31");
                                }

                                if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                        }
                    }
                    transScope.Complete();
                }
                return true;
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return false;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 修改入库单数据
        /// </summary>
        /// <param name="bill"></param>
        /// <param name="listGoods"></param>
        /// <param name="nOpStaffId"></param>
        /// <param name="strOpStaffName"></param>
        /// <param name="strErrText"></param>
        /// <returns></returns>
        public bool UpdateEnterWarehouseBill(EnterWarehouseBill bill, List<EnterWarehouseBillGoods> listGoods, long nOpStaffId, string strOpStaffName, out string strErrText)
        {
            try
            {
                using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(2, 0, 0)))
                {
                    using (StockDAO dao = new StockDAO())
                    {
                        //读取原入库单货物数据
                        List<EnterWarehouseBillGoods> listOldGoods = dao.LoadEnterWarehouseBillAllGoods(bill.Id, nOpStaffId, strOpStaffName, out strErrText);
                        if (listOldGoods == null)
                        {
                            return false;
                        }

                        //如果划拨计划所产生的入库单,则修改前必须检查新旧货物的数量
                        if (bill.PlanId > 0)
                        {
                            //检查每个品种数据
                            var grpOldGoods = listOldGoods.GroupBy(g => new { g.GoodsNo, g.BatchNo, g.Packing, g.ProductionDate, g.EnterWarehouseBillId });
                            foreach (var grpOld in grpOldGoods)
                            {
                                string strGoodsNo = grpOld.Key.GoodsNo;
                                string strBatchNo = grpOld.Key.BatchNo;
                                string strPacking = grpOld.Key.Packing;
                                string strProductionDate = grpOld.Key.ProductionDate;
                                long nEnterWarehouseBillId = grpOld.Key.EnterWarehouseBillId;
                                int nOldTotalPackages = grpOld.Sum(s => s.Packages);
                                decimal decOldTotalTunnages = grpOld.Sum(s => s.Tunnages);

                                List<EnterWarehouseBillGoods> listNew = listGoods.Where(g => g.GoodsNo == strGoodsNo && g.BatchNo == strBatchNo && (g.Packing ?? string.Empty) == strPacking && g.ProductionDate == strProductionDate && g.EnterWarehouseBillId == nEnterWarehouseBillId).ToList();
                                if (nOldTotalPackages != listNew.Sum(g => g.Packages) || decOldTotalTunnages != listNew.Sum(g => g.Tunnages))
                                {
                                    strErrText = string.Format(InnoSoft.LS.Resources.Strings.GoodsModifyBeforeAndAfterPackagesOrTunnagesNotEqual, strGoodsNo, strBatchNo, strPacking, strProductionDate);
                                    return false;
                                }
                            }

                            //检查总数量
                            if (listGoods.Sum(g => g.Packages) != listOldGoods.Sum(g => g.Packages) || listGoods.Sum(g => g.Tunnages) != listOldGoods.Sum(g => g.Tunnages))
                            {
                                strErrText = InnoSoft.LS.Resources.Strings.GoodsModifyBeforeAndAfterTotalPackagesOrTotalTunnagesNotEqual;
                                return false;
                            }
                        }

                        //新增入库货物数据
                        foreach (EnterWarehouseBillGoods goods in listGoods)
                        {
                            if (goods.Id == 0)
                            {
                                if (!dao.InsertEnterWarehouseBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                        }

                        //修改入库货物数据
                        foreach (EnterWarehouseBillGoods goods in listGoods)
                        {
                            if (goods.Id > 0)
                            {
                                if (!dao.UpdateEnterWarehouseBillGoods(goods, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                        }

                        //删除入库单货物数据
                        foreach (EnterWarehouseBillGoods o in listOldGoods)
                        {
                            if (listGoods.FindAll(delegate(EnterWarehouseBillGoods g) { return g.Id == o.Id; }).Count == 0)
                            {
                                if (!dao.DeleteEnterWarehouseBillGoods(o.Id, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                        }

                        //修改入库单数据
                        if (!dao.UpdateEnterWarehouseBill(bill, nOpStaffId, strOpStaffName, out strErrText))
                        {
                            return false;
                        }
                    }

                    using (CustomerDAO dao = new CustomerDAO())
                    {
                        //修改下力支费价格数据
                        List<CustomerForceFeePrice> listForceFeePrice = dao.LoadCustomerForceFeePricesByCustomerId(bill.CustomerId, nOpStaffId, strOpStaffName, out strErrText);
                        if (listForceFeePrice.Count == 0)
                        {
                            //新增力支费价格数据
                            CustomerForceFeePrice data = new CustomerForceFeePrice();
                            data.CustomerId = bill.CustomerId;
                            data.StartTime = bill.CreateTime;
                            data.EndTime = DateTime.Parse("9999-12-31");
                            data.LoadingForceFeePrice = 0;
                            data.UnloadingForceFeePrice = bill.UnloadingForceFeePrice;

                            if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return false;
                            }
                        }
                        else
                        {
                            int i = 0;
                            while (i < listForceFeePrice.Count)
                            {
                                if (bill.CreateTime.Date >= listForceFeePrice[i].StartTime.Date && bill.CreateTime.Date <= listForceFeePrice[i].EndTime.Date)
                                {
                                    break;
                                }
                                i++;
                            }
                            if (i < listForceFeePrice.Count)
                            {
                                //修改力支费价格数据
                                listForceFeePrice[i].UnloadingForceFeePrice = bill.UnloadingForceFeePrice;

                                if (!dao.UpdateCustomerForceFeePrice(listForceFeePrice[i], nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                //新增力支费价格数据
                                CustomerForceFeePrice data = new CustomerForceFeePrice();
                                data.CustomerId = bill.CustomerId;
                                data.StartTime = bill.CreateTime;
                                data.LoadingForceFeePrice = 0;
                                data.UnloadingForceFeePrice = bill.UnloadingForceFeePrice;

                                //计算截止时间
                                i = 0;
                                while (i < listForceFeePrice.Count)
                                {
                                    if (bill.CreateTime.Date < listForceFeePrice[i].StartTime.Date)
                                    {
                                        break;
                                    }
                                    i++;
                                }
                                if (i < listForceFeePrice.Count)
                                {
                                    data.EndTime = listForceFeePrice[i].StartTime.Date.AddDays(-1);
                                }
                                else
                                {
                                    data.EndTime = DateTime.Parse("9999-12-31");
                                }

                                if (!dao.InsertCustomerForceFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                        }

                        //修改仓储费价格数据
                        List<CustomerStorageFeePrice> listStorageFeePrice = dao.LoadCustomerStorageFeePricesByCustomerId(bill.CustomerId, nOpStaffId, strOpStaffName, out strErrText);
                        if (listStorageFeePrice.Count == 0)
                        {
                            //新增仓储费价格数据
                            CustomerStorageFeePrice data = new CustomerStorageFeePrice();
                            data.CustomerId = bill.CustomerId;
                            data.StartTime = bill.CreateTime;
                            data.EndTime = DateTime.Parse("9999-12-31");
                            data.StorageFeePrice = bill.StorageFeePrice;

                            if (!dao.InsertCustomerStorageFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                            {
                                return false;
                            }
                        }
                        else
                        {
                            int i = 0;
                            while (i < listStorageFeePrice.Count)
                            {
                                if (bill.CreateTime.Date >= listStorageFeePrice[i].StartTime.Date && bill.CreateTime.Date <= listStorageFeePrice[i].EndTime.Date)
                                {
                                    break;
                                }
                                i++;
                            }
                            if (i < listStorageFeePrice.Count)
                            {
                                //修改仓储费价格数据
                                listStorageFeePrice[i].StorageFeePrice = bill.StorageFeePrice;

                                if (!dao.UpdateCustomerStorageFeePrice(listStorageFeePrice[i], nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                //新增仓储费价格数据
                                CustomerStorageFeePrice data = new CustomerStorageFeePrice();
                                data.CustomerId = bill.CustomerId;
                                data.StartTime = bill.CreateTime;
                                data.StorageFeePrice = bill.StorageFeePrice;

                                //计算截止时间
                                i = 0;
                                while (i < listStorageFeePrice.Count)
                                {
                                    if (bill.CreateTime.Date < listStorageFeePrice[i].StartTime.Date)
                                    {
                                        break;
                                    }
                                    i++;
                                }
                                if (i < listStorageFeePrice.Count)
                                {
                                    data.EndTime = listStorageFeePrice[i].StartTime.Date.AddDays(-1);
                                }
                                else
                                {
                                    data.EndTime = DateTime.Parse("9999-12-31");
                                }

                                if (!dao.InsertCustomerStorageFeePrice(data, nOpStaffId, strOpStaffName, out strErrText))
                                {
                                    return false;
                                }
                            }
                        }
                    }
                    transScope.Complete();
                }
                return true;
            }
            catch (Exception e)
            {
                strErrText = e.Message;
                return false;
            }
        }