一个应该注意的问题
来源:互联网 发布:找不到java运行环境 编辑:程序博客网 时间:2024/05/17 07:34
public class outstorage : System.Web.UI.Page
...{
public string conn =Bill.Biz.DataBase.GetConnectionString("bill");
protected int PageSize = 20;
protected int page;
protected int itemCount;
protected int totalPage;
protected int adid;
protected int userid;
protected System.Web.UI.WebControls.Button newAdd;
protected System.Web.UI.WebControls.DropDownList ddlName;
protected System.Web.UI.WebControls.TextBox txtTitle;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.DataGrid Datagrid1;
protected System.Web.UI.WebControls.DropDownList ddrPageNum;
protected System.Web.UI.WebControls.Label lblPageInfo;
protected System.Web.UI.WebControls.Button btnFirstPage;
protected System.Web.UI.WebControls.Button btnPriPage;
protected System.Web.UI.WebControls.Button btnNextPage;
protected System.Web.UI.WebControls.Button btnLastPage;
protected System.Web.UI.WebControls.TextBox tbxPage;
protected System.Web.UI.WebControls.Button btnGo;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.Panel Panel1;
protected string condition = " 1=1 ";
private void Page_Load(object sender, System.EventArgs e)
...{
Bill.Biz.AgentAuth.Check();
userid =Convert.ToInt32(Session[Bill.Biz.AgentAuth.Session_Agent_Userid]);
itemCount = getCount();
if (itemCount==0)
...{
totalPage = 1;
}
else
...{
totalPage = itemCount%PageSize>0 ? itemCount/PageSize+1 : itemCount/PageSize;
}
if(!IsPostBack)
...{
ReadRecords();
}
}
public void Datagrid1_Edit(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
this.Datagrid1.EditItemIndex = e.Item.ItemIndex;
this.Datagrid1.DataBind();
ReadRecords();
}
private void getStrCondition()
...{
if(txtTitle.Text.Trim() != "")
...{
if(this.ddlName.SelectedValue=="0")
...{
condition += string.Format("and outstorage_name like '%{0}%'",txtTitle.Text.Trim().Replace("'","''"));
}
if(this.ddlName.SelectedValue=="1")
...{
condition += string.Format("and outstorage_class like '%{0}%'",txtTitle.Text.Trim().Replace("'","''"));
}
}
}
private int getCount()
...{
getStrCondition();
if(ViewState["itemCount"] == null || ViewState["keyword"].ToString() != this.condition)
...{
ViewState["keyword"] = this.condition;
string sql = string.Format("select count(*) from outstorage WHERE {0} ",condition);
int count = Convert.ToInt32(Bill.Biz.SqlHelper.ExecuteScalar(sql,conn));
ViewState["itemCount"] = count;
}
return Bill.Biz.Util.ToIntSafe(ViewState["itemCount"],0);
}
private void ReadRecords()
...{
PageSize =Convert.ToInt32(this.ddrPageNum.SelectedItem.Text);
if(ViewState["page"] == null || Convert.ToInt32(ViewState["page"]) < 1 )
...{
ViewState["page"] = 1;
}
else if(Convert.ToInt32(ViewState["page"]) > totalPage)
...{
ViewState["page"] = totalPage;
}
page = Convert.ToInt32(ViewState["page"]);
tbxPage.Text = page.ToString();
lblPageInfo.Text ="共"+ itemCount.ToString() + "项 " + page.ToString()+"/"+totalPage.ToString()+"页";
btnNextPage.Enabled = true;
btnLastPage.Enabled = true;
btnFirstPage.Enabled = true;
btnPriPage.Enabled = true;
if (itemCount<=PageSize || page * PageSize >= itemCount)
...{
btnNextPage.Enabled = false;
btnLastPage.Enabled = false;
}
if(page == 1)
...{
btnFirstPage.Enabled = false;
btnPriPage.Enabled = false;
}
string sqlStr;
sqlStr = string.Format(@"select top {0} * from outstorage where outstorage_id<=(select min(aa.outstorage_id) from (select top {1} outstorage_id from outstorage where {2} order by outstorage_id desc) aa) and {2} order by outstorage_id desc",PageSize,PageSize*page-PageSize+1,condition);
DataTable dt =Bill.Biz.SqlHelper.ExecuteDataset(sqlStr,conn).Tables[0];
dt.Columns.Add("newproduct_title");
dt.Columns.Add("newproduct_in");
dt.Columns.Add("newproduct_out");
foreach(DataRow dr in dt.Rows)
...{
if(dr["outstorage_name"].ToString().Length >= 24)
...{
dr["newproduct_title"] ="<a href='add_store.aspx?store_id="+dr["outstorage_id"].ToString()+"' title='"+dr["outstorage_name"].ToString()+"' >"+dr["outstorage_name"].ToString().Substring(0,23)+"</a>";
}
else
...{
dr["newproduct_title"] ="<a href='add_store.aspx?store_id="+dr["outstorage_id"].ToString()+"' title='"+dr["outstorage_name"].ToString()+"' >"+dr["outstorage_name"].ToString()+"</a>";
}
}
this.Datagrid1.DataSource = dt;
this.Datagrid1.DataBind();
}
public void Datagrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
//string key =((TextBox)e.Item.FindControl("product_id")).Text;
string key =this.Datagrid1.DataKeys[e.Item.ItemIndex].ToString();
string outstorageclass = ((TextBox)e.Item.FindControl("outstorage_class")).Text;
string outstoragenum = ((TextBox)e.Item.FindControl("outstorage_num")).Text;
string outstoragebeizhu = ((TextBox)e.Item.FindControl("outstorage_beizhu")).Text;
string sql="";
sql=string.Format("update outstorage set outstorage_class ='{0}',outstorage_num='{1}',outstorage_beizhu='{2}' where outstorage_id='{3}'",outstorageclass,outstoragenum,outstoragebeizhu,key);
SqlConnection constr = new SqlConnection(conn);
SqlCommand myCommand = new SqlCommand(sql,constr);
myCommand.Connection.Open();
if(this.userid.ToString() =="1" || this.userid.ToString()=="2")
...{
try
...{
myCommand.ExecuteNonQuery();
}
catch(SqlException)
...{
}
myCommand.Connection.Close();
this.Datagrid1.EditItemIndex = -1;
ReadRecords();
}
else
...{
Response.Write("<script language=javascript>alert('出错啦!请联系系统管理员','','')</script>");
}
}
public void Datagrid1_Delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
}
public void Datagrid1_Cancel(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
this.Datagrid1.EditItemIndex=-1;
ReadRecords();
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
...{
public string conn =Bill.Biz.DataBase.GetConnectionString("bill");
protected int PageSize = 20;
protected int page;
protected int itemCount;
protected int totalPage;
protected int adid;
protected int userid;
protected System.Web.UI.WebControls.Button newAdd;
protected System.Web.UI.WebControls.DropDownList ddlName;
protected System.Web.UI.WebControls.TextBox txtTitle;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.DataGrid Datagrid1;
protected System.Web.UI.WebControls.DropDownList ddrPageNum;
protected System.Web.UI.WebControls.Label lblPageInfo;
protected System.Web.UI.WebControls.Button btnFirstPage;
protected System.Web.UI.WebControls.Button btnPriPage;
protected System.Web.UI.WebControls.Button btnNextPage;
protected System.Web.UI.WebControls.Button btnLastPage;
protected System.Web.UI.WebControls.TextBox tbxPage;
protected System.Web.UI.WebControls.Button btnGo;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.Panel Panel1;
protected string condition = " 1=1 ";
private void Page_Load(object sender, System.EventArgs e)
...{
Bill.Biz.AgentAuth.Check();
userid =Convert.ToInt32(Session[Bill.Biz.AgentAuth.Session_Agent_Userid]);
itemCount = getCount();
if (itemCount==0)
...{
totalPage = 1;
}
else
...{
totalPage = itemCount%PageSize>0 ? itemCount/PageSize+1 : itemCount/PageSize;
}
if(!IsPostBack)
...{
ReadRecords();
}
}
public void Datagrid1_Edit(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
this.Datagrid1.EditItemIndex = e.Item.ItemIndex;
this.Datagrid1.DataBind();
ReadRecords();
}
private void getStrCondition()
...{
if(txtTitle.Text.Trim() != "")
...{
if(this.ddlName.SelectedValue=="0")
...{
condition += string.Format("and outstorage_name like '%{0}%'",txtTitle.Text.Trim().Replace("'","''"));
}
if(this.ddlName.SelectedValue=="1")
...{
condition += string.Format("and outstorage_class like '%{0}%'",txtTitle.Text.Trim().Replace("'","''"));
}
}
}
private int getCount()
...{
getStrCondition();
if(ViewState["itemCount"] == null || ViewState["keyword"].ToString() != this.condition)
...{
ViewState["keyword"] = this.condition;
string sql = string.Format("select count(*) from outstorage WHERE {0} ",condition);
int count = Convert.ToInt32(Bill.Biz.SqlHelper.ExecuteScalar(sql,conn));
ViewState["itemCount"] = count;
}
return Bill.Biz.Util.ToIntSafe(ViewState["itemCount"],0);
}
private void ReadRecords()
...{
PageSize =Convert.ToInt32(this.ddrPageNum.SelectedItem.Text);
if(ViewState["page"] == null || Convert.ToInt32(ViewState["page"]) < 1 )
...{
ViewState["page"] = 1;
}
else if(Convert.ToInt32(ViewState["page"]) > totalPage)
...{
ViewState["page"] = totalPage;
}
page = Convert.ToInt32(ViewState["page"]);
tbxPage.Text = page.ToString();
lblPageInfo.Text ="共"+ itemCount.ToString() + "项 " + page.ToString()+"/"+totalPage.ToString()+"页";
btnNextPage.Enabled = true;
btnLastPage.Enabled = true;
btnFirstPage.Enabled = true;
btnPriPage.Enabled = true;
if (itemCount<=PageSize || page * PageSize >= itemCount)
...{
btnNextPage.Enabled = false;
btnLastPage.Enabled = false;
}
if(page == 1)
...{
btnFirstPage.Enabled = false;
btnPriPage.Enabled = false;
}
string sqlStr;
sqlStr = string.Format(@"select top {0} * from outstorage where outstorage_id<=(select min(aa.outstorage_id) from (select top {1} outstorage_id from outstorage where {2} order by outstorage_id desc) aa) and {2} order by outstorage_id desc",PageSize,PageSize*page-PageSize+1,condition);
DataTable dt =Bill.Biz.SqlHelper.ExecuteDataset(sqlStr,conn).Tables[0];
dt.Columns.Add("newproduct_title");
dt.Columns.Add("newproduct_in");
dt.Columns.Add("newproduct_out");
foreach(DataRow dr in dt.Rows)
...{
if(dr["outstorage_name"].ToString().Length >= 24)
...{
dr["newproduct_title"] ="<a href='add_store.aspx?store_id="+dr["outstorage_id"].ToString()+"' title='"+dr["outstorage_name"].ToString()+"' >"+dr["outstorage_name"].ToString().Substring(0,23)+"</a>";
}
else
...{
dr["newproduct_title"] ="<a href='add_store.aspx?store_id="+dr["outstorage_id"].ToString()+"' title='"+dr["outstorage_name"].ToString()+"' >"+dr["outstorage_name"].ToString()+"</a>";
}
}
this.Datagrid1.DataSource = dt;
this.Datagrid1.DataBind();
}
public void Datagrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
//string key =((TextBox)e.Item.FindControl("product_id")).Text;
string key =this.Datagrid1.DataKeys[e.Item.ItemIndex].ToString();
string outstorageclass = ((TextBox)e.Item.FindControl("outstorage_class")).Text;
string outstoragenum = ((TextBox)e.Item.FindControl("outstorage_num")).Text;
string outstoragebeizhu = ((TextBox)e.Item.FindControl("outstorage_beizhu")).Text;
string sql="";
sql=string.Format("update outstorage set outstorage_class ='{0}',outstorage_num='{1}',outstorage_beizhu='{2}' where outstorage_id='{3}'",outstorageclass,outstoragenum,outstoragebeizhu,key);
SqlConnection constr = new SqlConnection(conn);
SqlCommand myCommand = new SqlCommand(sql,constr);
myCommand.Connection.Open();
if(this.userid.ToString() =="1" || this.userid.ToString()=="2")
...{
try
...{
myCommand.ExecuteNonQuery();
}
catch(SqlException)
...{
}
myCommand.Connection.Close();
this.Datagrid1.EditItemIndex = -1;
ReadRecords();
}
else
...{
Response.Write("<script language=javascript>alert('出错啦!请联系系统管理员','','')</script>");
}
}
public void Datagrid1_Delete(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
}
public void Datagrid1_Cancel(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
...{
this.Datagrid1.EditItemIndex=-1;
ReadRecords();
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
...{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
...{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
public class outstorage : System.Web.UI.Page
函数名称要和html页面的名称相同,否则会引起应用服务器错误!!!
- 一个应该注意的问题
- thcomm调用应该注意的一个问题
- Java开发向导页时应该注意的一个问题
- windows server 2012 VDI部署应该注意的一个问题
- 离职应该注意的问题
- 女生应该注意的问题
- 做外链应该注意的问题
- strcpy应该注意的问题
- 嵌入式应该注意的问题
- 一些应该注意的问题
- 作为一个程序员应该注意的地方
- 重写equals应该注意的一个细节
- Java的编程应该注意的问题
- 如果一个类内有指针引用的成员时应该注意的问题
- mysql 的表名和列名设计时应该注意的一个问题
- 使用静态数组应该注意的问题
- Java Thread应该注意的问题
- JAVA编程中应该注意的问题
- SQL注入天书—ASP注入漏洞全接触
- null
- 用MRTG监测Linux系统网络、CPU、内存和硬盘情况
- 第1章 一种新的Web设计方法
- 人力资源的真正职责是什么?
- 一个应该注意的问题
- 应用JAVASCRIPT 之 简易网页音乐播放程序
- oracle函数
- [Web开发] 微软的RSS协议扩展 - FeedSync 介绍 (3)
- 穷人创业的三个投资秘方
- 2008 Scripting Games
- [Web开发] 微软的RSS协议扩展 - FeedSync 介绍 (4)
- 如何评估项目工作量
- QQ机器人:世界上最小的叨客撒