Пример #1
0
        private bool DoEdit(int _id)
        {
            bool result = false;

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

            model.title   = txtTitle.Text.Trim();
            model.img_url = txtImgUrl.Text;
            //内容摘要提取内容前500个字符
            if (!string.IsNullOrEmpty(txtRemark.Text.Trim()) && txtRemark.Text.Trim().Length > 500)
            {
                model.remark = Vincent._DTcms.Utils.DropHTML(txtRemark.Text, 500);
            }
            else
            {
                model.remark = txtRemark.Text;
            }
            model.add_time = Vincent._DTcms.Utils.StrToDateTime(txtAddTime.Text.Trim());

            if (bll.Update(model))
            {
                AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Edit.ToString(), "修改" + this.channel_name + "频道内容:" + model.title); //记录日志
                result = true;
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 得到一个对象实体(重载,带事务)
        /// </summary>
        public Model.source_material GetModel(SqlConnection conn, SqlTransaction trans, int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,user_id,title,subtitle,img_url,remark,type,sort_id,add_time from " + databaseprefix + "source_material ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.source_material model = new Model.source_material();
            DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["user_id"] != null && ds.Tables[0].Rows[0]["user_id"].ToString() != "")
                {
                    model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["subtitle"] != null && ds.Tables[0].Rows[0]["subtitle"].ToString() != "")
                {
                    model.subtitle = ds.Tables[0].Rows[0]["subtitle"].ToString();
                }
                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["remark"] != null && ds.Tables[0].Rows[0]["remark"].ToString() != "")
                {
                    model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
                }
                if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "")
                {
                    model.type = int.Parse(ds.Tables[0].Rows[0]["type"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.source_material model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update " + databaseprefix + "source_material set ");
                        strSql.Append("user_id=@user_id,");
                        strSql.Append("title=@title,");
                        strSql.Append("subtitle=@subtitle,");
                        strSql.Append("img_url=@img_url,");
                        strSql.Append("remark=@remark,");
                        strSql.Append("type=@type,");
                        strSql.Append("sort_id=@sort_id,");
                        strSql.Append("add_time=@add_time");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@user_id",  SqlDbType.Int,         4),
                            new SqlParameter("@title",    SqlDbType.NVarChar,  100),
                            new SqlParameter("@subtitle", SqlDbType.NVarChar,  100),
                            new SqlParameter("@img_url",  SqlDbType.NVarChar,  255),
                            new SqlParameter("@remark",   SqlDbType.NVarChar,  500),
                            new SqlParameter("@type",     SqlDbType.Int,         4),
                            new SqlParameter("@sort_id",  SqlDbType.Int,         4),
                            new SqlParameter("@add_time", SqlDbType.DateTime),
                            new SqlParameter("@id",       SqlDbType.Int, 4)
                        };
                        parameters[0].Value = model.user_id;
                        parameters[1].Value = model.title;
                        parameters[2].Value = model.subtitle;
                        parameters[3].Value = model.img_url;
                        parameters[4].Value = model.remark;
                        parameters[5].Value = model.type;
                        parameters[6].Value = model.sort_id;
                        parameters[7].Value = model.add_time;
                        parameters[8].Value = model.id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #4
0
        private void ShowInfo(int _id)
        {
            BLL.source_material   bll   = new BLL.source_material();
            Model.source_material model = bll.GetModel(_id);

            txtAddTime.Text = model.add_time.ToString("yyyy-MM-dd HH:mm:ss");
            if (!string.IsNullOrEmpty(model.img_url))
            {
                txtImgUrl.Text = model.img_url;
            }
            txtTitle.Text  = model.title;
            txtRemark.Text = model.remark;
            txtSortId.Text = model.sort_id.ToString();
        }
Пример #5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.source_material model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "source_material(");
            strSql.Append("user_id,title,subtitle,img_url,remark,type,sort_id,add_time)");
            strSql.Append(" values (");
            strSql.Append("@user_id,@title,@subtitle,@img_url,@remark,@type,@sort_id,@add_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@user_id",  SqlDbType.Int,        4),
                new SqlParameter("@title",    SqlDbType.NVarChar, 100),
                new SqlParameter("@subtitle", SqlDbType.NVarChar, 100),
                new SqlParameter("@img_url",  SqlDbType.NVarChar, 255),
                new SqlParameter("@remark",   SqlDbType.NVarChar, 500),
                new SqlParameter("@type",     SqlDbType.Int,        4),
                new SqlParameter("@sort_id",  SqlDbType.Int,        4),
                new SqlParameter("@add_time", SqlDbType.DateTime)
            };
            parameters[0].Value = model.user_id;
            parameters[1].Value = model.title;
            parameters[2].Value = model.subtitle;
            parameters[3].Value = model.img_url;
            parameters[4].Value = model.remark;
            parameters[5].Value = model.type;
            parameters[6].Value = model.sort_id;
            parameters[7].Value = model.add_time;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Пример #6
0
        private bool DoAdd()
        {
            bool result = false;

            Model.source_material model = new Model.source_material();
            BLL.source_material   bll   = new BLL.source_material();

            model.title    = txtTitle.Text.Trim();
            model.subtitle = txtSubTitle.Text.Trim();
            model.img_url  = txtImgUrl.Text;
            //内容摘要提取内容前500个字符
            if (!string.IsNullOrEmpty(txtRemark.Text.Trim()) && txtRemark.Text.Trim().Length > 500)
            {
                model.remark = Vincent._DTcms.Utils.DropHTML(txtRemark.Text, 500);
            }
            else
            {
                model.remark = txtRemark.Text;
            }
            int user_id = 0;

            if (IsAdminLogin())
            {
                user_id = GetAdminInfo().id;
            }
            model.type     = type;
            model.user_id  = user_id;
            model.add_time = Vincent._DTcms.Utils.StrToDateTime(txtAddTime.Text.Trim());


            if (bll.Add(model) > 0)
            {
                AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Add.ToString(), "添加" + this.channel_name + "频道内容:" + model.title); //记录日志
                result = true;
            }
            return(result);
        }
