Exemple #1
0
        /// <summary>
        /// 增加一条数据,及其子表数据
        /// </summary>
        public int Add(Model.image model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into dt_image(");
            strSql.Append("title,sort,img_url,link_url,Typeid,Vipids)");
            strSql.Append(" values (");
            strSql.Append("@title,@sort,@img_url,@link_url,@Typeid,@Vipids)");
            strSql.Append(";set @ReturnValue= @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@title",       SqlDbType.NVarChar,  100),
                new SqlParameter("@sort",        SqlDbType.Int,         4),
                new SqlParameter("@img_url",     SqlDbType.NVarChar,  200),
                new SqlParameter("@link_url",    SqlDbType.NVarChar,  100),
                new SqlParameter("@Typeid",      SqlDbType.Int),
                new SqlParameter("@Vipids",      SqlDbType.NVarChar),
                new SqlParameter("@ReturnValue", SqlDbType.Int)
            };
            parameters[0].Value     = model.title;
            parameters[1].Value     = model.sort;
            parameters[2].Value     = model.img_url;
            parameters[3].Value     = model.link_url;
            parameters[4].Value     = model.Typeid;
            parameters[5].Value     = model.Vipids;
            parameters[6].Direction = ParameterDirection.Output;
            List <CommandInfo> sqllist = new List <CommandInfo>();
            CommandInfo        cmd     = new CommandInfo(strSql.ToString(), parameters);

            sqllist.Add(cmd);
            DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
            return((int)parameters[6].Value);
        }
