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;
namespace CY.WebForm.Pages.procurement
{
public partial class OutOfStorageEdit : 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;
OA_WarehouseInfoBLL _OA_WarehouseInfoBLL = null;
OA_CargoSpaceBLL _OA_CargoSpaceBLL = null;
OA_Inventory Inventory = null;
OA_OutOfStorage outOfStorage = null;
OA_OutOfStorageBLL _OA_OutOfStorageBLL = new OA_OutOfStorageBLL();
OA_BrandBLL _OA_BrandBLL = null;
OA_PaperWeightBLL _OA_PaperWeightBLL = null;
public OutOfStorageEdit()
{
_OA_PaperWeightBLL = new OA_PaperWeightBLL();
_OA_SpecificationBLL = new OA_SpecificationBLL();
_OA_BrandBLL = new OA_BrandBLL();
_OA_OutOfStorageBLL = new OA_OutOfStorageBLL();
outOfStorage = new OA_OutOfStorage();
_OA_WarehouseInfoBLL = new OA_WarehouseInfoBLL();
_OA_CargoSpaceBLL = new OA_CargoSpaceBLL();
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();
Inventory = new OA_Inventory();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.div_none.Visible = false;
this.div_tanPrice.Visible = false;
this.dwPaperWeight.Visible = false;
this.txtTenPrice.Visible = false;
this.div_td.Visible = false;
InitialData();
}
}
///
/// 初始化下拉列表
///
protected void InitialData()
{
//供应商
this.selSuppliers.DataSource = _OA_SuppliersBLL.getSupplierTable(CurrentUser.MemberId);
this.selSuppliers.DataBind();
this.selSuppliers.Items.Insert(0, new ListItem("请选择", ""));
//产品类别
this.dwCommity.Items.Insert(0, new ListItem("请选择", ""));
DataTable ds = _OA_CommodityBLL.SelectModelPage(CurrentUser.MemberId,"","true");
GetDataByLevel(this.dwCommity, ds, 0, 0);
//仓库
this.dwWarehouse.DataSource = _OA_WarehouseInfoBLL.getAllWarehouseInfo(CurrentUser.MemberId);
this.dwWarehouse.DataValueField = "Keyid";
this.dwWarehouse.DataTextField = "WarehouseName";
this.dwWarehouse.DataBind();
this.dwWarehouse.Items.Insert(0, new ListItem("请选择", ""));
this.dwBrand.Items.Insert(0, new ListItem("请选择", ""));
this.dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
this.dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
this.dwPaperWeight.Items.Insert(0, new ListItem("请选择", ""));
}
///
/// 产品类别
///
///
///
///
///
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 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("请选择", ""));
}
else
{
dwGoodsList.Items.Clear();
dwGoodsList.Items.Insert(0, new ListItem("请选择", ""));
}
indecChage();
}
protected void indecChage()
{
DataTable dt_brand = _OA_BrandBLL.getAllBrand(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
if (dt_brand.Rows.Count > 0)
{
dwBrand.DataSource = dt_brand;
dwBrand.DataTextField = "Name";
dwBrand.DataValueField = "Keyid";
dwBrand.DataBind();
}
else
{
dwBrand.Items.Clear();
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)
{
dwSpecification.DataSource = dt_Specefiction;
dwSpecification.DataTextField = "Name";
dwSpecification.DataValueField = "Keyid";
dwSpecification.DataBind();
}
else
{
dwSpecification.Items.Clear();
dwSpecification.Items.Insert(0, new ListItem("请选择", ""));
}
DataTable dt_PaperWeight = _OA_PaperWeightBLL.getPaperWeight(CurrentUser.MemberId, this.dwCommity.SelectedValue, this.dwGoodsList.SelectedValue);
if (dt_PaperWeight.Rows.Count > 0)
{
dwPaperWeight.DataSource = dt_PaperWeight;
dwPaperWeight.DataTextField = "Name";
dwPaperWeight.DataValueField = "Keyid";
dwPaperWeight.DataBind();
this.dwPaperWeight.Visible = true;
this.txtTenPrice.Visible = true;
this.div_td.Visible = true;
this.div_tanPrice.Visible = true;
this.div_none.Visible = true;
}
else
{
this.div_none.Visible = false;
this.div_tanPrice.Visible = false;
this.dwPaperWeight.Visible = false;
this.txtTenPrice.Visible = false;
this.div_td.Visible = false;
}
}
///
/// 根据产品名初始化数据
///
///
///
protected void dwGoodsList_SelectedIndexChanged(object sender, EventArgs e)
{
indecChage();
}
///
/// 产品添加
///
///
///
protected void btn_config_Click(object sender, EventArgs e)
{
Inventory.CargoSpaceId = 0;
Inventory.FirmId = CurrentUser.MemberId;
Inventory.GoodsId = dwGoodsList.SelectedValue.ToInt32();
Inventory.InventoryCount = txtQuantity.Value.ToInt32();
Inventory.LastUpdateTime = DateTime.Now;
Inventory.Operator = CurrentUser.ShortName;
Inventory.Remark = "";
Inventory.WarehouseId = dwWarehouse.SelectedValue.ToInt32();
Inventory.SpecificationId = this.dwSpecification.SelectedValue.ToInt32();
Inventory.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32()??0;
Inventory.BrandId = this.dwBrand.SelectedValue.ToInt32();
Inventory.UnitPrice = this.txtPrice.Value.ToDecimal2();
Inventory.TotalPrice = 0;
outOfStorage.FirmId = CurrentUser.MemberId;
outOfStorage.GoodsId = dwGoodsList.SelectedValue.ToInt32();
outOfStorage.CargoSpaceId = 0;
outOfStorage.LastUpdateTime = DateTime.Now;
outOfStorage.Operator = CurrentUser.ShortName;
outOfStorage.Remark = "";
outOfStorage.WarehouseId = dwWarehouse.SelectedValue.ToInt32();
outOfStorage.SuppliersId = selSuppliers.Value.ToInt32();
outOfStorage.AllMoney = txtAllMoney.Value.ToDecimal2();
outOfStorage.InfoType = Request["type"].ToString2();
outOfStorage.Price = txtPrice.Value.ToDecimal2();
outOfStorage.Quantity = txtQuantity.Value.ToInt32();
outOfStorage.TanPrice = this.txtTenPrice.Value.ToDecimal2();
outOfStorage.SpecificationId = this.dwSpecification.SelectedValue.ToInt32();
outOfStorage.PaperWeightId = this.dwPaperWeight.SelectedValue.ToInt32() ?? 0;
outOfStorage.BrandId = this.dwBrand.SelectedValue.ToInt32();
if (_OA_OutOfStorageBLL.InsertModel(Inventory, outOfStorage))
{
this.txtAllMoney.Value = "";
this.txtPrice.Value = "";
this.txtQuantity.Value = "";
this.txtTenPrice.Value = "";
JavaScript.MessageBox("操作成功", this,false,true);
}
else
{
JavaScript.MessageBox("添加失败", this);
}
}
}
}