using System; using System.Collections.Generic; using System.Text; using System.Data; using SysBaseLibs; using System.Web.Script.Serialization; using System.Web.UI.WebControls; using System.Web; using System.IO; namespace SysDataLibs.TableClass { #region Sys_AttachFiles public partial class Sys_AttachFiles_info : ITableInfo { #region Sys_AttachFiles表 字段信息 /// /// 为关键字段: Y --- PrimaryKey; /// 自动增长: Y; /// 数据类型: int; /// 数据长度: 4; /// 是否允许为空: N; /// 默认值: ; /// 描述: AttachID; /// public const string cAttachID = "AttachID"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nvarchar; /// 数据长度: 160; /// 是否允许为空: N; /// 默认值: ; /// 描述: ColumnId; /// public const string cColumnId = "ColumnId"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nvarchar; /// 数据长度: -1; /// 是否允许为空: Y; /// 默认值: ; /// 描述: Description; /// public const string cDescription = "Description"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nvarchar; /// 数据长度: 100; /// 是否允许为空: N; /// 默认值: ; /// 描述: FileExt; /// public const string cFileExt = "FileExt"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nvarchar; /// 数据长度: 1000; /// 是否允许为空: N; /// 默认值: ; /// 描述: FileName; /// public const string cFileName = "FileName"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nvarchar; /// 数据长度: 1000; /// 是否允许为空: N; /// 默认值: ; /// 描述: FilePath; /// public const string cFilePath = "FilePath"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nvarchar; /// 数据长度: 500; /// 是否允许为空: Y; /// 默认值: ; /// 描述: FileTitle; /// public const string cFileTitle = "FileTitle"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nchar; /// 数据长度: 20; /// 是否允许为空: N; /// 默认值: ; /// 描述: FileType; /// public const string cFileType = "FileType"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: varchar; /// 数据长度: 250; /// 是否允许为空: N; /// 默认值: ; /// 描述: SourceKey; /// public const string cSourceKey = "SourceKey"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: nvarchar; /// 数据长度: 160; /// 是否允许为空: N; /// 默认值: ; /// 描述: TableId; /// public const string cTableId = "TableId"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: smalldatetime; /// 数据长度: 4; /// 是否允许为空: N; /// 默认值: (getdate()); /// 描述: TimeCreated; /// public const string cTimeCreated = "TimeCreated"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: smalldatetime; /// 数据长度: 4; /// 是否允许为空: N; /// 默认值: (getdate()); /// 描述: TimeLastMod; /// public const string cTimeLastMod = "TimeLastMod"; /// /// 为关键字段: N ; /// 自动增长: N; /// 数据类型: varchar; /// 数据长度: 30; /// 是否允许为空: N; /// 默认值: ; /// 描述: UserIDLastMod; /// public const string cUserIDLastMod = "UserIDLastMod"; #endregion public Sys_AttachFiles_info() { } public Sys_AttachFiles_info(DataRow poRow) { CreateTableInfo(poRow); } public void CreateTableInfo(DataRow poRow) { _AttachID = UtilStr.StrFromObj(poRow[cAttachID]); _ColumnId = UtilStr.StrFromObj(poRow[cColumnId]); _Description = UtilStr.StrFromObj(poRow[cDescription]); _FileExt = UtilStr.StrFromObj(poRow[cFileExt]); _FileName = UtilStr.StrFromObj(poRow[cFileName]); _FilePath = UtilStr.StrFromObj(poRow[cFilePath]); _FileTitle = UtilStr.StrFromObj(poRow[cFileTitle]); _FileType = UtilStr.StrFromObj(poRow[cFileType]); _SourceKey = UtilStr.StrFromObj(poRow[cSourceKey]); _TableId = UtilStr.StrFromObj(poRow[cTableId]); _TimeCreated = UtilStr.StrFromObj(poRow[cTimeCreated]); _TimeLastMod = UtilStr.StrFromObj(poRow[cTimeLastMod]); _UserIDLastMod = UtilStr.StrFromObj(poRow[cUserIDLastMod]); } public Sys_AttachFiles_info(string pcAttachID, DBConnSql poDBConn) { if (pcAttachID.Trim().Length > 0 && poDBConn != null) { string lcSql = "select * from " + Tn.Sys_AttachFiles + " where AttachID='" + pcAttachID + "' order by AttachID desc "; rsQuery loQuery = poDBConn.OpenQuery(lcSql); if (loQuery != null && loQuery.IsOpened && loQuery.RecCount == 1) { loQuery.MoveFirst(); CreateTableInfo(loQuery.CurrentRow); } } } public Sys_AttachFiles_info(string pcTableId, string pcColumnId, string pcSourceKey, DBConnSql poDBConn) { if (pcTableId.Trim().Length > 0 && pcColumnId.Length > 0 && poDBConn != null) { string lcSql = "select * from " + Tn.Sys_AttachFiles + " where TableId='" + pcTableId + "' AND ColumnId='" + pcColumnId + "' AND SourceKey='" + pcSourceKey + "' order by AttachID desc "; rsQuery loQuery = poDBConn.OpenQuery(lcSql); if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0) { loQuery.MoveFirst(); CreateTableInfo(loQuery.CurrentRow); } } } private string _AttachID = ""; public string AttachID { get { return _AttachID; } set { _AttachID = value; } } private string _ColumnId = ""; public string ColumnId { get { return _ColumnId; } set { _ColumnId = value; } } private string _Description = ""; public string Description { get { return _Description; } set { _Description = value; } } private string _FileExt = ""; public string FileExt { get { return _FileExt; } set { _FileExt = value; } } private string _FileName = ""; public string FileName { get { return _FileName; } set { _FileName = value; } } private string _FilePath = ""; public string FilePath { get { return _FilePath; } set { _FilePath = value; } } private string _FileTitle = ""; public string FileTitle { get { return _FileTitle; } set { _FileTitle = value; } } private string _FileType = ""; public string FileType { get { return _FileType; } set { _FileType = value; } } private string _SourceKey = ""; public string SourceKey { get { return _SourceKey; } set { _SourceKey = value; } } private string _TableId = ""; public string TableId { get { return _TableId; } set { _TableId = value; } } private string _TimeCreated = ""; public string TimeCreated { get { return _TimeCreated; } set { _TimeCreated = value; } } private string _TimeLastMod = ""; public string TimeLastMod { get { return _TimeLastMod; } set { _TimeLastMod = value; } } private string _UserIDLastMod = ""; public string UserIDLastMod { get { return _UserIDLastMod; } set { _UserIDLastMod = value; } } public string DownPath() { return "../" + FilePath + "/" + FileName; } [ScriptIgnore] public rsXmlNode DataXMLNode { get { rsXmlNode loMainNode = new rsXmlNode("Sys_AttachFilesRecord", ""); rsXmlNode loNode = null; loNode = new rsXmlNode(cAttachID, AttachID); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cColumnId, ColumnId); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cDescription, Description); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cFileExt, FileExt); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cFileName, FileName); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cFilePath, FilePath); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cFileTitle, FileTitle); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cFileType, FileType); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cSourceKey, SourceKey); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cTableId, TableId); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cTimeCreated, TimeCreated); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cTimeLastMod, TimeLastMod); loMainNode.AddChild(loNode); loNode = new rsXmlNode(cUserIDLastMod, UserIDLastMod); loMainNode.AddChild(loNode); return loMainNode; } } public string InsertSql() { return " insert into " + Tn.Sys_AttachFiles + " " + " (" + cColumnId + "," + cDescription + "," + cFileExt + "," + cFileName + "," + cFilePath + "," + cFileTitle + "," + cFileType + "," + cSourceKey + "," + cTableId + "," + cTimeCreated + "," + cTimeLastMod + "," + cUserIDLastMod + ") " + " values ('" + _ColumnId + "','" + _Description + "','" + _FileExt + "','" + _FileName + "','" + _FilePath + "','" + _FileTitle + "','" + _FileType + "','" + _SourceKey + "','" + _TableId + "','" + _TimeCreated + "','" + _TimeLastMod + "','" + _UserIDLastMod + "') "; } public string UpdateSql() { return " update " + Tn.Sys_AttachFiles + " " + " 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 + "' " + " where " + cAttachID + "=" + _AttachID + ""; } public string DeleteSql() { return "Delete " + Tn.Sys_AttachFiles + " where " + cAttachID + "=" + _AttachID + ""; } public bool UpdateFile(FileUpload poFileUpload, UserSession poSession) { bool lbRetVal = false; //检查要上传的文件是否存在 if (poFileUpload.PostedFile.FileName.Trim() != "") { try { string UploadFileName = ""; string UploadFileDestination = ""; UploadFileName = poFileUpload.PostedFile.FileName; if (MyUtils.IsValidFileType(UploadFileName)) { UploadFileName = UploadFileName.Substring(UploadFileName.LastIndexOf("\\") + 1); this.FileExt = UploadFileName.Substring(UploadFileName.LastIndexOf(".") + 1, UploadFileName.Length - UploadFileName.LastIndexOf(".") - 1); if (string.IsNullOrEmpty(this.FileTitle)) this.FileTitle = UploadFileName.Remove(UploadFileName.LastIndexOf(".")); this.FilePath = SysDataLibs.AppEnv.SysSetObj.GetString("DOWNLOADPATH") + "/" + AppEnv.SysSetObj.GetString("ATTACHFILES") + "/" + this.TableId.ToUpper(); UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath; UploadFileDestination += this.FilePath; if (!Directory.Exists(UploadFileDestination)) { Directory.CreateDirectory(UploadFileDestination); } string lcDateRd = this.FileTitle + "-" + DateTime.Now.ToString("yyyyMMddHHmmssffffff") + "." + this.FileExt; this.FileName = lcDateRd.Replace(" ", ""); poFileUpload.PostedFile.SaveAs(UploadFileDestination + "/" + this.FileName); lbRetVal = poSession.DBConn.ExcuteSqlTran(this.InsertSql()); ThreadLog.LogInfo(poSession.UserInfo.Names + "(" + poSession.UserInfo.UserID + ")" + " update File " + this.DownPath()); lbRetVal = true; } } catch (Exception e) { ThreadLog.LogException(e); ThreadLog.LogErr("文件上传异常"); ThreadLog.LogException(e); lbRetVal = false; } } return lbRetVal; } } #endregion #region public class Sys_AttachFiles_Qry : rsQuery { public Int64 AttachID { get { return GetInt(Sys_AttachFiles_info.cAttachID); } // set { SetField(Sys_AttachFiles_info.cAttachID, value); } } public String ColumnId { get { return GetString(Sys_AttachFiles_info.cColumnId); } // set { SetField(Sys_AttachFiles_info.cColumnId, value); } } public String Description { get { return GetString(Sys_AttachFiles_info.cDescription); } // set { SetField(Sys_AttachFiles_info.cDescription, value); } } public String FileExt { get { return GetString(Sys_AttachFiles_info.cFileExt); } // set { SetField(Sys_AttachFiles_info.cFileExt, value); } } public String FileName { get { return GetString(Sys_AttachFiles_info.cFileName); } // set { SetField(Sys_AttachFiles_info.cFileName, value); } } public String FilePath { get { return GetString(Sys_AttachFiles_info.cFilePath); } // set { SetField(Sys_AttachFiles_info.cFilePath, value); } } public String FileTitle { get { return GetString(Sys_AttachFiles_info.cFileTitle); } // set { SetField(Sys_AttachFiles_info.cFileTitle, value); } } public String FileType { get { return GetString(Sys_AttachFiles_info.cFileType); } // set { SetField(Sys_AttachFiles_info.cFileType, value); } } public String SourceKey { get { return GetString(Sys_AttachFiles_info.cSourceKey); } // set { SetField(Sys_AttachFiles_info.cSourceKey, value); } } public String TableId { get { return GetString(Sys_AttachFiles_info.cTableId); } // set { SetField(Sys_AttachFiles_info.cTableId, value); } } public DateTime TimeCreated { get { return GetDateTime(Sys_AttachFiles_info.cTimeCreated); } // set { SetField(Sys_AttachFiles_info.cTimeCreated, value); } } public DateTime TimeLastMod { get { return GetDateTime(Sys_AttachFiles_info.cTimeLastMod); } // set { SetField(Sys_AttachFiles_info.cTimeLastMod, value); } } public String UserIDLastMod { get { return GetString(Sys_AttachFiles_info.cUserIDLastMod); } // set { SetField(Sys_AttachFiles_info.cUserIDLastMod, value); } } } #endregion }