📄 editlistinfo.aspx.cs
字号:
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 eInfo.data;
using eInfo.common;
namespace eInfo.sys
{
/// <summary>
/// EditListInfo 的摘要说明。
/// </summary>
public partial class EditListInfo : System.Web.UI.Page
{
string GetDSquery;
protected void Page_Load(object sender, System.EventArgs e)
{
try
{
string strType=Request.Params["Type"];
string strName=Request.Params["Name"];
string strByear=Request.Params["byear"];
string strBmonth=Request.Params["bmonth"];
string strBday=Request.Params["bday"];
string strEyear=Request.Params["eyear"];
string strEmonth=Request.Params["emonth"];
string strEday=Request.Params["eday"];
string filterQuery="",BeginDT,EndDT;
string flag="0000";
string[] filter=new string[4];
string strSearch="";
filter[0]="b.id="+strType+" ";
//获取类型名
DB mDB=new DB();
DataTable dt=mDB.GetInfoTypeInfo(strType);
string strTypeName;
if(dt==null)
{
strTypeName="";
}
else
{
strTypeName=dt.Rows[0][1].ToString();
flag=StringUtil.Set(flag,0);
}
strSearch=strSearch+"类型:"+strTypeName+";";
if((strName!="")&&(strName!=null))
{
filter[1]=" a.name like '%"+strName+"%' ";
strSearch=strSearch+"文档名称:"+strName+";";
flag=StringUtil.Set(flag,1);
}
if((strByear!="")&&(strByear!=null))
{
BeginDT=strByear+"-"+strBmonth+"-"+strBday;
filter[2]=" a.filedate > '"+BeginDT+"' ";
flag=StringUtil.Set(flag,2);
strSearch=strSearch+"开始时间:"+BeginDT+";";
}
if((strEyear!="")&&(strEyear!=null))
{
EndDT=strEyear+"-"+strEmonth+"-"+strEday;
filter[3]=" a.filedate < '"+EndDT+"' ";
flag=StringUtil.Set(flag,3);
strSearch=strSearch+"结束时间:"+EndDT+";";
}
lblSearch.Text=strSearch;
if(flag!="0000")
{
filterQuery=" where ";
for(int i=0;i<4;i++)
{
if(flag[i].ToString()=="1")
filterQuery=filterQuery+filter[i]+" and ";
}
//去除最后一个and;
//filterQuery=filterQuery.Substring(0,filterQuery.Length-5);
}
else
{
filterQuery=" where ";
}
GetDSquery="select a.id,a.name ,a.des,a.filesize,dbo.return_ny(a.filedate) as filedate ,b.name as type from info a,infotype b"+
filterQuery+" b.id=a.type order by a.filedate desc";
if (!(this.IsPostBack))
{
try
{
ViewState["Sort"]="";
ViewState["Page"]="0";
GridBind();
}
catch (Exception er)
{
String scriptString = "<script language=JavaScript> ";
scriptString += "alert('"+er.Message+"')</script>";
this.RegisterStartupScript("Script", scriptString);
}
}
}
catch (Exception er)
{
String scriptString = "<script language=JavaScript> ";
scriptString += "alert('"+er.Message+"')</script>";
this.RegisterStartupScript("Script", scriptString);
}
}
private void GridBind()
{
DataView MyDv;
DB myDB=new DB();
MyDv=myDB.SearchDV(GetDSquery);
if(!object.Equals(ViewState["Sort"],null))
MyDv.Sort =ViewState["Sort"].ToString() ;
MyDataGrid.DataSource=MyDv;
if(!object.Equals(ViewState["Page"],null))
MyDataGrid.CurrentPageIndex =int.Parse(ViewState["Page"].ToString()) ;
try
{
MyDataGrid.DataBind();
}
catch
{
MyDataGrid.CurrentPageIndex =MyDataGrid.PageCount -1;
MyDataGrid.DataBind ();
}
}
private void MyDataGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string Id=e.Item.Cells[0].Text.Trim();
DB admin=new DB();
if(admin.DelInfo(Id))
{
GridBind();
}
else
{
String scriptString = "<script language=JavaScript> ";
scriptString += "alert('删除失败!')</script>";
this.RegisterStartupScript("Script", scriptString);
}
}
private void MyDataGrid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
if (ViewState["Sort"].ToString()==e.SortExpression)
ViewState["Sort"]=e.SortExpression + " desc";
else
ViewState["Sort"]=e.SortExpression ;
GridBind();
}
private void MyDataGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
ViewState["Page"]=e.NewPageIndex.ToString();
GridBind();
}
private void MyDataGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string Id=e.Item.Cells[0].Text.Trim();
string Name=e.Item.Cells[2].Text.Trim();
string FileDate=e.Item.Cells[5].Text.Trim();
string type=e.Item.Cells[1].Text.Trim();
string url="EditInfo.aspx?type="+type+"&Name="+Name+"&fileDate="+FileDate+"&id="+Id;
Response.Redirect(url);
}
private void MyDataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
System.Web.UI.WebControls.Image TempImg;
TempImg=(System.Web.UI.WebControls.Image)e.Item.FindControl("ib_delete") ;
if(object.Equals(TempImg,null)==false)
{
TempImg.Attributes.Add("onClick","return confirm('确实要删除当前行记录吗?')");
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.MyDataGrid.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.MyDataGrid_ItemCreated);
this.MyDataGrid.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.MyDataGrid_PageIndexChanged);
this.MyDataGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.MyDataGrid_SortCommand);
this.MyDataGrid.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.MyDataGrid_UpdateCommand);
this.MyDataGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.MyDataGrid_DeleteCommand);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -