Beispiel #1
0
        public static void UpdateFile(Dal.Models.UploadFileInfo file, byte[] bufferCompressed, OleDbConnection conn, OleDbTransaction tran = null)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(" update UploadFile set FileName = ?, FileContent = ?, URL = ?, UploadTime = ? ");
            sb.Append(" where UploadFileID = ? ");
            Dal.OleDbHlper.ExecuteNonQuery(sb.ToString(), conn, CommandType.Text, tran
                                           , new OleDbParameter("@FileName", OleDbType.VarWChar)
            {
                Value = file.FileName
            }
                                           , new OleDbParameter("@FileContent", OleDbType.VarBinary)
            {
                Value = bufferCompressed
            }
                                           , new OleDbParameter("@URL", OleDbType.VarWChar)
            {
                Value = file.URL
            }
                                           , new OleDbParameter("@UploadTime", OleDbType.Date)
            {
                Value = DateTime.Now
            }
                                           , new OleDbParameter("@UploadFileID", OleDbType.Integer)
            {
                Value = file.UploadFileID
            });
        }
        public void ExportNoticeFile(HttpContext context)
        {
            OleDbConnection conn = new OleDbConnection(Dal.OleDbHlper.ConnectionString);

            conn.Open();

            int iNoticeID = 0;

            int.TryParse(context.Request["NoticeID"] ?? "0", out iNoticeID);
            Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(iNoticeID, null, "NoticeAppendix", conn);
            if (dUploadFileInfo != null)
            {
                try
                {
                    string strServerMapPath = Server.MapPath("/");
                    int    Index1           = dUploadFileInfo.URL.IndexOf("Content");
                    string Path             = strServerMapPath + dUploadFileInfo.URL.Substring(Index1).Replace("\\", "/");
                    DownLoad(context, Path);
                    conn.Close();
                }
                catch (Exception ex)
                {
                    hdMsg.Value = ex.Message;
                }
            }
        }
Beispiel #3
0
        public string GetInnerHtml(Dal.Models.UploadFileInfo UploadFileInfo)
        {
            StringBuilder sbFileName = new StringBuilder();

            sbFileName.AppendFormat("<a>{0}</a>", UploadFileInfo.FileName);
            sbFileName.Append("<br />");
            sbFileName.AppendFormat("<a  onclick='DeleteAppendix({0},{1},{2});return false;' title='删除' href=''>"
                                    , UploadFileInfo.UploadFileID, UploadFileInfo.OwnerID, UploadFileInfo.CorrelationID);
            sbFileName.Append("<i class='fa fa-trash-o'></i></a>");
            sbFileName.AppendFormat("   <a onclick=\'DownloadAppendix({0});return false;\' title='下载' href=''>", UploadFileInfo.UploadFileID);
            sbFileName.Append("<i class='fa fa-download'></i></a>");
            return(sbFileName.ToString());
        }
Beispiel #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(Dal.OleDbHlper.ConnectionString);

            conn.Open();

            // 更新内容
            Dal.Models.UploadFileInfo dUpdateContent = BLL.UploadFileInfo.GetUploadFile(0, 0, "UpdateContent", conn);
            if (dUpdateContent != null)
            {
                UpdateContent.InnerHtml = GetInnerHtml(dUpdateContent);
            }
            else
            {
                UpdateContent.InnerHtml = "暂未上传文件";
            }

            // Sql文
            Dal.Models.UploadFileInfo dUpdateSqlText = BLL.UploadFileInfo.GetUploadFile(0, 0, "UpdateSqlText", conn);
            if (dUpdateSqlText != null)
            {
                UpdateSqlText.InnerHtml = GetInnerHtml(dUpdateSqlText);
            }
            else
            {
                UpdateSqlText.InnerHtml = "暂未上传文件";
            }

            // 发布包
            Dal.Models.UploadFileInfo dUpdatePackage = BLL.UploadFileInfo.GetUploadFile(0, 0, "UpdatePackage", conn);
            if (dUpdatePackage != null)
            {
                UpdatePackage.InnerHtml = GetInnerHtml(dUpdatePackage);
            }
            else
            {
                UpdatePackage.InnerHtml = "暂未上传文件";
            }

            // 源代码
            Dal.Models.UploadFileInfo dUpdateSourceCode = BLL.UploadFileInfo.GetUploadFile(0, 0, "UpdateSourceCode", conn);
            if (dUpdateSourceCode != null)
            {
                UpdateSourceCode.InnerHtml = GetInnerHtml(dUpdateSourceCode);
            }
            else
            {
                UpdateSourceCode.InnerHtml = "暂未上传文件";
            }
            conn.Close();
        }
