?? lensprice.aspx.cs
字號:
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace NewGlassBook
{
/// <summary>
/// Summary description for lensPrice.
/// </summary>
public class LensPrice : MyPage
{
protected System.Web.UI.WebControls.Label lblWarning;
protected System.Web.UI.WebControls.LinkButton DeleteLink;
protected NewGlassBook.MyTextBox bPrice;
protected NewGlassBook.MyDropDownList aLevels;
protected NewGlassBook.MyDropDownList dBrand;
protected NewGlassBook.MyTextBox dPrice;
protected NewGlassBook.MyButton dbtn_query;
protected NewGlassBook.MyTextBox bDegreeS;
protected NewGlassBook.MyTextBox bDegreeE;
protected NewGlassBook.MyDropDownList dlevels;
protected NewGlassBook.MyButton dbtnReset;
protected NewGlassBook.MyButton dbtnOk;
protected NewGlassBook.SuperDataGrid dgShow;
protected NewGlassBook.MyDropDownList aBrandId;
static string strSql;//此處strSql是類中的變量,所以在類的各個地方都可以使用
protected Record r=new Record();//訪問數據庫用
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
aBrandBind();//顯示品牌
dbtnOk.Attributes["onClick"]="return lenspriceValid()";//客戶端驗證
}
}
protected string OpenWin(object obj)//打開修改價格頁面
{
if (!Convert.IsDBNull(obj))
{
return "window.open(\"lenspriceedit.aspx?id=" + obj.ToString() + "\", \"\",\"width=240,height=230,top=140,left=290\");return false;";
}
return "";
}
private void aBrandBind()
{
DataSet ds;
ds=r.GetData("brand","select * from brand where id like '0001%' and len(id)>4 order by id");
aBrandId.DataSource=ds;
aBrandId.DataTextField="BrandName";
aBrandId.DataValueField="id";
aBrandId.DataBind();//用來設置鏡片價格時的品牌
dBrand.DataSource=ds;
dBrand.DataTextField="BrandName";
dBrand.DataValueField="id";
dBrand.DataBind();//用來查詢鏡片價格時的品牌
ListItem li=new ListItem();//生成所有品牌項
li.Text="所有品牌";
li.Value="";
dBrand.Items.Insert(0,li);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.dbtnOk.Click += new System.EventHandler(this.dbtnOk_Click);
this.dbtnReset.Click += new System.EventHandler(this.dbtnReset_Click);
this.dbtn_query.Click += new System.EventHandler(this.dbtn_query_Click);
this.dgShow.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgShow_Change);
this.dgShow.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgShow_Delete);
this.dgShow.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgShow_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ClearTextBoxT()
{
bPrice.Text="";
bDegreeS.Text="";
bDegreeE.Text="";
}
private void dgShowOpen()
{
DataSet ds=r.GetData("a_b",strSql);
DataView dv=ds.Tables["a_b"].DefaultView;
dgShow.DataSource=dv;
dgShow.PagerStyle.Mode=PagerMode.NumericPages;
dgShow.DataBind();
}
public void dgShow_Change(Object sender, DataGridPageChangedEventArgs e)
{
dgShow.CurrentPageIndex = e.NewPageIndex;
dgShowOpen();
}
protected void dgShow_Delete(Object sender,DataGridCommandEventArgs e)
{
string id = e.Item.Cells[0].Text;
//得到當前記錄的末度數,找出該品牌的的起始度數是否有大于末度數,如果有,就不可以刪除
string CurrentEDegree=r.GetData("select degreeE from EyeGlassPrice where id="+id,1);
string BrandID=r.GetData("select brand from EyeGlassPrice where id="+id,1);
string priStrSql;
priStrSql="select DegreeS from EyeGlassPrice where";
priStrSql=priStrSql+" brand='"+BrandID+"' and degreeS>"+CurrentEDegree;
string NextDegree=r.GetData(priStrSql,1);
if(NextDegree=="")
{
if(r.ExecuteQuery("delete from EyeGlassPrice where ID="+id)==1)
{
lblWarning.Text="刪除成功!";
}
else
{
lblWarning.Text=r.ErrMsg;
}
dgShowOpen();
}
else
{
lblWarning.Text="該品牌有更高的級光存在,您不能刪除當前價格設置信息,請依次刪除";
}
}
private void dgShow_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.FindControl("DeleteLink")!= null)
{
((LinkButton) e.Item.FindControl("DeleteLink")).Attributes.Add("onClick", "return confirm('您確實要刪除當前記錄嗎?');");
}
if(e.Item.ItemIndex>-1)
{
if(e.Item.ItemType != ListItemType.Footer)
{
e.Item.Cells[5].Text=this.GetDot2Num(e.Item.Cells[5].Text);
e.Item.Cells[6].Text=this.GetDot2Num(e.Item.Cells[6].Text);
e.Item.Cells[7].Text=this.GetDot2Num(e.Item.Cells[7].Text);
}
}
}
private void dbtnOk_Click(object sender, System.EventArgs e)
{
string StrDegreeS=bDegreeS.Text;//輸入價格范圍的起始度數
strSql="select top 1 degreeE from EyeGlassPrice where";
strSql=strSql+ " brandid='"+aBrandId.SelectedItem.Value.ToString()+"' order by degreee desc";
DataSet ds=r.GetData("maxdegree",strSql);
if(ds.Tables["maxdegree"].Rows.Count>0)
{
string StrDegreeE=ds.Tables["maxdegree"].Rows[0]["degreee"].ToString();//取的庫中最大度數
if(float.Parse(StrDegreeS)<=float.Parse(StrDegreeE))//表明該度數范圍內的價格已經設置
{
lblWarning.Text="起始度數太小,請大于"+StrDegreeE+"度數";
return;
}
}
if(r.RequestInsert("EyeGlassPrice",Request)==1)//插入
{
lblWarning.Text="信息添加成功!";
ClearTextBoxT();
if(aLevels.SelectedIndex!=10)
{
aLevels.SelectedIndex=aLevels.SelectedIndex+1;
}
else
{
aLevels.SelectedIndex=1;
}
strSql="select top 1 right(brandname,len(brandname)-2) as brandname,* from";
strSql=strSql+" EyeGlassPrice b,brand a where a.id=b.brandid order by b.id desc";
dgShowOpen();
}
else
{
lblWarning.Text=r.ErrMsg;
}
}
private void dbtn_query_Click(object sender, System.EventArgs e)
{
string strBrand,strPrice;
strBrand=dBrand.SelectedItem.Value.ToString();
strPrice=dPrice.Text;
strSql="select right(brandname,len(brandname)-2) as brandname,* from";
strSql=strSql+" EyeGlassPrice b,brand a where a.id=b.brandid";
if(strBrand!="")
{
strSql=strSql+" and b.brandid='"+strBrand+"'";
}
if(strPrice!="")
{
strSql=strSql+" and b.price="+strPrice;
}
if(dlevels.SelectedItem.Value.ToString()!="0")
{
strSql=strSql+" and b.levels='"+dlevels.SelectedItem.Value.ToString()+"' ";
}
strSql=strSql+" order by b.brandid,b.degrees";
dgShow.CurrentPageIndex=0;
this.dgShowOpen();
}
private void dbtnReset_Click(object sender, System.EventArgs e)
{
this.ClearTextBox();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -