Ejemplo n.º 1
0
        private List <SimpleFileModel> ToSimpleFileModel(DataTable datatable)
        {
            List <SimpleFileModel> files = new List <SimpleFileModel>();

            foreach (DataRow dr in datatable.Rows)
            {
                SimpleFileModel sfm = new SimpleFileModel();

                sfm.FileID = dr["FileID"].ToInt32();

                sfm.SystemID     = dr["SystemID"].ToInt32();
                sfm.ModuleCode   = dr["ModuleCode"].ToString();
                sfm.CategoryCode = dr["CategoryCode"].ToString();
                sfm.MasterID     = dr["MasterID"].ToString();

                sfm.FileName = dr["FileName"].ToString();
                sfm.FileType = dr["FileType"].ToString();
                sfm.FileSize = dr["FileSize"].ToInt64();

                sfm.FilePath = dr["FilePath"].ToString();

                sfm.CreateDateTime = dr["CreateDateTime"].ToDateTime();
                sfm.FileStatus     = (FileState)dr["Status"].ToInt32();

                files.Add(sfm);
            }
            return(files);
        }
Ejemplo n.º 2
0
        public SimpleFileModel AddFile(int systemID, string moduleCode, string categoryCode, string masterID, string fileName, string fileType, byte[] fileContent, FileState fileState)
        {
            if (systemID <= 0)
            {
                throw new ArgumentException("参数 systemID 不能小于零!");
            }
            if (moduleCode.IsEmpty())
            {
                throw new ArgumentException("参数 moduleCode 不能为空!");
            }
            if (categoryCode.IsEmpty())
            {
                throw new ArgumentException("参数 categoryCode 不能为空!");
            }
            if (masterID.IsEmpty())
            {
                throw new ArgumentException("参数 masterID 不能为空!");
            }
            if (fileName.IsEmpty())
            {
                throw new ArgumentException("参数 fileName 不能为空!");
            }
            if (fileType.IsEmpty())
            {
                throw new ArgumentException("参数 fileType 不能为空!");
            }
            if (fileContent == null || fileContent.Length <= 0)
            {
                throw new ArgumentException("参数 fileContent 不能为空!");
            }

            string sql = "select isnull(max(fileid),0) from g_businessfile";

            SimpleFileModel sfm = new SimpleFileModel();

            sfm.FileID       = DB.ExeSqlForObject(sql, null).ToInt32(0) + 1;
            sfm.SystemID     = systemID;
            sfm.ModuleCode   = moduleCode;
            sfm.CategoryCode = categoryCode;
            sfm.MasterID     = masterID;

            sfm.FileName = fileName;
            sfm.FileType = fileType;
            sfm.FileSize = fileContent.Length;
            sfm.FilePath = "";

            sfm.CreateDateTime = DateTime.Now;
            sfm.FileStatus     = fileState;


            SqlParameterCollection spc = DB.CreateSqlParameterCollection();

            spc.Add("@FileID", sfm.FileID);
            spc.Add("@SystemID", sfm.SystemID);
            spc.Add("@ModuleCode", sfm.ModuleCode);
            spc.Add("@CategoryCode", sfm.CategoryCode);
            spc.Add("@MasterID", sfm.MasterID);

            spc.Add("@FileName", sfm.FileName);
            spc.Add("@FileType", sfm.FileType);
            spc.Add("@FileSize", sfm.FileSize);
            spc.Add("@FilePath", sfm.FilePath);

            spc.Add("@FileContent", fileContent);

            spc.Add("@CreateDateTime", sfm.CreateDateTime);
            spc.Add("@Status", (int)fileState);

            if (this.IsUseInnerTransaction)
            {
                DB.BeginTransaction();
            }

            try
            {
                sql = @"insert into g_BusinessFile(FileID,SystemID,ModuleCode,CategoryCode,MasterID,
FileName,FileType,FileSize,FileContent,FilePath,CreateDateTime,Status)
values(@FileID,@SystemID,@ModuleCode,@CategoryCode,@MasterID,
@FileName,@FileType,@FileSize,@FileContent,@FilePath,@CreateDateTime,@Status)";

//                sql = @"insert into g_BusinessFile(SystemID,ModuleCode,CategoryCode,MasterID,
//FileName,FileType,FileSize,FileContent,FilePath,CreateDateTime,Status)
//values(@SystemID,@ModuleCode,@CategoryCode,@MasterID,
//@FileName,@FileType,@FileSize,@FileContent,@FilePath,@CreateDateTime,@Status)";
                DB.ExecuteNonQuerySql(sql, spc);

                if (this.IsUseInnerTransaction)
                {
                    DB.CommitTransaction();
                }
            }
            catch
            {
                if (this.IsUseInnerTransaction)
                {
                    DB.RollbackTransaction();
                }

                throw;
            }

            return(sfm);
        }