Ejemplo n.º 1
0
        private bool DoAdd()
        {
            Model.Forum_Attachment model = new Model.Forum_Attachment();
            BLL.Forum_Attachment   bll   = new BLL.Forum_Attachment();
            //编写添加操作Begin
            //model.Id = txtId.Text;
            //model.UserId = txtUserId.Text;
            //model.BoardId = txtBoardId.Text;
            //model.TopicId = txtTopicId.Text;
            //model.PostId = txtPostId.Text;
            //model.UploadDatetime = txtUploadDatetime.Text;
            //model.Name = txtName.Text;
            //model.FileName = txtFileName.Text;
            //model.Description = txtDescription.Text;
            //model.FileType = txtFileType.Text;
            //model.FileSize = txtFileSize.Text;
            //model.IsImage = txtIsImage.Text;
            //model.Thumb = txtThumb.Text;
            //model.Download = txtDownload.Text;
            //model.Cost = txtCost.Text;
            //model.CostType = txtCostType.Text;
            //编写添加操作End

            if (bll.Add(model) > 0)
            {
                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加dt_Forum_Attachment:"
                            + model.Name); //记录日志
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        private void ShowInfo(int _id)
        {
            BLL.Forum_Attachment   bll   = new BLL.Forum_Attachment();
            Model.Forum_Attachment model = bll.GetModel(_id);
            //编写赋值操作Begin

            //txtId.Text = model.Id;
            //txtUserId.Text = model.UserId;
            //txtBoardId.Text = model.BoardId;
            //txtTopicId.Text = model.TopicId;
            //txtPostId.Text = model.PostId;
            //txtUploadDatetime.Text = model.UploadDatetime;
            //txtName.Text = model.Name;
            //txtFileName.Text = model.FileName;
            //txtDescription.Text = model.Description;
            //txtFileType.Text = model.FileType;
            //txtFileSize.Text = model.FileSize;
            //txtIsImage.Text = model.IsImage;
            //txtThumb.Text = model.Thumb;
            //txtDownload.Text = model.Download;
            //txtCost.Text = model.Cost;
            //txtCostType.Text = model.CostType;

            //编写赋值操作End
        }
Ejemplo n.º 3
0
        private bool DoEdit(int _id)
        {
            bool result = false;

            BLL.Forum_Attachment   bll   = new BLL.Forum_Attachment();
            Model.Forum_Attachment model = bll.GetModel(_id);

            //编写编辑操作Begin
            //model.Id = txtId.Text;
            //model.UserId = txtUserId.Text;
            //model.BoardId = txtBoardId.Text;
            //model.TopicId = txtTopicId.Text;
            //model.PostId = txtPostId.Text;
            //model.UploadDatetime = txtUploadDatetime.Text;
            //model.Name = txtName.Text;
            //model.FileName = txtFileName.Text;
            //model.Description = txtDescription.Text;
            //model.FileType = txtFileType.Text;
            //model.FileSize = txtFileSize.Text;
            //model.IsImage = txtIsImage.Text;
            //model.Thumb = txtThumb.Text;
            //model.Download = txtDownload.Text;
            //model.Cost = txtCost.Text;
            //model.CostType = txtCostType.Text;
            //编写编辑操作End

            if (bll.Update(model))
            {
                AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改管理员:" + model.Name); //记录日志
                result = true;
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.Forum_Attachment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "Forum_Attachment(");
            strSql.Append("UserId,BoardId,TopicId,PostId,UploadDatetime,Name,FileName,Description,FileType,FileSize,IsImage,Thumb,Download,Cost,CostType");
            strSql.Append(") values (");
            strSql.Append("@UserId,@BoardId,@TopicId,@PostId,@UploadDatetime,@Name,@FileName,@Description,@FileType,@FileSize,@IsImage,@Thumb,@Download,@Cost,@CostType");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserId",         SqlDbType.Int,         4),
                new SqlParameter("@BoardId",        SqlDbType.Int,         4),
                new SqlParameter("@TopicId",        SqlDbType.Int,         4),
                new SqlParameter("@PostId",         SqlDbType.Int,         4),
                new SqlParameter("@UploadDatetime", SqlDbType.DateTime),
                new SqlParameter("@Name",           SqlDbType.NVarChar,  256),
                new SqlParameter("@FileName",       SqlDbType.NVarChar,  256),
                new SqlParameter("@Description",    SqlDbType.NVarChar,  128),
                new SqlParameter("@FileType",       SqlDbType.NVarChar,   64),
                new SqlParameter("@FileSize",       SqlDbType.Int,         4),
                new SqlParameter("@IsImage",        SqlDbType.TinyInt,     1),
                new SqlParameter("@Thumb",          SqlDbType.TinyInt,     1),
                new SqlParameter("@Download",       SqlDbType.Int,         4),
                new SqlParameter("@Cost",           SqlDbType.Money,       8),
                new SqlParameter("@CostType",       SqlDbType.TinyInt, 1)
            };

            parameters[0].Value  = model.UserId;
            parameters[1].Value  = model.BoardId;
            parameters[2].Value  = model.TopicId;
            parameters[3].Value  = model.PostId;
            parameters[4].Value  = model.UploadDatetime;
            parameters[5].Value  = model.Name;
            parameters[6].Value  = model.FileName;
            parameters[7].Value  = model.Description;
            parameters[8].Value  = model.FileType;
            parameters[9].Value  = model.FileSize;
            parameters[10].Value = model.IsImage;
            parameters[11].Value = model.Thumb;
            parameters[12].Value = model.Download;
            parameters[13].Value = model.Cost;
            parameters[14].Value = model.CostType;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 删除一条数据,扩展方法无需重复调用,因为要删掉真实的文件
        /// </summary>
        public bool Delete(Model.Forum_Attachment model, int Id)
        {
            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.FileName))
                {
                    DTcms.Common.Utils.DeleteFile(model.FileName);
                }
            }

            return(dal.Delete(Id));
        }
