一个应该注意的问题

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页面的名称相同,否则会引起应用服务器错误!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值