public static void SetOrdinal(Dal.Models.Atlas atlas, OleDbConnection conn, OleDbTransaction trans = null) { if (atlas == null || atlas.AtlasID == null) { throw new Exception("参数错误!"); } Dal.Models.AtlasType type = atlas.SpecialtyID == null ? Dal.Models.AtlasType.Prize : Dal.Models.AtlasType.Specialty; int iOwnerID = type == Dal.Models.AtlasType.Specialty ? atlas.SpecialtyID.Value : atlas.PrizeID.Value; List <Dal.Models.Atlas> lstAtlas = GetAtlasList(iOwnerID, type, conn, trans).Where(a => a.AtlasID != atlas.AtlasID).ToList(); if (atlas.Ordinal == null || atlas.Ordinal > lstAtlas.Count) { lstAtlas.Add(atlas); } else if (atlas.Ordinal <= 0) { lstAtlas.Insert(0, atlas); } else { lstAtlas.Insert(atlas.Ordinal.Value - 1, atlas); } string strSql = " UPDATE Atlas set Ordinal = ? where AtlasID = ? "; for (int i = 0; i < lstAtlas.Count; i++) { Dal.OleDbHlper.ExecuteNonQuery(strSql, conn, CommandType.Text, trans , new OleDbParameter("@Ordinal", OleDbType.VarWChar) { Value = i + 1 } , new OleDbParameter("@AtlasID", OleDbType.Integer) { Value = lstAtlas[i].AtlasID.Value }); } }
public static void SaveFile(Dal.Models.UploadFileInfo file, OleDbConnection conn, OleDbTransaction tran = null) { string strRootDirectory = System.Web.HttpContext.Current.Request.PhysicalApplicationPath; if (file.SizeLimit == null || file.AmountLimit == null) { switch (file.Type) { case Dal.Models.FileType.DeclarationAppendix: Dal.Models.Appendix AppendixInfo = BLL.Appendix.GetAppendix(file.CorrelationID.Value, conn, tran); file.SizeLimit = AppendixInfo.SizeLimit; file.AmountLimit = 1; break; case Dal.Models.FileType.DeclarationAtlas: Dal.Models.Atlas AtlasInfo = BLL.Atlas.GetAtlas(file.CorrelationID.Value, conn, tran); file.SizeLimit = AtlasInfo.SizeLimit; file.AmountLimit = AtlasInfo.UploadLimitMax; break; case Dal.Models.FileType.DeclarationMedia: Dal.Models.Media media = BLL.Media.GetMedia(file.CorrelationID.Value, conn, tran); file.SizeLimit = media.SizeLimit; file.AmountLimit = 1; break; default: file.SizeLimit = 0; file.AmountLimit = 0; break; } } byte[] bufferCompressed = null; StringBuilder sb = new StringBuilder(); int iResult = 0; try { using (System.IO.FileStream StreamToZip = new System.IO.FileStream( strRootDirectory + file.URL, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { double dfileSize = StreamToZip.Length / 1048576; if (dfileSize > file.SizeLimit && file.SizeLimit != 0) { throw new Exception("上传文件大小超过设置范围内!"); } //try //{ // bufferCompressed = Compression.CompressFile(StreamToZip); //} //catch //{ // bufferCompressed = null; //} } if (file.CorrelationID == null) { sb.Append(" select UploadFileID from UploadFile where OwnerID = ? and FileName = ? "); iResult = Common.ToInt32(Dal.OleDbHlper.ExecuteScalar(sb.ToString(), conn, CommandType.Text, tran , new OleDbParameter("@OwnerID", OleDbType.Integer) { Value = file.OwnerID } , new OleDbParameter("@FileName", OleDbType.VarWChar) { Value = file.FileName })) ?? 0; if (iResult > 0 && iResult != file.UploadFileID) { throw new Exception("文件名重名!"); } if (file.UploadFileID == null) { InsertFile(file, bufferCompressed, conn, tran); } else { UpdateFile(file, bufferCompressed, conn, tran); } } else { if (file.Type.ToString() == "DeclarationAtlas") { sb.Append(" select UploadFileID from UploadFile where OwnerID = ? and CorrelationID = ? and FileName = ? "); iResult = Common.ToInt32(Dal.OleDbHlper.ExecuteScalar(sb.ToString(), conn, CommandType.Text, tran , new OleDbParameter("@OwnerID", OleDbType.Integer) { Value = file.OwnerID } , new OleDbParameter("@CorrelationID", OleDbType.Integer) { Value = file.CorrelationID } , new OleDbParameter("@FileName", OleDbType.VarWChar) { Value = file.FileName })) ?? 0; if (iResult == 0) { List <Dal.Models.UploadFileInfo> lstUploadFileInfo = BLL.UploadFileInfo.GetFileList( file.OwnerID, file.CorrelationID, "DeclarationAtlas", conn, tran); if (lstUploadFileInfo.Count() == file.AmountLimit && file.AmountLimit != 0) { throw new Exception("超过数量上限!"); } InsertFile(file, bufferCompressed, conn, tran); } else { if (file.UploadFileID == null || iResult == file.UploadFileID.Value) { file.UploadFileID = iResult; UpdateFile(file, bufferCompressed, conn, tran); } else { throw new Exception("文件名重名!"); } } } else { sb.Append(" select UploadFileID from UploadFile where OwnerID = ? and CorrelationID = ? and TypeCode = ? "); iResult = Common.ToInt32(Dal.OleDbHlper.ExecuteScalar(sb.ToString(), conn, CommandType.Text, tran , new OleDbParameter("@OwnerID", OleDbType.Integer) { Value = file.OwnerID } , new OleDbParameter("@CorrelationID", OleDbType.Integer) { Value = file.CorrelationID } , new OleDbParameter("@TypeCode", OleDbType.VarWChar) { Value = file.Type })) ?? 0; if (iResult > 0) { file.UploadFileID = iResult; UpdateFile(file, bufferCompressed, conn, tran); } else { InsertFile(file, bufferCompressed, conn, tran); } } } } catch (Exception ex) { throw ex; } finally { sb = null; bufferCompressed = null; GC.Collect(); } }
public static void SetAtlas(Dal.Models.Atlas atlas, OleDbConnection conn, OleDbTransaction tran = null) { if (string.IsNullOrEmpty(atlas.AtlasName) || atlas.UploadLimitMax == null || (atlas.PrizeID != null && atlas.SpecialtyID != null) || (atlas.PrizeID == null && atlas.SpecialtyID == null)) { throw new Exception("图集信息不全!"); } if (atlas.UploadLimitMin == null) { atlas.UploadLimitMin = 0; } Dal.Models.AtlasType type = atlas.SpecialtyID == null ? Dal.Models.AtlasType.Prize : Dal.Models.AtlasType.Specialty; int iOwnerID = type == Dal.Models.AtlasType.Specialty ? atlas.SpecialtyID.Value : atlas.PrizeID.Value; string strRecord = type == Dal.Models.AtlasType.Specialty ? "SpecialtyID" : "PrizeID"; Dal.Models.Atlas atlasOriginal = GetAtlas(iOwnerID, type, atlas.AtlasName, conn, tran); if (atlasOriginal != null && atlasOriginal.AtlasID != atlas.AtlasID) { throw new Exception("图集重名!"); } if (atlas.AtlasID == null) { string strSql = " insert into Atlas (" + strRecord + ", Ordinal, AtlasName, UploadLimitMax, UploadLimitMin, SizeLimit, IsRequired) values (?, ?, ?, ?, ?, ?, ?) "; Dal.OleDbHlper.ExecuteNonQuery(strSql, conn, CommandType.Text, tran , new OleDbParameter("@OwnerID", OleDbType.Integer) { Value = iOwnerID } , new OleDbParameter("@Ordinal", OleDbType.Integer) { Value = atlas.Ordinal } , new OleDbParameter("@AtlasName", OleDbType.VarWChar) { Value = atlas.AtlasName } , new OleDbParameter("@UploadLimitMax", OleDbType.Integer) { Value = atlas.UploadLimitMax } , new OleDbParameter("@UploadLimitMin", OleDbType.Integer) { Value = atlas.UploadLimitMin } , new OleDbParameter("@SizeLimit", OleDbType.Integer) { Value = atlas.SizeLimit } , new OleDbParameter("@IsRequired", OleDbType.Boolean) { Value = atlas.IsRequired }); atlas.AtlasID = GetAtlas(iOwnerID, type, atlas.AtlasName, conn, tran).AtlasID; } else { string strSql = " update Atlas set Ordinal = ?, AtlasName = ?, UploadLimitMax = ?, UploadLimitMin = ?, SizeLimit = ?, IsRequired = ? where AtlasID = ?"; Dal.OleDbHlper.ExecuteNonQuery(strSql, conn, CommandType.Text, tran , new OleDbParameter("@Ordinal", OleDbType.Integer) { Value = atlas.Ordinal } , new OleDbParameter("@AtlasName", OleDbType.VarWChar) { Value = atlas.AtlasName } , new OleDbParameter("@UploadLimitMax", OleDbType.Integer) { Value = atlas.UploadLimitMax } , new OleDbParameter("@UploadLimitMin", OleDbType.Integer) { Value = atlas.UploadLimitMin } , new OleDbParameter("@SizeLimit", OleDbType.Integer) { Value = atlas.SizeLimit } , new OleDbParameter("@IsRequired", OleDbType.Boolean) { Value = atlas.IsRequired } , new OleDbParameter("@AtlasID", OleDbType.Integer) { Value = atlas.AtlasID }); } SetOrdinal(atlas, conn, tran); }