asp.net micro-credit development (user group Management) _ Practical skills

Source: Internet
Author: User

The previous article has explained to the new user group, moves the user to the grouping function, this chapter mainly explains modifies the grouping name and deletes the grouping

Directly on the code, nonsense not to say, get the entity classes that you want to use for a grouped list

 <summary>
 ///Sub-group class
 ///</summary> public
 class Wxgroupsinfo
 {public
  string group_id {get; set;} Group numbering public
  string Group_name {get; set;} Group name Public
  string Group_count {get; set;} Group number
 } 

Foreground code:

<! DOCTYPE html>  

The

background code is as follows:
 

protected void Page_Load (object sender, EventArgs e) {if (!
    Page.IsPostBack) {bindgrouplist (); This.
   DataBind ();

   } private void Bindgrouplist () {weixinserver wxs = new Weixinserver ();

   Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

    Getaccesstoken (); Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
   System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.

   LENGTH-37);

   String jsonres = "";

   String content = cache["Allgroups_content"] as String;

    if (content = = null) {jsonres = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=" + access_tokento;
    HttpWebRequest myrequest = (HttpWebRequest) webrequest.create (jsonres);
    Myrequest.method = "Get"; HttpWebResponse myresponse = (httpwebresponse) myrequEst.
    GetResponse ();
    StreamReader reader = new StreamReader (Myresponse.getresponsestream (), Encoding.UTF8); Content = Reader.
    ReadToEnd (); Reader.

    Close (); Set cached data 7,000 seconds after expiration Cache.Insert ("Allgroups_content", content, NULL, DateTime.Now.AddSeconds (7000),
   System.Web.Caching.Cache.NoSlidingExpiration);


   Newtonsoft.json.dll file Jobject jsonobj = jobject.parse (content) should be referenced before use. int groupsnum = jsonobj["groups"].


   Count ();
   
   list<wxgroupsinfo> wxgrouplist = new list<wxgroupsinfo> ();

    for (int i = 0; i < Groupsnum i++) {wxgroupsinfo wginfo = new Wxgroupsinfo (); Wginfo. group_id = jsonobj["groups"][i]["ID".

    ToString (); Wginfo. Group_name = jsonobj["groups"][i]["Name".

    ToString (); Wginfo. Group_count = jsonobj["groups"][i]["Count"].

    ToString (); Wxgrouplist.
   ADD (Wginfo); } this.
   Repeatergrouplist.datasource = wxgrouplist; This.
  Repeatergrouplist.databind (); }///<summary>///binding event///</summary>///<param name= "sender" ></param>///<param name= "E" ></param> protected void Repeater Grouplist_itemdatabound (object sender, RepeaterItemEventArgs e) {if (e.item.itemtype==listitemtype.item| |

    E.item.itemtype==listitemtype.alternatingitem) {Label Lbxuhao = E.item.findcontrol ("Lbxuhao") as label;

    int num = 1; Lbxuhao.text = num.

    ToString (); for (int i = 0; I < this.
     repeatergrouplist.items.count;i++) {num = 1; Lbxuhao.text = num.
    ToString ();

    } LinkButton Linkbtndeletegroup = E.item.findcontrol ("Linkbtndeletegroup") as LinkButton; LINKBTNDELETEGROUP.ATTRIBUTES.ADD ("OnClick", "Return confirm" (' Are you sure you want to delete this group?) After deletion, the people within this group are about to revert to the default group!

   ')"); }///<summary>///execution Event///</summary>///<param name= "source" ></param>///<pa Ram Name= "E" ></param> protected void Repeatergrouplist_itemcommand (object source, RepeaterCommandEventArgs E ) {//scriptmanager.reGisterclientscriptblock (this. Page, this. GetType (), "", "alert (' Remove interface has been closed!
   '); location= ' wxgroupmanagelist.aspx '; ", true);
    if (E.commandname = = "Deletegroups") {weixinserver Wxs = new Weixinserver ();

    string res = "";

    Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

     Getaccesstoken (); Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
    System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.


    LENGTH-37);


    String posturl = "https://api.weixin.qq.com/cgi-bin/groups/delete?access_token=" + access_tokento;

    Post Data example: Post Data example: {"group": {"id": 108}} String GroupID = E.commandargument.tostring (); String postdata = "{\ Group\": {\ "id\": \ "" + GroupID.

    ToString () + "\"}}; res = Wxs.

    GetPage (PostURL, postdata); Scriptmanager.regIsterclientscriptblock (this. Page, this. GetType (), "", "alert (' Delete succeeded! Because of the caching problem, you may need to log on again to see the effect!
   '); location= ' wxgroupmanagelist.aspx '; ", true); }///<summary>///create group///</summary>///<param name= "sender" ></param>///&LT;PA Ram Name= "E" ></param> protected void Linkbtncreategroup_click (object sender, EventArgs e) {if (this.txtgr OupsName.Value.ToString (). Equals ("group name")) {////Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' cannot be empty!
    ') ', true);
    This.txtgroupsName.Focus ();
   Return
   } weixinserver Wxs = new Weixinserver ();

   string res = "";

   Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

    Getaccesstoken (); Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
   System.Web.Caching.Cache.NoSlidingExpiration); String ACCEss_tokento = Access_token. Substring, Access_token.


   LENGTH-37);


   String posturl = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token=" + access_tokento; String postdata = "{\ Group\": {\ "name\": \ "" + this.txtgroupsName.Value.ToString ().


   Trim () + "\"}}; res = Wxs.


   GetPage (PostURL, postdata); Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Create success! If it is not displayed, please exit and login again!
  '); location= ' wxgroupmanagelist.aspx '; ", true);

 }

Modify a page for a grouped name

Foreground code:

<! DOCTYPE html>  

Background code:

 protected void Page_Load (object sender, EventArgs e) {if (! Page.IsPostBack) {if (request.querystring["id"]!= null) {string group_id = request.querystring["id"].
     ToString (); String group_name = request.querystring["Name"].
     ToString (); This.txtGroupId.Text = group_id.
     ToString (); This.txtGroupName.Text = Group_name.
     ToString ();
    This.txtGroupName.Focus (); }}///<summary>///settings///</summary>///<param name= "Sender" ></param>/// ;p Aram Name= "E" ></param> protected void Linkbtnset_click (object sender, EventArgs e) {if (string.isnullorw Hitespace (This.txtGroupName.Text.ToString (). Trim ()) {Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' cannot be empty!
    '); ", true);
    This.txtGroupName.Focus ();
   Return } if (This.txtGroupName.Text.ToString (). Trim (). length>30) {Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert(' group name should be within 30 characters!
    '); ", true);
    This.txtGroupName.Focus ();
   Return
   } weixinserver Wxs = new Weixinserver ();

   string res = "";

   Read Accesstoken string access_token = cache["Access_token" as string from cache; if (Access_token = null) {//if empty, retrieve Access_token = Wxs.

    Getaccesstoken (); Set cached data 7,000 seconds after expiration Cache.Insert ("Access_token", Access_token, NULL, DateTime.Now.AddSeconds (7000),
   System.Web.Caching.Cache.NoSlidingExpiration); String access_tokento = Access_token. Substring, Access_token.


   LENGTH-37);


   String posturl = "https://api.weixin.qq.com/cgi-bin/groups/update?access_token=" + access_tokento; Post Data example: Post Data example: {"group": {"id": 108, "name": "Test2_modify2"}}//string PostData = "{\ Group\": {\ "name\": \ "" + This . txtgroupsName.Value.ToString ().
   Trim () + "\"}}; String postdata = "{\ Group\": {\ "id\": \ "" + txtGroupId.Text.ToString () + "\", "name\": \ "" +


   This.txtGroupName.Text.ToString () + "\"}}; res = Wxs. GetPage (PostURL, pOstdata);

   Use of the pre-required drug reference Newtonsoft.json.dll file Jobject jsonobj = Jobject.parse (res); Gets the correct |true|false that returns the result, string isright = jsonobj["Errcode"]. ToString ();//0 string istrueorfalse = jsonobj["ErrMsg"]. ToString ();//ok if (isright. Equals ("0") && istrueorfalse. Equals ("OK") {///after the successful modification, refresh the parent form and close this page Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Modify success! If not properly displayed, is a cache problem, please login again!
   '); Window.opener.location.reload (); This.close (); ", true); else {Scriptmanager.registerclientscriptblock (this. Page, this. GetType (), "", "alert (' Modify failed!
   '); This.close (); ", true;
 }


  }

This article has been sorted out to the ASP. NET micro-Credit Development tutorial Summary, you are welcome to learn to read.

The above is the user group management of all the core code, only for reference, I hope to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.