Exemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体(重载,带事务)
        /// </summary>
        public Model.brand GetModel(SqlConnection conn, SqlTransaction trans, int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,brandName,brandImgUrl,remark,isLock,managerId,sort_id,add_time,update_time from " + databaseprefix + "brand ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.brand model = new Model.brand();
            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]["brandName"] != null && ds.Tables[0].Rows[0]["brandName"].ToString() != "")
                {
                    model.brandName = ds.Tables[0].Rows[0]["brandName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["brandImgUrl"] != null && ds.Tables[0].Rows[0]["brandImgUrl"].ToString() != "")
                {
                    model.brandImgUrl = ds.Tables[0].Rows[0]["brandImgUrl"].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]["isLock"] != null && ds.Tables[0].Rows[0]["isLock"].ToString() != "")
                {
                    model.isLock = int.Parse(ds.Tables[0].Rows[0]["isLock"].ToString());
                }
                if (ds.Tables[0].Rows[0]["managerId"] != null && ds.Tables[0].Rows[0]["managerId"].ToString() != "")
                {
                    model.managerId = int.Parse(ds.Tables[0].Rows[0]["managerId"].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());
                }
                if (ds.Tables[0].Rows[0]["update_time"].ToString() != "")
                {
                    model.update_time = DateTime.Parse(ds.Tables[0].Rows[0]["update_time"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private void ShowInfo(int _id)
        {
            BLL.brand   bll   = new BLL.brand();
            Model.brand model = bll.GetModel(_id);

            txtAddTime.Text = model.add_time.ToString("yyyy-MM-dd HH:mm:ss");
            if (!string.IsNullOrEmpty(model.brandImgUrl))
            {
                txtBrandImgUrl.Text = model.brandImgUrl;
            }
            txtBrandName.Text       = model.brandName;
            txtRemark.Text          = model.remark;
            txtSortId.Text          = model.sort_id.ToString();
            rblIsLock.SelectedValue = model.isLock.ToString();
            //图片列表
            rptAlbumList.DataSource = model.brand_attach;
            rptAlbumList.DataBind();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.brand model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "brand(");
            strSql.Append("brandName,brandImgUrl,remark,isLock,managerId,sort_id,add_time,update_time)");
            strSql.Append(" values (");
            strSql.Append("@brandName,@brandImgUrl,@remark,@isLock,@managerId,@sort_id,@add_time,@update_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@brandName",   SqlDbType.NVarChar,   20),
                new SqlParameter("@brandImgUrl", SqlDbType.NVarChar,   50),
                new SqlParameter("@remark",      SqlDbType.NVarChar,  500),
                new SqlParameter("@isLock",      SqlDbType.Int,         4),
                new SqlParameter("@managerId",   SqlDbType.Int,         4),
                new SqlParameter("@sort_id",     SqlDbType.Int,         4),
                new SqlParameter("@add_time",    SqlDbType.DateTime),
                new SqlParameter("@update_time", SqlDbType.DateTime)
            };
            parameters[0].Value = model.brandName;
            parameters[1].Value = model.brandImgUrl;
            parameters[2].Value = model.remark;
            parameters[3].Value = model.isLock;
            parameters[4].Value = model.managerId;
            parameters[5].Value = model.sort_id;
            parameters[6].Value = model.add_time;
            parameters[7].Value = model.update_time;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.brand model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update " + databaseprefix + "brand set ");
                        strSql.Append("brandName=@brandName,");
                        strSql.Append("brandImgUrl=@brandImgUrl,");
                        strSql.Append("remark=@remark,");
                        strSql.Append("isLock=@isLock,");
                        strSql.Append("managerId=@managerId,");
                        strSql.Append("sort_id=@sort_id,");
                        strSql.Append("add_time=@add_time,");
                        strSql.Append("update_time=@update_time");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@brandName",   SqlDbType.NVarChar,   20),
                            new SqlParameter("@brandImgUrl", SqlDbType.NVarChar,   50),
                            new SqlParameter("@remark",      SqlDbType.NVarChar,  500),
                            new SqlParameter("@isLock",      SqlDbType.Int,         4),
                            new SqlParameter("@managerId",   SqlDbType.Int,         4),
                            new SqlParameter("@sort_id",     SqlDbType.Int,         4),
                            new SqlParameter("@add_time",    SqlDbType.DateTime),
                            new SqlParameter("@update_time", SqlDbType.DateTime),
                            new SqlParameter("@id",          SqlDbType.Int, 4)
                        };
                        parameters[0].Value = model.brandName;
                        parameters[1].Value = model.brandImgUrl;
                        parameters[2].Value = model.remark;
                        parameters[3].Value = model.isLock;
                        parameters[4].Value = model.managerId;
                        parameters[5].Value = model.sort_id;
                        parameters[6].Value = model.add_time;
                        parameters[7].Value = model.update_time;
                        parameters[8].Value = model.id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        #region 添加/修改相册
                        //删除原有的数据
                        bool bl = new brand_attach().Delete(" brand_id=" + model.id);
                        //添加、修改相册
                        if (model.brand_attach != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.brand_attach modelt in model.brand_attach)
                            {
                                strSql2 = new StringBuilder();
                                if (modelt.id > 0)
                                {
                                    strSql2.Append("update " + databaseprefix + "brand_attach set ");
                                    strSql2.Append("brand_id=@brand_id,");
                                    strSql2.Append("theme_id=@theme_id,");
                                    strSql2.Append("size=@size,");
                                    strSql2.Append("img_url=@img_url,");
                                    strSql2.Append("remark=@remark");
                                    strSql2.Append("small_imgurl=@small_imgurl");
                                    strSql2.Append("add_time=@add_time");
                                    strSql2.Append(" where id=@id");
                                    SqlParameter[] parameters2 =
                                    {
                                        new SqlParameter("@brand_id",     SqlDbType.Int,         4),
                                        new SqlParameter("@theme_id",     SqlDbType.Int,         4),
                                        new SqlParameter("@size",         SqlDbType.NChar,      10),
                                        new SqlParameter("@img_url",      SqlDbType.NChar,     100),
                                        new SqlParameter("@remark",       SqlDbType.NVarChar,  100),
                                        new SqlParameter("@small_imgurl", SqlDbType.NChar,     100),
                                        new SqlParameter("@add_time",     SqlDbType.DateTime),
                                        new SqlParameter("@id",           SqlDbType.Int, 4)
                                    };
                                    parameters2[0].Value = modelt.brand_id;
                                    parameters2[1].Value = modelt.theme_id;
                                    parameters2[2].Value = modelt.size;
                                    parameters2[3].Value = modelt.img_url;
                                    parameters2[4].Value = modelt.remark;
                                    parameters2[5].Value = modelt.small_imgurl;
                                    parameters2[6].Value = modelt.add_time;
                                    parameters2[7].Value = modelt.id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                                }
                                else
                                {
                                    strSql2.Append("insert into " + databaseprefix + "brand_attach(");
                                    strSql2.Append("brand_id,theme_id,size,img_url,remark,small_imgurl,add_time)");
                                    strSql2.Append(" values (");
                                    strSql2.Append("@brand_id,@theme_id,@size,@img_url,@remark,@small_imgurl,@add_time)");
                                    strSql2.Append(";select @@IDENTITY");
                                    SqlParameter[] parameters2 =
                                    {
                                        new SqlParameter("@brand_id",     SqlDbType.Int,        4),
                                        new SqlParameter("@theme_id",     SqlDbType.Int,        4),
                                        new SqlParameter("@size",         SqlDbType.NChar,     10),
                                        new SqlParameter("@img_url",      SqlDbType.NChar,    100),
                                        new SqlParameter("@remark",       SqlDbType.NVarChar, 100),
                                        new SqlParameter("@small_imgurl", SqlDbType.NChar,    100),
                                        new SqlParameter("@add_time",     SqlDbType.DateTime)
                                    };
                                    parameters2[0].Value = modelt.brand_id;
                                    parameters2[1].Value = modelt.theme_id;
                                    parameters2[2].Value = modelt.size;
                                    parameters2[3].Value = modelt.img_url;
                                    parameters2[4].Value = modelt.remark;
                                    parameters2[5].Value = modelt.small_imgurl;
                                    parameters2[6].Value = modelt.add_time;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                                }
                            }
                        }

                        #endregion

                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.brand model)
 {
     return(dal.Update(model));
 }
