using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Web;
|
using System.Web.UI;
|
using System.Web.UI.WebControls;
|
using CY.Model;
|
using CY.Infrastructure.Query;
|
using CY.BLL.OA;
|
using CY.Infrastructure.Common;
|
using System.Data;
|
namespace CY.WebForm.Pages.procurement
|
{
|
public partial class BrandEdit : BasePage
|
{
|
|
OA_BrandBLL _OA_BrandBLL = null;
|
OA_Brand brand = null;
|
OA_CommodityBLL _OA_CommodityBLL = null;
|
OA_GoodsInfoBLL _OA_GoodsInfoBLL = null;
|
|
public BrandEdit()
|
{
|
_OA_GoodsInfoBLL = new OA_GoodsInfoBLL();
|
_OA_CommodityBLL = new OA_CommodityBLL();
|
brand = new OA_Brand();
|
_OA_BrandBLL = new OA_BrandBLL();
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
{
|
if (!IsPostBack)
|
{
|
InitialSelData();
|
if (Request["EditKeyid"].ToInt32() > 0)
|
InitialData();
|
}
|
}
|
|
protected void InitialSelData()
|
{
|
DataTable ds = _OA_CommodityBLL.SelectModelPage(CurrentUser.MemberId, "", "true");
|
var dic = new Dictionary<string, string>();
|
|
GetDataByLevel(dwCommity, ds, 0, 0);
|
ChangeSelBrand(this.dwCommity.SelectedValue);
|
this.txtOrderNum.Value = _OA_BrandBLL.GetMaxOrderNum(CurrentUser.MemberId, "OA_Brand");
|
}
|
|
public static void GetDataByLevel(System.Web.UI.WebControls.DropDownList dwCommity, DataTable data, int parentId, int level)
|
{
|
DataRow[] result = data.Select(string.Format("ParentId={0}", parentId));
|
int i = -1;
|
while (++i < result.Length)
|
{
|
dwCommity.Items.Add(new ListItem(GetSplitChar(level) + result[i]["CommodityName"].ToString2(), result[i]["Keyid"].ToString2()));
|
GetDataByLevel(dwCommity, 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;
|
}
|
|
protected void InitialData()
|
{
|
brand = _OA_BrandBLL.getSingleBrand(Request["EditKeyid"].ToString2());
|
txtBrandName.Value = brand.Name;
|
this.dwCommity.SelectedValue = brand.CommodityId.ToString2();
|
ChangeSelBrand(brand.CommodityId.ToString2());
|
this.selGoodName.Value = brand.GoodsId.ToString2();
|
this.txtOrderNum.Value = brand.OrderNum.ToString2();
|
}
|
|
protected void btn_Submit_Click(object sender, EventArgs e)
|
{
|
if (Request["EditKeyid"].ToInt32() > 0)
|
{
|
brand = _OA_BrandBLL.getSingleBrand(Request["EditKeyid"].ToString2());
|
}
|
brand.GoodsId = this.selGoodName.Value.ToInt32();
|
brand.CommodityId = this.dwCommity.SelectedValue.ToInt32();
|
brand.FirmId = CurrentUser.MemberId;
|
brand.LastUpdateTime = DateTime.Now;
|
brand.Name = txtBrandName.Value;
|
brand.Operator = CurrentUser.ShortName;
|
brand.Remark = "";
|
brand.OrderNum = this.txtOrderNum.Value.ToInt32();
|
if (Request["EditKeyid"].ToInt32() > 0)
|
{
|
if (_OA_BrandBLL.UpdateModel(brand))
|
JavaScript.MessageBoxAndFirstRefresh("更新成功", this, false);
|
else
|
JavaScript.MessageBox("更新失败", this);
|
}
|
else
|
{
|
if (_OA_BrandBLL.InsertModel(brand))
|
JavaScript.MessageBoxCloseAndRefreshFirst("添加成功", this);
|
else
|
JavaScript.MessageBox("添加失败", this);
|
}
|
|
|
}
|
|
protected void dwCommity_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
this.selGoodName.DataSource = _OA_GoodsInfoBLL.SlectModleByCommity(this.dwCommity.SelectedValue, CurrentUser.MemberId);
|
this.selGoodName.DataValueField = "Keyid";
|
this.selGoodName.DataTextField = "GoodsName";
|
this.selGoodName.DataBind();
|
}
|
|
protected void ChangeSelBrand(string CommodityId)
|
{
|
this.selGoodName.DataSource = _OA_GoodsInfoBLL.SlectModleByCommity(CommodityId, CurrentUser.MemberId);
|
this.selGoodName.DataValueField = "Keyid";
|
this.selGoodName.DataTextField = "GoodsName";
|
this.selGoodName.DataBind();
|
}
|
|
}
|
}
|