?? s_buyer.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.Configuration;
using System.Data.SqlClient;
namespace Supermart
{
/// <summary>
/// S_buyer 的摘要說明。
/// </summary>
public class S_buyer : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image4;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Button btn_putin;
protected System.Web.UI.WebControls.TextBox txt_buyerName;
protected System.Web.UI.WebControls.TextBox txt_remark;
protected System.Web.UI.WebControls.Image Image5;
protected System.Web.UI.WebControls.DataGrid buyerlist;
protected System.Web.UI.WebControls.TextBox txt_phone;
protected System.Web.UI.WebControls.TextBox txt_address;
private string strConn=System.Configuration.ConfigurationSettings.AppSettings["SQLCONNECTION"];
private void Page_Load(object sender, System.EventArgs e)
{
Bindbuylist();
// 在此處放置用戶代碼以初始化頁面
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.btn_putin.Click += new System.EventHandler(this.btn_putin_Click);
this.buyerlist.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.buyerlist_PageIndexChanged);
this.buyerlist.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.buyerlist_DeleteCommand);
this.buyerlist.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.buyerlist_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 ccmd=new SqlCommand("select count(*) from buyer where buyerName='"+this.txt_buyerName.Text+"'",con);
int count=Convert.ToInt32(ccmd.ExecuteScalar());
if(count<1)
{
string mycmd="insert into buyer(buyerName,buyTime,latestBuy,totalMoney,remark)values('"+this.txt_buyerName.Text.Trim()+"','0',GetDate(),'0.00','"+this.txt_remark.Text.Trim()+"')";
SqlCommand cmd=new SqlCommand(mycmd,con);
cmd.ExecuteNonQuery();
Response.Write("<script>alert(\"添加成功!!\");</script>");
Bindbuylist();
}
else
{
Response.Write("<script>alert(\"該顧客已存在!!\");</script>");
}
con.Close();
this.txt_buyerName.Text="";
this.txt_remark.Text="";
}
public void Bindbuylist()
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from buyer",con);
DataSet ds=new DataSet();
sda.Fill(ds,"title");
sda.Dispose();
this.buyerlist.DataKeyField="buyerID";
this.buyerlist.DataSource=ds.Tables["title"].DefaultView;
this.buyerlist.DataBind();
con.Close();
}
private void buyerlist_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 buyerlist_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string empID=this.buyerlist.DataKeys[e.Item.ItemIndex].ToString();
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("delete from buyer where buyerID='"+empID+"'",con);
cmd.ExecuteNonQuery();
Bindbuylist();
}
private void buyerlist_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.buyerlist.CurrentPageIndex=e.NewPageIndex;
this.Bindbuylist();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -