<%@ Page language="c#" src="remark.aspx.cs" AutoEventWireup="false" Inherits="src.Mainlist" %>
<HTML>
<HEAD> </HEAD>
<body leftMargin="0" topMargin="0" rightMargin="0" width="190%">
<form id="Form1" method="post" runat="server">
<table width="190%" border="0" cellpadding="0" cellspacing="1" >
<tr>
<td bgcolor="#ffffff">
<table width="100%" height="16" border="0" cellpadding="1" cellspacing="0" >
<tr style="color:#FFFFFF;background-color:#718BD6;">
<td align="center" width="80"><asp:LinkButton id="LinkButton1" runat="server">采購單號</asp:LinkButton><asp:label id="pono" runat="server" ForeColor="Blue"></asp:label></td>
<td align="center" width="50"><asp:LinkButton id="LinkButton2" runat="server">供應商</asp:LinkButton><asp:label id="vendor" runat="server" ForeColor="Blue"></asp:label></td>
</tr>
</table>
<asp:datalist id="DL_Main" runat="server" OnSortCommand="MyDataGrid_Sort" AllowSorting="true" Width="100%">
<AlternatingItemStyle BackColor="#ececec"></AlternatingItemStyle>
<HeaderTemplate>
</HeaderTemplate> <ItemTemplate>
<table style="TABLE-LAYOUT: fixed; WORD-BREAK: break-all" bordercolor="#ffffff" height="22"
cellspacing="1" cellpadding="1" width="100%">
<tr>
<td width="80" align="center">
<input size="9" value="<%# DataBinder.Eval(Container.DataItem, "pono")%>" readonly="true" tabindex="2" style="text-align=center;border:1px solid # 999999">
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>
<table height="10" cellSpacing="2" cellPadding="0" width="100%" bgColor="#718BD6" border="0">
<tr>
<td align="center" width="80"><a href="datagrid2.aspx">轉到EXCEL</a></td>
<td align="center" width="60"><asp:Button id="Button1" Visible='<%# Session["UPower"].ToString()=="1"%>' runat="server" Text="發送" Height="24px"></asp:Button><asp:Button id="Button2" runat="server" Width="0px" ></asp:Button></td>
<td align="center" width="100">所有發送<input type="checkbox" name="chkall" value="on" onclick="CheckAll(this.form)" title='選中/取消 所有'></td>
<td align="left">共有
<asp:label id="lblRecordCount" runat="server" ForeColor="red"></asp:label>條記錄 當前為
<asp:label id="lblCurrentPage" runat="server" ForeColor="red"></asp:label>/
<asp:label id="lblPageCount" runat="server" ForeColor="red"></asp:label>頁
<asp:HyperLink id="lnkPrev" runat="server">上一頁</asp:HyperLink>
<asp:HyperLink id="lnkNext" runat="server">下一頁</asp:HyperLink>轉到第
<asp:textbox id="TextBox1" runat="server" Width="25px">1</asp:textbox>頁
<asp:button id="Button5" OnClick="SubmitBtn_Click5" runat="server" Width="20px" Text="轉"></asp:button>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</HTML>
------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Configuration;
namespace src
{
/// <summary>
/// Mainlist 的摘要说明。
/// </summary>
public class DBOperate
{
public DBOperate()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//输入SELECT语句,获得返回数据集
public static DataTable SelectFormForum(string sql,int start,int size,string tablename)
{
try
{
SqlConnection sqlConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["data"]);
SqlDataAdapter sqlAdapter1 = new SqlDataAdapter(sql, sqlConnection);
DataSet returns = new DataSet();
sqlAdapter1.Fill(returns,start,size,tablename);
string status;
for(int i=0;i<returns.Tables[0].Rows.Count;i++)
{
status=returns.Tables[0].Rows[i]["status"].ToString().Trim();
if (status=="2")
{
returns.Tables[0].Rows[i]["status"]="已簽回";
}
if (status=="1")
{
returns.Tables[0].Rows[i]["status"]="再協商";
}
if (status=="0")
{
returns.Tables[0].Rows[i]["status"]="新單";
}
if (status=="3")
{
returns.Tables[0].Rows[i]["status"]="已驗貨";
}
if (status=="4")
{
returns.Tables[0].Rows[i]["status"]="已收貨";
}
if (status=="5")
{
returns.Tables[0].Rows[i]["status"]="已結案";
}
if (status=="6")
{
returns.Tables[0].Rows[i]["status"]="已作廢";
}
}
string status3;
for(int i=0;i<returns.Tables[0].Rows.Count;i++)
{
status3=returns.Tables[0].Rows[i]["status3"].ToString().Trim();
if (status3=="0")
{
returns.Tables[0].Rows[i]["status3"]="未發送";
}
if (status3=="1")
{
returns.Tables[0].Rows[i]["status3"]="OK";
//returns.Tables[0].Rows[i]["part"]="-->"+returns.Tables[0].Rows[i]["part"];
}
}
return returns.Tables[0];
}
catch (Exception ex)
{
throw (ex);
}
}
public static DataTable SelectFormForum1(string sql)
{
try
{
SqlConnection sqlConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["data"]);
SqlDataAdapter sqlAdapter1 = new SqlDataAdapter(sql, sqlConnection);
DataSet returns = new DataSet();
sqlAdapter1.Fill(returns);
return returns.Tables[0];
}
catch (Exception ex)
{
throw (ex);
}
}
//返回一条记录
public static DataRow GetDataRow(string sql,string TableName)
{
try
{
SqlConnection sqlConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["data"]);
SqlDataAdapter sqlAdapter1 = new SqlDataAdapter(sql, sqlConnection);
DataSet product = new DataSet();
sqlAdapter1.Fill(product, TableName);
return product.Tables[0].Rows[0];
}
catch (Exception ex)
{
throw (ex);
}
}
//执行SQL语句,如UPDATE,INSERT等
public static void ExcSQL(string s)
{
SqlConnection sqlConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["data"]);
SqlCommand sqlCmd =new SqlCommand(s,sqlConnection);
sqlConnection.Open();
try
{
sqlCmd.ExecuteNonQuery();
}
catch(Exception ex)
{
throw (ex);
}
sqlConnection.Close();
}
//计算总共有多少条问题
public static int CalculateQRecord(int BID,int SID,string s)
{
try
{ //string purid=Request.QueryString["purid"];
DataRow dr=GetDataRow(s,"pur");
return System.Convert.ToInt32(dr["co"].ToString());
}
catch
{
return 0;
}
}
}
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");
}
}
}