?? s_putin.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.SqlClient;
using System.Configuration;
namespace Supermart
{
/// <summary>
/// S_putin 的摘要說明。
/// </summary>
public class S_putin : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image4;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label lb_ID;
protected System.Web.UI.WebControls.DropDownList ddl_worker;
protected System.Web.UI.WebControls.TextBox txt_introduce;
protected System.Web.UI.WebControls.TextBox txt_num;
protected System.Web.UI.WebControls.TextBox txt_provider;
protected System.Web.UI.WebControls.Image Image5;
protected System.Web.UI.WebControls.TextBox txt_merName;
protected System.Web.UI.WebControls.TextBox txt_cost;
protected System.Web.UI.WebControls.Button btn_putin;
protected System.Web.UI.WebControls.DataGrid stocklist;
protected System.Web.UI.WebControls.DropDownList ddl_depot;
protected System.Web.UI.WebControls.Label lb_Money;
protected System.Web.UI.WebControls.DropDownList ddl_type;
protected System.Web.UI.WebControls.TextBox txt_bit;
protected System.Web.UI.WebControls.Label lb_total;
private string strConn=System.Configuration.ConfigurationSettings.AppSettings["SQLCONNECTION"];
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("select top 1 * from stocklist order by stocklistID desc",con);
SqlDataReader sdr=cmd.ExecuteReader();
sdr.Read();
this.lb_ID.Text=sdr["stocklistID"].ToString();
int i=int.Parse(this.lb_ID.Text)+1;
this.lb_ID.Text=i.ToString();
sdr.Close();
con.Close();
Bindtype();
Binddepot();
Bindddlworker();
}
// 在此處放置用戶代碼以初始化頁面
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.txt_merName.TextChanged += new System.EventHandler(this.txt_merName_TextChanged);
this.txt_num.TextChanged += new System.EventHandler(this.txt_num_TextChanged);
this.txt_cost.TextChanged += new System.EventHandler(this.txt_cost_TextChanged);
this.btn_putin.Click += new System.EventHandler(this.btn_putin_Click);
this.stocklist.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.stocklist_PageIndexChanged);
this.stocklist.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.stocklist_DeleteCommand);
this.stocklist.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.stocklist_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btn_putin_Click(object sender, System.EventArgs e)
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("select count(*) from merchandise where merName='"+this.txt_merName.Text+"'",con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
SqlCommand cmd3=new SqlCommand("select * from merchandise where merName='"+this.txt_merName.Text+"'",con);
SqlDataReader sdr=cmd3.ExecuteReader();
sdr.Read();
int num1=int.Parse(sdr["stock"].ToString());
int num2=int.Parse(this.txt_num.Text);
int stock=num1+num2;
sdr.Close();
string mycmd1="update merchandise set cost='"+this.txt_cost.Text+"',stock='"+stock+"' where merName='"+this.txt_merName.Text+"'";
SqlCommand cmd1=new SqlCommand(mycmd1,con);
cmd1.ExecuteNonQuery();
}
else
{
string mycmd="insert into merchandise(merName,stocklistID,merBit,cost,stock,typeID,depotID,tradePrice,retailPrice) values('"+this.txt_merName.Text.Trim()+"','"+this.lb_ID.Text.Trim()+"','"+this.txt_bit.Text.Trim()+"','"+this.txt_cost.Text.Trim()+"','"+this.txt_num.Text.Trim()+"','"+this.ddl_type.SelectedValue+"','"+this.ddl_depot.SelectedValue+"','未定','未定')";
SqlCommand cmd2=new SqlCommand(mycmd,con);
cmd2.ExecuteNonQuery();
}
SqlCommand scmd=new SqlCommand("select count(*) from merlist where stocklistID='"+this.lb_ID.Text+"'",con);
int count1=Convert.ToInt32(scmd.ExecuteScalar());
if(count1<1)
{
string my2cmd="insert into stocklist(stocklistID,stodate,provider,worker,remark)values('"+this.lb_ID.Text.Trim()+"',GetDate(),'"+this.txt_provider.Text.Trim()+"','"+this.ddl_worker.SelectedValue+"','"+this.txt_introduce.Text.Trim()+"') ";
SqlCommand ccmd=new SqlCommand(my2cmd,con);
ccmd.ExecuteNonQuery();
}
else
{
SqlCommand acmd=new SqlCommand("update stocklist set stodate=GetDate()",con);
acmd.ExecuteNonQuery();
}
string merlist="insert into merlist(stocklistID,merName,merBit,cost,num,buyMoney)values('"+this.lb_ID.Text.Trim()+"','"+this.txt_merName.Text.Trim()+"','"+this.txt_bit.Text.Trim()+"','"+this.txt_cost.Text.Trim()+"','"+this.txt_num.Text.Trim()+"','"+this.lb_Money.Text.Trim()+"')";
SqlCommand dcmd=new SqlCommand(merlist,con);
dcmd.ExecuteNonQuery();
SqlCommand sum=new SqlCommand("select sum(Convert(float,buyMoney))as total from merlist where stocklistID='"+this.lb_ID.Text+"'",con);
SqlDataReader sdr1=sum.ExecuteReader();
sdr1.Read();
this.lb_total.Text=sdr1["total"].ToString();
sdr1.Close();
Bindlist();
this.txt_merName.Text="";
this.txt_num.Text="";
this.txt_bit.Text="";
this.txt_cost.Text="";
this.lb_Money.Text="0.00";
con.Close();
}
private void txt_merName_TextChanged(object sender, System.EventArgs e)
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("select count(*) from merchandise where merName='"+this.txt_merName.Text+"'",con);
int count=Convert.ToInt32(cmd.ExecuteScalar());
if(count>0)
{
SqlCommand cmd1=new SqlCommand("select* from merchandise where merName='"+this.txt_merName.Text+"'",con);
SqlDataReader sdr=cmd1.ExecuteReader();
sdr.Read();
this.txt_bit.Text="";
this.txt_bit.Text=sdr["merBit"].ToString();
this.txt_cost.Text=sdr["cost"].ToString();
this.ddl_type.SelectedValue=sdr["typeID"].ToString();
this.ddl_depot.SelectedValue=sdr["depotID"].ToString();
sdr.Close();
}
con.Close();
}
public void Bindlist()
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from merlist where stocklistID='"+this.lb_ID.Text+"'",con);
DataSet ds=new DataSet();
sda.Fill(ds,"title");
sda.Dispose();
this.stocklist.DataKeyField="ID";
this.stocklist.DataSource=ds.Tables["title"].DefaultView;
this.stocklist.DataBind();
con.Close();
}
private void txt_cost_TextChanged(object sender, System.EventArgs e)
{
if(this.txt_cost.Text!=""&&this.txt_num.Text!="")
{
int a=int.Parse(this.txt_num.Text);
float b=float.Parse(this.txt_cost.Text);
double c=a*b;
double T=(double)Math.Round(c,2);
this.lb_Money.Text=T.ToString();
}
else
{
this.lb_Money.Text="0.00";
}
}
private void txt_num_TextChanged(object sender, System.EventArgs e)
{
if(this.txt_cost.Text!=""&&this.txt_num.Text!="")
{
int a=int.Parse(this.txt_num.Text);
float b=float.Parse(this.txt_cost.Text);
double c=a*b;
double T=(double)Math.Round(c,2);
this.lb_Money.Text=T.ToString();
}
else
{
this.lb_Money.Text="0.00";
}
}
public void Bindtype()
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("select * from type",con);
SqlDataReader sdr=cmd.ExecuteReader();
this.ddl_type.DataSource=sdr;
this.ddl_type.DataTextField="typeName";
this.ddl_type.DataValueField="typeID";
this.ddl_type.DataBind();
sdr.Close();
con.Close();
}
public void Binddepot()
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("select * from depot",con);
SqlDataReader sdr=cmd.ExecuteReader();
this.ddl_depot.DataSource=sdr;
this.ddl_depot.DataTextField="depotName";
this.ddl_depot.DataValueField="depotID";
this.ddl_depot.DataBind();
sdr.Close();
con.Close();
}
public void Bindddlworker()
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("select * from personnel",con);
SqlDataReader sdr=cmd.ExecuteReader();
this.ddl_worker.DataSource=sdr;
this.ddl_worker.DataTextField="perName";
this.ddl_worker.DataValueField="perID";
this.ddl_worker.DataBind();
sdr.Close();
con.Close();
}
private void stocklist_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c");
((LinkButton)(e.Item.Cells[5].Controls[0])).Attributes.Add("onclick","return confirm('你確認刪除嗎?');");
}
}
private void stocklist_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string empID=this.stocklist.DataKeys[e.Item.ItemIndex].ToString();
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("delete from merlist where ID='"+empID+"'",con);
cmd.ExecuteNonQuery();
Bindlist();
}
private void stocklist_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.stocklist.CurrentPageIndex=e.NewPageIndex;
this.Bindlist();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -