FileSearch.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:14k
- 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 qminoa.Common;
- using qminoa.DA;
- namespace qminoa.Webs.FM
- {
- public class FileSearch : qminoa.Webs.PageBase
- {
- protected System.Web.UI.WebControls.Label lblID;
- protected System.Web.UI.WebControls.Label lblFID;
- protected System.Web.UI.WebControls.Label lblBID;
- protected string column;
- protected System.Web.UI.WebControls.Label lblErr;
- protected System.Web.UI.WebControls.Label lblObjNum;
- protected System.Web.UI.WebControls.DataGrid dgdFolder;
- protected System.Web.UI.WebControls.DropDownList dropType;
- protected System.Web.UI.WebControls.CheckBox chkType;
- protected System.Web.UI.WebControls.DropDownList dropDate;
- protected System.Web.UI.WebControls.Label Label11;
- protected System.Web.UI.WebControls.RadioButton rdoBetween;
- protected System.Web.UI.WebControls.TextBox txtDay;
- protected System.Web.UI.WebControls.TextBox txtMonth;
- protected System.Web.UI.WebControls.TextBox txtMinDate;
- protected System.Web.UI.WebControls.TextBox txtMaxDate;
- protected System.Web.UI.WebControls.RadioButton rdoDay;
- protected System.Web.UI.WebControls.Label lblMaxDate;
- protected System.Web.UI.WebControls.Label Label12;
- protected System.Web.UI.WebControls.RadioButton rdoMonth;
- protected System.Web.UI.WebControls.CheckBox chkDate;
- protected System.Web.UI.WebControls.Label Label5;
- protected System.Web.UI.WebControls.TextBox txtContent;
- protected System.Web.UI.WebControls.Label Label3;
- protected System.Web.UI.WebControls.Label Label4;
- protected System.Web.UI.WebControls.TextBox txtOwner;
- protected System.Web.UI.WebControls.LinkButton cmdOption;
- protected System.Web.UI.WebControls.ImageButton cmdExit;
- protected System.Web.UI.WebControls.Label Label2;
- protected System.Web.UI.WebControls.ImageButton imgSearch;
- protected System.Web.UI.WebControls.TextBox txtFileFolder;
- protected System.Web.UI.WebControls.TextBox txtKeyword;
- protected System.Web.UI.WebControls.Label Label1;
- protected System.Web.UI.WebControls.ImageButton cmdCloseSeach;
- protected System.Web.UI.WebControls.ImageButton cmdClose;
- protected System.Web.UI.WebControls.Image Image1;
- protected System.Web.UI.HtmlControls.HtmlGenericControl div1;
- protected System.Web.UI.HtmlControls.HtmlGenericControl divDate;
- protected System.Web.UI.HtmlControls.HtmlGenericControl divType;
- protected string key;
-
- private void Page_Load(object sender, System.EventArgs e)
- {
- if(!this.IsPostBack)
- {
- this.PageBegin("项目管理",true);
- FillAllTypes();
- }
-
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.imgSearch.Click += new System.Web.UI.ImageClickEventHandler(this.imgSearch_Click);
- this.cmdOption.Click += new System.EventHandler(this.cmdOption_Click);
- this.chkDate.CheckedChanged += new System.EventHandler(this.chkDate_CheckedChanged);
- this.rdoMonth.CheckedChanged += new System.EventHandler(this.rdoMonth_CheckedChanged);
- this.rdoDay.CheckedChanged += new System.EventHandler(this.rdoDay_CheckedChanged);
- this.rdoBetween.CheckedChanged += new System.EventHandler(this.rdoBetween_CheckedChanged);
- this.chkType.CheckedChanged += new System.EventHandler(this.chkType_CheckedChanged);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void imgSearch_Click(object sender, System.Web.UI.ImageClickEventArgs e)
- {
- DataView dv;
- DataView dvresult;
- if(chkDate.Checked==true||chkType.Checked==true)
- {
- if(chkDate.Checked==false)
- {
- dv = GetAllDoc();
- dvresult=TypeSearch(dv);
- }
- else if(chkType.Checked==false)
- {
- dv=Search_Date();
- dvresult=BindTable(dv).DefaultView;
- }
- else
- {
- dv=Search_Date();
- dvresult=TypeSearch(dv);
- }
- }
- else
- {
- dvresult=SearchWithOutCondition();
- if(dvresult.Count==0)
- {
- Response.Write("<script language='javascript'>alert('没有搜索到!');</script>");
- }
- }
- dgdFolder.DataSource=dvresult;
- dgdFolder.DataBind();
- }
- public DataView SearchWithOutCondition()
- {
- string foldername=txtFileFolder.Text.ToString();
- string keyword=txtKeyword.Text.ToString();
- string Content=txtContent.Text.ToString();
- string Owner=txtOwner.Text.ToString();
- if(txtFileFolder.Text==string.Empty)
- {
- foldername="%";
- }
- if(txtContent.Text==string.Empty)
- {
- Content="%";
- }
- if(txtKeyword.Text==string.Empty)
- {
- keyword="%";
- }
- if(txtOwner.Text==string.Empty)
- {
- Owner="%";
- }
- FileData data= (new FileA()).SearchForDoc(foldername,keyword,Content,Owner);
- DataView dv=data.Tables[FileData.FMDOCFOLDER_TABLE].DefaultView;
- DataView dvdata=BindTable(dv).DefaultView;
- return dvdata;
- }
- private void BindTodgd(DataView dv)
- {
- DataView dvdata=BindTable(dv).DefaultView;
- dgdFolder.DataSource=dvdata;
- dgdFolder.DataBind();
- }
- public DataView DateSearch(int opt,string SearchType)
- {
- FileData filedata =(new FileA()).LoadDocFolder(0);
- DataView dv=filedata.Tables[FileData.FMDOCFOLDER_TABLE].DefaultView;
-
- TimeSpan timespan;
- DateTime date;
- if(SearchType=="创建的文件")
- {
- switch(opt)
- {
- case 1:
- int day=Convert.ToInt32(txtDay.Text,10);
- try
- {
- timespan = new TimeSpan(day,0,0,0);
- date=DateTime.Now.Subtract(timespan);
- dv.RowFilter="CDate >='"+date+"'";
- }
- catch
- {
- Response.Write("<script language='javascript'>alert('不支持如此大的数字!');</script>");
- }
- break;
- case 2:
- int month=Convert.ToInt32(txtMonth.Text,10);
- try
- {
- timespan = new TimeSpan(30*month,0,0,0);
- date=DateTime.Now.Subtract(timespan);
- dv.RowFilter="CDate >='"+date+"'";
- }
- catch
- {
- Response.Write("<script language='javascript'>alert('不支持如此大的数字!');</script>");
- }
- break;
- case 3:
- if(txtMaxDate.Text==string.Empty||txtMinDate.Text==string.Empty)
- {
- Response.Write("<script language='javascript'>alert('日期没有填写完全!');</script>");
- dv.RowFilter="CDate>'"+DateTime.Today+"'";
- }
- else
- {
- try
- {
- DateTime Max=Convert.ToDateTime(txtMaxDate.Text);
- DateTime Min=Convert.ToDateTime(txtMinDate.Text);
- dv.RowFilter="CDate <= '"+Max+"' and CDate>='"+Min+"'";
- }
- catch
- {
- Response.Write("<script language='javascript'>alert('日期请写成####-##-##年月日的格式!');</script>");
- dv.RowFilter="CDate>'"+DateTime.Today+"'";
- }
- }
- break;
- }
- return dv;
- }
- else
- {
- DataTable dt=null;
- switch(opt)
- {
- case 1:
- int day=Convert.ToInt32(txtDay.Text,10);
- timespan = new TimeSpan(day,0,0,0);
- date=DateTime.Now.Subtract(timespan);
- dv.RowFilter="CDate >='"+date+"'";
- dt=GetIsUpdatedDoc(dv);
- break;
- case 2:
- int month=Convert.ToInt32(txtMonth.Text,10);
- timespan = new TimeSpan(30*month,0,0,0);
- date=DateTime.Now.Subtract(timespan);
- dv.RowFilter="CDate >='"+date+"'";
- dt=GetIsUpdatedDoc(dv);
- break;
- case 3:
- if(txtMaxDate.Text==string.Empty||txtMinDate.Text==string.Empty)
- {
- Response.Write("<script language='javascript'>alert('日期没有填写完全!');</script>");
- dv.RowFilter="CDate>'"+DateTime.Today+"'";
- }
- else
- {
- try
- {
- DateTime Max=Convert.ToDateTime(txtMaxDate.Text);
- DateTime Min=Convert.ToDateTime(txtMinDate.Text);
- dv.RowFilter="CDate <= '"+Max+"' and CDate>='"+Min+"'";
- dt=GetIsUpdatedDoc(dv);
- }
- catch
- {
- Response.Write("<script language='javascript'>alert('日期请写成####-##-##年月日的格式!');</script>");
- dv.RowFilter="CDate>'"+DateTime.Today+"'";
-
- }
- }
- break;
- }
- DataView _dv=dt.DefaultView;
- return _dv;
- }
- }
- private DataTable GetIsUpdatedDoc(DataView dv)
- {
- int count=dv.Count;
- DataTable dt=(new FileData()).Tables[FileData.FMDOCFOLDER_TABLE];
- for(int i=0;i<count;i++)
- {
- if(dv[i].Row[8].ToString()!=string.Empty)
- {
- DataRow row=dt.NewRow();
- row[0]=Convert.ToInt32(dv[i].Row[0].ToString(),10);
- row[1]=Convert.ToInt32(dv[i].Row[1].ToString(),10);
- row[3]=dv[i].Row[3].ToString();
- row[4]=Convert.ToInt32(dv[i].Row[4].ToString(),10);
- row[5]=dv[i].Row[5].ToString();
- row[7]=Convert.ToDateTime(dv[i].Row[7].ToString());
- row[8]=Convert.ToDateTime(dv[i].Row[8].ToString());
- row[9]=Convert.ToInt32(dv[i].Row[9].ToString(),10);
- row[13]=dv[i].Row[13].ToString();
- row[14]=dv[i].Row[14].ToString();
- dt.Rows.Add(row);
- }
- }
- return dt;
- }
-
- private DataView TypeSearch(DataView dv)
- {
- DataTable dtSearch=BindTable(dv);
- DataView dvSearch=dtSearch.DefaultView;
- dvSearch.RowFilter="type='"+dropType.SelectedItem.Text+"'";
- return dvSearch;
- }
- private DataView GetAllDoc()
- {
- FileData filedata =(new FileA()).LoadDocFolder(0);
- DataView dv=filedata.Tables[FileData.FMDOCFOLDER_TABLE].DefaultView;
- return dv;
- }
- private void cmdOption_Click(object sender, System.EventArgs e)
- {
- chkDate.Visible=true;
- chkType.Visible=true;
- }
- private void chkDate_CheckedChanged(object sender, System.EventArgs e)
- {
- divDate.Visible =!divDate.Visible;
- }
- private void chkType_CheckedChanged(object sender, System.EventArgs e)
- {
- divType.Visible =!divType.Visible;
- }
-
- public void FillAllTypes()
- {
- FileData filedata = (new FileA()).GetAllTypes();
- dropType.DataSource=filedata.Tables[FileData.FMFILEATT_TABLE].DefaultView;
- dropType.DataValueField=filedata.Tables[FileData.FMFILEATT_TABLE].Columns[FileData.ID_FIELD4].ToString();
- dropType.DataTextField=filedata.Tables[FileData.FMFILEATT_TABLE].Columns[FileData.TYPENAME_FIELD4].ToString();
- dropType.DataBind();
- }
-
- private void rdoMonth_CheckedChanged(object sender, System.EventArgs e)
- {
- if(rdoMonth.Checked==true)
- {
- txtMonth.Enabled=true;
- txtDay.Enabled =false;
- txtMaxDate.Enabled=false;
- txtMinDate.Enabled=false;
- }
- }
- private void rdoDay_CheckedChanged(object sender, System.EventArgs e)
- {
- if(rdoDay.Checked==true)
- {
- txtDay.Enabled=true;
- txtMonth.Enabled=false;
- txtMaxDate.Enabled=false;
- txtMinDate.Enabled=false;
- }
- }
- private void rdoBetween_CheckedChanged(object sender, System.EventArgs e)
- {
- if(rdoBetween.Checked==true)
- {
- txtMaxDate.Enabled=true;
- txtMinDate.Enabled=true;
- txtDay.Enabled=false;
- txtMonth.Enabled=false;
- }
- }
- public DataTable BindTable(DataView dv)
- {
- DataTable dtSearch = new DataTable("Search");
- DataColumnCollection d= dtSearch.Columns;
- d.Add("folderid",typeof(System.Int32));
- d.Add("hifolderid", typeof(System.Int32));
- d.Add("name",typeof(System.String));
- d.Add("path",typeof(System.String));
- d.Add("type",typeof(System.String));
- d.Add("empid",typeof(System.String));
- d.Add("Cdate",typeof(System.String));
- int recordcount = dv.Count;
- for(int i=0;i<recordcount;i++)
- {
- DataRow row = dtSearch.NewRow();
- row["folderid"]=Convert.ToInt32(dv[i].Row[1].ToString(),10);
- row["hifolderid"] =Convert.ToInt32(dv[i].Row[0].ToString(),10);
- row["name"]=dv[i].Row[14].ToString()+dv[i].Row[3].ToString();
- int fid=Convert.ToInt32(dv[i].Row[0].ToString(),10);
- row["path"]=GetPath(fid);
- DateTime time=Convert.ToDateTime(dv[i].Row[7].ToString());
- row["Cdate"]=time.Year+"-"+time.Month+"-"+time.Day;
- row["empid"]=(new FileA()).GetEmpName(Convert.ToInt32(dv[i].Row[9].ToString()));
- row["type"]=dv[i].Row[13].ToString();
- dtSearch.Rows.Add(row);
- }
- return dtSearch;
- }
- private string GetPath(int fid)
- {
- FileA fa= new FileA();
- string fpath=fa.GetDocPath(fid);
- return fpath;
- }
-
- public DataView Search_Date()
- {
- DataView dv;
- if(rdoDay.Checked==true)
- {
- dv=DateSearch(1,dropDate.SelectedItem.Text);
- }
- else if(rdoMonth.Checked==true)
- {
- dv=DateSearch(2,dropDate.SelectedItem.Text);
- }
- else
- {
- dv=DateSearch(3,dropDate.SelectedItem.Text);
- }
- return dv;
- }
- private void dgdFolder_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
- {
- ListItemType itemType = e.Item.ItemType;
- e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
- if (itemType == ListItemType.Item )
- {
- e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
- }
- else if( itemType == ListItemType.AlternatingItem)
- {
- e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
- }
- }
- }
- }