protected void Page_Load(object sender, EventArgs e) { int id = RequestTool.RequestInt("id", 0); int pid = RequestTool.RequestInt("pid", 0); model = B_Lebi_weixin_menu.GetModel(id); if (model == null) { model = new Lebi_weixin_menu(); } else { pid = model.parentid; } pmodel = B_Lebi_weixin_menu.GetModel(pid); if (pmodel == null) { pmodel = new Lebi_weixin_menu(); } if (model.url.Contains("weixinlogin=1")) { IsLogin = 1; } }
/// <summary> /// 对象实体绑定数据 /// </summary> public Lebi_weixin_menu ReaderBind(IDataReader dataReader) { Lebi_weixin_menu model = new Lebi_weixin_menu(); object ojb; ojb = dataReader["id"]; if (ojb != null && ojb != DBNull.Value) { model.id = (int)ojb; } model.name = dataReader["name"].ToString(); model.type = dataReader["type"].ToString(); model.url = dataReader["url"].ToString(); ojb = dataReader["Sort"]; if (ojb != null && ojb != DBNull.Value) { model.Sort = (int)ojb; } ojb = dataReader["parentid"]; if (ojb != null && ojb != DBNull.Value) { model.parentid = (int)ojb; } ojb = dataReader["DT_id"]; if (ojb != null && ojb != DBNull.Value) { model.DT_id = (int)ojb; } return(model); }
/// <summary> /// 安全方式绑定对象表单 /// </summary> public Lebi_weixin_menu SafeBindForm(Lebi_weixin_menu model) { if (HttpContext.Current.Request["name"] != null) { model.name = Shop.Tools.RequestTool.RequestSafeString("name"); } if (HttpContext.Current.Request["type"] != null) { model.type = Shop.Tools.RequestTool.RequestSafeString("type"); } if (HttpContext.Current.Request["url"] != null) { model.url = Shop.Tools.RequestTool.RequestSafeString("url"); } if (HttpContext.Current.Request["Sort"] != null) { model.Sort = Shop.Tools.RequestTool.RequestInt("Sort", 0); } if (HttpContext.Current.Request["parentid"] != null) { model.parentid = Shop.Tools.RequestTool.RequestInt("parentid", 0); } if (HttpContext.Current.Request["DT_id"] != null) { model.DT_id = Shop.Tools.RequestTool.RequestInt("DT_id", 0); } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Lebi_weixin_menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [Lebi_weixin_menu] set "); strSql.Append("name= @name,"); strSql.Append("type= @type,"); strSql.Append("url= @url,"); strSql.Append("Sort= @Sort,"); strSql.Append("parentid= @parentid,"); strSql.Append("DT_id= @DT_id"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@name", SqlDbType.NVarChar, 50), new SqlParameter("@type", SqlDbType.NVarChar, 50), new SqlParameter("@url", SqlDbType.NVarChar, 255), new SqlParameter("@Sort", SqlDbType.Int, 4), new SqlParameter("@parentid", SqlDbType.Int, 4), new SqlParameter("@DT_id", SqlDbType.Int, 4) }; parameters[0].Value = model.id; parameters[1].Value = model.name; parameters[2].Value = model.type; parameters[3].Value = model.url; parameters[4].Value = model.Sort; parameters[5].Value = model.parentid; parameters[6].Value = model.DT_id; SqlUtils.SqlUtilsInstance.TextExecuteNonQuery(strSql.ToString(), parameters); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Lebi_weixin_menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [Lebi_weixin_menu]("); strSql.Append("name,type,url,Sort,parentid,DT_id)"); strSql.Append(" values ("); strSql.Append("@name,@type,@url,@Sort,@parentid,@DT_id)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@name", model.name), new SqlParameter("@type", model.type), new SqlParameter("@url", model.url), new SqlParameter("@Sort", model.Sort), new SqlParameter("@parentid", model.parentid), new SqlParameter("@DT_id", model.DT_id) }; object obj = SqlUtils.SqlUtilsInstance.TextExecuteNonQuery(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 保存菜单 /// </summary> public void Menu_Edit() { int id = RequestTool.RequestInt("id", 0); int IsLogin = RequestTool.RequestInt("IsLogin", 0); Lebi_weixin_menu model = B_Lebi_weixin_menu.GetModel(id); bool addflag = false; if (model == null) { model = new Lebi_weixin_menu(); addflag = true; } model = B_Lebi_weixin_menu.BindForm(model); //if (model.parentid == 0) // model.url = ""; if (IsLogin == 1) { if (!model.url.Contains("weixinlogin=1")) { if (model.url.Contains("?")) { model.url += "&weixinlogin=1"; } else { model.url += "?weixinlogin=1"; } } } else { if (model.url.Contains("weixinlogin=1")) { if (model.url.Contains("?")) { model.url = model.url.Replace("?weixinlogin=1", ""); } else { model.url = model.url.Replace("&weixinlogin=1", ""); } } } if (addflag) { B_Lebi_weixin_menu.Add(model); } else { B_Lebi_weixin_menu.Update(model); } Response.Write("{\"msg\":\"OK\"}"); }
/// <summary> /// 删除菜单 /// </summary> public void Menu_Del() { int id = RequestTool.RequestInt("id", 0); Lebi_weixin_menu model = B_Lebi_weixin_menu.GetModel(id); if (model == null) { Response.Write("{\"msg\":\"" + Tag("参数错误") + "\"}"); return; } B_Lebi_weixin_menu.Delete("id=" + id + " or parentid=" + id + ""); Response.Write("{\"msg\":\"OK\"}"); }
/// <summary> /// 下载菜单 /// </summary> public string DownMenu() { try { string res = Get("https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + Token + ""); JavaScriptSerializer jss = new JavaScriptSerializer(); //KeyValue menu = jss.Deserialize<KeyValue>(res); //KeyValue button = jss.Deserialize<KeyValue>(menu.V); Model.weixin.Downmenu dmenu = jss.Deserialize <Model.weixin.Downmenu>(res); //List<Model.weixin.menu> menus = jss.Deserialize<List<Model.weixin.menu>>(button.V); if (dmenu.menu.button != null) { B_Lebi_weixin_menu.Delete("id>0"); int i = 100; foreach (Model.weixin.menu m in dmenu.menu.button) { Lebi_weixin_menu model = new Lebi_weixin_menu(); model.name = m.name; model.Sort = i; model.url = m.url; model.type = m.type; B_Lebi_weixin_menu.Add(model); model.id = B_Lebi_weixin_menu.GetMaxId(); i--; foreach (Model.weixin.menu sm in m.sub_button) { Lebi_weixin_menu smodel = new Lebi_weixin_menu(); smodel.name = sm.name; smodel.Sort = i; smodel.url = sm.url; smodel.type = sm.type; smodel.parentid = model.id; B_Lebi_weixin_menu.Add(smodel); i--; } } } return("OK"); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 得到一个对象实体 by id /// </summary> public Lebi_weixin_menu GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from [Lebi_weixin_menu] "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Lebi_weixin_menu model = new Lebi_weixin_menu(); DataSet ds = SqlUtils.SqlUtilsInstance.TextExecuteDataset(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.name = ds.Tables[0].Rows[0]["name"].ToString(); model.type = ds.Tables[0].Rows[0]["type"].ToString(); model.url = ds.Tables[0].Rows[0]["url"].ToString(); if (ds.Tables[0].Rows[0]["Sort"].ToString() != "") { model.Sort = int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString()); } if (ds.Tables[0].Rows[0]["parentid"].ToString() != "") { model.parentid = int.Parse(ds.Tables[0].Rows[0]["parentid"].ToString()); } if (ds.Tables[0].Rows[0]["DT_id"].ToString() != "") { model.DT_id = int.Parse(ds.Tables[0].Rows[0]["DT_id"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 得到一个对象实体 by where条件 /// </summary> public Lebi_weixin_menu GetModel(string strWhere) { if (strWhere.IndexOf("lbsql{") > 0) { SQLPara para = new SQLPara(strWhere, "", ""); return(GetModel(para)); } StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from [Lebi_weixin_menu] "); strSql.Append(" where " + strWhere + ""); Lebi_weixin_menu model = new Lebi_weixin_menu(); DataSet ds = SqlUtils.SqlUtilsInstance.TextExecuteDataset(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } model.name = ds.Tables[0].Rows[0]["name"].ToString(); model.type = ds.Tables[0].Rows[0]["type"].ToString(); model.url = ds.Tables[0].Rows[0]["url"].ToString(); if (ds.Tables[0].Rows[0]["Sort"].ToString() != "") { model.Sort = int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString()); } if (ds.Tables[0].Rows[0]["parentid"].ToString() != "") { model.parentid = int.Parse(ds.Tables[0].Rows[0]["parentid"].ToString()); } if (ds.Tables[0].Rows[0]["DT_id"].ToString() != "") { model.DT_id = int.Parse(ds.Tables[0].Rows[0]["DT_id"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Lebi_weixin_menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [Lebi_weixin_menu]("); strSql.Append("[name],[type],[url],[Sort],[parentid],[DT_id])"); strSql.Append(" values ("); strSql.Append("@name,@type,@url,@Sort,@parentid,@DT_id)"); OleDbParameter[] parameters = { new OleDbParameter("@name", model.name), new OleDbParameter("@type", model.type), new OleDbParameter("@url", model.url), new OleDbParameter("@Sort", model.Sort), new OleDbParameter("@parentid", model.parentid), new OleDbParameter("@DT_id", model.DT_id) }; AccessUtils.Instance.TextExecuteNonQuery(strSql.ToString(), parameters); return(1); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Lebi_weixin_menu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update [Lebi_weixin_menu] set "); strSql.Append("[name]=@name,"); strSql.Append("[type]=@type,"); strSql.Append("[url]=@url,"); strSql.Append("[Sort]=@Sort,"); strSql.Append("[parentid]=@parentid,"); strSql.Append("[DT_id]=@DT_id"); strSql.Append(" where id=" + model.id); OleDbParameter[] parameters = { new OleDbParameter("@name", model.name), new OleDbParameter("@type", model.type), new OleDbParameter("@url", model.url), new OleDbParameter("@Sort", model.Sort), new OleDbParameter("@parentid", model.parentid), new OleDbParameter("@DT_id", model.DT_id) }; AccessUtils.Instance.TextExecuteNonQuery(strSql.ToString(), parameters); }
/// <summary> /// 更新一条数据 /// </summary> public static void Update(Lebi_weixin_menu model) { D_Lebi_weixin_menu.Instance.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public static int Add(Lebi_weixin_menu model) { return(D_Lebi_weixin_menu.Instance.Add(model)); }
/// <summary> /// 安全方式绑定表单数据 /// </summary> public static Lebi_weixin_menu SafeBindForm(Lebi_weixin_menu model) { return(D_Lebi_weixin_menu.Instance.SafeBindForm(model)); }