protected void Page_Load(object sender, EventArgs e) { _db = new MyFamilyDatabaseDataContext(); short occId = 0; if (!short.TryParse(Request["OccupationId"] ?? "0", out occId)) { _OccupationId = null; } else { _OccupationId = occId; } PersonInfo pInfo = Session["LogedInUserInfo"] as PersonInfo; if (pInfo != null) { lblLogin.Text = string.Format("Welcome <a href='./PersonInfo.aspx?PersonID={0}'>{1}</a>", pInfo.PersonID, pInfo.FullName); } else { lblLogin.Text = "<a href='./LoginPage.aspx'>Login</a>"; } }
protected void LinqDataSource1_Inserted(object sender, LinqDataSourceStatusEventArgs e) { PersonInfo p = e.Result as PersonInfo; if (p.SpouseID != null && p.SpouseID != 0) { try { //Updating SpouseID after submit using (MyFamilyDatabaseDataContext db = new MyFamilyDatabaseDataContext()) { PersonInfo spouse = db.PersonInfos.Where(sp => sp.PersonID == p.SpouseID).FirstOrDefault(); spouse.SpouseID = p.PersonID; db.SubmitChanges(); } } catch (Exception) { //Eat any exception } } ExtMethods.SendAddEmail(p); Response.Redirect("./PersonInfo.aspx?PersonID=" + p.PersonID); }
protected void Page_Load(object sender, EventArgs e) { _db = new MyFamilyDatabaseDataContext(); //_db.Log = Response.Output; //_db.PersonInfos.Where(p => p.SpouseID > 0 && p.Spouse.SpouseID != p.PersonID).ToList(); //return; foreach (PersonInfo personInfo in _db.PersonInfos.Where(p => p.PersonID != 0)) { if (personInfo.SpouseID != null && personInfo.SpouseID != 0) { PersonInfo spouse = _db.PersonInfos.Where(p => p.PersonID == personInfo.SpouseID).FirstOrDefault(); if (spouse == null) { ExtMethods.WriteLine(Response, "Spouse not found: " + personInfo.SpouseID); } else { if (personInfo.PersonID != spouse.SpouseID) { ExtMethods.WriteLine(Response, string.Format("Spouse Mismatch: PersonId={0}, Person.SpouseID={1}, Spouse.SpouseID={2}", personInfo.PersonID, personInfo.SpouseID, spouse.SpouseID)); } } } } }
protected void LinqDataSource1_Deleting(object sender, LinqDataSourceDeleteEventArgs e) { lblError.Visible = true; PersonInfo p = e.OriginalObject as PersonInfo; if (p.PersonID == 0) { e.Cancel = true; return; } if (p.SpouseID != null && p.SpouseID > 0) { e.Cancel = true; lblError.Text = "Remove Spouse of the person before deleting."; return; } using (MyFamilyDatabaseDataContext db = new MyFamilyDatabaseDataContext()) { PersonInfo spouse = db.PersonInfos.Where(o => o.SpouseID == p.PersonID).FirstOrDefault(); if (spouse != null && spouse.PersonID != 0) { e.Cancel = true; lblError.Text = "Person is already marked as Spouse for " + spouse.PersonID + ", update Person first."; return; } if (db.PersonInfos.Where(c => c.FatherID == p.PersonID).Count() > 0) { e.Cancel = true; lblError.Text = "Person is already father."; return; } } }
protected void Button1_Click(object sender, EventArgs e) { using (MyFamilyDatabaseDataContext db = new MyFamilyDatabaseDataContext()) { //string uName = TextBox1.Text; string uName = this.DropDownList1.SelectedValue; string uPwd = TextBox2.Text; PersonInfo pInfo = db.PersonInfos.Where(p => p.UserName.ToLower() == uName.ToLower() && p.Password == uPwd).FirstOrDefault(); if (pInfo != null) { Session["LogedInUserInfo"] = pInfo; //Send back to the page where user came from. If user directly landed to this page, send to Default.aspx if (ViewState["GoBackTo"] != null) { Response.Redirect(ViewState["GoBackTo"].ToString()); } else { Response.Redirect("./Default.aspx"); } } else { Session["LogedInUserInfo"] = null; Response.Write("Invalid UserName or Password"); } } }
protected void Page_Load(object sender, EventArgs e) { _db = new MyFamilyDatabaseDataContext(); //_db.Log = Response.Output; int id; if (!int.TryParse(Request["PersonID"], out id)) { id = 22; //Default to Qamar Uddin Baqai } _PersonInfo = _db.PersonInfos.Where(p => p.PersonID == id).FirstOrDefault(); _LogedInUserInfo = Session["LogedInUserInfo"] as PersonInfo; if (_LogedInUserInfo != null) { lblLogin.Text = string.Format("Welcome <a href='./PersonInfo.aspx?PersonID={0}'>{1}</a>", _LogedInUserInfo.PersonID, _LogedInUserInfo.FullName); } else { lblLogin.Text = "<a href='./LoginPage.aspx'>Login</a>"; } }
protected override void OnUnload(EventArgs e) { if (_db != null) { _db.Dispose(); _db = null; } }
protected void Page_Load(object sender, EventArgs e) { //Adding this page to Cache for 5 mins. Response.Cache.SetExpires(DateTime.Now.AddSeconds(300)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); PersonInfo pInfo = Session["LogedInUserInfo"] as PersonInfo; if (pInfo != null) { lblLogin.Text = string.Format("Welcome <a href='./PersonInfo.aspx?PersonID={0}'>{1}</a>", pInfo.PersonID, pInfo.FullName); } else { lblLogin.Text = "<a href='./LoginPage.aspx'>Login</a>"; } db = new MyFamilyDatabaseDataContext(); //db.Log = Response.Output; TreeView1.Nodes.Clear(); TreeNode rootNode = new TreeNode(); rootNode.Value = "-1"; rootNode.Text = "Baqai Family"; rootNode.SelectAction = TreeNodeSelectAction.Expand; TreeView1.Nodes.Add(rootNode); var allMale = db.PersonInfos.Where(p => p.PersonID != 0 && (p.FatherID == null || p.FatherID == 0) && p.Gender == "Male" && p.FullName.Contains("Baqai")).OrderBy(o => o.FullName); DateTime start = DateTime.Now; foreach (PersonInfo male in allMale) { TreeNode childNode = new TreeNode(); childNode.Text = male.FullName; childNode.Value = male.PersonID.ToString(); childNode.SelectAction = TreeNodeSelectAction.Expand; childNode.Text = string.Format("<a href='./PersonInfo.aspx?PersonID={0}'>{1}</a>", male.PersonID, male.FullName); rootNode.ChildNodes.Add(childNode); PopulateChildren(childNode, male); } //rootNode.ChildNodes.Add(new TreeNode((DateTime.Now - start).ToString())); }
protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e) { lblErrors.Visible = false; PersonInfo p = e.NewObject as PersonInfo; if (p == null) { e.Cancel = true; return; } if (string.IsNullOrEmpty(p.FullName)) { e.Cancel = true; return; } using (MyFamilyDatabaseDataContext db = new MyFamilyDatabaseDataContext()) { //Validate if other person's Spouse is not defined. PersonInfo spouse = null; if (p.SpouseID != null && p.SpouseID != 0) { spouse = db.PersonInfos.Where(sp => sp.PersonID == p.SpouseID).FirstOrDefault(); //If Spouse is already married to someone else if (spouse.SpouseID != 0 && spouse.SpouseID != null) { lblErrors.Text = "Spouse is invalid. <a href='./PersonInfo.aspx?PersonID=" + spouse.PersonID + "'>" + spouse.FullName + "</a> is already married to " + spouse.Spouse.FullName; lblErrors.Visible = true; e.Cancel = true; return; } //If Spouse gender is same if (p.Gender == spouse.Gender) { lblErrors.Text = "Spouse is invalid. Both can't have same gender."; lblErrors.Visible = true; e.Cancel = true; return; } } //Get New ID int newPersonId = db.PersonInfos.Max(person => person.PersonID) + 1; p.PersonID = newPersonId; } }
protected void LinqDataSource1_Updating(object sender, LinqDataSourceUpdateEventArgs e) { lblError.Visible = true; PersonInfo p = e.NewObject as PersonInfo; /*if (p.SpouseID == 0) p.SpouseID = null; * if (p.OccupationID == 0) p.OccupationID = null; * if (p.FatherID == 0) p.Father = null; * if (p.ManagedBy == 0) p.ManagedBy = null;*/ using (MyFamilyDatabaseDataContext db = new MyFamilyDatabaseDataContext()) { //Validate if other person's Spouse is not someone else PersonInfo spouse = null; if (p.SpouseID != null && p.SpouseID != 0) { spouse = db.PersonInfos.Where(sp => sp.PersonID == p.SpouseID).FirstOrDefault(); //If Spouse is already married to someone else if (spouse.SpouseID != 0 && spouse.SpouseID != null && spouse.SpouseID != p.PersonID) { lblError.Text = "Spouse is invalid. <a href='./PersonInfo.aspx?PersonID=" + spouse.PersonID + "'>" + spouse.FullName + "</a> is already married to " + spouse.Spouse.FullName; lblError.Visible = true; e.Cancel = true; return; } //If Spouse gender is same if (p.Gender == spouse.Gender) { lblError.Text = "Spouse is invalid. Both can't have same gender."; lblError.Visible = true; e.Cancel = true; return; } } } }
protected void Button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtOccupation.Text)) { Response.Write("Occupation can't be empty"); return; } try { using (MyFamilyDatabaseDataContext db = new MyFamilyDatabaseDataContext()) { Occupation occupation = new Occupation(); occupation.OccupationDesc = txtOccupation.Text; db.Occupations.InsertOnSubmit(occupation); db.SubmitChanges(); Response.Write("New occupation inserted"); } } catch (Exception ex) { Response.Write(ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { _db = new MyFamilyDatabaseDataContext(); }