DATALIST正反向排序,带▲和▼提示的【转二】

public class Mainlist : System.Web.UI.Page
{
   protected System.Web.UI.WebControls.HyperLink HyperLink1;
   protected System.Data.SqlClient.SqlConnection sqlConnection2;
   protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter2;
   protected System.Web.UI.WebControls.Label LblManagers,pono,vendor;
   protected System.Web.UI.WebControls.Label lblRecordCount;
   protected System.Web.UI.WebControls.Label lblCurrentPage;
   protected System.Web.UI.WebControls.Label lblPageCount;
   protected System.Web.UI.WebControls.Panel Panel1;
   protected System.Web.UI.WebControls.TextBox TextBox1;
   protected System.Web.UI.WebControls.HyperLink lnkPrev;
   protected System.Web.UI.WebControls.HyperLink lnkNext;
   protected System.Web.UI.WebControls.Label LblB;
   protected System.Web.UI.WebControls.Label Label1;
   protected System.Web.UI.WebControls.DropDownList DropDownList1;
   protected System.Web.UI.WebControls.DataList DL_Main;
   int PageSize,CurrentPage,PageCount;
        public string navigation;
   public TextBox    txtIndex;
   public DataRow dr,dr1;
   public int a,d;
   string SortField;
        protected System.Web.UI.WebControls.LinkButton LinkButton1,LinkButton2,LinkButton3,LinkButton4,LinkButton5;
   protected System.Web.UI.WebControls.Button Button1,Button2,Button3,Button4,Button5,Button6,Button7,Button8,Button9;

   protected System.Web.UI.HtmlControls.HtmlInputRadioButton RadSelected; 
   protected System.Web.UI.HtmlControls.HtmlInputHidden rd;

