public static void SetOrdinal(Dal.Models.Appendix appendix, OleDbConnection conn, OleDbTransaction trans = null) { if (appendix == null || appendix.AppendixID == null) { throw new Exception("参数错误!"); } Dal.Models.AppendixType tp = appendix.SpecialtyID == null ? Dal.Models.AppendixType.Prize : Dal.Models.AppendixType.Specialty; int iOwnerID = tp == Dal.Models.AppendixType.Specialty ? appendix.SpecialtyID.Value : appendix.PrizeID.Value; List <Dal.Models.Appendix> lstAppendix = GetAppendixList(iOwnerID, tp, conn, trans).Where(s => s.AppendixID != appendix.AppendixID).ToList(); if (appendix.Ordinal == null || appendix.Ordinal > lstAppendix.Count) { lstAppendix.Add(appendix); } else if (appendix.Ordinal <= 0) { lstAppendix.Insert(0, appendix); } else { lstAppendix.Insert(appendix.Ordinal.Value - 1, appendix); } string strSql = " UPDATE Appendix set Ordinal = ? where AppendixID = ? "; for (int i = 0; i < lstAppendix.Count; i++) { Dal.OleDbHlper.ExecuteNonQuery(strSql, conn, CommandType.Text, trans , new OleDbParameter("@Ordinal", OleDbType.Integer) { Value = i + 1 } , new OleDbParameter("@AppendixID", OleDbType.Integer) { Value = lstAppendix[i].AppendixID.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 SetAppendix(Dal.Models.Appendix appendix, OleDbConnection conn, OleDbTransaction tran = null) { if (string.IsNullOrEmpty(appendix.AppendixName) || appendix.UploadLimitMax == null || (appendix.PrizeID != null && appendix.SpecialtyID != null) || (appendix.PrizeID == null && appendix.SpecialtyID == null)) { throw new Exception("附件集信息不全!"); } if (appendix.UploadLimitMin == null) { appendix.UploadLimitMin = 0; } Dal.Models.AppendixType type = appendix.SpecialtyID == null ? Dal.Models.AppendixType.Prize : Dal.Models.AppendixType.Specialty; int iOwnerID = type == Dal.Models.AppendixType.Specialty ? appendix.SpecialtyID.Value : appendix.PrizeID.Value; string strRecord = type == Dal.Models.AppendixType.Specialty ? "SpecialtyID" : "PrizeID"; Dal.Models.Appendix appendixOriginal = GetAppendix(iOwnerID, type, appendix.AppendixName, conn, tran); if (appendix.AppendixID != null && appendix.AppendixID > 0)//编辑 { string strSql = " update Appendix set Ordinal = ?, AppendixName = ?, UploadLimitMax = ?, UploadLimitMin = ?, SizeLimit = ?, IsRequired = ? where AppendixID = ?"; Dal.OleDbHlper.ExecuteNonQuery(strSql, conn, CommandType.Text, tran , new OleDbParameter("@Ordinal", OleDbType.Integer) { Value = appendix.Ordinal } , new OleDbParameter("@AppendixName", OleDbType.VarWChar) { Value = appendix.AppendixName } , new OleDbParameter("@UploadLimitMax", OleDbType.Integer) { Value = appendix.UploadLimitMax } , new OleDbParameter("@UploadLimitMin", OleDbType.Integer) { Value = appendix.UploadLimitMin } , new OleDbParameter("@SizeLimit", OleDbType.Integer) { Value = appendix.SizeLimit } , new OleDbParameter("@IsRequired", OleDbType.Boolean) { Value = appendix.IsRequired } , new OleDbParameter("@AppendixID", OleDbType.Integer) { Value = appendix.AppendixID }); } else { if (appendixOriginal != null && appendixOriginal.AppendixID != appendix.AppendixID) { throw new Exception("附件重名!"); } else { string strSql = " insert into Appendix (" + strRecord + ", Ordinal, AppendixName, 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 = appendix.Ordinal } , new OleDbParameter("@AppendixName", OleDbType.VarWChar) { Value = appendix.AppendixName } , new OleDbParameter("@UploadLimitMax", OleDbType.Integer) { Value = appendix.UploadLimitMax } , new OleDbParameter("@UploadLimitMin", OleDbType.Integer) { Value = appendix.UploadLimitMin } , new OleDbParameter("@SizeLimit", OleDbType.Integer) { Value = appendix.SizeLimit } , new OleDbParameter("@IsRequired", OleDbType.Boolean) { Value = appendix.IsRequired }); appendix.AppendixID = GetAppendix(iOwnerID, type, appendix.AppendixName, conn, tran).AppendixID; } } SetOrdinal(appendix, conn, tran); }