SecurityFMPage.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:15k
源码类别:

.net编程

开发平台:

Others

  1. using System;
  2. using System.Collections;
  3. using System.Data;
  4. using System.Web.UI.WebControls; 
  5. using qminoa.Common; 
  6. using qminoa.DA; 
  7. using qminoa.BLL; 
  8. namespace qminoa.Webs.FM
  9. {
  10. public class SecurityFMPage : qminoa.Webs.PageBase
  11. {
  12. protected System.Web.UI.WebControls.DataGrid dgdFolder;
  13. protected System.Web.UI.WebControls.Image Image1;
  14. protected System.Web.UI.WebControls.ImageButton cmdClose;
  15. protected System.Web.UI.WebControls.ImageButton cmdBack;
  16. protected System.Web.UI.WebControls.ImageButton cmdForword;
  17. protected System.Web.UI.WebControls.ImageButton cmdUp;
  18. protected System.Web.UI.WebControls.ImageButton cmdSeach;
  19. protected System.Web.UI.WebControls.ImageButton cmdFolderShow;
  20. protected System.Web.UI.WebControls.ImageButton cmdNewFolder;
  21. protected System.Web.UI.WebControls.ImageButton cmdNewFile;
  22. protected System.Web.UI.WebControls.Label lblAddress;
  23. protected System.Web.UI.WebControls.TextBox txtFolderPath;
  24. protected System.Web.UI.WebControls.Image imgDrive;
  25. protected System.Web.UI.WebControls.ImageButton cmdGoto;
  26. protected System.Web.UI.WebControls.Label lblObjNum;
  27. protected System.Web.UI.WebControls.Label lblLastID;
  28. protected System.Web.UI.WebControls.Label lblID;
  29. protected System.Web.UI.WebControls.Label lblFID;
  30. protected System.Web.UI.WebControls.Label lblBID;
  31. static int DocId;
  32. static int  id;
  33. static int  Type;
  34. static int fm_empid;
  35. private void Page_Load(object sender, System.EventArgs e)
  36. {
  37. if(!IsPostBack)
  38. {
  39. this.PageBegin("项目管理",true);
  40. fm_empid=Convert.ToInt16(this.Empid);
  41. DocId=Convert.ToInt32(Request.QueryString["fid"],10); 
  42. id= Convert.ToInt32( Request.QueryString["Id"],10);
  43. Type=Convert.ToInt32(Request.QueryString["type"],10);
  44. txtFolderPath.Text="C:\";
  45. if(Type==-1)
  46. {
  47. if( id!=0 && DocId==0)
  48. {
  49. RightForReBind_Folder(id,0,fm_empid);
  50. }
  51. else if(id==0 && DocId!=0)
  52. {
  53. RightForReBind_Doc(0,DocId,fm_empid);
  54. }
  55. else if(id!=0 && DocId!=0)
  56. {
  57. int fid = Convert.ToInt32(Session["_fm_id"].ToString());
  58. if(id!=fid )
  59. {
  60. RightForReBind_Folder(id,DocId,fm_empid);
  61. }
  62. else
  63. {
  64. RightForReBind_Doc(id,DocId,fm_empid);
  65. }
  66. }
  67. }
  68. else if((id!=0 && Type==-2) || (id!=0 && Type==-3) )
  69. {
  70. RightForReBind_Folder(id,0,fm_empid);
  71. UpdateLeftTree();
  72. }
  73. else if(Type==-4)
  74. {
  75. RightForReBind_Folder(id,DocId,fm_empid);
  76. }
  77. else
  78. {
  79. FirstLoad();
  80. UpdateLeftTree();
  81. }
  82. }
  83. }
  84. public void FirstLoad()
  85. {
  86. FileData filedata = (new  FileA()).LoadFile();
  87. DataView dv=filedata.Tables[FileData.FMDOCFOLDER_TABLE].DefaultView;
  88. DataTable dt=CreateTable(dv);
  89. dgdFolder.DataSource =dt.DefaultView; 
  90. dgdFolder.DataBind();
  91. txtFolderPath.Text="C:\";
  92. Session["_fm_id"]=0;
  93. }
  94. public void RightForReBind_Doc(int folderid,int docid,int empid)
  95. {
  96. int depid=(new FileRight()).GetDepId(empid);
  97. string rightctr_emp=(new FileBLL()).GetDocRight(docid,empid);
  98. if(rightctr_emp=="Admin"||rightctr_emp=="Write"||rightctr_emp=="Read")
  99. {
  100. Response.Redirect("fmNewFile.aspx?fid="+id+"&did="+docid+"&type=-1",true);
  101. }
  102. else
  103. {
  104. string rightctr_dep=(new FileBLL()).GetDocRightForDep(docid,depid); 
  105. if(rightctr_dep=="Admin"||rightctr_dep=="Write"||rightctr_dep=="Read")
  106. {
  107. Response.Redirect("fmNewFile.aspx?fid="+id+"&did="+DocId+"&type=-1",true);
  108. }
  109. else
  110. {
  111. Response.Write("<script language='javascript'>alert('您没有权限访问这个文件!');</script>"); 
  112. if(folderid==0)
  113. {
  114. FirstLoad();
  115. }
  116. else
  117. {
  118. ReBind(folderid);
  119. }
  120. }
  121. }
  122. }
  123. public void  RightForReBind_Folder(int folderid,int docid,int empid)
  124. {
  125. string rightctr_emp=(new FileBLL()).GetFolderRight(folderid,empid);
  126. if(rightctr_emp=="Admin"||rightctr_emp=="Write"||rightctr_emp=="Read")
  127. {
  128. ReBind(folderid);
  129. }
  130. else
  131. {
  132. int depid=(new FileRight()).GetDepId(empid); 
  133. string rightctr_dep=(new FileBLL()).GetFolderRightForDep(folderid,depid); 
  134. if(rightctr_dep=="Admin"||rightctr_dep=="Write"||rightctr_dep=="Read")
  135. {
  136. ReBind(folderid);
  137. }
  138. else 
  139. {   
  140. Response.Write("<script language='javascript'>alert('您没有权限访问改文件夹!');</script>"); 
  141. FirstLoad();
  142. }
  143. }
  144. }
  145. public void ReBind(int id)
  146. {
  147. DataView dvdata; 
  148. FileData filedata =(new FileA()).LoadDocFolder(id);
  149. dvdata=filedata.Tables[FileData.FMDOCFOLDER_TABLE].DefaultView;
  150. DataTable dt=CreateTable(dvdata);
  151. dgdFolder.DataSource=dt.DefaultView;
  152. dgdFolder.DataBind(); 
  153. cmdBack.ImageUrl="img/button/fmback.gif"; 
  154. txtFolderPath.Text=GetPath(id);
  155. Session["_fm_id"]=id;
  156. }
  157. private string GetPath(int fid)
  158. {    
  159. FileA fa= new FileA();
  160. string fpath=fa.GetDocPath(fid); 
  161. return fpath;
  162. }
  163. private void cmdNewFolder_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  164. {
  165. int fid =id;
  166. Response.Redirect("fmNewFolder.aspx?id="+fid+"&type=-2");
  167. }
  168. #region Web Form Designer generated code
  169. override protected void OnInit(EventArgs e)
  170. {
  171. //
  172. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  173. //
  174. InitializeComponent();
  175. base.OnInit(e);
  176. }
  177. /// <summary>
  178. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  179. /// 此方法的内容。
  180. /// </summary>
  181. private void InitializeComponent()
  182. {   
  183. this.cmdUp.Click += new System.Web.UI.ImageClickEventHandler(this.cmdUp_Click);
  184. this.cmdSeach.Click += new System.Web.UI.ImageClickEventHandler(this.cmdSeach_Click);
  185. this.cmdNewFolder.Click += new System.Web.UI.ImageClickEventHandler(this.cmdNewFolder_Click);
  186. this.cmdNewFile.Click += new System.Web.UI.ImageClickEventHandler(this.cmdNewFile_Click);
  187. this.dgdFolder.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgdFolder_ItemCommand);
  188. this.dgdFolder.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgdFolder_EditCommand);
  189. this.Load += new System.EventHandler(this.Page_Load);
  190. this.dgdFolder.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgdFolder_ItemCreated);
  191. }
  192. #endregion
  193. private void cmdNewFile_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  194. {
  195.             int fid=id;
  196. FileA fa=new FileA();
  197. fa.UpdateFileCont();
  198. if(txtFolderPath.Text=="C:\")
  199. {
  200. Response.Redirect("fmNewFile.aspx?did=0&fid=0&type=-2",true);
  201. }
  202. else
  203. Response.Redirect("fmNewFile.aspx?did=0&fid="+id+"&type=-2",true);
  204. }
  205. }
  206. private void cmdSeach_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  207. {
  208. Response.Redirect("FileSearch.aspx",false);
  209. }
  210. private void cmdUp_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  211. {
  212. try
  213. {
  214. int _id = Convert.ToInt32(Session["_fm_id"].ToString(),10);
  215. int _fid=FileA.gethifolderid(_id);
  216. id=_fid;
  217. if(_fid!=0)
  218. {
  219. RightForReBind_Folder(_fid,0,fm_empid);
  220. }
  221. else
  222. {
  223. FirstLoad();
  224. }
  225. }
  226. catch
  227. {}
  228. }
  229. private void dgdFolder_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  230. {
  231. int FolderId =Convert.ToInt32(e.Item.Cells[1].Text);
  232. int DocId=Convert.ToInt32(e.Item.Cells[0].Text); 
  233. if(e.CommandName=="edit") 
  234. {  
  235. if( DocId==0 && FolderId!=0 )
  236. {
  237. RightForEdit_Folder(FolderId,0,fm_empid);
  238. }
  239. else if(DocId!=0 && FolderId!=0)
  240. {
  241. int id=Convert.ToInt32(Session["_fm_id"].ToString());
  242. if( FolderId!=id )
  243. {
  244. RightForEdit_Folder(FolderId,DocId,fm_empid);
  245. }
  246. else
  247. {
  248. RightForReBind_Doc(FolderId,DocId,fm_empid);
  249. }
  250. }
  251. else if( DocId!=0 && FolderId==0 )
  252. {
  253. RightForReBind_Doc(FolderId,DocId,fm_empid);
  254. }
  255. }
  256. }
  257. public  void dgdFolder_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  258. {
  259. if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem||e.Item.ItemType==ListItemType.EditItem)
  260. {
  261. TableCell myTableCell = new TableCell(); 
  262. myTableCell = e.Item.Cells[10];
  263. LinkButton myDeleteButton =new LinkButton(); 
  264. int count=myTableCell.Controls.Count;
  265. myDeleteButton = (LinkButton)myTableCell.Controls[0];
  266. myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除该记录吗?');");
  267. }
  268. }
  269. public void dgdFolder_delete(object Sender , DataGridCommandEventArgs E)
  270. {
  271. int FolderId =Convert.ToInt32(E.Item.Cells[1].Text);
  272. int DocId=Convert.ToInt32(E.Item.Cells[0].Text); 
  273. if(FolderId==0)
  274. {
  275. if(RightForManage_Doc(DocId)==true)
  276. {
  277. DeleteDoc(DocId,fm_empid);
  278. FirstLoad();
  279. }
  280. else
  281. {
  282. Response.Write("<script language='javascript'>alert('您没有权限管理该文件!');</script>"); 
  283. }
  284. }
  285. else
  286. {
  287. if(RightForManage_Folder(FolderId)==true)
  288. {
  289. if( DocId==0)
  290. {
  291. DeleteFolder(FolderId);
  292. }
  293. else
  294. {   
  295. int fid;
  296. fid = Convert.ToInt32(Session["_fm_id"].ToString());
  297. if(FolderId==fid)
  298. {
  299. if(RightForManage_Doc(DocId)==true)
  300. {
  301. DeleteDoc(DocId,fm_empid);
  302. ReBind(fid);
  303. }
  304. }
  305. else
  306. {
  307. DeleteFolder(FolderId); 
  308. ReBind(fid);
  309. }
  310. }
  311. UpdateLeftTree();
  312. }
  313. else
  314. {
  315. Response.Write("<script language='javascript'>alert('您没有权限管理该文件夹!');</script>"); 
  316. }
  317. }
  318. }
  319. public void DeleteFolder(int folderid)
  320. {
  321. FileA FileA =new FileA(); 
  322. ArrayList arrlist=(new FileA()).GetDelFolderId(folderid);
  323. for(int i=0;i<arrlist.Count;i++)
  324. {
  325. int foldid=Convert.ToInt32(arrlist[i].ToString(),10); 
  326. FileA.DeleteFolder(foldid,fm_empid,1); 
  327. }
  328. ArrayList arrlistDoc= FileA.GetDelDocId(arrlist);
  329. for(int j=0;j<arrlistDoc.Count;j++)
  330. {
  331. int docid=Convert.ToInt32(arrlistDoc[j].ToString(),10);
  332. DeleteDoc(docid,fm_empid);
  333. }
  334. int fid=Convert.ToInt32(Session["_fm_id"].ToString(),10);
  335. if(fid==0)
  336. {
  337. FirstLoad();
  338. }
  339. else
  340. {
  341. ReBind(fid);
  342. }
  343. }
  344. public void DeleteDoc(int docid,int empid)
  345. {
  346. FileA filedata=new FileA();
  347. filedata.DeleteDoc(docid,empid);  
  348. }
  349. public bool RightForManage_Folder(int folderid)
  350. {
  351. int depid=(new FileRight()).GetDepId(fm_empid); 
  352. string rightctr_dep=(new FileBLL()).GetFolderRightForDep(folderid,depid); 
  353. if(rightctr_dep=="Admin")
  354. {
  355. return true;
  356. }
  357. else
  358. {
  359. string rightctr_emp=(new FileBLL()).GetFolderRight(folderid,fm_empid);
  360. if(rightctr_emp=="Admin")
  361. {
  362. return true;
  363. }
  364. else
  365. {
  366. return false;
  367. }
  368. }
  369. }
  370. public bool RightForManage_Doc(int docid)
  371. {
  372. int depid=(new FileRight()).GetDepId(fm_empid);
  373. string rightctr_dep=(new FileBLL()).GetDocRightForDep(docid,depid); 
  374. if(rightctr_dep=="Admin")
  375. {
  376. return true;
  377. }
  378. else
  379. {
  380. string rightctr_emp=(new FileBLL()).GetDocRight(docid,fm_empid);
  381. if(rightctr_emp=="Admin")
  382. {
  383. return true;
  384. }
  385. else
  386. {
  387. return false;
  388. }
  389. }
  390. }
  391. public void  RightForEdit_Folder(int folderid,int docid,int empid)
  392. {
  393. string rightctr_emp=(new FileBLL()).GetFolderRight(folderid,empid);
  394. if(rightctr_emp=="Admin"||rightctr_emp=="Write"||rightctr_emp=="Read")
  395. {
  396. Response.Redirect("fmNewFolder.aspx?type=-3&id="+ folderid+"&docid="+docid); 
  397. }
  398. else
  399. {
  400. int depid=(new FileRight()).GetDepId(empid); 
  401. string rightctr_dep=(new FileBLL()).GetFolderRightForDep(folderid,depid); 
  402. if(rightctr_dep=="Admin"||rightctr_dep=="Write"||rightctr_dep=="Read")
  403. {
  404. Response.Redirect("fmNewFolder.aspx?type=-3&id="+ folderid+"&docid="+docid);
  405. }
  406. else 
  407. {
  408. Response.Write("<script language='javascript'>alert('您没有权限访问改文件夹!');</script>"); 
  409. }
  410. }
  411. }
  412. public DataTable CreateTable(DataView dv)
  413. {
  414. DataTable dvtable=new DataTable();
  415. DataColumnCollection d= dvtable.Columns; 
  416. d.Add("folderid",typeof(System.Int32)); 
  417. d.Add("Docid", typeof(System.Int32));
  418. d.Add("fname",typeof(System.String)); 
  419. d.Add("typename",typeof(System.String));
  420. d.Add("note",typeof(System.String));
  421. d.Add("empid",typeof(System.String));
  422. d.Add("cdate",typeof(System.String));
  423. int recordcount = dv.Count;
  424. for(int i=0;i<recordcount;i++)
  425. {
  426. DataRow row = dvtable.NewRow();
  427. row["folderid"]=Convert.ToInt32(dv[i].Row[0].ToString(),10);
  428. row["Docid"] =Convert.ToInt32(dv[i].Row[1].ToString(),10);
  429. row["fname"]=dv[i].Row[14].ToString()+dv[i].Row[3].ToString();
  430. row["note"]=dv[i].Row[5].ToString();     
  431. DateTime cdate=Convert.ToDateTime(dv[i].Row[7].ToString());
  432. row["cdate"]=cdate.Year+"-"+cdate.Month+"-"+cdate.Day;   
  433. row["empid"]=(new FileA()).GetEmpName(Convert.ToInt32(dv[i].Row[9].ToString()));
  434. row["typename"]=dv[i].Row[13].ToString();
  435. dvtable.Rows.Add(row);
  436. }
  437. return dvtable;
  438. }
  439. private void dgdFolder_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  440. {
  441. if(e.CommandName=="move")
  442. {
  443. int did=Convert.ToInt32(e.Item.Cells[0].Text.ToString(),10);
  444. int fid=Convert.ToInt32(e.Item.Cells[1].Text.ToString(),10);
  445. if(did==0&&fid!=0)
  446. {
  447. if(RightForManage_Folder(fid)==true)
  448. {
  449. Response.Redirect("fmSelFolder.aspx?DocId="+did+"&FolderId="+fid);
  450. }
  451. else
  452. {
  453. Response.Write("<script language='javascript'>alert('您没有权限管理该文件夹!');</script>"); 
  454. }
  455. }
  456. else if(did!=0&&fid==0)
  457. {
  458. if(RightForManage_Doc(did)==true)
  459. {
  460. Response.Redirect("fmSelFolder.aspx?DocId="+did+"&FolderId="+fid);
  461. }
  462. else
  463. {
  464. Response.Write("<script language='javascript'>alert('您没有权限管理该文件!');</script>"); 
  465. }
  466. }
  467. else if(did!=0&&fid!=0)
  468. {
  469. int id=Convert.ToInt32(Session["_fm_id"].ToString());
  470. if(fid!=id )
  471. {
  472. if(RightForManage_Folder(fid)==true)
  473. {
  474. Response.Redirect("fmSelFolder.aspx?DocId="+did+"&FolderId="+fid);
  475. }
  476. else
  477. {
  478. Response.Write("<script language='javascript'>alert('您没有权限管理该文件夹!');</script>"); 
  479. }
  480. }
  481. else
  482. {
  483. if(RightForManage_Doc(did)==true)
  484. {
  485. Response.Redirect("fmSelFolder.aspx?DocId="+did+"&FolderId="+fid);
  486. }
  487. else
  488. {
  489. Response.Write("<script language='javascript'>alert('您没有权限管理该文件!');</script>"); 
  490. }
  491. }
  492. }
  493. }
  494. }
  495. private void UpdateLeftTree()
  496. {
  497. Response.Write("<script>parent.frmDocTree.location.reload();</script>");
  498. }
  499.    private void dgdFolder_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
  500. {
  501. ListItemType itemType = e.Item.ItemType;
  502. e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#fff7ce';cursor='hand';" ;
  503. if (itemType == ListItemType.Item )
  504. {
  505. e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#dedfde';";
  506. }
  507. else if( itemType == ListItemType.AlternatingItem)
  508. {
  509. e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#ffffff';";
  510. }
  511. }
  512. }
  513. }