📄 contract_stat.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.Configuration;
namespace cms
{
/// <summary>
/// contract_stat 的摘要说明。
/// </summary>
public class contract_stat : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList Ddl_stat;
protected System.Web.UI.WebControls.TextBox Tbx_date;
protected System.Web.UI.WebControls.Button Btn_ok;
protected System.Web.UI.WebControls.Label Lbl_money;
protected System.Web.UI.WebControls.Label Lbl_count;
protected System.Web.UI.WebControls.Button Btn_exit;
protected System.Web.UI.WebControls.DropDownList Ddl_kind;
protected System.Web.UI.WebControls.DropDownList Ddl_product;
protected System.Web.UI.WebControls.DropDownList Ddl_customer;
SqlConnection cn;
private void Page_Load(object sender, System.EventArgs e)
{//判断用户是否为合法用户
try
{
if(Session["User_power"].ToString ()=="0"||Session["User_power"].ToString ()=="2") ;
else
{
Response.End ();
}
}
catch
{
Response.Write ("您不是合法用户,请登入后再操作,<a href='default.aspx'>返回</a>");
Response.End ();
}
//**
//客户名称下拉列表框绑定
string strconn= ConfigurationSettings.AppSettings["dsn"];
//连接本地计算机的CMS数据库
SqlConnection cn0= new SqlConnection (strconn);
if(!IsPostBack)
{
cn0.Open ();
string mysql="select * from customer";
SqlCommand cm0=new SqlCommand (mysql,cn0);
SqlDataReader dr0=cm0.ExecuteReader ();
Ddl_customer.Items .Add (new ListItem("所有","-1") );
while(dr0.Read ())
{
Ddl_customer.Items .Add (new ListItem(dr0["Custom_name"].ToString(),dr0["Custom_id"].ToString()) );
}
cn0.Close ();
产品名称下拉列表框绑定
cn0.Open();
string mysql1="select * from product";
SqlCommand cm1=new SqlCommand (mysql1,cn0);
SqlDataReader dr1=cm1.ExecuteReader ();
//Ddl_product.Items .Add (new ListItem("所有","-1") );
while(dr1.Read ())
{
Ddl_product.Items .Add (new ListItem(dr1["Product_name"].ToString() ,dr1["Product_id"].ToString()) );
}
cn0.Close ();
}
cn=new SqlConnection(strconn);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Btn_ok.Click += new System.EventHandler(this.Btn_ok_Click);
this.Btn_exit.Click += new System.EventHandler(this.Btn_exit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Btn_ok_Click(object sender, System.EventArgs e)
{
if(Ddl_stat.SelectedItem.Value=="0")
{
string strsql="select sum(Contract_price),sum(Product_book) from contract,contract_detail where Contract_start='"+Tbx_date.Text+"' and contract.Contract_id=contract_detail.Contract_id";
if (Ddl_customer.SelectedItem.Value!="-1")//如果“客户”有选择
{
strsql=strsql+" and contract.Custom_id='"+Ddl_customer.SelectedItem.Value+"'";
}
if (Ddl_product.SelectedItem.Value!="-1")//如果“产品”有选择
{
strsql=strsql+" and contract_detail.Product_id='"+Ddl_product.SelectedItem.Value+"'";
}
if (Ddl_kind.SelectedItem.Value!="-1")//如果“合同状态”有选择
{
strsql=strsql+" and contract.Contract_state='"+Ddl_kind.SelectedItem.Value+"'";
}
SqlCommand cm=new SqlCommand(strsql,cn);
cn.Open();
SqlDataReader dr=cm.ExecuteReader();
if(dr.Read())
{
Lbl_money.Text="本日总金额为:"+dr[0].ToString();
Lbl_count.Text="本日销售量为:"+dr[1].ToString();
}
else
{
Lbl_money.Text="本日总金额为:0";
Lbl_count.Text="本日销售量为:0";
}
cn.Close();
}
else if(Ddl_stat.SelectedItem.Value=="1")
{
string strsql="select sum(Contract_price),sum(Product_book) from contract,contract_detail where Contract_start like'"+Tbx_date.Text+"%' and contract.Contract_id=contract_detail.Contract_id";
if (Ddl_customer.SelectedItem.Value!="-1")//如果“客户”有选择
{
strsql=strsql+" and contract.Custom_id='"+Ddl_customer.SelectedItem.Value+"'";
}
if (Ddl_product.SelectedItem.Value!="-1")//如果“产品”有选择
{
strsql=strsql+" and contract_detail.Product_id='"+Ddl_product.SelectedItem.Value+"'";
}
if (Ddl_kind.SelectedItem.Value!="-1")//如果“合同状态”有选择
{
strsql=strsql+" and contract.Contract_state='"+Ddl_kind.SelectedItem.Value+"'";
}
SqlCommand cm=new SqlCommand(strsql,cn);
cn.Open();
SqlDataReader dr=cm.ExecuteReader();
if(dr.Read())
{
Lbl_money.Text="本月总金额为:"+dr[0].ToString();
Lbl_count.Text="本月销售量为:"+dr[1].ToString();
}
else
{
Lbl_money.Text="本月总金额为:0";
Lbl_count.Text="本月销售量为:0";
}
cn.Close();
}
else
{
string strsql="select sum(Contract_price),sum(Product_book) from contract,contract_detail where Contract_start like'"+Tbx_date.Text+"%' and contract.Contract_id=contract_detail.Contract_id";
if (Ddl_customer.SelectedItem.Value!="-1")//如果“客户”有选择
{
strsql=strsql+" and contract.Custom_id='"+Ddl_customer.SelectedItem.Value+"'";
}
if (Ddl_product.SelectedItem.Value!="-1")//如果“产品”有选择
{
strsql=strsql+" and contract_detail.Product_id='"+Ddl_product.SelectedItem.Value+"'";
}
if (Ddl_kind.SelectedItem.Value!="-1")//如果“合同状态”有选择
{
strsql=strsql+" and contract.Contract_state='"+Ddl_kind.SelectedItem.Value+"'";
}
SqlCommand cm=new SqlCommand(strsql,cn);
cn.Open();
SqlDataReader dr=cm.ExecuteReader();
if(dr.Read())
{
Lbl_money.Text="本年总金额为:"+dr[0].ToString();
Lbl_count.Text="本年销售量为:"+dr[1].ToString();
}
else
{
Lbl_money.Text="本年总金额为:0";
Lbl_count.Text="本年销售量为:0";
}
cn.Close();
}
}
private void Btn_exit_Click(object sender, System.EventArgs e)
{
Response.Redirect("default.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -