using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using CY.Infrastructure.Common; using CY.Model; using CY.BLL.OA; using System.Text; namespace CY.WebForm.Pages.procurement { public partial class CommodityEdit : BasePage { OA_CommodityBLL _OA_CommodityBLL = null; OA_Commodity Commodity = null; OA_BrandBLL _OA_BrandBLL = null; public CommodityEdit() { _OA_BrandBLL = new OA_BrandBLL(); _OA_CommodityBLL = new OA_CommodityBLL(); Commodity = new OA_Commodity(); } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Commodity"); if (Request["Keyid"].ToInt32() > 0) { InitialCommityData(); } } } protected void InitialCommityData() { Commodity = _OA_CommodityBLL.SelectSingleModel(Request["Keyid"].ToString2()); if (Commodity != null) { this.txtCommodityName.Value = Commodity.CommodityName; //this.selIsPaper.Value = Commodity.IsPaper.ToString2(); this.selIsUsed.Value = Commodity.IsUsed.ToString2(); this.txtOrderNum.Value = Commodity.OrderNum.ToString2(); //selParent.Value = Commodity.ParentId.ToString2(); } else { this.txtCommodityName.Value = ""; this.selIsUsed.Value = "True"; this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Commodity"); } } #region 上级父类数据初始化 public void InitialData() { DataTable ds = _OA_CommodityBLL.SelectModelPage(CurrentUser.MemberId, "", "true"); var dic = new Dictionary(); //selParent.Items.Insert(0, new ListItem("请选择", "0")); //GetDataByLevel(selParent, ds,0,0); } public static void GetDataByLevel(System.Web.UI.HtmlControls.HtmlSelect sel, DataTable data, int parentId, int level) { DataRow[] result = data.Select(string.Format("ParentId={0}", parentId)); int i = -1; while (++i < result.Length) { sel.Items.Add(new ListItem(GetSplitChar(level) + result[i]["CommodityName"].ToString2(), result[i]["Keyid"].ToString2())); GetDataByLevel(sel, data, result[i]["Keyid"].ToInt32().Value, level + 1); } } public static string GetSplitChar(int level) { string splitchar = ""; int i = -1; while (++i < level) { splitchar += "."; } return splitchar; } #endregion /// /// 点击提交、修改或添加货品类别 /// /// /// protected void btn_config_Click(object sender, EventArgs e) { if (Request["Keyid"].ToInt32() > 0) { Commodity = _OA_CommodityBLL.SelectSingleModel(Request["Keyid"].ToString2()); } Commodity.OrderNum = this.txtOrderNum.Value.ToInt32(); Commodity.CommodityName = txtCommodityName.Value; Commodity.FirmId = CurrentUser.MemberId; Commodity.IsPaper = 0; Commodity.IsUsed = MyConvert.ConvertToBoolean(this.selIsUsed.Value); Commodity.LastUpdateTime = DateTime.Now; Commodity.ParentId = 0; Commodity.Remark = ""; if (Request["Keyid"].ToInt32() > 0) { if (_OA_CommodityBLL.UpdateModel(Commodity)) JavaScript.MessageBox("更新成功", this, true, true); else JavaScript.MessageBox("更新失败", this); } else { Commodity.Operator = CurrentUser.ShortName; if (_OA_CommodityBLL.insertModel(Commodity)) { //InitialCommityData(); this.txtCommodityName.Value = ""; this.selIsUsed.Value = "True"; this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Commodity"); JavaScript.MessageBox("添加成功", this, false, true); } else { JavaScript.MessageBox("添加失败", this); } } } } }