📄 productmarket.aspx.cs
字号:
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 System.Data.OleDb;
namespace SCard.admin
{
/// <summary>
/// productMarket 的摘要说明。
/// </summary>
public class productMarket : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlPName;
protected System.Web.UI.WebControls.DropDownList ddlState;
protected System.Web.UI.WebControls.Button btnSelect;
protected DevCenter.OleDbPager OleDbPager1;
//protected System.Web.UI.WebControls.DropDownList ddlSales;
protected System.Web.UI.WebControls.DropDownList ddlClass;
protected System.Web.UI.WebControls.Label lblCost;
protected System.Web.UI.WebControls.Label lblGain;
protected System.Web.UI.WebControls.Label lblSales;
//protected System.Web.UI.HtmlControls.HtmlTable SalesCPTable;
protected System.Web.UI.WebControls.DropDownList ddlSales;
protected System.Web.UI.WebControls.DataList PDataList;
//protected System.Web.UI.WebControls.DataGrid PLDataGrid;
private void Page_Load(object sender, System.EventArgs e)
{
//权限检查
if( Session["adminName"]==null || Session["adminName"].ToString() == String.Empty )
{
Response.Write("<font color=#ff0000 style='FONT-SIZE: 12px'>对不起,您没足够权限访问此页!!</font><br>");
Response.Write("<a href=index.aspx target=_top style='FONT-SIZE: 12px'>重新登陆</a><br>");
Response.End();
return;
}
if( !IsPostBack )
{
getddlClassData();//绑定 类别选框
//getddlSalesData();//绑定 销售人选框
//SalesCPTable.Visible = false;
}
}
private void getddlClassData()//绑定 类别选框
{
DBConn myDB = new DBConn();
string sql="select * from Category order by CID desc";
ddlClass.DataSource = myDB.getDataReader(sql);
ddlClass.DataTextField = "CName";
ddlClass.DataValueField = "CID";
ddlClass.DataBind();
myDB.Close();
ddlClass.Items.Insert(0,new ListItem("所有分类","-1"));
}
/*
private void getddlSalesData()//绑定 销售人选框
{
DBConn myDB = new DBConn();
string sql="select * from Sales order by SalesID desc";
ddlSales.DataSource = myDB.getDataReader(sql);
ddlSales.DataTextField = "SalesName";
ddlSales.DataValueField = "SalesID";
ddlSales.DataBind();
myDB.Close();
ddlSales.Items.ExecuteNonQuery(0,new ListItem("所有销售人","-1"));
}
*/
private void getSalesCG( string mySql )//某个销售人 已售出的卡的 成本,利润 汇总
{
DBConn myDB = new DBConn();
OleDbDataReader mydr = myDB.getDataReader( mySql );
if( mydr.Read() )
{
lblCost.Text = double.Parse( mydr["Cost"].ToString() ).ToString("C");
lblGain.Text = double.Parse( mydr["Gain"].ToString() ).ToString("C");
}
if( lblCost.Text == String.Empty )
{
lblCost.Text = "0";
}
if( lblGain.Text == String.Empty )
{
lblGain.Text = "0";
}
mydr.Close();
myDB.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ddlClass.SelectedIndexChanged += new System.EventHandler(this.ddlClass_SelectedIndexChanged);
this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click);
this.PDataList.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.PDataList_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ddlClass_SelectedIndexChanged(object sender, System.EventArgs e)
{
string strCID = ddlClass.SelectedValue;
if( strCID.Equals("-1") )
{
ddlPName.SelectedIndex = 0;
ddlPName.Enabled = false;
}
else
{
DBConn myDB = new DBConn();
string sql="select * from Products where CID=" + strCID + " order by PID desc";
ddlPName.DataSource = myDB.getDataReader(sql);
ddlPName.DataTextField = "PName";
ddlPName.DataValueField = "PID";
ddlPName.DataBind();
myDB.Close();
ddlPName.Items.Insert(0,new ListItem("所有商品","-1"));
ddlPName.Enabled = true;
}
}
private void btnSelect_Click(object sender, System.EventArgs e)
{
string mySql = "select *,PCPrice*PStock as [StockPrice],(select count(*) from PList where PList.PID=Products.PID and CardState=1) as [NSellNum],(PNPrice*(select count(*) from PList where PList.PID=Products.PID and CardState=1)) as [TotalPrice] from Products order by PID desc";
//string strSales = ddlSales.SelectedValue;
string strClass = ddlClass.SelectedValue;
string strPName = ddlPName.SelectedValue;
///if( strSales.Equals("-1") )//所有 销售人
///{
if( !strClass.Equals("-1") )//某个分类
{
mySql = "select *,PCPrice*PStock as [StockPrice],(select count(*) from PList where PList.PID=Products.PID and CardState=1) as [NSellNum],(PNPrice*(select count(*) from PList where PList.PID=Products.PID and CardState=1)) as [TotalPrice] from Products where CID=" + strClass + " order by PID desc";
if( !strPName.Equals("-1") )//某个商品
{
mySql = "select *,PCPrice*PStock as [StockPrice],(select count(*) from PList where PList.PID=Products.PID and CardState=1) as [NSellNum],(PNPrice*(select count(*) from PList where PList.PID=Products.PID and CardState=1)) as [TotalPrice] from Products where PID=" + strPName + " order by PID desc";
}
}
/*///
}
else//某个 销售人
{
mySql = "select *,PCPrice*PStock as [StockPrice],(select count(*) from PList where PList.PID=Products.PID and CardState=1) as [NSellNum],(PNPrice*(select count(*) from PList where PList.PID=Products.PID and CardState=1)) as [TotalPrice] from Products where SalesID=" + strSales + " order by PID desc";
//某个销售人 已售出的卡的 成本,利润 汇总
string sql = "select sum(PCPrice)*count(Plist.PLID) as [Cost]," +
"sum(PNPrice)*count(Plist.PLID)- sum(PCPrice)*count(Plist.PLID) as [Gain] " +
"from Products,Plist " +
"where SalesID="+ strSales +" and PList.PID=Products.PID and PList.CardState=1";
if( !strClass.Equals("-1") )
{
mySql = "select *,PCPrice*PStock as [StockPrice],(select count(*) from PList where PList.PID=Products.PID and CardState=1) as [NSellNum],(PNPrice*(select count(*) from PList where PList.PID=Products.PID and CardState=1)) as [TotalPrice] from Products where CID=" + strClass + " and SalesID=" + strSales + " order by PID desc";
//
sql = "select sum(PCPrice)*count(Plist.PLID) as [Cost]," +
"sum(PNPrice)*count(Plist.PLID)- sum(PCPrice)*count(Plist.PLID) as [Gain] " +
"from Products,Plist " +
"where CID=" + strClass + " and SalesID="+ strSales +" and PList.PID=Products.PID and PList.CardState=1";
if( !strPName.Equals("-1") )
{
mySql = "select *,PCPrice*PStock as [StockPrice],(select count(*) from PList where PList.PID=Products.PID and CardState=1) as [NSellNum],(PNPrice*(select count(*) from PList where PList.PID=Products.PID and CardState=1)) as [TotalPrice] from Products where PID=" + strPName + " and SalesID=" + strSales + " order by PID desc";
//
sql = "select sum(PCPrice)*count(Plist.PLID) as [Cost]," +
"sum(PNPrice)*count(Plist.PLID)- sum(PCPrice)*count(Plist.PLID) as [Gain] " +
"from Products,Plist " +
"where Products.PID=" + strPName + " and SalesID="+ strSales +" and PList.PID=Products.PID and PList.CardState=1";
}
}
getSalesCG( sql );//某个销售人 已售出的卡的 成本,利润 汇总
lblSales.Text = ddlSales.Items[ ddlSales.SelectedIndex ].Text;
SalesCPTable.Visible = true;
}
///*/
/*
DBConn myDB = new DBConn();
PDataList.DataSource = myDB.getDataReader( mySql );
PDataList.DataKeyField = "PID";
PDataList.DataBind();
myDB.Close();
*/
PDataList.DataKeyField = "PID";
//分页
MyOleDbPager oleDbPager = new MyOleDbPager();
oleDbPager.setAttribute( OleDbPager1, "PDataList", mySql, "10000000-PID", 1);
}
private void PDataList_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
DataGrid myDataGrid = (DataGrid)e.Item.FindControl("PLDataGrid");
if(myDataGrid != null)
{
string mySql="select * from PList where PId=" + PDataList.DataKeys[e.Item.ItemIndex].ToString();
string strState = ddlState.SelectedValue;
if( !strState.Equals("-1") )
{
mySql="select * from PList where CardState=" + strState + " and PId=" + PDataList.DataKeys[e.Item.ItemIndex].ToString();
}
DBConn myDB = new DBConn();
myDataGrid.DataSource = myDB.getDataReader( mySql );
myDataGrid.DataBind();
myDB.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -