Пример #1
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id = 0)
        {
            Order_Batch model      = null;
            int         contractId = RequestInt("contractid");

            if (contractId == 0)
            {
                return(LayerAlertErrorAndClose("请选择一个合同!"));
            }
            if (id == 0)
            {
                model       = new Order_Batch();
                model.Batch = Bll.BllOrder_Batch.GetBatch(contractId);
            }
            else
            {
                model = Bll.BllOrder_Batch.First(o => o.Id == id);
                if (model == null)
                {
                    return(LayerAlertErrorAndClose("记录不存在!"));
                }
                model.Batch = model.Batch.Value;
            }
            ViewBag.contractId = contractId;
            return(View(model));
        }
        /// <summary>
        /// 修改产品信息
        /// </summary>
        /// <param name="batch"></param>
        /// <returns></returns>
        public static bool EditProInfo(Order_Batch batch)
        {
            if (batch == null)
            {
                return(false);
            }

            var list = BllOrder_BatchProduct.Query(o => o.BatchId == batch.Id);

            if (list != null && list.Count > 0)
            {
                foreach (var item in list)
                {
                    item.UnitPerCost = batch.UnitPerCost;
                    item.Unit        = batch.Unit;
                    item.Cost        = item.UnitValue * batch.UnitPerCost;
                    item.TotalCost   = item.UnitValue * batch.UnitPerCost * item.Quantity;
                }
                int rows = Update(list);
                if (rows == 0)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        public ActionResult Save(Order_Batch model)
        {
            int contractId = RequestInt("contractid");

            if (contractId == 0)
            {
                return(LayerAlertErrorAndReturn("请选择一个合同!"));
            }

            if (model.Id > 0)
            {
                model = Bll.BllOrder_Batch.First(o => o.Id == model.Id);
                if (model == null)
                {
                    return(Response404());
                }
            }
            else
            {
                model = new Order_Batch();
            }

            decimal totalcost = RequestDecimal("totalcost");

            if (totalcost == 0)
            {
                return(LayerAlertErrorAndReturn("请填写物流费用!"));
            }
            decimal unitvalue = RequestDecimal("unitvalue");

            if (unitvalue == 0)
            {
                return(LayerAlertErrorAndReturn("请填写总体积或重量!"));
            }

            model.ContractId  = contractId;
            model.Batch       = RequestInt("batch");
            model.BatchNo     = RequestString("batchno");
            model.TotalCost   = RequestDecimal("totalcost");
            model.UnitType    = RequestByte("unittype");
            model.UnitValue   = RequestDecimal("unitvalue");
            model.Unit        = RequestString("unit");
            model.Quantity    = RequestInt("quantity");
            model.UnitPerCost = model.TotalCost / (decimal)model.UnitValue;
            model.AddTime     = DateTime.Now;
            model.AdminId     = MyInfo.Id;

            int rows = 0;

            if (model.Id > 0)
            {
                rows = Bll.BllOrder_Batch.Update(model);
                //相应修改产品的信息
                if (rows > 0)
                {
                    Bll.BllOrder_BatchProduct.EditProInfo(model);
                }
            }
            else
            {
                rows = Bll.BllOrder_Batch.Insert(model);
            }
            if (rows > 0)
            {
                return(LayerAlertSuccessAndRefresh((model.Id > 0 ? "修改" : "添加") + "成功"));
            }
            else
            {
                return(LayerAlertErrorAndReturn((model.Id > 0 ? "修改" : "添加") + "失败"));
            }
        }