public static MembersList LoadMembers() { string MRMISGADBConn = ConfigurationManager.ConnectionStrings["MRMISGADBConnect"].ToString(); MRMISGADB db = new MRMISGADB(MRMISGADBConn); MembersList target = new MembersList(); var memb = from p in db.Players orderby p.Name select p; _count = 0; foreach (var item in memb) { MrMember newMember = new MrMember() { pID = item.PlayerID, name = item.Name, fname = item.FName, lname = item.LName, gender = item.Sex, hcp = item.Hcp, memberNumber = item.MemberID, title = item.Title, hdate = item.HDate, del = item.Delete }; newMember.active = SignupList.CountPlayersActiveSignupEntries(item.PlayerID); target.Members.Add(newMember); _count++; } Count = _count; return(target); }
private bool IsInputValid(MrMember memb) { lblErrorMsg.Text = ""; bool ok = true; memb.name = tbMName.Text; memb.memberNumber = tbMid.Text.Trim(); memb.title = tbTitle.Text.Trim(); memb.lname = tbLName.Text.Trim(); memb.fname = tbFName.Text.Trim(); memb.gender = ddlGender.SelectedIndex + 1; memb.hcp = tbHcp.Text.Trim(); memb.hdate = Convert.ToDateTime(tbHDate.Text); memb.pID = Convert.ToInt32(tbPid.Text); if (ddlDel.SelectedIndex == 1) { // Want to delete Member Record // make sure there are no active signup records // if (ActiveSignups > 0) { // have entries for this player in signup database // string verb = (ActiveSignups == 1) ? "is" : "are"; lblErrorMsg.Text = string.Format("Cannot mark member for deletion because there {0} {1} active signup entires", (ActiveSignups == 1)?"is":"are", ActiveSignups); ddlDel.SelectedIndex = 0; // reset drop down list ok = false; } else { ok = true; } } return(ok); }
protected void deletePlayerInfo(MrMember memb) { ActiveSignups = Convert.ToInt32(Session["ActiveSignups"]); playerID = Convert.ToInt32(Session["PlayerID"]); string MRMISGADBConn = ConfigurationManager.ConnectionStrings["MRMISGADBConnect"].ToString(); MRMISGADB db = new MRMISGADB(MRMISGADBConn); var item = db.Players.FirstOrDefault(p => p.PlayerID == memb.pID); if (item != null) { db.Players.DeleteOnSubmit(item); var se = from pl in db.PlayersList where ((pl.PlayerID == memb.pID) && (pl.Marked == 1)) select pl; db.PlayersList.DeleteAllOnSubmit(se); db.SubmitChanges(); Label2.Text = string.Format("Player {0} {1} Deleted.", item.PlayerID, item.Name); } else { lblErrorMsg.Text = string.Format("Player {0} {1} NOT deleted because player does not exist in database!", memb.pID, memb.name); } }
protected void btnDelete_Click(object sender, EventArgs e) { MrMember mInfo = new MrMember(); ActiveSignups = Convert.ToInt32(Session["ActiveSignups"]); playerID = Convert.ToInt32(Session["PlayerID"]); if (IsInputValid(mInfo)) { deletePlayerInfo(mInfo); UpdatePanel1.Visible = false; DisplayPanel.Visible = true; Response.Redirect("editmember.aspx", true); } else { lblErrorMsg.Visible = true; } // Server.Transfer("editmember.aspx"); }
protected void btnSave_Click(object sender, EventArgs e) { MrMember mInfo = new MrMember(); ActiveSignups = Convert.ToInt32(Session["ActiveSignups"]); playerID = Convert.ToInt32(Session["PlayerID"]); if (IsInputValid(mInfo)) { savePlayerInfo(mInfo); UpdatePanel1.Visible = false; DisplayPanel.Visible = true; mlcount = ShowMembers(); lblMemberCount.Visible = false; } else { lblErrorMsg.Visible = true; } }
private void savePlayerInfo(MrMember memb) { string action = ""; string MRMISGADBConn = ConfigurationManager.ConnectionStrings["MRMISGADBConnect"].ToString(); MRMISGADB db = new MRMISGADB(MRMISGADBConn); var item = db.Players.FirstOrDefault(p => p.PlayerID == memb.pID); if (item != null) { item.Name = memb.name; item.LName = memb.lname; item.FName = memb.fname; item.Hcp = memb.hcp; item.HDate = memb.hdate; item.MemberID = memb.memberNumber; item.Sex = memb.gender; item.Title = memb.title; item.Delete = memb.del; action = "updated"; } else { Players p = new Players() { PlayerID = memb.pID, Name = memb.name, LName = memb.lname, FName = memb.fname, Hcp = memb.hcp, HDate = memb.hdate, MemberID = memb.memberNumber, Sex = memb.gender, Title = memb.title, Delete = memb.del }; db.Players.InsertOnSubmit(p); action = "inserted"; } db.SubmitChanges(); Label2.Text = string.Format("{0} {1} {2} in database.", memb.pID, memb.name, action); }