fmNewFile.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:18k
- using System;
- using System.Data;
- using System.Web.UI.WebControls;
- using System.IO;
- using qminoa.Common;
- using qminoa.DA;
- using qminoa.BLL;
- namespace qminoa.Webs.FM
- {
- public class fmNewFile : qminoa.Webs.PageBase
- {
- protected System.Web.UI.WebControls.ImageButton cmdSaveCon;
-
- const string UpFilePath="UpFiles";
- protected string FileName;
- protected int FileSize;
- protected string FileType;
- protected string FilePath;
- protected string dType;
-
- protected int DocType;
- protected static int id;
- protected static int type;
- protected static int docid;
- protected string keyword;
- protected string note;
- protected string docname;
- static int fm_empid;
- static int righttype;
- protected System.Web.UI.WebControls.Label lblURL;
- protected System.Web.UI.WebControls.Label lblFileID;
- protected System.Web.UI.WebControls.Label lblID;
- protected System.Web.UI.WebControls.Label lblErr;
- protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
- protected System.Web.UI.WebControls.ImageButton cmdExit;
- protected System.Web.UI.WebControls.ImageButton cmdSaveExi;
- protected System.Web.UI.WebControls.DataGrid dgdRight;
- protected System.Web.UI.WebControls.LinkButton cmdRightAdd;
- protected System.Web.UI.WebControls.LinkButton cmdRightSet;
- protected System.Web.UI.WebControls.Button cmdUpFile;
- protected System.Web.UI.WebControls.Label lblFileName;
- protected System.Web.UI.WebControls.DataGrid dgdFileInf;
- protected System.Web.UI.WebControls.RadioButton rdoExe;
- protected System.Web.UI.WebControls.RadioButton rdoPdf;
- protected System.Web.UI.WebControls.RadioButton rdoMedia;
- protected System.Web.UI.WebControls.RadioButton rdoNote;
- protected System.Web.UI.WebControls.RadioButton rdoZip;
- protected System.Web.UI.WebControls.RadioButton rdoBmp;
- protected System.Web.UI.WebControls.RadioButton rdoHtml;
- protected System.Web.UI.WebControls.RadioButton rdoAccess;
- protected System.Web.UI.WebControls.RadioButton rdoPpt;
- protected System.Web.UI.WebControls.RadioButton rdoExcel;
- protected System.Web.UI.WebControls.RadioButton rdoWord;
- protected System.Web.UI.WebControls.RadioButton rdoOther;
- protected System.Web.UI.WebControls.LinkButton cmdFileIco;
- protected System.Web.UI.WebControls.Label lblEName;
- protected System.Web.UI.WebControls.Label Label7;
- protected System.Web.UI.WebControls.Label lblCDate;
- protected System.Web.UI.WebControls.Label Label6;
- protected System.Web.UI.WebControls.Label lblFileLoc;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
- protected System.Web.UI.WebControls.TextBox txtKeyWord;
- protected System.Web.UI.WebControls.Label Label3;
- protected System.Web.UI.WebControls.TextBox txtNote;
- protected System.Web.UI.WebControls.Label Label4;
- protected System.Web.UI.WebControls.Label Label2;
- protected System.Web.UI.WebControls.TextBox txtFileName;
- protected System.Web.UI.WebControls.Label Label1;
- protected System.Web.UI.HtmlControls.HtmlGenericControl DIV1;
- protected System.Web.UI.HtmlControls.HtmlInputFile File1;
- private void Page_Load(object sender, System.EventArgs e)
- {
- if(!this.IsPostBack)
- {
- this.PageBegin("文档管理",true);
- fm_empid=Convert.ToInt16(this.Empid);
- docid=Convert.ToInt32(Request.QueryString["did"]);
- id = Convert.ToInt32(Request.QueryString["fid"]);
- type=Convert.ToInt32(Request.QueryString["type"]);
- righttype=Convert.ToInt32(Request.Params["righttype"],10);
- Session["_folderid"]=id;
- Session["_docid"]=docid;
- Session["Type"]=type;
- Session["RightType"]=righttype;
- filldgdRight(docid,fm_empid);
- if(type==-2&&righttype!=5)
- {
- if(docid==0 && id==0)
- {
- lblFileLoc.Text="C:\";
- lblCDate.Text=Convert.ToString( DateTime.Now.Year+"-"+DateTime.Now.Month+"-"+DateTime.Now.Day);
- lblEName.Text=this.EmpName;
- }
- else if(docid==0&&id!=0)
- {
- lblFileLoc.Text="---"+GetPath(id);
- lblCDate.Text=Convert.ToString( DateTime.Now.Year+"-"+DateTime.Now.Month+"-"+DateTime.Now.Day);
- lblEName.Text=this.EmpName;
- }
- }
- else if(type==-1||type==-3)
- {
- DataView data=GetDoc(docid);
- string time;
- time =Convert.ToString(data[0].Row[7].ToString());
- lblCDate.Text=time;
- txtFileName.Text = data[0].Row[2].ToString();
- txtKeyWord.Text= data[0].Row[4].ToString();
- txtNote.Text=data[0].Row[5].ToString();
- lblEName.Text=(new FileA()).GetEmpName(Convert.ToInt32(data[0].Row[9].ToString()));;
- int rdotype= Convert.ToInt32(data[0].Row[3].ToString());
- Setrdo(rdotype);
- if(id==0 && docid!=0)
- {
- lblFileLoc.Text ="C:\";
- }
- else if(id!=0 && docid!=0)
- {
- lblFileLoc.Text=GetPath(id);
- }
- BindToDataGrid(docid);
- RightforWrite();
- }
- else if(righttype==5)
- {
- if(Session["NewDoc"]!=null)
- {
- DataTable data=(DataTable)Session["NewDoc"];
- txtFileName.Text=data.Rows[0][0].ToString();
- lblFileLoc.Text=data.Rows[0][1].ToString();
- txtKeyWord.Text=data.Rows[0][2].ToString();
- txtNote.Text=data.Rows[0][3].ToString();
- lblCDate.Text=data.Rows[0][4].ToString();
- lblEName.Text=this.EmpName;
- int typeindex=Convert.ToInt32(data.Rows[0][5].ToString(),10);
- Setrdo(typeindex);
- BindToDataGrid(0);
- }
- filldgdRight(0,fm_empid);
- }
- }
- }
- private void filldgdRight(int docid,int empid)
- {
- FileData filedata = (new FileRight()).GetDocCtr(docid,empid,0);
- dgdRight.DataSource =filedata.Tables[FileData.FMDOCFOLDERCTR_TABLE].DefaultView;
- dgdRight.DataBind();
- }
- public void RightforWrite()
- {
- int depid=(new FileRight()).GetDepId(fm_empid);
- string rightctr_dep=(new FileBLL()).GetDocRightForDep(docid,depid);
- if(rightctr_dep=="Admin")
- {
- cmdRightSet.Visible=true;
- }
- else if(rightctr_dep=="Write")
- {
- cmdRightSet.Visible=false;
- }
- else if(rightctr_dep=="Read")
- {
- cmdRightSet.Visible=false;
- txtFileName.Enabled=false;
- txtKeyWord.Enabled=false;
- txtNote.Enabled=false;
- cmdFileIco.Enabled=false;
- cmdUpFile.Enabled=false;
- }
- else
- {
- string rightctr_emp=(new FileBLL()).GetDocRight(docid,fm_empid);
- if(rightctr_emp=="Admin")
- {
- cmdRightSet.Visible=true;
- }
- else if(rightctr_emp=="Write")
- {
- cmdRightSet.Visible=false;
- }
- else if(rightctr_emp=="Read")
- {
- cmdRightSet.Visible=false;
- txtFileName.Enabled=false;
- txtKeyWord.Enabled=false;
- txtNote.Enabled=false;
- cmdFileIco.Enabled=false;
- cmdUpFile.Enabled=false;
- }
- }
- }
- private void BindToDataGrid(int docid)
- {
- DataView dvdata;
- if(docid==0)
- {
- FileData data=(new FileA()).GetNullFileCont();
- dvdata=data.Tables[FileData.FILECONT_TABLE].DefaultView;
- }
- else
- {
- FileData data =(new FileA()).ShowAllFileCont();
- dvdata=data.Tables[FileData.FILECONT_TABLE].DefaultView;
- dvdata.RowFilter="DocId="+docid;
- }
- if(dvdata.Count == 0)
- {
- dgdFileInf.Visible=false;
- }
- else
- {
- int cout=dvdata.Count;
- dgdFileInf.Visible=true;
- dgdFileInf.DataSource=dvdata;
- dgdFileInf.DataBind();
- }
- }
- #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.cmdFileIco.Click += new System.EventHandler(this.cmdFileIco_Click);
- this.dgdFileInf.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgdFileInf_ItemCreated);
- this.dgdFileInf.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgdFileInf_DeleteCommand);
- this.cmdUpFile.Click += new System.EventHandler(this.cmdUpFile_Click);
- this.cmdRightSet.Click += new System.EventHandler(this.cmdRightSet_Click);
- this.cmdRightAdd.Click += new System.EventHandler(this.cmdRightAdd_Click);
- this.dgdRight.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgdRight_ItemCreated);
- this.dgdRight.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgdRight_DeleteCommand);
- this.cmdSaveExi.Click += new System.Web.UI.ImageClickEventHandler(this.cmdSaveExi_Click);
- this.cmdExit.Click += new System.Web.UI.ImageClickEventHandler(this.cmdExit_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
-
- #endregion
- private void cmdRightSet_Click(object sender, System.EventArgs e)
- {
- dgdRight.Visible=!dgdRight.Visible;
- cmdRightAdd.Visible=!cmdRightAdd.Visible;
- }
- private void cmdFileIco_Click(object sender, System.EventArgs e)
- {
- DIV1.Visible = !DIV1.Visible;
- rdoOther.Checked =true;
- }
- private void cmdSaveExi_Click(object sender, System.Web.UI.ImageClickEventArgs e)
- {
- SaveDocRight();
- if(docid==0 && id==0 && type==-2)
- {
- Saveinfo(0,1);
- Response.Redirect("SecurityFMPage.aspx",true);
- }
- else if(docid==0 && id!=0 && type==-2)
- {
- Saveinfo(id,0);
- Response.Redirect("SecurityFMPage.aspx?Id="+id+"&type=-2",true);
- }
- else if(type==-1||type==-3)
- {
- Saveinfo(docid,1);
- if(id==0&&docid!=0)
- {
- Response.Redirect("SecurityFMPage.aspx",true);
- }
- else
- {
- Response.Redirect("SecurityFMPage.aspx?Id="+id+"&type=-2",true);
- }
- }
- }
- private void Saveinfo(int foldid,int layer)
- {
- docname=txtFileName.Text;
- note=txtNote.Text;
- keyword=txtKeyWord.Text;
- DocType=GetFileTypeID();
- FileA filedata = new FileA();
- filedata.ChangDocInfo(foldid,docname,note,DateTime.Now,keyword,fm_empid,DocType,layer);
- }
- private DataView GetDoc(int docid)
- {
- FileData filedata=(new FileA()).SeachAllDocs(0);
- DataView dvdata=filedata.Tables[FileData.FMDOC_TABLE].DefaultView;
- dvdata.RowFilter="DocId="+docid;
- return dvdata;
- }
- private void Setrdo(int index)
- {
- switch(index)
- {
- case 1:
- rdoOther.Checked=true;
- break;
- case 2:
- rdoWord.Checked=true;
- break;
- case 3:
- rdoExcel.Checked=true;
- break;
- case 4:
- rdoBmp.Checked=true;
- break;
- case 5:
- rdoAccess.Checked=true;
- break;
- case 6:
- rdoPpt.Checked=true;
- break;
- case 7:
- rdoHtml.Checked=true;
- break;
- case 8:
- rdoNote.Checked=true;
- break;
- case 9:
- rdoExe.Checked=true;
- break;
- case 10:
- rdoPdf.Checked=true;
- break;
- case 11:
- rdoMedia.Checked=true;
- break;
- case 12:
- rdoZip.Checked=true;
- break;
- }
- }
- private int GetFileTypeID()
- {
- int TypeIndex=1;
-
- if (rdoOther.Checked==true)
- TypeIndex=1;
- else if (rdoWord.Checked==true)
- TypeIndex=2;
- else if (rdoExcel.Checked==true)
- TypeIndex=3;
- else if (rdoBmp.Checked==true)
- TypeIndex=4;
- else if (rdoAccess.Checked==true)
- TypeIndex=5;
- else if (rdoPpt.Checked==true)
- TypeIndex=6;
- else if (rdoHtml.Checked==true)
- TypeIndex=7;
- else if (rdoNote.Checked==true)
- TypeIndex=8;
- else if (rdoExe.Checked==true)
- TypeIndex=9;
- else if (rdoPdf.Checked==true)
- TypeIndex=10;
- else if (rdoMedia.Checked==true)
- TypeIndex=11;
- else if (rdoZip.Checked==true)
- TypeIndex=12;
- return TypeIndex;
- }
- private void cmdUpFile_Click(object sender, System.EventArgs e)
- {
- string Mapname=null;
- try
- {
- string [] up =this.File1.PostedFile.FileName.Split(new char []{'\'});
- string p=MapPath("")+"\"+UpFilePath+"\"+up[up.Length-1];
- if(File.Exists(p))
- {
- Response.Write("<script language='javascript'>alert('该文件名已经存在!');</script>");
- }
- else
- {
- FileSize=File1.PostedFile.ContentLength;
- byte[] arrFile=new byte[FileSize];
- if(FileSize>0)
- {
- string [] Date=DateTime.Now.ToString().Split(' ');
- string [] name1= Date[0].Split('-');
- string [] name2=Date[1].Split(':');
- for(int i=0;i<3;i++)
- {
- Mapname+=name1[i]+name2[i];
- }
- Mapname=Mapname+up[up.Length-1];
- FileName=up[up.Length-1];
- string [] getdoctype=FileName.Split('.');
- dType=getdoctype[1].ToString();
- FilePath="\"+UpFilePath+"\"+Mapname;
- FileSize=File1.PostedFile.ContentLength;
- FileType=File1.PostedFile.ContentType;
- Stream StreamReader = File1.PostedFile.InputStream;
- StreamReader.Read(arrFile,0,FileSize);
- FileA FileA=new FileA();
- FileA.InsertFileCont(docid,FileName,FilePath,FileSize,FileType,arrFile,dType);
- BindToDataGrid(docid);
- this.File1.PostedFile.SaveAs(MapPath("")+"\"+UpFilePath+"\"+Mapname);
- Response.Write("<script language='javascript'>alert('上传成功!');</script>");
- }
- else
- {
- Response.Write("<script language='javascript'>alert('上传失败!');</script>");
- }
- }
- }
- catch
- {
- Response.Write("<script language='javascript'>alert('上传失败!');</script>");
- }
- }
- private void dgdFileInf_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
- {
- int filecontid = Convert.ToInt32(e.Item.Cells[0].Text);
- FileA fa = new FileA();
- fa.DeleteFileCont(filecontid);
- BindToDataGrid(docid);
- }
- private string GetPath(int fid)
- {
- FileA fa= new FileA();
- string fpath=fa.GetDocPath(fid);
- return fpath;
- }
- private void cmdExit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
- {
- if(type==-2)
- {
- FileA fa=new FileA();
- fa.UpdateFileCont();
- }
- Response.Redirect("SecurityFMPage.aspx?Id="+id+"&type=-2",true);
- }
- public void SaveDocRight()
- {
- int num=dgdRight.Items.Count;
- FileRight fright =new FileRight();
- for(int i=0;i<num;i++)
- {
- int key=Convert.ToInt32(dgdRight.Items[i].Cells[0].Text.ToString(),10);
- int empid=FileRight.GetEmpId(dgdRight.Items[i].Cells[1].Text.Trim());
- if(empid>0)
- {
- fright.SaveDocRight(GetSaveData_emp(empid,i,key),2);
- }
- else
- {
- int Depid=(new FileRight()).GetDepId(dgdRight.Items[i].Cells[1].Text.Trim());
- fright.SaveDocRight(GetSaveData_dep(Depid,i,key),6);
- }
- }
- }
- public FileData GetSaveData_dep(int DepId,int index,int key)
- {
- int DocId = FileRight.Right_GetDocFolderId(key);
- FileData rightdata=new FileData();
- DataTable userdata =rightdata.Tables[FileData.FMDOCFOLDERCTR_TABLE];
- DataRow row =userdata.NewRow();
- row[0]=0;
- row[1]=DocId;
- row[2]=DepId;
- row[3]=0;
- if(((RadioButton)dgdRight.Items[index].FindControl("radAdmin")).Checked==true)
- row[4]=1;
- else row[4]=0;
- if(((RadioButton)dgdRight.Items[index].FindControl("radRead")).Checked==true)
- row[5]=1;
- else row[5]=0;
- if(((RadioButton)dgdRight.Items[index].FindControl("radWrite")).Checked==true)
- row[6]=1;
- else row[6]=0;
- row[7]=DepId;
-
- userdata.Rows.Add(row);
- userdata.AcceptChanges();
- rightdata.AcceptChanges();
- return rightdata;
- }
-
- public FileData GetSaveData_emp(int EmpId,int index,int key)
- {
- int DocId = FileRight.Right_GetDocFolderId(key);
- FileData rightdata=new FileData();
- DataTable userdata =rightdata.Tables[FileData.FMDOCFOLDERCTR_TABLE];
- DataRow row =userdata.NewRow();
- row[0]=0;
- row[1]=DocId;
- row[2]=0;
- row[3]=EmpId;
- if(((RadioButton)dgdRight.Items[index].FindControl("radAdmin")).Checked==true)
- row[4]=1;
- else row[4]=0;
- if(((RadioButton)dgdRight.Items[index].FindControl("radRead")).Checked==true)
- row[5]=1;
- else row[5]=0;
- if(((RadioButton)dgdRight.Items[index].FindControl("radWrite")).Checked==true)
- row[6]=1;
- else row[6]=0;
- row[7]=EmpId;
- userdata.Rows.Add(row);
- userdata.AcceptChanges();
- rightdata.AcceptChanges();
- return rightdata;
- }
- private void dgdRight_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
- {
- int rightkey=Convert.ToInt32(e.Item.Cells[0].Text);
- FileA fa = new FileA();
- fa.DeleteRight(rightkey,1);
- this.WriteOptLog("删除文件权限信息:"+rightkey.ToString());
- filldgdRight(docid,fm_empid);
- }
- private void cmdRightAdd_Click(object sender, System.EventArgs e)
- {
- if(Session["NewDoc"]!=null)
- {
- Session["NewDoc"]=null;
- }
- if(type==-2)
- {
- DataTable data= new DataTable();
- DataColumnCollection d= data.Columns;
- d.Add("title",typeof(System.String));
- d.Add("location", typeof(System.String));
- d.Add("keyword",typeof(System.String));
- d.Add("note",typeof(System.String));
- d.Add("cdate",typeof(System.String));
- d.Add("filetype",typeof(System.Int32));
- DataRow row=data.NewRow();
- row[0]=txtFileName.Text;
- row[1]=lblFileLoc.Text;
- row[2]=txtKeyWord.Text;
- row[3]=txtNote.Text;
- row[4]=lblCDate.Text;
- row[5]=GetFileTypeID();
- data.Rows.Add(row);
- data.AcceptChanges();
- Session["NewDoc"]=data;
- }
- Response.Redirect("SetRightType.aspx?fid=0&did="+docid+"&type=5");
- }
- private void dgdFileInf_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
- {
- if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
- {
- TableCell myTableCell = new TableCell();
- myTableCell = e.Item.Cells[5];
- LinkButton myDeleteButton =new LinkButton();
- int count=myTableCell.Controls.Count;
- myDeleteButton = (LinkButton)myTableCell.Controls[0];
- myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除这个附件吗?');");
- }
- }
- private void dgdRight_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
- {
- if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
- {
- TableCell myTableCell = new TableCell();
- myTableCell = e.Item.Cells[5];
- LinkButton myDeleteButton =new LinkButton();
- int count=myTableCell.Controls.Count;
- myDeleteButton = (LinkButton)myTableCell.Controls[0];
- myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除这条权限吗?');");
- }
- }
- }
- }