Ejemplo n.º 6
0
        private void delete(HttpContext context)
        {
            if (modelUser != null)
            {
                Model.Forum_Attachment model = bll.GetModel(aid);

                if (model.UserId == modelUser.UserId)
                {
                    bll.Delete(model, aid);
                    context.Response.AddHeader("Content-Type", "text/html");
                    context.Response.Write("ok!");
                    context.Response.End();
                }
            }
        }
Ejemplo n.º 7
0
        private void down(HttpContext context)
        {
            Model.Forum_Attachment model = bll.GetModel(aid);

            if (!BLL.Forum_BoardPermission.CheckPermission(model.BoardId + "|" + modelUser.GroupId, "ViewAttachment"))
            {
                context.Response.Redirect(new Web.UI.BasePage().getlink(sitepath,
                                                                        new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("出错了,你还没有下载附件的权限呢!"))));

                return;
            }


            if (model != null)
            {
                //取得文件物理路径
                string fullFileName = Utils.GetMapPath(model.FileName);
                if (!File.Exists(fullFileName))
                {
                    context.Response.Redirect(new Web.UI.BasePage().getlink(sitepath,
                                                                            new Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("出错了,您要下载的文件不存在或已经被删除!"))));
                    return;
                }

                model.Download += 1;
                bll.Update(model);

                FileInfo file = new FileInfo(fullFileName);                                                                     //路径
                context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");                                   //解决中文乱码
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(model.Name)); //解决中文文件名乱码
                context.Response.AddHeader("Content-length", file.Length.ToString());
                context.Response.ContentType = "application/zip";
                context.Response.WriteFile(file.FullName);
                context.Response.End();
            }
        }
