Example #1
0
        public ActionResult Save(int id = 0, int year = 0)
        {
            Supplier_RawMaterialPrice model = null;

            if (id < 1)
            {
                return(View(model));
            }

            model = Bll.BllSupplier_RawMaterialPrice.GetModel(id);
            if (model == null)
            {
                return(LayerAlertErrorAndReturn("加载原材料价格信息失败,未找到该原材料价格"));
            }

            var list = Bll.BllSupplier_Price.GetSelectList(0, "Id,RawMaterialPriceId,Years,Month,Price,Display,YearsMonth"
                                                           , "RawMaterialPriceId=" + model.Id, "YearsMonth");

            var selectList = list.Select(o => o.Years).Distinct();

            ViewBag.SelectList = CreateSelectList(selectList, year);

            if (list == null || list.Count() < 1)
            {
                return(View(model));
            }

            //显示的价格年份
            int years = year < 1 ? selectList.First().GetValueOrDefault() : year;

            var priceModel = list.Where(o => o.Years == years).ToList();

            if (priceModel == null || priceModel.Count() < 1)
            {
                return(View(model));
            }

            ViewBag.prices2 = priceModel;

            return(View(model));
        }
Example #2
0
        public ActionResult Save(Supplier_RawMaterialPrice rawmaterialPrice, int Years = 0)
        {
            Supplier_RawMaterialPrice model = Bll.BllSupplier_RawMaterialPrice.First(o => o.Id == rawmaterialPrice.Id && o.Display != 2) ?? new Supplier_RawMaterialPrice();

            //如果原材料不存在,返回提示
            var rawMaterialModel = Bll.BllSupplier_RawMaterial.First(o => o.SAPCode == rawmaterialPrice.SAPCode && o.Display != 2);

            if (rawMaterialModel == null)
            {
                return(LayerAlertErrorAndReturn("原材料代码不存在,请重新输入"));
            }
            //根据供应商信息,查询供应商ID,如果供应商不存在,返回提示
            var supplierModel = Bll.BllSupplier_List.First(o => o.Code == rawmaterialPrice.Code && o.Display != 2 && o.Id > 0);

            if (supplierModel == null)
            {
                return(LayerAlertErrorAndReturn("供应商代码不存在,请重新输入"));
            }

            //保存价格
            model.RawMaterialId  = rawMaterialModel.SAPCode;
            model.VendorId       = supplierModel.Code;
            model.PriceFrequency = rawmaterialPrice.PriceFrequency;
            model.LastUserId     = MyInfo.Id;
            model.LastDate       = DateTime.Now;
            model.Display        = 1;
            bool isok = false;

            DateTime datetime = DateTime.Now;

            //编辑报价表
            if (rawmaterialPrice.Id < 1)
            {
                //相同的原材料和相同的供应商不能重复添加
                var rawmaterialPriceModel = Bll.BllSupplier_RawMaterialPrice.First(o => o.VendorId == model.VendorId && o.RawMaterialId == model.RawMaterialId &&
                                                                                   o.Display != 2);
                if (rawmaterialPriceModel != null)
                {
                    return(LayerAlertErrorAndReturn("该原材料对应的供应商已存在,请选择修改操作"));
                }

                model.AddDate   = model.LastDate;
                model.AddUserId = model.LastUserId;
                model.Id        = Bll.BllSupplier_RawMaterialPrice.Insert(model);
                if (model.Id < 1)
                {
                    return(LayerAlertErrorAndReturn("添加失败,请联系管理员"));
                }
            }
            else
            {
                isok = Bll.BllSupplier_RawMaterialPrice.Update(model) > 0;
                if (!isok)
                {
                    return(LayerAlertErrorAndReturn("修改失败,请联系管理员"));
                }
            }

            List <Supplier_Price> prices = new List <Supplier_Price>();

            for (int i = 1; i < 13; i++)
            {
                prices.Add(new Supplier_Price
                {
                    RawMaterialPriceId = model.Id,
                    Years      = Years,
                    Month      = i,
                    Price      = RequestDecimal("month" + i),
                    AddDate    = datetime,
                    AddUserId  = MyInfo.Id,
                    LastDate   = datetime,
                    LastUserId = MyInfo.Id,
                    Display    = 1,
                    YearsMonth = $"{Years}-{i}-1".ToDateTime()
                });
            }

            //编辑价格表
            isok = Bll.BllSupplier_Price.InsertPrice(Years, model.Id, prices);

            return(isok ? LayerAlertSuccessAndRefresh("保存成功") : LayerAlertErrorAndReturn("保存失败"));
        }