private bool DoEdit(int _id) { try { BLL.category bll = new BLL.category(); Model.category model = bll.GetModel(_id); int parentId = int.Parse(ddlParentId.SelectedValue); model.channel_id = this.channel_id; model.call_index = txtCallIndex.Text.Trim(); model.title = txtTitle.Text.Trim(); //如果選擇的父ID不是自己,則更改 if (parentId != model.id) { model.parent_id = parentId; } model.sort_id = int.Parse(txtSortId.Text.Trim()); model.seo_title = txtSeoTitle.Text; model.seo_keywords = txtSeoKeywords.Text; model.seo_description = txtSeoDescription.Text; model.link_url = txtLinkUrl.Text.Trim(); model.img_url = txtImgUrl.Text.Trim(); model.content = txtContent.Value; if (!bll.Update(model)) { return(false); } } catch { return(false); } return(true); }
private void materialButton2_Click(object sender, EventArgs e) { if (saveondatabase) { Category.name = betterTextBox1.Text; Category.updated_at = DateTime.Now; Category.created_at = DateTime.Now; Category.admin_id = INFO.admin_id; db.SaveChanges(); } else { var db = Model.DatabaseConfigure.getConfigure(); var newcate = new Model.category() { name = betterTextBox1.Text, created_at = DateTime.Now, updated_at = DateTime.Now, admin_id = INFO.admin_id, }; db.categories.Add(newcate); db.SaveChanges(); saveondatabase = true; } }
private bool DoAdd() { try { Model.category model = new Model.category(); BLL.category bll = new BLL.category(); model.channel_id = this.channel_id; model.call_index = txtCallIndex.Text.Trim(); model.title = txtTitle.Text.Trim(); model.parent_id = int.Parse(ddlParentId.SelectedValue); model.sort_id = int.Parse(txtSortId.Text.Trim()); model.seo_title = txtSeoTitle.Text; model.seo_keywords = txtSeoKeywords.Text; model.seo_description = txtSeoDescription.Text; model.link_url = txtLinkUrl.Text.Trim(); model.img_url = txtImgUrl.Text.Trim(); model.content = txtContent.Value; if (bll.Add(model) < 1) { return(false); } } catch { return(false); } return(true); }
public Viwer(int id) { InitializeComponent(); Category = db.categories.Find(id); betterTextBox1.Text = Category.name; saveondatabase = true; }
private void ShowInfo(int _id) { BLL.category bll = new BLL.category(); Model.category model = bll.GetModel(_id); this.ddlParentId.SelectedValue = model.parent_id.ToString(); this.txtTitle.Text = model.title; this.txtSortId.Text = model.sort_id.ToString(); this.txtSeoTitle.Text = model.seo_title; this.txtSeoKeywords.Text = model.seo_keywords; this.txtSeoDescription.Text = model.seo_description; this.txtLinkUrl.Text = model.link_url; this.txtImgUrl.Text = model.img_url; this.txtContent.Value = model.content; }
private void SaveButton_Click(object sender, EventArgs e) { var categoryName = CategoryNameField.Text; var categoryDescription = CategoryDescriptionField.Text; var parentCateogryName = ParentCategoryList.Text; using (var dbCtx = new POSApplication.Model.posdbEntities()) { var item = dbCtx.categories.SingleOrDefault(x => x.CategoryName == categoryName); if (item != null && categoryName.CompareTo(item.CategoryName) == 0) { Model.category c = (from x in dbCtx.categories where x.CategoryName == categoryName select x).First(); c.CategoryName = CategoryNameField.Text; c.ParentCategoryID = getCategoryID(ParentCategoryList.Text); c.Description = CategoryDescriptionField.Text; dbCtx.SaveChanges(); MessageBox.Show("Changes Updated Successfully."); } else if (item == null) { if (categoryName == parentCateogryName) { MessageBox.Show("This will result in Category Loop. Please select a different Parent Category."); } else { var r = new Model.category { CategoryName = categoryName, ParentCategoryID = getCategoryID(parentCateogryName), Description = categoryDescription }; dbCtx.categories.Add(r); dbCtx.SaveChanges(); MessageBox.Show("New Category " + categoryName + " has been added."); SuccessfulCategoryAddition(); } } } loadExistingCategories(); loadParentCategoryCombo(); }
/// <summary> /// 修改子节点的ID列表及深度(自身迭代) /// </summary> /// <param name="parent_id"></param> private void UpdateChilds(SqlConnection conn, SqlTransaction trans, int parent_id) { //查找父节点信息 Model.category model = GetModel(conn, trans, parent_id); if (model != null) { //查找子节点 string strSql = "select id from dt_category where parent_id=" + parent_id; DataSet ds = DbHelperSQL.Query(conn, trans, strSql); //带事务 foreach (DataRow dr in ds.Tables[0].Rows) { //修改子节点的ID列表及深度 int id = int.Parse(dr["id"].ToString()); string class_list = model.class_list + id + ","; int class_layer = model.class_layer + 1; DbHelperSQL.ExecuteSql(conn, trans, "update dt_category set class_list='" + class_list + "', class_layer=" + class_layer + " where id=" + id); //带事务 //调用自身迭代 this.UpdateChilds(conn, trans, id); //带事务 } } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.category model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into dt_category("); strSql.Append("channel_id,title,parent_id,class_list,class_layer,sort_id,link_url,img_url,content,seo_title,seo_keywords,seo_description)"); strSql.Append(" values ("); strSql.Append("@channel_id,@title,@parent_id,@class_list,@class_layer,@sort_id,@link_url,@img_url,@content,@seo_title,@seo_keywords,@seo_description)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@parent_id", SqlDbType.Int, 4), new SqlParameter("@class_list", SqlDbType.NVarChar, 500), new SqlParameter("@class_layer", SqlDbType.Int, 4), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@link_url", SqlDbType.NVarChar, 255), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@seo_title", SqlDbType.NVarChar, 255), new SqlParameter("@seo_keywords", SqlDbType.NVarChar, 255), new SqlParameter("@seo_description", SqlDbType.NVarChar, 255) }; parameters[0].Value = model.channel_id; parameters[1].Value = model.title; parameters[2].Value = model.parent_id; parameters[3].Value = model.class_list; parameters[4].Value = model.class_layer; parameters[5].Value = model.sort_id; parameters[6].Value = model.link_url; parameters[7].Value = model.img_url; parameters[8].Value = model.content; parameters[9].Value = model.seo_title; parameters[10].Value = model.seo_keywords; parameters[11].Value = model.seo_description; object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务 model.id = Convert.ToInt32(obj); if (model.parent_id > 0) { Model.category model2 = GetModel(conn, trans, model.parent_id); //带事务 model.class_list = model2.class_list + model.id + ","; model.class_layer = model2.class_layer + 1; } else { model.class_list = "," + model.id + ","; model.class_layer = 1; } //修改节点列表和深度 DbHelperSQL.ExecuteSql(conn, trans, "update dt_category set class_list='" + model.class_list + "', class_layer=" + model.class_layer + " where id=" + model.id); //带事务 trans.Commit(); } catch { trans.Rollback(); return(0); } } } return(model.id); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.category model) { using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString)) { conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //先判断选中的父节点是否被包含 if (IsContainNode(model.id, model.parent_id)) { //查找旧数据 Model.category oldModel = GetModel(model.id); //查找旧父节点数据 string class_list = "," + model.parent_id + ","; int class_layer = 1; if (oldModel.parent_id > 0) { Model.category oldParentModel = GetModel(conn, trans, oldModel.parent_id); //带事务 class_list = oldParentModel.class_list + model.parent_id + ","; class_layer = oldParentModel.class_layer + 1; } //先提升选中的父节点 DbHelperSQL.ExecuteSql(conn, trans, "update dt_category set parent_id=" + oldModel.parent_id + ",class_list='" + class_list + "', class_layer=" + class_layer + " where id=" + model.parent_id); //带事务 UpdateChilds(conn, trans, model.parent_id); //带事务 } //更新子节点 if (model.parent_id > 0) { Model.category model2 = GetModel(conn, trans, model.parent_id); //带事务 model.class_list = model2.class_list + model.id + ","; model.class_layer = model2.class_layer + 1; } else { model.class_list = "," + model.id + ","; model.class_layer = 1; } StringBuilder strSql = new StringBuilder(); strSql.Append("update dt_category set "); strSql.Append("channel_id=@channel_id,"); strSql.Append("title=@title,"); strSql.Append("parent_id=@parent_id,"); strSql.Append("class_list=@class_list,"); strSql.Append("class_layer=@class_layer,"); strSql.Append("sort_id=@sort_id,"); strSql.Append("link_url=@link_url,"); strSql.Append("img_url=@img_url,"); strSql.Append("content=@content,"); strSql.Append("seo_title=@seo_title,"); strSql.Append("seo_keywords=@seo_keywords,"); strSql.Append("seo_description=@seo_description"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@channel_id", SqlDbType.Int, 4), new SqlParameter("@title", SqlDbType.NVarChar, 100), new SqlParameter("@parent_id", SqlDbType.Int, 4), new SqlParameter("@class_list", SqlDbType.NVarChar, 500), new SqlParameter("@class_layer", SqlDbType.Int, 4), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@link_url", SqlDbType.NVarChar, 255), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@seo_title", SqlDbType.NVarChar, 255), new SqlParameter("@seo_keywords", SqlDbType.NVarChar, 255), new SqlParameter("@seo_description", SqlDbType.NVarChar, 255), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.channel_id; parameters[1].Value = model.title; parameters[2].Value = model.parent_id; parameters[3].Value = model.class_list; parameters[4].Value = model.class_layer; parameters[5].Value = model.sort_id; parameters[6].Value = model.link_url; parameters[7].Value = model.img_url; parameters[8].Value = model.content; parameters[9].Value = model.seo_title; parameters[10].Value = model.seo_keywords; parameters[11].Value = model.seo_description; parameters[12].Value = model.id; DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters); //更新子节点 UpdateChilds(conn, trans, model.id); trans.Commit(); } catch { trans.Rollback(); return(false); } } } return(true); }
private void Bind() { BLL.article bll = new BLL.article(); Model.article_goods model = bll.GetGoodsModel(id); if (model != null) { LabTel.Text = model.dianhua; lblConnet.Text = model.lianxiren; lblTitle.Text = model.title; lblContent.Text = model.content; Image1Url = model.img_url; lblSellPrice.Text = model.single_price.ToString(); lblTotalPrice.Text = model.sell_price.ToString(); lblyajin.Text = model.shangpinType.ToString(); lblZjprice.Text = model.market_price.ToString(); //lblzuoxiang.Text = model.zuoxiang; lblpingshu.Text = model.mianji.ToString(); BLL.category bllCata = new BLL.category(); Model.category Cata = bllCata.GetModel(model.xianlu); lblNo.Text = model.shequ; switch (model.category_id) { case 302: hire.Visible = true; sell.Visible = false; break; case 303: hire.Visible = false; sell.Visible = true; break; case 328: hire.Visible = true; sell.Visible = true; break; } //if (Cata != null) //{ // int Pid = Cata.parent_id; // string FirstStaton = bllCata.GetModel(Pid).title; if (model.quyu == 0 || string.IsNullOrEmpty(model.quyu.ToString())) { lblStation.Text = "無資料"; } else { lblStation.Text = model.quyu.ToString() + "%"; } // } lblhuxing.Text = model.stock_quantity == 1 ? "有" : "無"; Cata = bllCata.GetModel(model.category_id); lblxingneng.Text = model.xingneng; lblAge.Text = model.fuwuxiangju.ToString(); if (!string.IsNullOrEmpty(model.link_url)) { lbllouceng.Text = model.link_url.ToString(); } //if (Cata != null) //{ // lblyongtu.Text = Cata.title; //} lblFenQu.Text = GetUserArea(model.point); if (model.jiaqianQJ == 0 || string.IsNullOrEmpty(model.jiaqianQJ.ToString())) { lblchwei.Text = "無資料"; } else { lblchwei.Text = model.jiaqianQJ.ToString() + "%"; } //lblshequ.Text = model.shequ; if (model.huxing == 0 || string.IsNullOrEmpty(model.huxing.ToString())) { lbldizhi.Text = "無資料"; } else { lbldizhi.Text = model.huxing.ToString() + "米"; } string Adress = model.dizhi; string Values = model.goods_no; big5Address = System.Web.HttpUtility.UrlEncode(Adress, Encoding.GetEncoding("UTF-8")); if (!string.IsNullOrEmpty(Values)) { if (Values.IndexOf('|') > 0) { string[] ArrList = Values.Split('|'); X = ArrList[0]; Y = ArrList[1]; } } foreach (var item in model.albums) { Images += " <li><a href='" + item.small_img + "'><img src=\"" + item.small_img + "\" alt=\"" + item.remark + "\" width=\"68\" height=\"50\" rel=\"" + item.big_img + "\"/></a></li>"; } repdateImgae.DataSource = model.albums; repdateImgae.DataBind(); } }
private bool DoAdd() { try { Model.category model = new Model.category(); BLL.category bll = new BLL.category(); model.channel_id = this.channel_id; model.title = txtTitle.Text.Trim(); model.parent_id = int.Parse(ddlParentId.SelectedValue); model.sort_id = int.Parse(txtSortId.Text.Trim()); model.seo_title = txtSeoTitle.Text; model.seo_keywords = txtSeoKeywords.Text; model.seo_description = txtSeoDescription.Text; model.link_url = txtLinkUrl.Text.Trim(); model.img_url = txtImgUrl.Text.Trim(); model.content = txtContent.Value; if (bll.Add(model) < 1) { return false; } } catch { return false; } return true; }
private void Bind() { BLL.article bll = new BLL.article(); Model.article_goods model = bll.GetGoodsModel(id); if (model != null) { p_1.Visible = false; p_2_3.Visible = true; p_2.Visible = false; if (model.category_id == 298) { p_1.Visible = true; p_2_3.Visible = false; p_2.Visible = false; } if (model.category_id == 299) { pingshu.Visible = false; p_1.Visible = false; p_2_3.Visible = false; p_2.Visible = true; } LabTel.Text = model.dianhua; lblConnet.Text = model.lianxiren; lblTitle.Text = model.title; lblSingPrice.Text = model.yongtu; lblContent.Text = model.content; Image1Url = model.img_url; lblprice.Text = model.sell_price.ToString(); //lblyajin.Text = model.yajin.ToString(); lblZjprice.Text = model.sell_price.ToString(); lblzuoxiang.Text = model.zuoxiang; lblpingshu.Text = model.mianji.ToString(); BLL.category bllCata = new BLL.category(); Model.category Cata = bllCata.GetModel(model.xianlu); if (Cata != null) { int Pid = Cata.parent_id; string FirstStaton = bllCata.GetModel(Pid).title; lblStation.Text = FirstStaton + "-" + Cata.title; } lblhuxing.Text = GetTypleWhereTilte(model.huxing, null); Cata = bllCata.GetModel(model.category_id); lblxingneng.Text = model.xingneng; lblAge.Text = model.digg_good.ToString(); if (!string.IsNullOrEmpty(model.louceng)) { lbllouceng.Text = model.louceng.ToString(); } if (Cata != null) { lblyongtu.Text = Cata.title; } lblchwei.Text = model.chewei; lblPort.Text = model.chewei; lblshequ.Text = model.shequ; lbldizhi.Text = model.dizhi; string Adress = model.dizhi; string Values = model.goods_no; big5Address = System.Web.HttpUtility.UrlEncode(Adress, Encoding.GetEncoding("UTF-8")); if (!string.IsNullOrEmpty(Values)) { if (Values.IndexOf('|') > 0) { string[] ArrList = Values.Split('|'); X = ArrList[0]; Y = ArrList[1]; } } foreach (var item in model.albums) { Images += " <li><a href='" + item.small_img + "'><img src=\"" + item.small_img + "\" alt=\"" + item.remark + "\" width=\"68\" height=\"50\" rel=\"" + item.big_img + "\"/></a></li>"; } #region 宴會廳 lblDestTable.Text = model.link_url; //桌數 lblkictich.Text = "無"; if (model.stock_quantity == 1) { lblkictich.Text = "有"; //廚房 } lblStag.Text = "無"; if (model.fangshi == 1) { lblStag.Text = "有"; //舞台 } lblMuisu.Text = "無"; if (model.quyu == 1) { lblMuisu.Text = "無"; //音響 } lbllou1.Text = model.louceng; #endregion #region 戶外廣告 lblForm.Text = model.shangpinType; lblLou2.Text = model.louceng; lblChiCun.Text = model.fuwuxiangju; #endregion repdateImgae.DataSource = model.albums; repdateImgae.DataBind(); } }