⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lensprice.aspx.cs

📁 ASP.NET编写的眼镜行分销系统的程序.
💻 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 + -