using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CY.BLL.Inquiry; using CY.Model; using CY.Infrastructure.Common; using CY.Model.Inquiry; namespace CY.WebForm.Pages.sysInquiry { public partial class PaperPriceList : BasePage { #region 变量 PaperInfoBLL _paperInfoBLL = new PaperInfoBLL(); BrandInfoBLL _brandInfoBLL = new BrandInfoBLL(); PaperTypeBLL _paperTypeBLL = new PaperTypeBLL(); #endregion #region 属性 /// /// 纸张信息json字符串 /// public string PaperListStr { get; set; } #endregion #region 方法 /// /// 获取纸张信息json字符串 /// /// private string GetPaperListStr() { PaperListStr = "[{ id: -1, parentId: 0, name: \"纸张列表\" }"; //PaperListStr += " ,{id:" + model.PapeId + ",parentId:-1,name:\"" + model.PaperName + "\"}"; IEnumerable paperTypeList = _paperTypeBLL.GetPaperTypeList(); if (paperTypeList != null && paperTypeList.Count() > 0) { foreach (SysInquiry_PaperType paperType in paperTypeList) { int paperTypeKeyId = paperType.KeyId + 1000; PaperListStr += " ,{id:" + paperTypeKeyId + ",parentId:-1,name:\"" + paperType.PaperTypeName + "\"}"; IEnumerable paperInfoList = _paperInfoBLL.GetPaperListByPaperType(paperType.KeyId); if (paperInfoList != null && paperInfoList.Count() > 0) { foreach (SysInquiry_PaperInfo paperInfo in paperInfoList) { PaperListStr += " ,{id:" + paperInfo.PapeId + ",parentId:" + paperTypeKeyId + ",name:\"" + paperInfo.PaperName + "\"}"; } } } } PaperListStr += "]"; return PaperListStr; } ///// ///// 绑定品牌列表 ///// //private void BindddlDefaultBrand() //{ // this.ddlBrandList.DataSource = _brandInfoBLL.GetBrandList(); // this.ddlBrandList.DataTextField = "BrandName"; // this.ddlBrandList.DataValueField = "KeyId"; // this.ddlBrandList.DataBind(); //} #endregion #region 事件 /// /// 初始化 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (InquiryConditionObj.FirmId.ToString() == UtilConst.AdminFirmId) { this.hidIsFirm.Value = "false"; } else { this.hidIsFirm.Value = "true"; } GetPaperListStr(); //BindddlDefaultBrand(); } if (Request["Init"] != null) { string result = string.Empty; string brandListStr = string.Empty; string resultList = string.Empty; string str = string.Empty; int paperId = int.Parse(Request["paperId"].ToString()); IList brandList = _paperInfoBLL.GetBrandInfoByPaper(paperId); if (brandList != null && brandList.Count > 0) { foreach (SysInquiry_BrandInfo brand in brandList) { str += "{brandKey:" + brand.KeyId + ",brandName:'" + brand.BrandName + "'},"; } if (!string.IsNullOrEmpty(str)) { str = str.Substring(0, str.Length - 1); } } brandListStr = "[" + str + "]"; int brandId = -1; if (Request["brandId"].ToString() == "") { if (brandList != null && brandList.Count > 0) brandId = brandList[0].KeyId; } else { brandId = int.Parse(Request["brandId"].ToString()); } str = string.Empty; IEnumerable paperPriceList = _paperInfoBLL.GetAllPaperPriceList(paperId, brandId, InquiryConditionObj.InquiryId); if (paperPriceList != null && paperPriceList.Count() > 0) { foreach (Inquiry_PaperPriceInfo model in paperPriceList) { str += "{ GramWeight:" + model.GramWeight + ",PaperPrice:" + model.PaperPrice.ToString("0.00") + "},"; } if (!string.IsNullOrEmpty(str)) { str = str.Substring(0, str.Length - 1); } } resultList = "[" + str + "]"; result = "{brandId:" + brandId + ",paperPriceList:" + resultList + ",brandList:" + brandListStr + "}"; Response.Write(result); Response.End(); } if (Request["save"] != null) { List modelList = new List(); Inquiry_PaperPriceInfo model = null; int paperId = int.Parse(Request["paperId"].ToString()); int brandId = int.Parse(Request["brandId"].ToString()); string priceList = Request["priceList"].ToString(); bool isSuccess = false; string result = string.Empty; if (string.IsNullOrEmpty(priceList)) { result = "该品牌下的纸张没有设置相关克重,保存失败"; } else { int gramWeightValue = -1; decimal paperPrice = 0; string[] priceListArry = priceList.Split(','); foreach (string priceListStr in priceListArry) { string[] priceStr = priceListStr.Split(':'); gramWeightValue = int.Parse(priceStr[0]); paperPrice = Convert.ToDecimal(priceStr[1]); model = new Inquiry_PaperPriceInfo(); model.PaperId = paperId; model.FirmId = InquiryConditionObj.ActualFirmId; model.BrandId = brandId; model.GramWeight = gramWeightValue; model.PaperPrice = paperPrice; model.Unit = "元"; model.Status = true; model.Operater = CurrentUser.ShortName; model.OperateTime = DateTime.Now; model.LastUpdateTime = DateTime.Now; modelList.Add(model); } isSuccess = _paperInfoBLL.SavePaperPrice(modelList, InquiryConditionObj); if (isSuccess) { result = "保存成功"; } else { result = "保存失败"; } } Response.Write(result); Response.End(); } } #endregion } }