   public static string add1(string s,string ss,string s1)
   {
                               string str="" ;
                               if (s1!=""&&s1!=null)
                               {
     str=" and "+s+ss+"'"+s1+"' ";
                               }
                              return str;
   }
   public static string add2(string s,string s1,string s2)
   {
                               string str="" ;
                               if (s1!=""&&s1!=null){
                                if(s2!=""&&s2!=null)
                               {
     str=" and "+s+">='"+s1+"' and "+s+"<='"+s2+"' ";
                               }
                                else
                               {
     str=" and "+s+"='"+s1+"' ";
                               }
                              }
                              return str;
   }  
   public void BindGrid(string str) 
   {

     //if(!Page.IsPostBack)
     //{
     int BID,SID;
     if ((Request.QueryString["BID"]==null)||(Request.QueryString["SID"]==null))
     {
      BID=1;
      SID=200;
     }
     else
     {
      BID=System.Convert.ToInt32(Request.QueryString["BID"]);
      SID=System.Convert.ToInt32(Request.QueryString["SID"]);
     }
                PageSize=System.Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["MainList"]);
     CurrentPage = 0; 
     //计算总共有多少记录
                               string str1,str2,str3;

if( Session["status1"]==null && Request.QueryString["status1"]!=null)
{
string status1=Request.QueryString["status1"];
Session["status1"]=status1;

else if(Request.QueryString["status1"]!=null)
{
string status1=Request.QueryString["status1"];
Session["status1"]=status1;
}

if ((Session["status1"]!="" && Session["status1"]!=null && Session["upower"].ToString()=="3") || ( Session["status1"]!="" && Session["status1"]!=null && Session["upower"].ToString()=="4") || ( Session["status1"]!="" && Session["status1"]!=null && Session["upower"].ToString()=="1"))
{

str1="SELECT COUNT(*) as co from pur where P_ID<>'' and status3='1' and depno='"+Session["section"]+"' ";
str2="select * from pur where P_ID<>'' and status3='1' and depno='"+Session["section"]+"' "; 
str3="select pono as 采購單號,vendor as 供應商,part as 料號,specification as 料品名稱規格,unit as 單位,qty as 數量,recqty as 驗收總數,unprc as 單价,left(convert(varchar(10),precdate,120),10) as 交貨日期,orderno as 訂單號碼,left(convert(varchar(10),indate,120),10) as 下單日期,left(convert(varchar(10),signdate,120),10) as 簽回日期,(case status when 0 then '新單' when 1 then '再協商' when 2 then '已簽回' when 3 then '已驗貨' when 4 then '已收貨' when 5 then '已結案' when 6 then '已作廢' end) as 狀態 from pur where P_ID<>'' and status3='1' and depno='"+Session["section"]+"' "; 
        
     DateTime t=DateTime.Now;
                DateTime tnow= t.AddDays(-1);
     DateTime tttnow= t.AddDays(+2);
string ttnow=t.Year.ToString()+"-"+t.Month.ToString()+"-"+t.Day.ToString();
string bnow=tnow.Year.ToString()+"-"+tnow.Month.ToString()+"-"+tnow.Day.ToString();
string ttttnow=tttnow.Year.ToString()+"-"+tttnow.Month.ToString()+"-"+tttnow.Day.ToString();

                               //Session["status"]=Request.QueryString["status"];

                               if ((string)Session["status1"]=="0")
                                {
                     str1+=" and status='"+Session["status1"]+"' ";
                     str2+=" and status='"+Session["status1"]+"' ";
      str3+=" and status='"+Session["status1"]+"' ";
         }
                               else if ((string)Session["status1"]=="6")
                                {
                     str1+=" and status='"+Session["status1"]+"' and cancletime >='"+ bnow+"' ";
                     str2+=" and status='"+Session["status1"]+"' and cancletime >='"+ bnow+"' ";
      str3+=" and status='"+Session["status1"]+"' and cancletime >='"+ bnow+"' ";
         }
                               else if ((string)Session["status1"]=="2")
                                {
                     str1+=" and status='"+Session["status1"]+"' and signdate >= '"+ bnow +"' ";
                     str2+=" and status='"+Session["status1"]+"' and signdate >= '"+ bnow +"' ";
      str3+=" and status='"+Session["status1"]+"' and signdate >= '"+ bnow +"' ";
                                }
          else if ((string)Session["status1"]=="1")
                                {
                     str1+=" and status='"+Session["status1"]+"' ";
                     str2+=" and status='"+Session["status1"]+"' ";
      str3+=" and status='"+Session["status1"]+"' ";
                                }
          else if ((string)Session["status1"]=="22")
                                {
                     str1+=" and status='2' and precdate <= '"+ ttttnow +"' ";
                     str2+=" and status='2' and precdate <= '"+ ttttnow +"' ";
      str3+=" and status='2' and precdate <= '"+ ttttnow +"' ";
                                }
if(str!="") //这里是正反向排序
{
if(Session["flag"]=="")
    {
   Session["flag"]="false";

if (Session["flag"]=="false") //不能用ViewState,只能用Session
{
str2=str2+ " order by "+str+" desc ";
str3=str3+ " order by "+str+" desc ";
   Session["flag"]="true";
}
else 
{
str2=str2+ " order by "+str+" asc ";
str3=str3+ " order by "+str+" asc ";
   Session["flag"]="false";
}
}

else
{
str2+= " order by indate desc,pono desc " ;
str3+= " order by indate desc,pono desc " ;
}
                              Session["str1"]=str1;
                              Session["str2"]=str2;
         Session["str3"]=str3;
}

else if ((Session["status1"]!="" && Session["status1"]!=null && Session["upower"].ToString()!="3") || ( Session["status1"]!="" && Session["status1"]!=null && Session["upower"].ToString()!="4") || ( Session["status1"]!="" && Session["status1"]!=null && Session["upower"].ToString()!="1"))
{

str1="SELECT COUNT(*) as co from pur where P_ID<>'' and status3='1' ";
str2="select * from pur where P_ID<>'' and status3='1' "; 
str3="select pono as 采購單號,vendor as 供應商,part as 料號,specification as 料品名稱規格,unit as 單位,qty as 數量,recqty as 驗收總數,unprc as 單价,left(convert(varchar(10),precdate,120),10) as 交貨日期,orderno as 訂單號碼,left(convert(varchar(10),indate,120),10) as 下單日期,left(convert(varchar(10),signdate,120),10) as 簽回日期,(case status when 0 then '新單' when 1 then '再協商' when 2 then '已簽回' when 3 then '已驗貨' when 4 then '已收貨' when 5 then '已結案' when 6 then '已作廢' end) as 狀態 from pur where P_ID<>'' and status3='1' "; 
        
     DateTime t=DateTime.Now;
                DateTime tnow= t.AddDays(-1);
     DateTime tttnow= t.AddDays(+2);
string ttnow=t.Year.ToString()+"-"+t.Month.ToString()+"-"+t.Day.ToString();
string bnow=tnow.Year.ToString()+"-"+tnow.Month.ToString()+"-"+tnow.Day.ToString();
string ttttnow=tttnow.Year.ToString()+"-"+tttnow.Month.ToString()+"-"+tttnow.Day.ToString();

                               if ((string)Session["status1"]=="0")
                                {
                     str1+=" and status='"+Session["status1"]+"' ";
                     str2+=" and status='"+Session["status1"]+"' ";
      str3+=" and status='"+Session["status1"]+"' ";
         }
                               else if ((string)Session["status1"]=="6")
                                {
                     str1+=" and status='"+Session["status1"]+"' and cancletime >='"+ bnow+"' ";
                     str2+=" and status='"+Session["status1"]+"' and cancletime >='"+ bnow+"' ";
      str3+=" and status='"+Session["status1"]+"' and cancletime >='"+ bnow+"' ";
         }
                               else if ((string)Session["status1"]=="2")
                                {
                     str1+=" and status='"+Session["status1"]+"' and signdate >= '"+ bnow +"' ";
                     str2+=" and status='"+Session["status1"]+"' and signdate >= '"+ bnow +"' ";
      str3+=" and status='"+Session["status1"]+"' and signdate >= '"+ bnow +"' ";
                                }
          else if ((string)Session["status1"]=="1")
                                {
                     str1+=" and status='"+Session["status1"]+"' ";
                     str2+=" and status='"+Session["status1"]+"' ";
      str3+=" and status='"+Session["status1"]+"' ";
                                }
          else if ((string)Session["status1"]=="22")
                                {
                     str1+=" and status='2' and precdate <= '"+ ttttnow +"' ";
                     str2+=" and status='2' and precdate <= '"+ ttttnow +"' ";
      str3+=" and status='2' and precdate <= '"+ ttttnow +"' ";
                                }
if(str!="" && str=="pono") //这里是正反向排序
{
if(Session["flag"]=="")
    {
   Session["flag"]="false";

if (Session["flag"]=="false" && str=="pono") //不能用ViewState,只能用Session
{
str2=str2+ " order by "+str+" desc ";
str3=str3+ " order by "+str+" desc ";
pono.Text = "▲";
   Session["flag"]="true";
}
else 
{
str2=str2+ " order by "+str+" asc ";
str3=str3+ " order by "+str+" asc ";
pono.Text = "▼";
   Session["flag"]="false";
}
}

else if(str!="" && str=="vendor") //这里是正反向排序
{
if(Session["flag"]=="")
    {
   Session["flag"]="false";

if (Session["flag"]=="false" && str=="vendor") //不能用ViewState,只能用Session
{
str2=str2+ " order by "+str+" desc ";
str3=str3+ " order by "+str+" desc ";
vendor.Text = "▲";
   Session["flag"]="true";
}
else 
{
str2=str2+ " order by "+str+" asc ";
str3=str3+ " order by "+str+" asc ";
vendor.Text = "▼";
   Session["flag"]="false";
}
}

else
{
str2+= " order by indate desc,pono desc " ;
str3+= " order by indate desc,pono desc " ;
}
                              Session["str1"]=str1;
                              Session["str2"]=str2;
         Session["str3"]=str3;
}
else
{
str1=Session["str1"].ToString();
str2=Session["str2"].ToString();
str3=Session["str3"].ToString();
}
                                         
     int RecordCount = DBOperate.CalculateQRecord(BID, SID,str1);
     lblRecordCount.Text = RecordCount.ToString();
     //计算总共有多少页
     PageCount = (RecordCount+PageSize-1)/PageSize;
     if (PageCount<=0)
      PageCount=1;
     lblPageCount.Text = PageCount.ToString();
     //获取页面参数
     if (Request.QueryString["Page"] != null)
      CurrentPage=Convert.ToInt32(Request.QueryString["Page"]);
     else
      CurrentPage=1;
     if (PageCount<CurrentPage)
      CurrentPage=PageCount;
     if (CurrentPage<=0)
      CurrentPage=1;

     //ListBind();
     //设定导入的起终地址
     int StartIndex = (CurrentPage-1)*PageSize;
                   string tablestr="pur";
     //this.DL_Main.DataSource= DBOperate.SelectFormForum(sqlstr,StartIndex,PageSize,tablestr);
                           DataTable dt=DBOperate.SelectFormForum(str2,StartIndex,PageSize,tablestr);
                           this.DL_Main.DataSource=dt;
     this.Page.DataBind();
     lnkNext.Enabled = true;
     lnkPrev.Enabled = true;
     if(CurrentPage==(PageCount))
     {
      lnkNext.Enabled = false;
     }
     else
      lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?BID="+ BID.ToString()+"&SID="+ SID.ToString()+"&Page="+Convert.ToString(CurrentPage+1);
     if(CurrentPage==1)
      lnkPrev.Enabled = false;
     else
      lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?BID="+ BID.ToString()+"&SID="+ SID.ToString()+"&Page="+Convert.ToString(CurrentPage-1);
     lblCurrentPage.Text = CurrentPage.ToString();
     //}
   } 
  
   public void SubmitBtn_Click5(object sender, System.EventArgs e) 
   {       
    Response.Redirect( "remark.aspx?Page="+TextBox1.Text);
   }

   private void Page_Load(object sender, System.EventArgs e)
   {

            if (!this.IsPostBack)
    {
     BindGrid("");
    }
  
   }

   override protected void OnInit(EventArgs e)
   {
    InitializeComponent();
    base.OnInit(e);
        }

   private void InitializeComponent()
   { 
      this.Button1.Click += new System.EventHandler(this.Button1_Click);
        this.Button2.Click += new System.EventHandler(this.Button2_Click);
            this.Button3.Click += new System.EventHandler(this.Button3_Click);
        this.Button4.Click += new System.EventHandler(this.Button4_Click);
            this.Button6.Click += new System.EventHandler(this.Button6_Click);
        this.Button7.Click += new System.EventHandler(this.Button7_Click);
      this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click); 
      this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
      this.LinkButton3.Click += new System.EventHandler(this.LinkButton3_Click);
      this.LinkButton4.Click += new System.EventHandler(this.LinkButton4_Click);
      this.LinkButton5.Click += new System.EventHandler(this.LinkButton5_Click);
      this.Load += new System.EventHandler(this.Page_Load); 
    this.DL_Main.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.DL_Main_ItemDataBound);
    }

        private void DL_Main_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {  
   }

     private void LinkButton1_Click(object sender, System.EventArgs e)
   {
    BindGrid("pono");
   }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值