Exemplo n.º 6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.brand model)
 {
     return(dal.Add(model));
 }
Exemplo n.º 7
0
        private bool DoEdit(int _id)
        {
            bool result = false;

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

            model.brandName   = txtBrandName.Text.Trim();
            model.brandImgUrl = txtBrandImgUrl.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.isLock  = Vincent._DTcms.Utils.StrToInt(this.rblIsLock.SelectedValue, 1);
            model.sort_id = Vincent._DTcms.Utils.StrToInt(txtSortId.Text.Trim(), 99);
            int managerId = 0;

            if (IsAdminLogin())
            {
                managerId = GetAdminInfo().id;
            }
            model.managerId   = managerId;
            model.add_time    = Vincent._DTcms.Utils.StrToDateTime(txtAddTime.Text.Trim());
            model.update_time = DateTime.Now;


            #region 保存相册====================
            //检查是否有自定义图片
            if (txtBrandImgUrl.Text.Trim() == "")
            {
                model.brandImgUrl = hidFocusPhoto.Value;
            }
            if (model.brand_attach != null)
            {
                model.brand_attach.Clear();
            }
            string[] albumArr    = Request.Form.GetValues("hid_photo_name");
            string[] remarkArr   = Request.Form.GetValues("hid_photo_remark");
            string[] categoryArr = Request.Form.GetValues("hid_photo_category");
            string[] sizeArr     = Request.Form.GetValues("hid_photo_size");
            if (albumArr != null)
            {
                List <Model.brand_attach> ls = new List <Model.brand_attach>();
                for (int i = 0; i < albumArr.Length; i++)
                {
                    string[] imgArr = albumArr[i].Split('|');
                    int      img_id = Vincent._DTcms.Utils.StrToInt(imgArr[0], 0);
                    if (imgArr.Length == 3)
                    {
                        if (!string.IsNullOrEmpty(remarkArr[i]))
                        {
                            ls.Add(new Model.brand_attach {
                                brand_id     = _id,
                                theme_id     = Vincent._DTcms.Utils.StrToInt(categoryArr[i], 0),
                                img_url      = imgArr[1].Trim(),
                                small_imgurl = imgArr[2].Trim(),
                                remark       = remarkArr[i],
                                size         = sizeArr[i].Trim()
                            });
                        }
                        else
                        {
                            ls.Add(new Model.brand_attach {
                                brand_id     = _id,
                                theme_id     = Vincent._DTcms.Utils.StrToInt(categoryArr[i], 0),
                                img_url      = imgArr[1].Trim(),
                                small_imgurl = imgArr[2].Trim(),
                                size         = sizeArr[i].Trim()
                            });
                        }
                    }
                }
                model.brand_attach = ls;
            }
            #endregion

            if (bll.Update(model))
            {
                AddAdminLog(Vincent._DTcms.DTEnums.ActionEnum.Edit.ToString(), "修改" + this.channel_name + "频道内容:" + model.brandName); //记录日志
                result = true;
            }

            return(result);
        }