コード例 #1
0
        private bool DoEdit(int _id)
        {
            try
            {
                BLL.images   bll   = new BLL.images();
                Model.images model = bll.GetModel(_id);

                model.title      = txtName.Text;
                model.link_url   = txtUrl.Text;
                model.img_url    = txtImgUrl.Text;
                model.is_lock    = int.Parse(rblHide.SelectedValue);
                model.sort_id    = Utils.StrToInt(txtSort.Text, 99);
                model.back_color = txtColor.Text;
                model.content    = txtContent.Value;
                model.sign       = txtSign.Text;
                //判断上传图片
                if (this.imgUpload.HasFile)
                {
                    //上传前先删除原图片
                    if (!string.IsNullOrEmpty(model.img_url))
                    {
                        Utils.DeleteFile(model.img_url);
                    }
                    DTcms.Model.upLoad upfile = new Web.UI.UpLoad().fileSaveAs(this.imgUpload.PostedFile, 0, false, false);
                    if (upfile.status > 0)
                    {
                        model.img_url = upfile.path;
                    }
                }
                else
                {
                    //判断是否需要删除原图
                    if (txtImgUrl.Text.Trim() == "" && !string.IsNullOrEmpty(model.img_url))
                    {
                        Utils.DeleteFile(model.img_url);
                    }
                    model.img_url = txtImgUrl.Text.Trim();
                }
                if (bll.Update(model))
                {
                    AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改图片信息" + model.title); //记录日志
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.images model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "images set ");
            strSql.Append("is_lock=@is_lock,");
            strSql.Append("sort_id=@sort_id,");
            strSql.Append("add_time=@add_time,");
            strSql.Append("sign=@sign,");
            strSql.Append("title=@title,");
            strSql.Append("img_url=@img_url,");
            strSql.Append("link_url=@link_url,");
            strSql.Append("back_color=@back_color,");
            strSql.Append("content=@content");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@is_lock",    SqlDbType.TinyInt,     1),
                new SqlParameter("@sort_id",    SqlDbType.Int,         4),
                new SqlParameter("@add_time",   SqlDbType.DateTime),
                new SqlParameter("@sign",       SqlDbType.NVarChar,  255),
                new SqlParameter("@title",      SqlDbType.NVarChar,  255),
                new SqlParameter("@img_url",    SqlDbType.NVarChar,  255),
                new SqlParameter("@link_url",   SqlDbType.NVarChar,  255),
                new SqlParameter("@back_color", SqlDbType.NVarChar,  255),
                new SqlParameter("@content",    SqlDbType.NText),
                new SqlParameter("@id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.is_lock;
            parameters[1].Value = model.sort_id;
            parameters[2].Value = model.add_time;
            parameters[3].Value = model.sign;
            parameters[4].Value = model.title;
            parameters[5].Value = model.img_url;
            parameters[6].Value = model.link_url;
            parameters[7].Value = model.back_color;
            parameters[8].Value = model.content;
            parameters[9].Value = model.id;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// 返回一个实体
        /// </summary>
        public Model.images GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select is_lock,id,sort_id,add_time,sign,title,img_url,link_url,back_color,back_color,content from " + databaseprefix + "images where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                Model.images model = new Model.images();
                if (ds.Tables[0].Rows[0]["is_lock"].ToString() != "")
                {
                    model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString());
                }
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (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());
                }
                model.sign       = ds.Tables[0].Rows[0]["sign"].ToString();
                model.title      = ds.Tables[0].Rows[0]["title"].ToString();
                model.img_url    = ds.Tables[0].Rows[0]["img_url"].ToString();
                model.link_url   = ds.Tables[0].Rows[0]["link_url"].ToString();
                model.back_color = ds.Tables[0].Rows[0]["back_color"].ToString();
                model.content    = ds.Tables[0].Rows[0]["content"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
 private void ShowInfo(int _id)
 {
     BLL.images   bll   = new BLL.images();
     Model.images model = bll.GetModel(_id);
     txtName.Text          = model.title;
     txtUrl.Text           = model.link_url;
     txtSort.Text          = model.sort_id.ToString();
     rblHide.SelectedValue = model.is_lock.ToString();
     txtSign.Text          = model.sign;
     txtColor.Text         = model.back_color;
     txtContent.Value      = model.content;
     txtName.Focus(); //设置焦点,防止JS无法提交
     //图片
     txtImgUrl.Text = model.img_url;
     if (!string.IsNullOrEmpty(model.img_url))
     {
         ImgDiv.Visible  = true;
         ImgUrl.ImageUrl = model.img_url;
     }
 }
コード例 #5
0
        private bool DoAdd()
        {
            try
            {
                BLL.images   bll   = new BLL.images();
                Model.images model = new Model.images();

                model.title      = txtName.Text;
                model.link_url   = txtUrl.Text;
                model.img_url    = txtImgUrl.Text;
                model.is_lock    = int.Parse(rblHide.SelectedValue);
                model.sort_id    = Utils.StrToInt(txtSort.Text, 99);
                model.add_time   = DateTime.Now;
                model.back_color = txtColor.Text;
                model.content    = txtContent.Value;
                model.sign       = txtSign.Text;
                //判断上传图片
                if (this.imgUpload.HasFile)
                {
                    DTcms.Model.upLoad upfile = new Web.UI.UpLoad().fileSaveAs(this.imgUpload.PostedFile, 0, false, false);
                    if (upfile.status > 0)
                    {
                        model.img_url = upfile.path;
                    }
                }
                else
                {
                    model.img_url = txtImgUrl.Text.Trim();
                }
                if (bll.Add(model) > 0)
                {
                    AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "添加图片信息" + model.title); //记录日志
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            return(false);
        }
コード例 #6
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.images model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "images(");
            strSql.Append("is_lock,sort_id,add_time,sign,title,img_url,link_url,back_color,content");
            strSql.Append(") values(");
            strSql.Append("@is_lock,@sort_id,@add_time,@sign,@title,@img_url,@link_url,@back_color,@content)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@is_lock",    SqlDbType.TinyInt,     1),
                new SqlParameter("@sort_id",    SqlDbType.Int,         4),
                new SqlParameter("@add_time",   SqlDbType.DateTime),
                new SqlParameter("@sign",       SqlDbType.NVarChar,  255),
                new SqlParameter("@title",      SqlDbType.NVarChar,  255),
                new SqlParameter("@img_url",    SqlDbType.NVarChar,  255),
                new SqlParameter("@link_url",   SqlDbType.NVarChar,  255),
                new SqlParameter("@back_color", SqlDbType.NVarChar,  255),
                new SqlParameter("@content",    SqlDbType.NText)
            };
            parameters[0].Value = model.is_lock;
            parameters[1].Value = model.sort_id;
            parameters[2].Value = model.add_time;
            parameters[3].Value = model.sign;
            parameters[4].Value = model.title;
            parameters[5].Value = model.img_url;
            parameters[6].Value = model.link_url;
            parameters[7].Value = model.back_color;
            parameters[8].Value = model.content;
            object obj = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.images model)
 {
     return(dal.Update(model));
 }
コード例 #8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.images model)
 {
     return(dal.Add(model));
 }