Beispiel #5
0
        public void InitPage(int id)
        {
            OleDbConnection conn = new OleDbConnection(Dal.OleDbHlper.ConnectionString);

            conn.Open();

            OleDbTransaction tran = conn.BeginTransaction();

            Dal.Models.Notice notice = BLL.Notice.GetNotice(id, conn, tran);
            txtTitle.Text         = notice.Title;
            txtNoticeContent.Text = notice.NoticeContent;
            NoticeID.Value        = id.ToString();
            TbxOrdinal.Text       = notice.Ordinal == null ? "" : notice.Ordinal.ToString();

            lblTitle.Text      = notice.Title;
            lblDate.Text       = Convert.ToDateTime(notice.LastEditTime).ToString("yyyy-MM-dd");
            nContent.InnerHtml = notice.NoticeContent;

            Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(id, null, "NoticeAppendix", conn, tran);
            if (dUploadFileInfo != null)
            {
                StringBuilder sbInnerHtml = new StringBuilder();
                sbInnerHtml.Append(dUploadFileInfo.FileName);
                sbInnerHtml.AppendFormat("<a class='DeleteNoticeAppendix' onclick='DeleteNoticeAppendix({0});return false;' title='删除' href=''>", id);
                sbInnerHtml.Append("<i class='fa fa-trash-o'></i>");
                sbInnerHtml.Append("</a>");
                sbInnerHtml.AppendFormat("   <a class='DownloadNoticeAppendix' onclick=\"DownloadAppendix({0});return false;\" title='下载' href=''>", id);
                sbInnerHtml.Append("<i class='fa fa-download'></i></a></td>");
                tdUploadFileInfo.InnerHtml = sbInnerHtml.ToString();

                tabLookUploadFileInfo.Visible  = true;
                tdLookUploadFileInfo.InnerHtml = sbInnerHtml.ToString();
            }
            else
            {
                tabLookUploadFileInfo.Visible = false;
                tdUploadFileInfo.InnerHtml    = "暂未上传附件!";
            }
            conn.Close();
            hdMsg.Value = "";
        }
Beispiel #6
0
        public static void InsertFile(Dal.Models.UploadFileInfo file, byte[] bufferCompressed, OleDbConnection conn, OleDbTransaction tran = null)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(" insert into UploadFile(TypeCode, OwnerID, CorrelationID, FileName, FileContent, URL, UploadTime) ");
            sb.Append(" values(?, ?, ?, ?, ?, ?, ?) ");
            Dal.OleDbHlper.ExecuteNonQuery(sb.ToString(), conn, CommandType.Text, tran
                                           , new OleDbParameter("@TypeCode", OleDbType.VarWChar)
            {
                Value = file.Type.ToString()
            }
                                           , new OleDbParameter("@OwnerID", OleDbType.Integer)
            {
                Value = file.OwnerID
            }
                                           , new OleDbParameter("@CorrelationID", OleDbType.Integer)
            {
                Value = file.CorrelationID
            }
                                           , new OleDbParameter("@FileName", OleDbType.VarWChar)
            {
                Value = file.FileName
            }
                                           , new OleDbParameter("@FileContent", OleDbType.VarBinary)
            {
                Value = bufferCompressed
            }
                                           , new OleDbParameter("@URL", OleDbType.VarWChar)
            {
                Value = file.URL
            }
                                           , new OleDbParameter("@UploadTime", OleDbType.Date)
            {
                Value = DateTime.Now
            });
        }
Beispiel #7
0
        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();
            }
        }
