protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "InsertNew") { GridViewRow row = GridView1.FooterRow; TextBox txtFirstName = row.FindControl("txtFirstNameNew") as TextBox; TextBox txtLastName = row.FindControl("txtLastNameNew") as TextBox; TextBox txtEmail = row.FindControl("txtEmailNew") as TextBox; TextBox txtPhone = row.FindControl("txtPhoneNew") as TextBox; DropDownList ddlStatus = row.FindControl("ddlStatusNew") as DropDownList; if (txtFirstName != null && txtLastName != null && txtEmail != null && ddlStatus != null) { using (ProjectTrackerContainer context = new ProjectTrackerContainer()) { Invest invest = new Invest(); invest.FirstName = txtFirstName.Text; invest.LastName = txtLastName.Text; invest.Email = txtEmail.Text; invest.Phone = txtPhone.Text; invest.InvestStatusId = Convert.ToInt32(ddlStatus.SelectedValue); context.Invests.Add(invest); WriteInvest(context, invest); BindGrid(); } } } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; Label lblId = row.FindControl("lblId") as Label; TextBox txtFirstName = row.FindControl("txtFirstName") as TextBox; TextBox txtLastName = row.FindControl("txtLastName") as TextBox; TextBox txtEmail = row.FindControl("txtEmail") as TextBox; TextBox txtPhone = row.FindControl("txtPhone") as TextBox; DropDownList ddlStatus = row.FindControl("ddlStatus") as DropDownList; if (txtFirstName != null && txtLastName != null && txtEmail != null && ddlStatus != null) { using (ProjectTrackerContainer context = new ProjectTrackerContainer()) { //int investorId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value); int investorId = Convert.ToInt32(lblId.Text); Invest invest = context.Invests.First(x => x.Id == investorId); invest.FirstName = txtFirstName.Text; invest.LastName = txtLastName.Text; invest.Email = txtEmail.Text; invest.Phone = txtPhone.Text; invest.InvestStatusId = Convert.ToInt32(ddlStatus.SelectedValue); WriteInvest(context, invest); GridView1.EditIndex = -1; BindGrid(); } } }
private void WriteInvest(ProjectTrackerContainer context, Invest invest) { var result = context.Entry(invest).GetValidationResult(); if (!result.IsValid) { lblMsg.Text = result.ValidationErrors.First().ErrorMessage; } else { context.SaveChanges(); lblMsg.Text = "Saved successfully."; //ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('Investor Added Successfully!')</script>"); } }
private bool SetPIValue(int investId) { using (ProjectTrackerContainer db = new ProjectTrackerContainer()) { Invest invest; if (investId == 0) // new PI { if (!TextBoxFirstName.Text.Equals(string.Empty) && !TextBoxLastName.Text.Equals(string.Empty)) { invest = new Invest() { FirstName = TextBoxFirstName.Text.Trim(), LastName = TextBoxLastName.Text.Trim(), Email = TextBoxEmail.Text, Phone = TextBoxPhone.Text, InvestStatusId = Convert.ToInt32(ddlStatus.SelectedValue), IsApproved = chkApproved.Checked, IsPilot = chkPilot.Checked }; //check existing PI with same name if (db.Invests.Any(i => i.FirstName == invest.FirstName && i.LastName == invest.LastName)) { return(false); } if (ddlStatus.SelectedItem.Text == "Non-Hawaii Client" || ddlStatus.SelectedItem.Text == "UH Student") { invest.NonHawaiiClient = TextBoxNonHawaii.Text; } TextBox txtNonUHOther = GridViewNonUH.FooterRow.FindControl("txtNonUHOther") as TextBox; invest.NonUHClient = txtNonUHOther.Text; TextBox txtDegreeOther = GridViewDegree.FooterRow.FindControl("txtDegreeOther") as TextBox; invest.OtherDegree = txtDegreeOther.Text; TextBox txtCommunityPartnerOther = GridViewCommunityPartner.FooterRow.FindControl("txtCommunityPartnerOther") as TextBox; invest.OtherCommunityPartner = txtCommunityPartnerOther.Text; db.Invests.Add(invest); db.SaveChanges(); investId = invest.Id; //PageUtility.SendNotificationByEmail("PI", investId, User.Identity.Name); SendNotificationEmail(invest.Id); } } else { invest = db.Invests.First(i => i.Id == investId); if (!Page.User.IsInRole("Admin") && invest.IsApproved) { //Response.Write("<script>alert('This PI has been approved, please contact with admin group for any changes.');</script>"); return(false); } else { if (invest != null && !TextBoxFirstName.Text.Equals(string.Empty) && !TextBoxLastName.Text.Equals(string.Empty)) { invest.FirstName = TextBoxFirstName.Text.Trim(); invest.LastName = TextBoxLastName.Text.Trim(); invest.Email = TextBoxEmail.Text; invest.Phone = TextBoxPhone.Text; invest.InvestStatusId = Convert.ToInt32(ddlStatus.SelectedValue); if (ddlStatus.SelectedItem.Text == "Non-Hawaii Client" || ddlStatus.SelectedItem.Text == "UH Student") { invest.NonHawaiiClient = TextBoxNonHawaii.Text; } TextBox txtNonUHOther = GridViewNonUH.FooterRow.FindControl("txtNonUHOther") as TextBox; invest.NonUHClient = txtNonUHOther.Text; TextBox txtDegreeOther = GridViewDegree.FooterRow.FindControl("txtDegreeOther") as TextBox; invest.OtherDegree = txtDegreeOther.Text; TextBox txtCommunityPartnerOther = GridViewCommunityPartner.FooterRow.FindControl("txtCommunityPartnerOther") as TextBox; invest.OtherCommunityPartner = txtCommunityPartnerOther.Text; invest.IsApproved = chkApproved.Checked; invest.IsPilot = chkPilot.Checked; db.SaveChanges(); } } } #region update PI affiliations List <int> newAffliIdList = GetInvestJabsomAffil(); List <int> prevAffilIdList = new List <int>(); ICollection <JabsomAffil> jabsomAffils = db.Invests.First(i => i.Id == investId).JabsomAffils; foreach (JabsomAffil affil in jabsomAffils) { prevAffilIdList.Add(affil.Id); } var newNotPrevAffilList = newAffliIdList.Except(prevAffilIdList).ToList(); var prevNotNewAffilList = prevAffilIdList.Except(newAffliIdList).ToList(); if (prevNotNewAffilList.Count > 0) { foreach (var expiredId in prevNotNewAffilList) { //project.ProjectBioStats.First(b => b.BioStats_Id == expiredId).EndDate = DateTime.Parse(_currentDate); var jabsomAffil = jabsomAffils.First(j => j.Id == expiredId); jabsomAffils.Remove(jabsomAffil); } } if (newNotPrevAffilList.Count > 0) { foreach (var newId in newNotPrevAffilList) { var jabsomAffil = db.JabsomAffils.First(j => j.Id == newId); jabsomAffils.Add(jabsomAffil); } } db.SaveChanges(); #endregion } return(true); }