Пример #7
0
        /// <summary>
        /// 文件上传完成之后并保存到数据库
        /// </summary>
        /// <param name="postedFile">文件流</param>
        /// <returns>上传后文件信息</returns>
        public string fileSaveAs2(HttpPostedFile postedFile)
        {
            try
            {
                string fileExt              = Vincent._DTcms.Utils.GetFileExt(postedFile.FileName);                     //文件扩展名,不含“.”
                int    fileSize             = postedFile.ContentLength;                                                 //获得文件大小,以字节为单位
                string fileName             = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(@"\") + 1); //取得原文件名
                string newFileName          = Vincent._DTcms.Utils.GetRamCode() + "." + fileExt;                        //随机生成新的文件名
                string newThumbnailFileName = "thumb_" + newFileName;                                                   //随机生成缩略图文件名
                string upLoadPath           = GetUpLoadPath();                                                          //上传目录相对路径
                string fullUpLoadPath       = Vincent._DTcms.Utils.GetMapPath(upLoadPath);                              //上传目录的物理路径
                string newFilePath          = upLoadPath + newFileName;                                                 //上传后的路径
                string newThumbnailPath     = upLoadPath + newThumbnailFileName;                                        //上传后的缩略图路径

                //检查文件扩展名是否合法
                if (!CheckFileExt(fileExt))
                {
                    return("{\"status\": 0, \"msg\": \"不允许上传" + fileExt + "类型的文件!\"}");
                }
                //检查文件大小是否合法
                if (!CheckFileSize(fileExt, fileSize))
                {
                    return("{\"status\": 0, \"msg\": \"文件超过限制的大小啦!\"}");
                }
                //检查上传的物理路径是否存在,不存在则创建
                if (!Directory.Exists(fullUpLoadPath))
                {
                    Directory.CreateDirectory(fullUpLoadPath);
                }

                //保存文件
                postedFile.SaveAs(fullUpLoadPath + newFileName);
                //如果是图片,检查图片是否超出最大尺寸,是则裁剪
                if (IsImage(fileExt) && (this.siteConfig.imgmaxheight > 0 || this.siteConfig.imgmaxwidth > 0))
                {
                    Vincent._DTcms.Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newFileName,
                                                                this.siteConfig.imgmaxwidth, this.siteConfig.imgmaxheight);
                }

                #region 保存到数据库
                try
                {
                    Model.source_material model = new Model.source_material();
                    BLL.source_material   bll   = new BLL.source_material();

                    model.img_url = newFilePath; //上传后文件的相对路径
                    Model.users userInfo = HttpContext.Current.Session[Vincent._DTcms.DTKeys.SESSION_USER_INFO] as Model.users;
                    model.type     = 3;          //表示上传的是照片
                    model.user_id  = userInfo != null ? userInfo.id : 0;
                    model.add_time = Vincent._DTcms.Utils.StrToDateTime(DateTime.Now.ToString());
                    bll.Add(model);
                }
                catch (Exception)
                {
                    return("{\"status\": 0, \"msg\": \"图片保存过程中发生意外错误!\"}");
                }
                #endregion

                //处理完毕,返回JOSN格式的文件信息
                return("{\"status\": 1, \"msg\": \"上传文件成功!\", \"name\": \""
                       + fileName + "\", \"path\": \"" + newFilePath + "\", \"thumb\": \""
                       + newThumbnailPath + "\", \"size\": " + fileSize + ", \"ext\": \"" + fileExt + "\"}");
            }
            catch
            {
                return("{\"status\": 0, \"msg\": \"上传过程中发生意外错误!\"}");
            }
        }
Пример #8
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.source_material model)
 {
     return(dal.Update(model));
 }
Пример #9
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.source_material model)
 {
     return(dal.Add(model));
 }