SHARE
TWEET

Untitled

a guest Jun 8th, 2017 31 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public partial class view_classes : System.Web.UI.Page
  2. {
  3.  
  4.     Centre myCentre;
  5.     Member loggedInMember;
  6.  
  7.     protected void Page_Load(object sender, EventArgs e)
  8.     {
  9.         //if statement to make sure the list box will not repoplate if the page is refreshed
  10.         if(!IsPostBack)
  11.         {
  12.             //Binding the listbox to the Product dictionary
  13.             ViewStaff_lb.DataSource = myCentre.getMembers().Select(m => new { id = m.Key, fname = m.Value.FirstName, lname = m.Value.LastName,});
  14.             ViewStaff_lb.DataTextField = "fname";
  15.             ViewStaff_lb.DataTextField = "lname";          
  16.             ViewStaff_lb.DataValueField = "id";
  17.             ViewStaff_lb.DataBind();
  18.         }
  19.  
  20.         if (Session["myCentre"] == null)
  21.         {
  22.             myCentre = new Centre("CCCSportsCentre - Glasgow", "Glasgow, Scotland", "Ryan Grant");
  23.             myCentre.loadMembersFromDB();
  24.  
  25.             Session["myCentre"] = myCentre;
  26.         }
  27.         else
  28.         {
  29.             //load a session variable into normal variable
  30.             myCentre = (Centre)Session["myCentre"];
  31.         }
  32.  
  33.         if (Session["AdminLoggedIn"] == null)
  34.         {
  35.             Response.Redirect("home.aspx");
  36.         }
  37.     }
  38.  
  39.     protected void edit_btn_Click(object sender, EventArgs e)
  40.     {
  41.         string fname = txt_fname.Text;
  42.         string lname = txt_lname.Text;
  43.         string username = txt_username.Text;
  44.         string password = txt_password.Text;
  45.         string dob = txt_dob.Text;
  46.         string email = txt_email.Text;
  47.         string Mtype = txt_mtype.Text;
  48.  
  49.         //make sure all fields are filled
  50.         if (username == "" || password == "" || fname == "" || lname == "" ||dob == "" || email == "" || Mtype == "")          
  51.         {
  52.             lbl_message.Text = "Please enter all details.";
  53.         }
  54.         //if username exists
  55.         else if (myCentre.getMembers().ContainsKey(username))
  56.         {
  57.             lbl_message.Text = "Username is already in use - please try again.";
  58.         }
  59.         //if the admin tries to enter a membership type that isnt valid
  60.         else if(!txt_mtype.Text.Equals("Staff") || !txt_mtype.Text.Equals("Adult") ||
  61.             !txt_mtype.Text.Equals("Child") || !txt_mtype.Text.Equals("Family"))
  62.         {
  63.             lbl_message.Text = "please enter either Adult, Child, Family or Staff for the membership type";
  64.         }
  65.         else
  66.         {
  67.             //gets the selected user from the session and deletes it before adding the new edited membership
  68.             Member selectedMember = (Member)Session["selectedMember"];
  69.             myCentre.clearMembersFromDictionary(selectedMember);
  70.  
  71.             //admin creates a new member for the centre
  72.             Member newMember = new Member(fname, lname, username, password, email, dob, Mtype);
  73.             myCentre.getMembers().Add(username, newMember);
  74.             myCentre.ClearMembersFromDB();
  75.             myCentre.SaveMembersToDB();
  76.  
  77.             Session["selectedMember"] = null;
  78.             lbl_message.Text = "member has been edited!";
  79.         }
  80.     }
  81.  
  82.     protected void addStaff_btn_Click(object sender, EventArgs e)
  83.     {
  84.         string fname = txt_fname.Text;
  85.         string lname = txt_lname.Text;
  86.         string username = txt_username.Text;
  87.         string password = txt_password.Text;
  88.         string dob = txt_dob.Text;
  89.         string email = txt_email.Text;
  90.         string Mtype = txt_mtype.Text;
  91.  
  92.         //if the username exists or text boxes are null then throw error message
  93.         if (username == "" || password == "" || fname == "" || lname == "" ||
  94.              dob == "" || email == "" || Mtype == "")
  95.         {
  96.             lbl_message.Text = "Please enter all details.";
  97.         }
  98.         //if username is in use
  99.         else if (myCentre.getMembers().ContainsKey(username))
  100.         {
  101.             lbl_message.Text = "Username is already in use - please try again.";
  102.         }
  103.         else
  104.         {
  105.             //creates new member
  106.             Member newMember = new Member(fname, lname, username, password, email, dob, Mtype);
  107.             myCentre.getMembers().Add(username, newMember);
  108.             myCentre.ClearMembersFromDB();
  109.             myCentre.SaveMembersToDB();
  110.             lbl_message.Text = "member has been added!";
  111.         }
  112.        
  113.     }
  114.  
  115.     protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
  116.     {
  117.         //retireve the selected item from the list box
  118.         string selectedMemberId = ViewStaff_lb.SelectedValue;
  119.  
  120.         //use id to retrive the correct member from dict
  121.         Member selectedMember = myCentre.getMembers()[selectedMemberId];
  122.  
  123.         //show details in textboxes allowing the staff member to edit the dteails
  124.         txt_id.Text = Convert.ToString(selectedMember.ID);
  125.         txt_fname.Text = Convert.ToString(selectedMember.FirstName);
  126.         txt_lname.Text = Convert.ToString(selectedMember.LastName);
  127.         txt_username.Text = Convert.ToString(selectedMember.Username);
  128.         txt_password.Text = Convert.ToString(selectedMember.Password);
  129.         txt_dob.Text = Convert.ToString(selectedMember.Dob);
  130.         txt_email.Text = Convert.ToString(selectedMember.Email);
  131.         txt_mtype.Text = Convert.ToString(selectedMember.MembershipType);
  132.  
  133.         selectedMember = (Member)Session["selectedMember"];
  134.  
  135.     }
  136.  
  137.     protected void btn_clear_Click(object sender, EventArgs e)
  138.     {
  139.         Response.Redirect("editStaff.aspx");
  140.     }
  141. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top