Ejemplo n.º 8
0
        private void EditorHandler(HttpContext context, string name)
        {
            //检查用户是否登录
            modelUser = new Page.ForumPage().GetOnlineUser();
            if (modelUser == null)
            {
                context.Response.Write("{\"status\":0, \"msg\":\"对不起,用户尚未登录或已超时!\"}");
                return;
            }

            string fieldName = "upfile";

            string[] allowExtensions = null;
            int      sizeLimit       = 0;

            switch (name)
            {
            case "image":
                sizeLimit       = siteConfig.imgsize;
                allowExtensions = siteConfig.fileextension.Split(',');
                break;

            case "scrawl":
                sizeLimit       = 2048000;
                allowExtensions = new string[] { ".png" };
                break;

            case "video":
                sizeLimit       = siteConfig.videosize;
                allowExtensions = siteConfig.videoextension.Split(',');
                break;

            case "file":
                sizeLimit       = siteConfig.attachsize;
                allowExtensions = siteConfig.fileextension.Split(',');
                break;

            default:
                JsonHelper.WriteJson(context, new
                {
                    status = "参数传输错误!"
                });
                return;
            }
            if (sizeLimit <= 0 || allowExtensions.Length == 0)
            {
                JsonHelper.WriteJson(context, new
                {
                    status = "参数传输错误!"
                });
                return;
            }
            if (name == "scrawl")
            {
                string uploadFileName  = Utils.GetRamCode() + ".png";
                byte[] uploadFileBytes = Convert.FromBase64String(context.Request[fieldName]);

                string Url                = new UpLoad().GetUpLoadPath() + uploadFileName;
                string localPath          = Utils.GetMapPath(Url);
                string ErrorMessage       = string.Empty;
                DTEnums.ResultState State = DTEnums.ResultState.Success;
                try
                {
                    if (!Directory.Exists(Path.GetDirectoryName(localPath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(localPath));
                    }
                    File.WriteAllBytes(localPath, uploadFileBytes);
                    State = DTEnums.ResultState.Success;
                }
                catch (Exception e)
                {
                    State        = DTEnums.ResultState.FileAccessError;
                    ErrorMessage = e.Message;
                }
                JsonHelper.WriteJson(context, new
                {
                    state    = Utils.GetStateString(State),
                    url      = Url,
                    title    = uploadFileName,
                    original = uploadFileName,
                    error    = ErrorMessage
                });
            }
            else
            {
                context.Response.ContentType = "text/plain";
                HttpPostedFile _upfile = context.Request.Files[fieldName];
                Model.upLoad   model   = new UpLoad().fileSaveAs(_upfile, allowExtensions, sizeLimit, false, false, 0, 0);

                if (model.status > 0)
                {
                    //{"aid":374,"name":"27.gif","filename":"2016/11/02/4225885467939.gif","isimage":true}

                    Model.Forum_Attachment attModel = new Model.Forum_Attachment();

                    attModel.IsImage  = 1;
                    attModel.Name     = model.name;
                    attModel.BoardId  = board_id;
                    attModel.TopicId  = topic_id;
                    attModel.PostId   = post_id;
                    attModel.FileName = model.path;
                    attModel.FileSize = model.size / 1024;;
                    attModel.FileType = model.ext.Replace(".", "");
                    attModel.UserId   = modelUser.UserId;

                    attModel.Id = new BLL.Forum_Attachment().Add(attModel);


                    string callback = context.Request["callback"];
                    string editorId = context.Request["editorid"];

                    JsonHelper.WriteJson(context, new
                    {
                        state        = "SUCCESS",
                        type         = "." + model.ext,
                        size         = model.size / 1024,
                        url          = model.path,
                        name         = model.name,
                        originalName = model.name
                    });
                }
                else
                {
                    JsonHelper.WriteJson(context, new
                    {
                        status = model.msg
                    });
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Forum_Attachment DataRowToModel(DataRow row)
        {
            if (row != null)
            {
                Model.Forum_Attachment model = new Model.Forum_Attachment();

                if (row["Id"].ToString() != "")
                {
                    model.Id = int.Parse(row["Id"].ToString());
                }
                if (row["UserId"].ToString() != "")
                {
                    model.UserId = int.Parse(row["UserId"].ToString());
                }
                if (row["BoardId"].ToString() != "")
                {
                    model.BoardId = int.Parse(row["BoardId"].ToString());
                }
                if (row["TopicId"].ToString() != "")
                {
                    model.TopicId = int.Parse(row["TopicId"].ToString());
                }
                if (row["PostId"].ToString() != "")
                {
                    model.PostId = int.Parse(row["PostId"].ToString());
                }
                if (row["UploadDatetime"].ToString() != "")
                {
                    model.UploadDatetime = DateTime.Parse(row["UploadDatetime"].ToString());
                }
                model.Name        = row["Name"].ToString();
                model.FileName    = row["FileName"].ToString();
                model.Description = row["Description"].ToString();
                model.FileType    = row["FileType"].ToString();
                if (row["FileSize"].ToString() != "")
                {
                    model.FileSize = int.Parse(row["FileSize"].ToString());
                }
                if (row["IsImage"].ToString() != "")
                {
                    model.IsImage = int.Parse(row["IsImage"].ToString());
                }
                if (row["Thumb"].ToString() != "")
                {
                    model.Thumb = int.Parse(row["Thumb"].ToString());
                }
                if (row["Download"].ToString() != "")
                {
                    model.Download = int.Parse(row["Download"].ToString());
                }
                if (row["Cost"].ToString() != "")
                {
                    model.Cost = decimal.Parse(row["Cost"].ToString());
                }
                if (row["CostType"].ToString() != "")
                {
                    model.CostType = int.Parse(row["CostType"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Forum_Attachment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "Forum_Attachment set ");

            strSql.Append(" UserId = @UserId , ");
            strSql.Append(" BoardId = @BoardId , ");
            strSql.Append(" TopicId = @TopicId , ");
            strSql.Append(" PostId = @PostId , ");
            strSql.Append(" UploadDatetime = @UploadDatetime , ");
            strSql.Append(" Name = @Name , ");
            strSql.Append(" FileName = @FileName , ");
            strSql.Append(" Description = @Description , ");
            strSql.Append(" FileType = @FileType , ");
            strSql.Append(" FileSize = @FileSize , ");
            strSql.Append(" IsImage = @IsImage , ");
            strSql.Append(" Thumb = @Thumb , ");
            strSql.Append(" Download = @Download , ");
            strSql.Append(" Cost = @Cost , ");
            strSql.Append(" CostType = @CostType  ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",             SqlDbType.Int,         4),
                new SqlParameter("@UserId",         SqlDbType.Int,         4),
                new SqlParameter("@BoardId",        SqlDbType.Int,         4),
                new SqlParameter("@TopicId",        SqlDbType.Int,         4),
                new SqlParameter("@PostId",         SqlDbType.Int,         4),
                new SqlParameter("@UploadDatetime", SqlDbType.DateTime),
                new SqlParameter("@Name",           SqlDbType.NVarChar,  256),
                new SqlParameter("@FileName",       SqlDbType.NVarChar,  256),
                new SqlParameter("@Description",    SqlDbType.NVarChar,  128),
                new SqlParameter("@FileType",       SqlDbType.NVarChar,   64),
                new SqlParameter("@FileSize",       SqlDbType.Int,         4),
                new SqlParameter("@IsImage",        SqlDbType.TinyInt,     1),
                new SqlParameter("@Thumb",          SqlDbType.TinyInt,     1),
                new SqlParameter("@Download",       SqlDbType.Int,         4),
                new SqlParameter("@Cost",           SqlDbType.Money,       8),
                new SqlParameter("@CostType",       SqlDbType.TinyInt, 1)
            };

            parameters[0].Value  = model.Id;
            parameters[1].Value  = model.UserId;
            parameters[2].Value  = model.BoardId;
            parameters[3].Value  = model.TopicId;
            parameters[4].Value  = model.PostId;
            parameters[5].Value  = model.UploadDatetime;
            parameters[6].Value  = model.Name;
            parameters[7].Value  = model.FileName;
            parameters[8].Value  = model.Description;
            parameters[9].Value  = model.FileType;
            parameters[10].Value = model.FileSize;
            parameters[11].Value = model.IsImage;
            parameters[12].Value = model.Thumb;
            parameters[13].Value = model.Download;
            parameters[14].Value = model.Cost;
            parameters[15].Value = model.CostType;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.Forum_Attachment model)
 {
     return(dal.Update(model));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.Forum_Attachment model)
 {
     return(dal.Add(model));
 }