|
楼主 |
发表于 2007-4-26 17:10
|
显示全部楼层
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Web.UI.WebControls;
using DataLogical.Dining;
using EDSWebCommon;
using System.Text;
namespace Dining
{
/// <summary>
/// DINStockMng 的摘要说明。
/// </summary>
public class DINStockMng : EdsBasePage
{
protected System.Web.UI.WebControls.LinkButton LBtnInList;
protected System.Web.UI.WebControls.LinkButton LBtnOutList;
protected System.Web.UI.WebControls.LinkButton LBtnBackList;
protected System.Web.UI.WebControls.DropDownList DDLDiningSel;
protected System.Web.UI.WebControls.LinkButton BtnQuery;
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
protected System.Web.UI.WebControls.TextBox TextboxGoodsName;
protected Newtouch.Web.UI.NavigationBar NavigationBar1;
protected newtouch.controls.WebPager WebPager1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
FormLoad();
InitTree();
if(Session["DINStockMng_strWhere"]==null)
{
this.TreeView1.ExpandLevel=2;
}
else
{
DoRevert();
}
}
}
private void BuildTree(DataTable dt,DataView dvParent, TreeNode OldNode)
{
try
{
foreach(DataRowView row in dvParent)
{
if(row["parentid"].ToString()==OldNode.NodeData)
{
TreeNode node = new TreeNode();
node.Text = row["name"].ToString();
node.NodeData = row["recordid"].ToString();
OldNode.Nodes.Add(node);
DataView dv=new DataView(dt,string.Format("parentid='{0}'",node.NodeData),"recordid",DataViewRowState.CurrentRows);
// BuildTree(dt,dv,node);
}
}
}
catch(Exception ex)
{
Page.RegisterStartupScript("alert",string.Format("<script>alert('{0}')</script>",ex.Message));
}
}
private void InitTree()
{
try
{
// DIN_GOODS goods = new DIN_GOODS();
// DataTable dt = goods.GetAllList();
DataLogical.Dining.DIN_BaseData dbd = new DataLogical.Dining.DIN_BaseData();
DataTable dt =dbd.GetBottomGoods2();
TreeNode node = new TreeNode();
node.Text = "库存信息";
node.NodeData = "9DF39745-5C24-4382-9A5F-DED1315B3848";
DataView dv = new DataView(dt,"parentid='9DF39745-5C24-4382-9A5F-DED1315B3848'","recordid",DataViewRowState.CurrentRows);
BuildTree(dt,dv,node);
TreeView1.Nodes.Add(node);
}
catch(Exception ex)
{
Page.RegisterStartupScript("alert",string.Format("<script>alert('{0}')</script>",ex.Message));
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.LBtnInList.Click += new System.EventHandler(this.LBtnInList_Click);
this.LBtnOutList.Click += new System.EventHandler(this.LBtnOutList_Click);
this.LBtnBackList.Click += new System.EventHandler(this.LBtnBackList_Click);
this.DDLDiningSel.SelectedIndexChanged += new System.EventHandler(this.DDLDiningSel_SelectedIndexChanged);
this.BtnQuery.Click += new System.EventHandler(this.BtnQuery_Click);
this.TreeView1.SelectedIndexChange += new Microsoft.Web.UI.WebControls.SelectEventHandler(this.TreeView1_SelectedIndexChange);
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
this.WebPager1.PageIndexChanged += new newtouch.controls.PageIndexChangeEventHandler(this.WebPager1_PageIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void FormLoad()
{
try
{
string SQL="";
//检查高级权限
if (EDSWebCommon.sysUser.getIsAdmin("23"))
{
SQL="";
}
else
{
//检查是否有浏览权限:
if (EDSWebCommon.sysUser.getIsBrowse("23"))
{
SQL=Session["userid"].ToString();
}
else
{
SQL="nopower";
}
}
//绑定 [服务餐厅]
System.Web.UI.WebControls.ListItem li = new ListItem("--请选择餐厅--","no");
DDLDiningSel.Items.Add(li);
DataLogical.Dining.DIN_BaseData db = new DataLogical.Dining.DIN_BaseData();
DataTable dtDining = db.GetDinRoom(SQL);
foreach(DataRow row in dtDining.Rows)
{
DDLDiningSel.Items.Add(new ListItem(row["sd_depName"]as string, row["sd_depid"].ToString()));
}
DDLDiningSel.SelectedValue="no";
// DataLogical.Dining.DIN_Depot dd = new DataLogical.Dining.DIN_Depot();
//绑定 [库存数据]按层次取所有的库存,不考虑所属餐厅,所以暂时不用
// DataTable dtDIN_Depot = dd.GetAllStockByGoodsId("0");
// DataGrid1.DataSource = dtDIN_Depot;
// DataGrid1.DataBind();
//
// DataTable dtDIN_Depot = dd.GetList(" 1=2 ");
// DataGrid1.DataSource = dtDIN_Depot;
// DataGrid1.DataBind();
ViewState["DINStockMng_strWhere"]=" 1=2 ";
WebPager1.CurrentPageIndex=1;
dgBind();
}
catch(Exception ex)
{
Page.RegisterStartupScript("alert",string.Format("<script>alert('{0}')</script>",ex.Message));
}
}
private void TreeView1_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
{
try
{
string nodename = TreeView1.SelectedNodeIndex;
string[] s = nodename.Split('.');
Microsoft.Web.UI.WebControls.TreeNode node = new Microsoft.Web.UI.WebControls.TreeNode();
if(s.Length!=0)
node = TreeView1.Nodes[Int32.Parse(s[0])];
for(int i=1;i<s.Length;i++)
{
node = node.Nodes[Int32.Parse(s)];
}
DataLogical.Dining.DIN_Depot dd = new DataLogical.Dining.DIN_Depot();
DataTable dtDIN_Depot = dd.GetAllStockByGoodsId(node.NodeData,DDLDiningSel.SelectedValue);
DataGrid1.DataSource = dtDIN_Depot;
DataGrid1.DataBind();
}
catch(Exception ex)
{
Page.RegisterStartupScript("alert",string.Format("<script>alert('{0}')</script>",ex.Message));
}
}
private void BtnQuery_Click(object sender, System.EventArgs e)
{
try
{
// DataLogical.Dining.DIN_Depot dd = new DataLogical.Dining.DIN_Depot();
// DataTable dtDIN_Depot = dd.GetAllStockByGoodsName(this.TextboxGoodsName.Text,this.DDLDiningSel.SelectedValue);
// DataGrid1.DataSource = dtDIN_Depot;
// DataGrid1.DataBind();
StringBuilder SQLCondition = new StringBuilder(" 1=1 ");
if(TextboxGoodsName.Text!="")
SQLCondition.AppendFormat(" and goodsname='{0}'",TextboxGoodsName.Text);
if(this.DDLDiningSel.SelectedValue!="no")
SQLCondition.AppendFormat(" and diningID='{0}'",DDLDiningSel.SelectedValue);
ViewState["DINStockMng_strWhere"]=SQLCondition.ToString();
WebPager1.CurrentPageIndex=1;
dgBind();
PreRevert();
}
catch(Exception ex)
{
Page.RegisterStartupScript("alert",string.Format("<script>alert('{0}')</script>",ex.Message));
}
}
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
if(e.CommandName=="Edit")
{
DataLogical.Dining.DIN_Depot dd = new DataLogical.Dining.DIN_Depot();
dd.UpdateInv(e.Item.Cells[0].Text,((TextBox)e.Item.Cells[8].Controls[1]).Text);
}
}
catch(Exception ex)
{
Page.RegisterStartupScript("alert",string.Format("<script>alert('{0}')</script>",ex.Message));
}
}
private void LBtnInList_Click(object sender, System.EventArgs e)
{
PreRevert();
if(!IsSelectDining()) return;
Session["diningid"]=DDLDiningSel.SelectedValue;
Response.Redirect(string.Format("InStockMng.aspx?menuid={0}",Request.QueryString["menuid"]));
}
private void LBtnOutList_Click(object sender, System.EventArgs e)
{
PreRevert();
if(!IsSelectDining()) return;
Session["diningid"]=DDLDiningSel.SelectedValue;
Response.Redirect(string.Format("OutStockMng.aspx?menuid={0}",Request.QueryString["menuid"]));
}
private void LBtnBackList_Click(object sender, System.EventArgs e)
{
PreRevert();
if(!IsSelectDining()) return;
Session["diningid"]=DDLDiningSel.SelectedValue;
Response.Redirect(string.Format("BackStockMng.aspx?menuid={0}",Request.QueryString["menuid"]));
}
private bool IsSelectDining()
{
try
{
if(this.DDLDiningSel.SelectedValue.ToString()=="no")
{
Page.RegisterStartupScript("alert",string.Format("<script>alert('{0}')</script>","请选择餐厅!"));
return false;
}
else
return true;
}
catch
{
return false;
}
}
private void dgBind()
{
DataTable dt=null;
string strWhere=ViewState["DINStockMng_strWhere"].ToString();
string strTabName="DIN_Depot";
string strOrderby=" inputdate desc ";
string strFld=" *,quantityDepot - quantityInput + quantityOut as Depotresult ";
dt=EDSWebCommon.Pager.DoPaging(WebPager1,strTabName,strFld,strWhere,strOrderby);
this.DataGrid1.DataSource=dt;
this.DataGrid1.DataKeyField="depotid";
this.DataGrid1.DataBind();
}
private void WebPager1_PageIndexChanged(object sender, newtouch.controls.PageIndexChangeEventArgs e)
{
this.WebPager1.CurrentPageIndex=e.NewPageIndex;
dgBind();
}
private void PreRevert()
{
ClassRevert cr=new ClassRevert();
cr.SQLCondition=ViewState["DINStockMng_strWhere"].ToString();
cr.WebPage=WebPager1.CurrentPageIndex;
cr.TreeViewExpand=TreeView1.ExpandLevel;
cr.DiningID=this.DDLDiningSel.SelectedValue;
cr.GoodsName=this.TextboxGoodsName.Text;
Session["DINStockMng_strWhere"]=cr;
}
private void DoRevert()
{
ClassRevert cr=(ClassRevert)Session["DINStockMng_strWhere"];
ViewState["DINStockMng_strWhere"]=cr.SQLCondition;
ViewState["DINStockMng_strWhere"]=cr.SQLCondition;
WebPager1.CurrentPageIndex=cr.WebPage;
TreeView1.ExpandLevel=cr.TreeViewExpand;
DDLDiningSel.SelectedValue=cr.DiningID;
TextboxGoodsName.Text=cr.GoodsName;
WebPager1.CurrentPageIndex=cr.WebPage;
dgBind();
}
private void DDLDiningSel_SelectedIndexChanged(object sender, System.EventArgs e)
{
Session["DINInStockUC_strWhere"]=null;
Session["DINOutStockUC_strWhere"]=null;
Session["DINBackStockUC_strWhere"]=null;
}
}
} |
|