Sys_AttachFiles_info.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using SysBaseLibs;
  6. using System.Web.Script.Serialization;
  7. using System.Web.UI.WebControls;
  8. using System.Web;
  9. using System.IO;
  10. namespace SysDataLibs.TableClass
  11. {
  12. #region Sys_AttachFiles
  13. public partial class Sys_AttachFiles_info : ITableInfo
  14. {
  15. #region Sys_AttachFiles表 字段信息
  16. /// <summary>
  17. /// 为关键字段: Y --- PrimaryKey;
  18. /// 自动增长: Y;
  19. /// 数据类型: int;
  20. /// 数据长度: 4;
  21. /// 是否允许为空: N;
  22. /// 默认值: ;
  23. /// 描述: AttachID;
  24. /// </summary>
  25. public const string cAttachID = "AttachID";
  26. /// <summary>
  27. /// 为关键字段: N ;
  28. /// 自动增长: N;
  29. /// 数据类型: nvarchar;
  30. /// 数据长度: 160;
  31. /// 是否允许为空: N;
  32. /// 默认值: ;
  33. /// 描述: ColumnId;
  34. /// </summary>
  35. public const string cColumnId = "ColumnId";
  36. /// <summary>
  37. /// 为关键字段: N ;
  38. /// 自动增长: N;
  39. /// 数据类型: nvarchar;
  40. /// 数据长度: -1;
  41. /// 是否允许为空: Y;
  42. /// 默认值: ;
  43. /// 描述: Description;
  44. /// </summary>
  45. public const string cDescription = "Description";
  46. /// <summary>
  47. /// 为关键字段: N ;
  48. /// 自动增长: N;
  49. /// 数据类型: nvarchar;
  50. /// 数据长度: 100;
  51. /// 是否允许为空: N;
  52. /// 默认值: ;
  53. /// 描述: FileExt;
  54. /// </summary>
  55. public const string cFileExt = "FileExt";
  56. /// <summary>
  57. /// 为关键字段: N ;
  58. /// 自动增长: N;
  59. /// 数据类型: nvarchar;
  60. /// 数据长度: 1000;
  61. /// 是否允许为空: N;
  62. /// 默认值: ;
  63. /// 描述: FileName;
  64. /// </summary>
  65. public const string cFileName = "FileName";
  66. /// <summary>
  67. /// 为关键字段: N ;
  68. /// 自动增长: N;
  69. /// 数据类型: nvarchar;
  70. /// 数据长度: 1000;
  71. /// 是否允许为空: N;
  72. /// 默认值: ;
  73. /// 描述: FilePath;
  74. /// </summary>
  75. public const string cFilePath = "FilePath";
  76. /// <summary>
  77. /// 为关键字段: N ;
  78. /// 自动增长: N;
  79. /// 数据类型: nvarchar;
  80. /// 数据长度: 500;
  81. /// 是否允许为空: Y;
  82. /// 默认值: ;
  83. /// 描述: FileTitle;
  84. /// </summary>
  85. public const string cFileTitle = "FileTitle";
  86. /// <summary>
  87. /// 为关键字段: N ;
  88. /// 自动增长: N;
  89. /// 数据类型: nchar;
  90. /// 数据长度: 20;
  91. /// 是否允许为空: N;
  92. /// 默认值: ;
  93. /// 描述: FileType;
  94. /// </summary>
  95. public const string cFileType = "FileType";
  96. /// <summary>
  97. /// 为关键字段: N ;
  98. /// 自动增长: N;
  99. /// 数据类型: varchar;
  100. /// 数据长度: 250;
  101. /// 是否允许为空: N;
  102. /// 默认值: ;
  103. /// 描述: SourceKey;
  104. /// </summary>
  105. public const string cSourceKey = "SourceKey";
  106. /// <summary>
  107. /// 为关键字段: N ;
  108. /// 自动增长: N;
  109. /// 数据类型: nvarchar;
  110. /// 数据长度: 160;
  111. /// 是否允许为空: N;
  112. /// 默认值: ;
  113. /// 描述: TableId;
  114. /// </summary>
  115. public const string cTableId = "TableId";
  116. /// <summary>
  117. /// 为关键字段: N ;
  118. /// 自动增长: N;
  119. /// 数据类型: smalldatetime;
  120. /// 数据长度: 4;
  121. /// 是否允许为空: N;
  122. /// 默认值: (getdate());
  123. /// 描述: TimeCreated;
  124. /// </summary>
  125. public const string cTimeCreated = "TimeCreated";
  126. /// <summary>
  127. /// 为关键字段: N ;
  128. /// 自动增长: N;
  129. /// 数据类型: smalldatetime;
  130. /// 数据长度: 4;
  131. /// 是否允许为空: N;
  132. /// 默认值: (getdate());
  133. /// 描述: TimeLastMod;
  134. /// </summary>
  135. public const string cTimeLastMod = "TimeLastMod";
  136. /// <summary>
  137. /// 为关键字段: N ;
  138. /// 自动增长: N;
  139. /// 数据类型: varchar;
  140. /// 数据长度: 30;
  141. /// 是否允许为空: N;
  142. /// 默认值: ;
  143. /// 描述: UserIDLastMod;
  144. /// </summary>
  145. public const string cUserIDLastMod = "UserIDLastMod";
  146. #endregion
  147. public Sys_AttachFiles_info() { }
  148. public Sys_AttachFiles_info(DataRow poRow)
  149. {
  150. CreateTableInfo(poRow);
  151. }
  152. public void CreateTableInfo(DataRow poRow)
  153. {
  154. _AttachID = UtilStr.StrFromObj(poRow[cAttachID]);
  155. _ColumnId = UtilStr.StrFromObj(poRow[cColumnId]);
  156. _Description = UtilStr.StrFromObj(poRow[cDescription]);
  157. _FileExt = UtilStr.StrFromObj(poRow[cFileExt]);
  158. _FileName = UtilStr.StrFromObj(poRow[cFileName]);
  159. _FilePath = UtilStr.StrFromObj(poRow[cFilePath]);
  160. _FileTitle = UtilStr.StrFromObj(poRow[cFileTitle]);
  161. _FileType = UtilStr.StrFromObj(poRow[cFileType]);
  162. _SourceKey = UtilStr.StrFromObj(poRow[cSourceKey]);
  163. _TableId = UtilStr.StrFromObj(poRow[cTableId]);
  164. _TimeCreated = UtilStr.StrFromObj(poRow[cTimeCreated]);
  165. _TimeLastMod = UtilStr.StrFromObj(poRow[cTimeLastMod]);
  166. _UserIDLastMod = UtilStr.StrFromObj(poRow[cUserIDLastMod]);
  167. }
  168. public Sys_AttachFiles_info(string pcAttachID, DBConnSql poDBConn)
  169. {
  170. if (pcAttachID.Trim().Length > 0 && poDBConn != null)
  171. {
  172. string lcSql = "select * from " + Tn.Sys_AttachFiles + " where AttachID='" + pcAttachID + "' order by AttachID desc ";
  173. rsQuery loQuery = poDBConn.OpenQuery(lcSql);
  174. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount == 1)
  175. {
  176. loQuery.MoveFirst();
  177. CreateTableInfo(loQuery.CurrentRow);
  178. }
  179. }
  180. }
  181. public Sys_AttachFiles_info(string pcTableId, string pcColumnId, string pcSourceKey, DBConnSql poDBConn)
  182. {
  183. if (pcTableId.Trim().Length > 0 && pcColumnId.Length > 0 && poDBConn != null)
  184. {
  185. string lcSql = "select * from " + Tn.Sys_AttachFiles + " where TableId='" + pcTableId + "' AND ColumnId='" + pcColumnId + "' AND SourceKey='" + pcSourceKey + "' order by AttachID desc ";
  186. rsQuery loQuery = poDBConn.OpenQuery(lcSql);
  187. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0)
  188. {
  189. loQuery.MoveFirst();
  190. CreateTableInfo(loQuery.CurrentRow);
  191. }
  192. }
  193. }
  194. private string _AttachID = "";
  195. public string AttachID
  196. {
  197. get { return _AttachID; }
  198. set { _AttachID = value; }
  199. }
  200. private string _ColumnId = "";
  201. public string ColumnId
  202. {
  203. get { return _ColumnId; }
  204. set { _ColumnId = value; }
  205. }
  206. private string _Description = "";
  207. public string Description
  208. {
  209. get { return _Description; }
  210. set { _Description = value; }
  211. }
  212. private string _FileExt = "";
  213. public string FileExt
  214. {
  215. get { return _FileExt; }
  216. set { _FileExt = value; }
  217. }
  218. private string _FileName = "";
  219. public string FileName
  220. {
  221. get { return _FileName; }
  222. set { _FileName = value; }
  223. }
  224. private string _FilePath = "";
  225. public string FilePath
  226. {
  227. get { return _FilePath; }
  228. set { _FilePath = value; }
  229. }
  230. private string _FileTitle = "";
  231. public string FileTitle
  232. {
  233. get { return _FileTitle; }
  234. set { _FileTitle = value; }
  235. }
  236. private string _FileType = "";
  237. public string FileType
  238. {
  239. get { return _FileType; }
  240. set { _FileType = value; }
  241. }
  242. private string _SourceKey = "";
  243. public string SourceKey
  244. {
  245. get { return _SourceKey; }
  246. set { _SourceKey = value; }
  247. }
  248. private string _TableId = "";
  249. public string TableId
  250. {
  251. get { return _TableId; }
  252. set { _TableId = value; }
  253. }
  254. private string _TimeCreated = "";
  255. public string TimeCreated
  256. {
  257. get { return _TimeCreated; }
  258. set { _TimeCreated = value; }
  259. }
  260. private string _TimeLastMod = "";
  261. public string TimeLastMod
  262. {
  263. get { return _TimeLastMod; }
  264. set { _TimeLastMod = value; }
  265. }
  266. private string _UserIDLastMod = "";
  267. public string UserIDLastMod
  268. {
  269. get { return _UserIDLastMod; }
  270. set { _UserIDLastMod = value; }
  271. }
  272. public string DownPath()
  273. {
  274. return "../" + FilePath + "/" + FileName;
  275. }
  276. [ScriptIgnore]
  277. public rsXmlNode DataXMLNode
  278. {
  279. get
  280. {
  281. rsXmlNode loMainNode = new rsXmlNode("Sys_AttachFilesRecord", "");
  282. rsXmlNode loNode = null;
  283. loNode = new rsXmlNode(cAttachID, AttachID);
  284. loMainNode.AddChild(loNode);
  285. loNode = new rsXmlNode(cColumnId, ColumnId);
  286. loMainNode.AddChild(loNode);
  287. loNode = new rsXmlNode(cDescription, Description);
  288. loMainNode.AddChild(loNode);
  289. loNode = new rsXmlNode(cFileExt, FileExt);
  290. loMainNode.AddChild(loNode);
  291. loNode = new rsXmlNode(cFileName, FileName);
  292. loMainNode.AddChild(loNode);
  293. loNode = new rsXmlNode(cFilePath, FilePath);
  294. loMainNode.AddChild(loNode);
  295. loNode = new rsXmlNode(cFileTitle, FileTitle);
  296. loMainNode.AddChild(loNode);
  297. loNode = new rsXmlNode(cFileType, FileType);
  298. loMainNode.AddChild(loNode);
  299. loNode = new rsXmlNode(cSourceKey, SourceKey);
  300. loMainNode.AddChild(loNode);
  301. loNode = new rsXmlNode(cTableId, TableId);
  302. loMainNode.AddChild(loNode);
  303. loNode = new rsXmlNode(cTimeCreated, TimeCreated);
  304. loMainNode.AddChild(loNode);
  305. loNode = new rsXmlNode(cTimeLastMod, TimeLastMod);
  306. loMainNode.AddChild(loNode);
  307. loNode = new rsXmlNode(cUserIDLastMod, UserIDLastMod);
  308. loMainNode.AddChild(loNode);
  309. return loMainNode;
  310. }
  311. }
  312. public string InsertSql()
  313. {
  314. return " insert into " + Tn.Sys_AttachFiles + " " +
  315. " (" + cColumnId + "," + cDescription + "," + cFileExt + "," + cFileName + "," + cFilePath + "," + cFileTitle + "," + cFileType + "," + cSourceKey + "," + cTableId + "," + cTimeCreated + "," + cTimeLastMod + "," + cUserIDLastMod + ") " +
  316. " values ('" + _ColumnId + "','" + _Description + "','" + _FileExt + "','" + _FileName + "','" + _FilePath + "','" + _FileTitle + "','" + _FileType + "','" + _SourceKey + "','" + _TableId + "','" + _TimeCreated + "','" + _TimeLastMod + "','" + _UserIDLastMod + "') ";
  317. }
  318. public string UpdateSql()
  319. {
  320. return " update " + Tn.Sys_AttachFiles + " " +
  321. " set " + cColumnId + "='" + _ColumnId + "'," + cDescription + "='" + _Description + "'," + cFileExt + "='" + _FileExt + "'," + cFileName + "='" + _FileName + "'," + cFilePath + "='" + _FilePath + "'," + cFileTitle + "='" + _FileTitle + "'," + cFileType + "='" + _FileType + "'," + cSourceKey + "='" + _SourceKey + "'," + cTableId + "='" + _TableId + "'," + cTimeCreated + "='" + _TimeCreated + "'," + cTimeLastMod + "='" + _TimeLastMod + "'," + cUserIDLastMod + "='" + _UserIDLastMod + "' " +
  322. " where " + cAttachID + "=" + _AttachID + "";
  323. }
  324. public string DeleteSql()
  325. {
  326. return "Delete " + Tn.Sys_AttachFiles + " where " + cAttachID + "=" + _AttachID + "";
  327. }
  328. public bool UpdateFile(FileUpload poFileUpload, UserSession poSession)
  329. {
  330. bool lbRetVal = false;
  331. //检查要上传的文件是否存在
  332. if (poFileUpload.PostedFile.FileName.Trim() != "")
  333. {
  334. try
  335. {
  336. string UploadFileName = "";
  337. string UploadFileDestination = "";
  338. UploadFileName = poFileUpload.PostedFile.FileName;
  339. if (MyUtils.IsValidFileType(UploadFileName))
  340. {
  341. UploadFileName = UploadFileName.Substring(UploadFileName.LastIndexOf("\\") + 1);
  342. this.FileExt = UploadFileName.Substring(UploadFileName.LastIndexOf(".") + 1, UploadFileName.Length - UploadFileName.LastIndexOf(".") - 1);
  343. if (string.IsNullOrEmpty(this.FileTitle))
  344. this.FileTitle = UploadFileName.Remove(UploadFileName.LastIndexOf("."));
  345. this.FilePath = SysDataLibs.AppEnv.SysSetObj.GetString("DOWNLOADPATH") + "/" + AppEnv.SysSetObj.GetString("ATTACHFILES") + "/" + this.TableId.ToUpper();
  346. UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath;
  347. UploadFileDestination += this.FilePath;
  348. if (!Directory.Exists(UploadFileDestination))
  349. {
  350. Directory.CreateDirectory(UploadFileDestination);
  351. }
  352. string lcDateRd = this.FileTitle + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + "." + this.FileExt;
  353. this.FileName = lcDateRd.Replace(" ", "");
  354. poFileUpload.PostedFile.SaveAs(UploadFileDestination + "/" + this.FileName);
  355. lbRetVal = poSession.DBConn.ExcuteSqlTran(this.InsertSql());
  356. ThreadLog.LogInfo(poSession.UserInfo.Names + "(" + poSession.UserInfo.UserID + ")" + " update File " + this.DownPath());
  357. lbRetVal = true;
  358. }
  359. }
  360. catch (Exception e)
  361. {
  362. ThreadLog.LogException(e);
  363. ThreadLog.LogErr("文件上传异常");
  364. ThreadLog.LogException(e);
  365. lbRetVal = false;
  366. }
  367. }
  368. return lbRetVal;
  369. }
  370. }
  371. #endregion
  372. #region
  373. public class Sys_AttachFiles_Qry : rsQuery
  374. {
  375. public Int64 AttachID
  376. {
  377. get { return GetInt(Sys_AttachFiles_info.cAttachID); }
  378. // set { SetField(Sys_AttachFiles_info.cAttachID, value); }
  379. }
  380. public String ColumnId
  381. {
  382. get { return GetString(Sys_AttachFiles_info.cColumnId); }
  383. // set { SetField(Sys_AttachFiles_info.cColumnId, value); }
  384. }
  385. public String Description
  386. {
  387. get { return GetString(Sys_AttachFiles_info.cDescription); }
  388. // set { SetField(Sys_AttachFiles_info.cDescription, value); }
  389. }
  390. public String FileExt
  391. {
  392. get { return GetString(Sys_AttachFiles_info.cFileExt); }
  393. // set { SetField(Sys_AttachFiles_info.cFileExt, value); }
  394. }
  395. public String FileName
  396. {
  397. get { return GetString(Sys_AttachFiles_info.cFileName); }
  398. // set { SetField(Sys_AttachFiles_info.cFileName, value); }
  399. }
  400. public String FilePath
  401. {
  402. get { return GetString(Sys_AttachFiles_info.cFilePath); }
  403. // set { SetField(Sys_AttachFiles_info.cFilePath, value); }
  404. }
  405. public String FileTitle
  406. {
  407. get { return GetString(Sys_AttachFiles_info.cFileTitle); }
  408. // set { SetField(Sys_AttachFiles_info.cFileTitle, value); }
  409. }
  410. public String FileType
  411. {
  412. get { return GetString(Sys_AttachFiles_info.cFileType); }
  413. // set { SetField(Sys_AttachFiles_info.cFileType, value); }
  414. }
  415. public String SourceKey
  416. {
  417. get { return GetString(Sys_AttachFiles_info.cSourceKey); }
  418. // set { SetField(Sys_AttachFiles_info.cSourceKey, value); }
  419. }
  420. public String TableId
  421. {
  422. get { return GetString(Sys_AttachFiles_info.cTableId); }
  423. // set { SetField(Sys_AttachFiles_info.cTableId, value); }
  424. }
  425. public DateTime TimeCreated
  426. {
  427. get { return GetDateTime(Sys_AttachFiles_info.cTimeCreated); }
  428. // set { SetField(Sys_AttachFiles_info.cTimeCreated, value); }
  429. }
  430. public DateTime TimeLastMod
  431. {
  432. get { return GetDateTime(Sys_AttachFiles_info.cTimeLastMod); }
  433. // set { SetField(Sys_AttachFiles_info.cTimeLastMod, value); }
  434. }
  435. public String UserIDLastMod
  436. {
  437. get { return GetString(Sys_AttachFiles_info.cUserIDLastMod); }
  438. // set { SetField(Sys_AttachFiles_info.cUserIDLastMod, value); }
  439. }
  440. }
  441. #endregion
  442. }