private void SetCollabCtr(CollabCtr cc) { lblCCId.Text = cc.Id > 0 ? cc.Id.ToString() : ""; txtCCName.Value = cc.Name; txtCCAbbrv.Value = cc.NameAbbrv; txtStartDate.Text = cc.StartDate != default(DateTime) ? Convert.ToDateTime(cc.StartDate).ToShortDateString() : ""; txtEndDate.Text = cc.EndDate != null?Convert.ToDateTime(cc.EndDate).ToShortDateString() : ""; txtNextInvoiceDate.Text = cc.NextInvoiceDate != null?Convert.ToDateTime(cc.NextInvoiceDate).ToShortDateString() : ""; txtName.Value = cc.Contact; txtPhone.Value = cc.Phone; txtEmail.Value = cc.Email; txtFiscalName.Value = cc.FiscalContact; txtFiscalPhone.Value = cc.FiscalPhone; txtFiscalEmail.Value = cc.FiscalEmail; txtFiscalMail1.Value = cc.FiscalMail1; txtFiscalMail2.Value = cc.FiscalMail2; txtFiscalCity.Value = cc.City; ddlFiscalState.Value = cc.State != null ? cc.State : ""; txtFiscalZip.Value = cc.ZipCode; ddlBillingSchedule.Value = cc.BillingSchedule != null ? cc.BillingSchedule : ""; txtBillOther.Text = cc.BillOther; txtMemo.Value = cc.Memo; }
private CollabCtr GetCollabCtr(int ccId) { DateTime dt; CollabCtr cc = new CollabCtr() { Id = ccId, Name = txtCCName.Value, NameAbbrv = txtCCAbbrv.Value, StartDate = DateTime.TryParse(txtStartDate.Text, out dt) ? dt : DateTime.Now, EndDate = DateTime.TryParse(txtEndDate.Text, out dt) ? dt : (DateTime?)null, NextInvoiceDate = DateTime.TryParse(txtNextInvoiceDate.Text, out dt) ? dt : (DateTime?)null, Contact = txtName.Value, Phone = txtPhone.Value, Email = txtEmail.Value, FiscalContact = txtFiscalName.Value, FiscalPhone = txtFiscalPhone.Value, FiscalEmail = txtFiscalEmail.Value, FiscalMail1 = txtFiscalMail1.Value, FiscalMail2 = txtFiscalMail2.Value, City = txtFiscalCity.Value, State = ddlFiscalState.Value, ZipCode = txtFiscalZip.Value, BillingSchedule = ddlBillingSchedule.Value, BillOther = ddlBillingSchedule.Value == "Other" ? txtBillOther.Text : "", Memo = txtMemo.Value, Creator = Page.User.Identity.Name, CreateDate = DateTime.Now }; return(cc); }
private void ClearEditForm() { CollabCtr newCtr = new CollabCtr(); newCtr.StartDate = default(DateTime); SetCollabCtr(newCtr); }
private CollabCtr GetCollabCtrById(int id) { CollabCtr ctr = null; using (ProjectTrackerContainer db = new ProjectTrackerContainer()) { ctr = db.CollabCtr.FirstOrDefault(t => t.Id == id); } return(ctr); }
protected void btnSave_Click(object sender, EventArgs e) { int ccId = 0; Int32.TryParse(lblCCId.Text, out ccId); CollabCtr cc = GetCollabCtr(ccId); if (SaveCC(cc) < 0) { //error handling } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModalScript", PageUtility.LoadEditScript(false), false); BindRptCC(); }
protected void rptCC_ItemCommand(Object sender, RepeaterCommandEventArgs e) { if (((Button)e.CommandSource).Text.Equals("Edit")) { lblCCId.Text = ((Button)e.CommandSource).CommandArgument; int id = 0; int.TryParse(lblCCId.Text, out id); if (id > 0) { CollabCtr cc = GetCollabCtrById(id); if (cc != null) { SetCollabCtr(cc); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModalScript", PageUtility.LoadEditScript(true), false); } } } }
private int SaveCC(CollabCtr cc) { int ccid = -1; try { using (ProjectTrackerContainer db = new ProjectTrackerContainer()) { if (cc.Id > 0) //update { var prevCC = db.CollabCtr.FirstOrDefault(c => c.Id == cc.Id); if (prevCC != null) { db.Entry(prevCC).CurrentValues.SetValues(cc); } } else //new { db.CollabCtr.Add(cc); } db.SaveChanges(); ccid = cc.Id; } } catch (Exception ex) { throw ex; } finally { // } return(ccid); }
/// <summary> /// Loads Collaborative Center form given id. /// </summary> /// <param name="id">Referred collab center id.</param> private void LoadCCForm(int id) { collabCtrProjSxn.Visible = true; collabCtrClientAgmtSxn.Visible = true; var dropDownSource = new Dictionary <int, string>(); var dropDownSourcewString = new Dictionary <string, string>(); /// Populates dropdowns of projects and client agreements associated with the collaboration center. using (ProjectTrackerContainer db = new ProjectTrackerContainer()) { /// List of Collab Centers dropDownSource = db.CollabCtr .OrderBy(c => c.NameAbbrv) .Where(c => c.Id > 0) .Select(x => new { x.Id, FullName = (x.NameAbbrv + " | " + x.Name) }) .ToDictionary(c => c.Id, c => c.FullName); PageUtility.BindDropDownList(ddlCollab, dropDownSource, string.Empty); /// Pulls list of projects associated with collaborative center OR /// if collaborative center is SONDH, pulls the projects with /// "MOU" listed as the grant payment. dropDownSource = db.Project2 .GroupJoin( db.JabsomAffils, p => p.GrantDepartmentFundingType, ja => ja.Id, (p, ja) => new { p, ja }) .Where(y => y.p.ClientAgmt.FirstOrDefault().CollabCtrId == id || (id == 116 && y.ja.FirstOrDefault().Name == "School of Nursing & Dental Hygiene") && (y.p.IsMOU == 1 || y.p.GrantOther.Contains("MOU") || (y.p.AknOther.Contains("MOU")))) .OrderByDescending(y => y.p.Id) .Select(x => new { x.p.Id, FullName = (x.p.Id + " " + x.p.Title).Substring(0, 150) }) .Distinct() .ToDictionary(d => d.Id, d => d.FullName); PageUtility.BindDropDownList(ddlCollabCtrProjects, dropDownSource, "-- List of Projects for Collaborative Center --"); /// Pulls list of Client Agreements associated with collaborative center. dropDownSourcewString = db.ClientAgmt .Join(db.CollabCtr, ca => ca.CollabCtrId, cct => cct.Id, (ca, cct) => new { ca, cct }) .Where(z => z.ca.CollabCtrId == id) .OrderByDescending(y => y.ca.Id) .Select(x => new { /*x.ca.Id*/ x.ca.AgmtId, FullName = (x.ca.Id + " - " + x.ca.AgmtId + " - " + x.ca.ProjectPhase + " - Project ID " + x.ca.Project2Id).Substring(0, 150) }) .Distinct() .ToDictionary(d => d.AgmtId, d => d.FullName); PageUtility.BindDropDownList(ddlCollabCtrClientAgmts, dropDownSourcewString, "-- List of Client Agreements for Collaborative Center --"); } CollabCtr cc = GetCollabCtrById(id); if (cc != null) { SetCollabCtr(cc); if (cc.Id > 0) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModalScript", PageUtility.LoadEditScript(true), false); } } }