Beispiel #8
0
        public static void LoadFile(Dal.Models.UploadFileInfo file, OleDbConnection conn, OleDbTransaction tran = null)
        {
            if (file == null || file.UploadFileID == null)
            {
                throw new NullReferenceException("文件编号不允许为空!");
            }

            StringBuilder sb     = new StringBuilder();
            string        strSql = " SELECT UploadFileID,TypeCode,OwnerID,CorrelationID,FileName,URL,UploadTime FROM UploadFile where UploadFileID = ? ";

            IDataReader reader = Dal.OleDbHlper.ExecuteReader(strSql, conn, CommandType.Text, tran
                                                              , new OleDbParameter("@UploadFileID", OleDbType.Integer)
            {
                Value = file.UploadFileID
            });

            if (reader.Read())
            {
                if (string.IsNullOrEmpty(file.URL))
                {
                    file.URL = reader["URL"].ToString();
                }

                file.URL = file.URL.Replace("/", "\\");

                if (file.URL.Contains("Evaluation\\WebSite\\Content"))
                {
                    file.URL = file.URL.Substring(file.URL.IndexOf("Evaluation\\WebSite\\Content") + "Evaluation\\WebSite\\".Length + 1);
                }
            }

            reader.Close();

            string strFileName = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + file.URL;

            if (!File.Exists(strFileName))
            {
                strSql = " SELECT FileContent FROM UploadFile where UploadFileID = ? ";
                reader = Dal.OleDbHlper.ExecuteReader(strSql, conn, CommandType.Text, tran
                                                      , new OleDbParameter("@UploadFileID", OleDbType.Integer)
                {
                    Value = file.UploadFileID
                });

                if (reader.Read())
                {
                    if (reader["FileContent"] != null && reader["FileContent"] != DBNull.Value)
                    {
                        byte[] byteFileContent = (byte[])reader["FileContent"];
                        if (byteFileContent != null && byteFileContent.LongLength > 0)
                        {
                            BLL.Compression.DecompressFile(byteFileContent, strFileName);
                        }
                        else
                        {
                            throw new Exception("找不到指定的文件!");
                        }
                    }
                    else
                    {
                        //throw new Exception("找不到指定的文件!");
                    }
                }
            }
        }
Beispiel #9
0
        protected void lbkConserve_Click(object sender, EventArgs e)
        {
            OleDbConnection conn = new OleDbConnection(Dal.OleDbHlper.ConnectionString);

            conn.Open();

            OleDbTransaction tran            = conn.BeginTransaction();
            string           strActivityType = Session["ActivityType"].ToString();

            Dal.Models.Activity activity = BLL.Activity.GetActivity(strActivityType, conn, tran);
            if (activity == null)
            {
                hdMsg.Value = "当前活动已关闭,请联系活动管理人员!";
                return;
            }

            Dal.Models.Notice notice = new Dal.Models.Notice();
            if (ViewState["NoticeID"] == null)
            {
                try
                {
                    notice.ActivityID    = Convert.ToInt32(activity.ActivityID);
                    notice.Title         = txtTitle.Text.Trim();
                    notice.NoticeContent = txtNoticeContent.Text;
                    notice.CreateTime    = DateTime.Now;
                    notice.EffectTime    = DateTime.Now;//Convert.ToDateTime(txtStartDate.Text);
                    int iOrdinal = 0;
                    if (!string.IsNullOrEmpty(TbxOrdinal.Text) && Int32.TryParse(TbxOrdinal.Text, out iOrdinal))
                    {
                        notice.Ordinal = iOrdinal;//Convert.ToInt32(TbxOrdinal.Text);
                    }
                    ViewState["NoticeID"] = BLL.Notice.CreateNotice(notice, Convert.ToInt32(activity.ActivityID), conn, tran);
                    NoticeID.Value        = ViewState["NoticeID"].ToString();

                    Dal.Models.UploadFileInfo dUploadFileInfo = BLL.UploadFileInfo.GetUploadFile(Convert.ToInt32(NoticeID.Value), null, "NoticeAppendix", conn, tran);
                    if (dUploadFileInfo != null)
                    {
                        StringBuilder sbInnerHtml = new StringBuilder();
                        sbInnerHtml.Append(dUploadFileInfo.FileName);
                        sbInnerHtml.AppendFormat("<a class='DeleteNoticeAppendix' onclick='DeleteNoticeAppendix({0});return false;' title='删除' href=''>", NoticeID.Value);
                        sbInnerHtml.Append("<i class='fa fa-trash-o'></i>");
                        sbInnerHtml.Append("</a>");
                        sbInnerHtml.AppendFormat("   <a class='DownloadNoticeAppendix' onclick=\"DownloadAppendix({0});return false;\" title='下载' href=''>", NoticeID.Value);
                        sbInnerHtml.Append("<i class='fa fa-download'></i></a></td>");

                        tdUploadFileInfo.InnerHtml = sbInnerHtml.ToString();
                    }
                    else
                    {
                        tdUploadFileInfo.InnerHtml = "暂未上传附件!";
                    }
                    tran.Commit();
                    hdMsg.Value = "发布成功!";
                }
                catch (Exception)
                {
                    tran.Rollback();
                    hdMsg.Value = "发布失败!";
                    conn.Close();
                    return;
                }
            }
            else
            {
                UpdateNoticeBack();
            }
            conn.Close();
        }