using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Web;
|
using System.Web.UI;
|
using System.Web.UI.WebControls;
|
using CY.BLL.OA;
|
using System.Data;
|
using System.Data.SqlClient;
|
using CY.Infrastructure.Common;
|
using CY.Model;
|
using CY.BLL.Sys;
|
|
namespace CY.WebForm.Pages.procurement
|
{
|
public partial class ProcurementEdit : BasePage
|
{
|
OA_SpecificationBLL _OA_SpecificationBLL = null;
|
OA_SuppliersBLL _OA_SuppliersBLL = null;
|
OA_CommodityBLL _OA_CommodityBLL = null;
|
OA_GoodsInfoBLL _OA_GoodsInfoBLL = null;
|
OA_ProcurementBLL _OA_ProcurementBLL = null;
|
OA_GoodsInfo GoodsInfo = null;
|
OA_Procurement procurement = null;
|
Sys_DictionaryBLL bll_Sys_DictionaryBLL = null;
|
OA_BrandBLL _OA_BrandBLL = null;
|
OA_PaperWeightBLL _OA_PaperWeightBLL = null;
|
string Keyid = string.Empty;
|
|
public ProcurementEdit()
|
{
|
_OA_PaperWeightBLL = new OA_PaperWeightBLL();
|
_OA_SpecificationBLL = new OA_SpecificationBLL();
|
_OA_BrandBLL = new OA_BrandBLL();
|
procurement = new OA_Procurement();
|
_OA_CommodityBLL = new OA_CommodityBLL();
|
_OA_ProcurementBLL = new OA_ProcurementBLL();
|
_OA_SuppliersBLL = new OA_SuppliersBLL();
|
_OA_GoodsInfoBLL = new OA_GoodsInfoBLL();
|
GoodsInfo = new OA_GoodsInfo();
|
bll_Sys_DictionaryBLL = new Sys_DictionaryBLL();
|
}
|
|
protected void Page_Load(object sender, EventArgs e)
|
{
|
if (!IsPostBack)
|
{
|
InitialData();
|
if (dwCommity.SelectedItem.Text != "纸张")
|
{
|
this.tanDiv.Visible = false;
|
this.tanDiv1.Visible = true;
|
this.dwPaperWeight.Visible = false;
|
this.trWeight.Visible = false;
|
this.div_td.Visible = false;
|
this.div_td1.Visible = true;
|
}
|
dwBrand.Items.Insert(0, new ListItem("请选择", ""));
|
dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
|
dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
|
|
}
|
}
|
|
/// <summary>
|
/// 初始化下拉列表
|
/// </summary>
|
protected void InitialData()
|
{
|
|
///供应商
|
selSuppliers.DataSource = _OA_SuppliersBLL.getSupplierTable(CurrentUser.MemberId);
|
selSuppliers.DataBind();
|
selSuppliers.Items.Insert(0, new ListItem("请选择", ""));
|
///产品类别
|
///
|
dwCommity.Items.Insert(0, new ListItem("请选择", ""));
|
DataTable ds = _OA_CommodityBLL.SelectModelPage(CurrentUser.MemberId, "", "true");
|
GetDataByLevel(dwCommity, ds, 0, 0);
|
|
if (Request["Keyid"].ToInt32() > 0)
|
{
|
Keyid = Request["Keyid"].ToString();
|
ShowProcurementData();
|
}
|
|
|
}
|
|
private void ShowProcurementData()
|
{
|
OA_Procurement procurementModel = null;
|
procurementModel = new OA_Procurement();
|
procurementModel = _OA_ProcurementBLL.SelectSingleModel(Keyid);
|
|
this.selSuppliers.Value = procurementModel.SuppliersId.ToString();
|
this.dwCommity.SelectedValue = procurementModel.Commodityid.ToString();
|
DataTable ds = _OA_GoodsInfoBLL.SlectModleByCommity(dwCommity.SelectedValue, CurrentUser.MemberId);
|
if (ds.Rows.Count > 0)
|
{
|
dwGoodsList.DataSource = ds;
|
dwGoodsList.DataTextField = "GoodsName";
|
dwGoodsList.DataValueField = "Keyid";
|
dwGoodsList.DataBind();
|
}
|
else
|
{
|
dwGoodsList.Items.Clear();
|
dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
|
}
|
this.dwGoodsList.SelectedValue = procurementModel.GoodsId.ToString();
|
indecChage();
|
this.dwBrand.SelectedValue = procurementModel.BrandId.ToString();
|
this.dwSpecification.SelectedValue = procurementModel.SpecificationId.ToString();
|
this.dwPaperWeight.SelectedValue = procurementModel.PaperWeightId.ToString();
|
this.txtQuantity.Value = procurementModel.Quantity.ToString();
|
this.txtPrice.Value = procurementModel.Price.ToString();
|
this.txtTenPrice.Value = procurementModel.TanPrice.ToString();
|
this.txtAllMoney.Value = procurementModel.AllMoney.ToString();
|
this.txtRemark.Value = procurementModel.Remark;
|
|
}
|
|
/// <summary>
|
/// 产品类别
|
/// </summary>
|
/// <param name="dwCommity"></param>
|
/// <param name="data"></param>
|
/// <param name="parentId"></param>
|
/// <param name="level"></param>
|
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;
|
}
|
|
/// <summary>
|
/// 类别选取
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void dwCommity_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
|
DataTable ds = _OA_GoodsInfoBLL.SlectModleByCommity(dwCommity.SelectedValue, CurrentUser.MemberId);
|
if (ds.Rows.Count > 0)
|
{
|
dwGoodsList.DataSource = ds;
|
dwGoodsList.DataTextField = "GoodsName";
|
dwGoodsList.DataValueField = "Keyid";
|
dwGoodsList.DataBind();
|
dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
|
|
dwBrand.Items.Clear();
|
dwBrand.Items.Insert(0, new ListItem("请选择", ""));
|
|
dwSpecification.Items.Clear();
|
dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
|
|
dwPaperWeight.Items.Clear();
|
dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
|
|
if (dwCommity.SelectedItem.Text == "纸张")
|
{
|
this.dwPaperWeight.Visible = true;
|
this.trWeight.Visible = true;
|
this.tanDiv.Visible = true;
|
this.tanDiv1.Visible = false;
|
this.div_td.Visible = true;
|
this.div_td1.Visible = false;
|
}
|
else
|
{
|
this.dwPaperWeight.Visible = false;
|
this.trWeight.Visible = false;
|
this.tanDiv.Visible = false;
|
this.tanDiv1.Visible = true;
|
this.div_td.Visible = false;
|
this.div_td1.Visible = true;
|
}
|
}
|
else
|
{
|
dwGoodsList.Items.Clear();
|
dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
|
|
dwBrand.Items.Clear();
|
dwBrand.Items.Insert(0, new ListItem("请选择", ""));
|
|
dwSpecification.Items.Clear();
|
dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
|
|
dwPaperWeight.Items.Clear();
|
dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
|
}
|
//indecChage();
|
}
|
|
/// <summary>
|
/// 根据产品名初始化数据
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void dwGoodsList_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
indecChage();
|
}
|
|
/// <summary>
|
/// 根据货品类别和货品名称选择规格和品牌
|
/// </summary>
|
protected void indecChage()
|
{
|
///品牌
|
DataTable dt_brand = _OA_BrandBLL.getAllBrand(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
|
if (dt_brand.Rows.Count > 0)
|
{
|
this.dwBrand.DataSource = dt_brand;
|
this.dwBrand.DataTextField = "Name";
|
this.dwBrand.DataValueField = "Keyid";
|
this.dwBrand.DataBind();
|
}
|
else
|
{
|
this.dwBrand.Items.Clear();
|
this.dwBrand.Items.Insert(0, new ListItem("请选择", ""));
|
}
|
DataTable dt_Specefiction = _OA_SpecificationBLL.getAllSpecification(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
|
//规格
|
if (dt_Specefiction.Rows.Count > 0)
|
{
|
this.dwSpecification.DataSource = dt_Specefiction;
|
this.dwSpecification.DataTextField = "Name";
|
this.dwSpecification.DataValueField = "Keyid";
|
this.dwSpecification.DataBind();
|
}
|
else
|
{
|
this.dwSpecification.Items.Clear();
|
this.dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
|
}
|
///如果是纸张类型 则加载克重
|
OA_Commodity model = _OA_CommodityBLL.getCommodityId(CurrentUser.MemberId);
|
if (model.Keyid.ToString() == this.dwCommity.SelectedValue)
|
{
|
DataTable dt_PaperWeight = _OA_PaperWeightBLL.getPaperWeight(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
|
///克重
|
if (dt_PaperWeight.Rows.Count > 0)
|
{
|
this.dwPaperWeight.DataSource = dt_PaperWeight;
|
this.dwPaperWeight.DataTextField = "Name";
|
this.dwPaperWeight.DataValueField = "Keyid";
|
this.dwPaperWeight.DataBind();
|
this.dwPaperWeight.Visible = true;
|
this.trWeight.Visible = true;
|
this.tanDiv.Visible = true;
|
this.tanDiv1.Visible = false;
|
this.div_td.Visible = true;
|
this.div_td1.Visible = false;
|
}
|
else
|
{
|
this.dwPaperWeight.Items.Clear();
|
this.dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
|
}
|
}
|
else
|
{
|
this.dwPaperWeight.Visible = false;
|
this.trWeight.Visible = false;
|
this.tanDiv.Visible = false;
|
this.tanDiv1.Visible = true;
|
this.div_td.Visible = false;
|
this.div_td1.Visible = true;
|
}
|
}
|
|
protected void btn_config_Click(object sender, EventArgs e)
|
{
|
procurement.AllMoney = this.txtAllMoney.Value.ToDecimal2();
|
procurement.Quantity = this.txtQuantity.Value.ToInt32();
|
procurement.Price = this.txtPrice.Value.ToDecimal2();
|
procurement.LastUpdateTime = DateTime.Now;
|
procurement.Operator = CurrentUser.ShortName;
|
procurement.SuppliersId = this.selSuppliers.Value.ToInt32();
|
procurement.FirmId = CurrentUser.MemberId;
|
procurement.GoodsId = this.dwGoodsList.SelectedValue.ToInt32();
|
procurement.Remark = this.txtRemark.Value;
|
procurement.BrandId = this.dwBrand.SelectedValue.ToInt32();
|
procurement.SpecificationId = this.dwSpecification.SelectedValue.ToInt32();
|
procurement.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32() ?? 0;
|
procurement.TanPrice = this.txtTenPrice.Value.ToDecimal2() ?? 0;
|
procurement.Commodityid = this.dwCommity.SelectedValue.ToInt32();
|
procurement.PurchaseStatusId = bll_Sys_DictionaryBLL.GetKeyIdByKeyid(0, "采购状态"); ///采购状态
|
procurement.ClearingStatusId = bll_Sys_DictionaryBLL.GetKeyIdByKeyid(0, "结账状态"); ///结算状态
|
procurement.PurchaseTime = DateTime.Now;
|
if (Request["Keyid"].ToInt32() > 0)
|
{
|
OA_Procurement procurementModel = new OA_Procurement();
|
procurementModel = _OA_ProcurementBLL.SelectSingleModel(Request["Keyid"]);
|
procurementModel.SuppliersId = this.selSuppliers.Value.ToInt32();
|
procurementModel.Commodityid = this.dwCommity.SelectedValue.ToInt32();
|
procurementModel.GoodsId = this.dwGoodsList.SelectedValue.ToInt32();
|
procurementModel.BrandId = this.dwBrand.SelectedValue.ToInt32();
|
procurementModel.SpecificationId = this.dwSpecification.SelectedValue.ToInt32();
|
procurementModel.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32();
|
procurementModel.Quantity = this.txtQuantity.Value.ToInt32();
|
procurementModel.Price = this.txtPrice.Value.ToDecimal2();
|
procurementModel.TanPrice = this.txtTenPrice.Value.ToDecimal2();
|
procurementModel.AllMoney = this.txtAllMoney.Value.ToDecimal2();
|
procurementModel.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32() ?? 0;
|
procurementModel.LastUpdateTime = DateTime.Now;
|
procurementModel.Operator = CurrentUser.ShortName;
|
procurementModel.Remark = this.txtRemark.Value;
|
if (_OA_ProcurementBLL.UpdateModel(procurementModel))
|
{
|
JavaScript.RefreshDIVOpener(this);
|
}
|
else
|
{
|
JavaScript.MessageBox("修改失败", this);
|
}
|
}
|
else
|
{
|
if (_OA_ProcurementBLL.insertModel(procurement))
|
{
|
ClearData();
|
//JavaScript.RefreshDIVOpener(this);
|
JavaScript.MessageBox("操作成功", this, false, true);
|
}
|
else
|
{
|
JavaScript.MessageBox("添加失败", this);
|
}
|
}
|
|
}
|
public void ClearData()
|
{
|
dwCommity_SelectedIndexChanged(null, null);
|
|
txtQuantity.Value = "";
|
txtPrice.Value = "";
|
txtTenPrice.Value = "";
|
txtAllMoney.Value = "";
|
}
|
}
|
}
|