一个应该注意的问题

来源:互联网 发布:找不到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() + "项 &nbsp;" + 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 窗体设计器生成的代码
    }

 public class outstorage : System.Web.UI.Page

函数名称要和html页面的名称相同,否则会引起应用服务器错误!!!

原创粉丝点击