PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/VisualFlow/WF/FreeFrm/AttachmentUpload.aspx.cs

#
C# | 236 lines | 217 code | 15 blank | 4 comment | 31 complexity | 9a3332009456b6f5460d8e0ad978b1d0 MD5 | raw file
Possible License(s): AGPL-3.0
  1. using System;
  2. using System.IO;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Web;
  6. using System.Web.UI.WebControls;
  7. using System.Web.UI.HtmlControls;
  8. using System.Web.UI;
  9. using BP.Web;
  10. using BP.Sys;
  11. using BP.DA;
  12. public partial class WF_FreeFrm_UploadFile : WebPage
  13. {
  14. /// <summary>
  15. /// ath.
  16. /// </summary>
  17. public string NoOfObj
  18. {
  19. get
  20. {
  21. return this.Request.QueryString["NoOfObj"];
  22. }
  23. }
  24. public string PKVal
  25. {
  26. get
  27. {
  28. return this.Request.QueryString["PKVal"];
  29. }
  30. }
  31. public string IsBTitle
  32. {
  33. get
  34. {
  35. return this.Request.QueryString["IsBTitle"];
  36. }
  37. }
  38. public string IsReadonly
  39. {
  40. get
  41. {
  42. return this.Request.QueryString["IsReadonly"];
  43. }
  44. }
  45. public string DelPKVal
  46. {
  47. get
  48. {
  49. return this.Request.QueryString["DelPKVal"];
  50. }
  51. }
  52. public string FK_FrmAttachment
  53. {
  54. get
  55. {
  56. return this.Request.QueryString["FK_FrmAttachment"];
  57. }
  58. }
  59. protected void Page_Load(object sender, EventArgs e)
  60. {
  61. if (this.DoType == "Del")
  62. {
  63. FrmAttachmentDB delDB = new FrmAttachmentDB();
  64. delDB.MyPK = this.DelPKVal;
  65. delDB.DirectDelete();
  66. }
  67. if (this.DoType == "Down")
  68. {
  69. FrmAttachmentDB downDB = new FrmAttachmentDB();
  70. downDB.MyPK = this.MyPK;
  71. downDB.Retrieve();
  72. BP.PubClass.DownloadFile(downDB.FileFullName, downDB.FileName);
  73. this.WinClose();
  74. return;
  75. }
  76. BP.Sys.FrmAttachment athDesc = new BP.Sys.FrmAttachment();
  77. athDesc.MyPK = this.FK_FrmAttachment;
  78. if (athDesc.RetrieveFromDBSources() == 0)
  79. {
  80. }
  81. this.Title = athDesc.Name;
  82. this.Pub1.AddTable("width='100%'");
  83. if (this.IsBTitle == "1")
  84. {
  85. this.Pub1.AddTR();
  86. this.Pub1.AddTDTitle("IDX");
  87. if (athDesc.Sort.Contains(","))
  88. this.Pub1.AddTDTitle("类别");
  89. this.Pub1.AddTDTitle("文件名");
  90. this.Pub1.AddTDTitle("大小KB");
  91. this.Pub1.AddTDTitle("上传日期");
  92. this.Pub1.AddTDTitle("上传人");
  93. if (athDesc.IsNote)
  94. this.Pub1.AddTDTitle("备注");
  95. this.Pub1.AddTDTitle("操作");
  96. this.Pub1.AddTREnd();
  97. }else
  98. {
  99. this.Pub1.AddTR();
  100. this.Pub1.AddTD("IDX");
  101. if (athDesc.Sort.Contains(","))
  102. this.Pub1.AddTD("类别");
  103. this.Pub1.AddTD("文件名");
  104. this.Pub1.AddTD("大小KB");
  105. this.Pub1.AddTD("上传日期");
  106. this.Pub1.AddTD("上传人");
  107. if (athDesc.IsNote)
  108. this.Pub1.AddTD("备注");
  109. this.Pub1.AddTD("操作");
  110. this.Pub1.AddTREnd();
  111. }
  112. BP.Sys.FrmAttachmentDBs dbs = new BP.Sys.FrmAttachmentDBs();
  113. dbs.Retrieve(FrmAttachmentDBAttr.FK_FrmAttachment, this.FK_FrmAttachment,
  114. FrmAttachmentDBAttr.RefPKVal, this.PKVal);
  115. int i = 0;
  116. foreach (FrmAttachmentDB db in dbs)
  117. {
  118. i++;
  119. this.Pub1.AddTR();
  120. this.Pub1.AddTDIdx(i);
  121. if (athDesc.Sort.Contains(","))
  122. this.Pub1.AddTD(db.Sort);
  123. // this.Pub1.AddTDIdx(i++);
  124. if (athDesc.IsDownload)
  125. this.Pub1.AddTD("<a href='AttachmentUpload.aspx?DoType=Down&MyPK=" + db.MyPK + "' target=_blank ><img src='../../Images/FileType/" + db.FileExts + ".gif' border=0 onerror=\"src='../../Images/FileType/Undefined.gif'\" />" + db.FileName + "</a>");
  126. else
  127. this.Pub1.AddTD(db.FileName);
  128. this.Pub1.AddTD(db.FileSize);
  129. this.Pub1.AddTD(db.RDT);
  130. this.Pub1.AddTD(db.RecName);
  131. if (athDesc.IsNote)
  132. this.Pub1.AddTD(db.MyNote);
  133. if (athDesc.IsDelete && this.IsReadonly != "1")
  134. this.Pub1.AddTD("<a href=\"javascript:Del('" + this.FK_FrmAttachment + "','" + this.PKVal + "','" + db.MyPK + "')\">删除</a>");
  135. else
  136. this.Pub1.AddTD("");
  137. this.Pub1.AddTREnd();
  138. }
  139. if (athDesc.IsUpload && this.IsReadonly!="1")
  140. {
  141. this.Pub1.AddTR();
  142. this.Pub1.AddTDBegin("colspan=7");
  143. this.Pub1.Add("文件:");
  144. System.Web.UI.WebControls.FileUpload fu = new System.Web.UI.WebControls.FileUpload();
  145. fu.ID = "file";
  146. fu.BorderStyle = BorderStyle.NotSet;
  147. this.Pub1.Add(fu);
  148. if (athDesc.Sort.Contains(","))
  149. {
  150. string[] strs = athDesc.Sort.Split(',');
  151. BP.Web.Controls.DDL ddl = new BP.Web.Controls.DDL();
  152. ddl.ID = "ddl";
  153. foreach (string str in strs)
  154. {
  155. if (str == null || str == "")
  156. continue;
  157. ddl.Items.Add(new ListItem(str, str));
  158. }
  159. this.Pub1.Add(ddl);
  160. }
  161. if (athDesc.IsNote)
  162. {
  163. TextBox tb = new TextBox();
  164. tb.ID = "TB_Note";
  165. tb.Attributes["Width"] = "100%";
  166. tb.Attributes["class"] = "TBNote";
  167. tb.Columns = 30;
  168. this.Pub1.Add("&nbsp;备注:");
  169. this.Pub1.Add(tb);
  170. }
  171. Button btn = new Button();
  172. btn.Text = "上传";
  173. btn.ID = "Btn_Upload";
  174. btn.CssClass = "Btn";
  175. btn.Click += new EventHandler(btn_Click);
  176. this.Pub1.Add(btn);
  177. this.Pub1.AddTDEnd();
  178. this.Pub1.AddTREnd();
  179. }
  180. this.Pub1.AddTableEnd();
  181. }
  182. void btn_Click(object sender, EventArgs e)
  183. {
  184. BP.Sys.FrmAttachment athDesc = new BP.Sys.FrmAttachment(this.FK_FrmAttachment);
  185. System.Web.UI.WebControls.FileUpload fu = this.Pub1.FindControl("file") as System.Web.UI.WebControls.FileUpload;
  186. if (fu.HasFile == false || fu.FileName.Length <= 2)
  187. {
  188. this.Alert("请选择上传的文件.");
  189. return;
  190. }
  191. if (System.IO.Directory.Exists(athDesc.SaveTo) == false)
  192. System.IO.Directory.CreateDirectory(athDesc.SaveTo);
  193. int oid = BP.DA.DBAccess.GenerOID();
  194. string exp = "";
  195. string saveTo = athDesc.SaveTo + "\\" + oid + "." + fu.FileName.Substring(fu.FileName.LastIndexOf('.') + 1);
  196. fu.SaveAs(saveTo);
  197. FileInfo info = new FileInfo(saveTo);
  198. FrmAttachmentDB dbUpload = new FrmAttachmentDB();
  199. dbUpload.MyPK = athDesc.FK_MapData + oid.ToString();
  200. dbUpload.FK_FrmAttachment = this.FK_FrmAttachment;
  201. dbUpload.RefPKVal = this.PKVal.ToString();
  202. dbUpload.FK_MapData = athDesc.FK_MapData;
  203. dbUpload.FileExts = info.Extension;
  204. dbUpload.FileFullName = saveTo;
  205. dbUpload.FileName = fu.FileName;
  206. dbUpload.FileSize = (float)info.Length;
  207. dbUpload.RDT = DataType.CurrentDataTime;
  208. dbUpload.Rec = BP.Web.WebUser.No;
  209. dbUpload.RecName = BP.Web.WebUser.Name;
  210. if (athDesc.IsNote)
  211. dbUpload.MyNote = this.Pub1.GetTextBoxByID("TB_Note").Text;
  212. if (athDesc.Sort.Contains(","))
  213. dbUpload.Sort = this.Pub1.GetDDLByID("ddl").SelectedItemStringVal;
  214. dbUpload.Insert();
  215. this.Response.Redirect("AttachmentUpload.aspx?IsBTitle=" + this.IsBTitle + "&FK_FrmAttachment=" + this.FK_FrmAttachment + "&PKVal=" + this.PKVal, true);
  216. }
  217. }