Exemple #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.image GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from dt_image ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                #region  父表信息
                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]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sort"] != null && ds.Tables[0].Rows[0]["sort"].ToString() != "")
                {
                    model.sort = int.Parse(ds.Tables[0].Rows[0]["sort"].ToString());
                }
                if (ds.Tables[0].Rows[0]["img_url"] != null && ds.Tables[0].Rows[0]["img_url"].ToString() != "")
                {
                    model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString();
                }
                if (ds.Tables[0].Rows[0]["link_url"] != null && ds.Tables[0].Rows[0]["link_url"].ToString() != "")
                {
                    model.link_url = ds.Tables[0].Rows[0]["link_url"].ToString();
                }
                if (ds.Tables[0].Rows[0]["Typeid"] != null && ds.Tables[0].Rows[0]["Typeid"].ToString() != "")
                {
                    model.Typeid = int.Parse(ds.Tables[0].Rows[0]["Typeid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Vipids"] != null && ds.Tables[0].Rows[0]["Vipids"].ToString() != "")
                {
                    model.Vipids = ds.Tables[0].Rows[0]["Vipids"].ToString();
                }
                #endregion  父表信息end



                return(model);
            }
            else
            {
                return(null);
            }
        }
        private bool DoEdit(int _id)
        {
            bool result = true;

            DAL.imagedal bll   = new DAL.imagedal();
            Model.image  model = bll.GetModel(_id);

            model.title = txtTitle.Text.Trim();
            model.sort  = Convert.ToInt32(txtSortId.Text);

            if (fileUpImage.HasFile)
            {
                string extendName = fileUpImage.FileName.Substring(fileUpImage.FileName.LastIndexOf('.'));
                string filename   = DateTime.Now.ToString("yyyyMMddhhmmss") + extendName;
                if (!System.IO.Directory.Exists(Server.MapPath("../upload/file/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("../upload/file/"));
                }

                fileUpImage.SaveAs(Server.MapPath("../upload/file/" + filename));
                model.img_url = "../upload/file/" + filename;
            }
            else
            {
                model.img_url = ViewState["file"] == null ? "" : ViewState["file"].ToString();
            }
            model.Vipids = "";
            bool isSelect = false;

            for (int i = 0; i < checkSysUser.Items.Count; i++)
            {
                if (checkSysUser.Items[i].Selected == true)
                {
                    if (i != 0)
                    {
                        model.Vipids += checkSysUser.Items[i].Value + ",";
                        isSelect      = true;
                    }
                }
            }
            if (isSelect == false)
            {
                model.Vipids = "-1";
            }
            else
            {
                model.Vipids = model.Vipids.Trim(',');
            }

            if (!bll.Update(model))
            {
                result = false;
            }

            return(result);
        }
Exemple #4
0
 private void ShowInfo(int _id)
 {
     DAL.imagedal bll   = new DAL.imagedal();
     Model.image  model = bll.GetModel(_id);
     txtTitle.Text         = model.title;
     txtSortId.Text        = model.sort.ToString();
     txtlink_url.Text      = model.link_url;
     ViewState["file"]     = model.img_url;
     ddlType.SelectedValue = model.Typeid.ToString();
     // LitAlbumList.Text = GetAlbumHtml(model.albums, model.img_url);
 }
Exemple #5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.image model)
 {
     using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
     {
         conn.Open();
         using (SqlTransaction trans = conn.BeginTransaction())
         {
             try
             {
                 StringBuilder strSql = new StringBuilder();
                 strSql.Append("update dt_image set ");
                 strSql.Append("title=@title,");
                 strSql.Append("sort=@sort,");
                 strSql.Append("img_url=@img_url,");
                 strSql.Append("link_url=@link_url,");
                 strSql.Append("Typeid=@Typeid,");
                 strSql.Append("Vipids=@Vipids");
                 strSql.Append(" where id=@id");
                 SqlParameter[] parameters =
                 {
                     new SqlParameter("@title",    SqlDbType.NVarChar,  100),
                     new SqlParameter("@sort",     SqlDbType.Int,         4),
                     new SqlParameter("@img_url",  SqlDbType.NVarChar,  200),
                     new SqlParameter("@link_url", SqlDbType.NVarChar,  100),
                     new SqlParameter("@Typeid",   SqlDbType.Int),
                     new SqlParameter("@Vipids",   SqlDbType.NVarChar),
                     new SqlParameter("@id",       SqlDbType.Int, 4)
                 };
                 parameters[0].Value = model.title;
                 parameters[1].Value = model.sort;
                 parameters[2].Value = model.img_url;
                 parameters[3].Value = model.link_url;
                 parameters[4].Value = model.Typeid;
                 parameters[5].Value = model.Vipids;
                 parameters[6].Value = model.id;
                 DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                 trans.Commit();
             }
             catch
             {
                 trans.Rollback();
                 return(false);
             }
         }
     }
     return(true);
 }
Exemple #6
0
        private bool DoAdd()
        {
            bool result = true;

            Model.image  model = new Model.image();
            DAL.imagedal bll   = new DAL.imagedal();


            model.title    = txtTitle.Text.Trim();
            model.sort     = Convert.ToInt32(txtSortId.Text);
            model.link_url = txtlink_url.Text;
            model.Typeid   = Convert.ToInt32(ddlType.SelectedValue);
            //儲存相冊
            string[] albumArr  = Request.Form.GetValues("hide_photo_name");
            string[] remarkArr = Request.Form.GetValues("hide_photo_remark");

            if (albumArr != null && albumArr.Length >= 0)
            {
                string[] imgArr = albumArr[0].Split('|');
                if (imgArr != null && imgArr.Length >= 1)
                {
                    model.img_url = imgArr[1]; //focus_photo.Value;
                }
            }
            if (fileUpImage.HasFile)
            {
                string extendName = fileUpImage.FileName.Substring(fileUpImage.FileName.LastIndexOf('.'));
                string filename   = DateTime.Now.ToString("yyyyMMddhhmmss") + extendName;
                if (!System.IO.Directory.Exists(Server.MapPath("../upload/logo/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("../upload/logo/"));
                }

                fileUpImage.SaveAs(Server.MapPath("../upload/logo/" + filename));
                string url = HttpContext.Current.Request.Url.Host;
                model.img_url = "http://" + url + "/upload/logo/" + filename;
            }
            if (bll.Add(model) < 1)
            {
                result = false;
            }
            return(result);
        }
        private void ShowInfo(int _id)
        {
            DAL.imagedal bll   = new DAL.imagedal();
            Model.image  model = bll.GetModel(_id);
            txtTitle.Text     = model.title;
            txtSortId.Text    = model.sort.ToString();
            ViewState["file"] = model.img_url;

            // LitAlbumList.Text = GetAlbumHtml(model.albums, model.img_url);

            if (!string.IsNullOrEmpty(model.Vipids))
            {
                for (int i = 0; i < checkSysUser.Items.Count; i++)
                {
                    if (model.Vipids.Contains(checkSysUser.Items[i].Value))
                    {
                        checkSysUser.Items[i].Selected = true;
                    }
                }
            }
        }
Exemple #8
0
        private bool DoEdit(int _id)
        {
            bool result = true;

            DAL.imagedal bll   = new DAL.imagedal();
            Model.image  model = bll.GetModel(_id);

            model.title    = txtTitle.Text.Trim();
            model.sort     = Convert.ToInt32(txtSortId.Text);
            model.link_url = txtlink_url.Text;
            model.Typeid   = Convert.ToInt32(ddlType.SelectedValue);

            if (fileUpImage.HasFile)
            {
                string extendName = fileUpImage.FileName.Substring(fileUpImage.FileName.LastIndexOf('.'));
                string filename   = DateTime.Now.ToString("yyyyMMddhhmmss") + extendName;
                if (!System.IO.Directory.Exists(Server.MapPath("../upload/logo/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("../upload/logo/"));
                }

                fileUpImage.SaveAs(Server.MapPath("../upload/logo/" + filename));
                string url = HttpContext.Current.Request.Url.Host;
                model.img_url = "http://" + url + "/upload/logo/" + filename;
            }
            else
            {
                model.img_url = ViewState["file"] == null ? "" : ViewState["file"].ToString();
            }
            if (!bll.Update(model))
            {
                result = false;
            }

            return(result);
        }
        private bool DoAdd()
        {
            bool result = true;

            Model.image  model = new Model.image();
            DAL.imagedal bll   = new DAL.imagedal();


            model.title = txtTitle.Text.Trim();
            model.sort  = Convert.ToInt32(txtSortId.Text);

            model.Typeid = 3;
            //儲存相冊
            string[] albumArr  = Request.Form.GetValues("hide_photo_name");
            string[] remarkArr = Request.Form.GetValues("hide_photo_remark");

            if (albumArr != null && albumArr.Length >= 0)
            {
                string[] imgArr = albumArr[0].Split('|');
                if (imgArr != null && imgArr.Length >= 1)
                {
                    model.img_url = imgArr[1]; //focus_photo.Value;
                }
            }
            if (fileUpImage.HasFile)
            {
                string extendName = fileUpImage.FileName.Substring(fileUpImage.FileName.LastIndexOf('.'));
                string filename   = DateTime.Now.ToString("yyyyMMddhhmmss") + extendName;
                if (!System.IO.Directory.Exists(Server.MapPath("../upload/file/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("../upload/file/"));
                }

                fileUpImage.SaveAs(Server.MapPath("../upload/file/" + filename));
                model.img_url = "../upload/file/" + filename;
            }

            model.Vipids = "";
            bool isSelect = false;

            for (int i = 0; i < checkSysUser.Items.Count; i++)
            {
                if (checkSysUser.Items[i].Selected == true)
                {
                    model.Vipids += checkSysUser.Items[i].Value + ",";
                    isSelect      = true;
                }
            }
            if (isSelect == false)
            {
                model.Vipids = "-1";
            }
            else
            {
                model.Vipids = model.Vipids.Trim(',');
            }
            if (bll.Add(model) < 1)
            {
                result = false;
            }
            return(result);
        }