protected void gvDeadlines_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } DeadlineCurrency dc = UserDeadlines[e.RowIndex]; DeadlineCurrency dcOriginal = new DeadlineCurrency(); util.CopyObject(dc, dcOriginal); Controls_mfbTypeInDate typeinNew = (Controls_mfbTypeInDate)gvDeadlines.Rows[e.RowIndex].FindControl("mfbUpdateDeadlineDate"); Controls_mfbDecimalEdit typeinNewHours = (Controls_mfbDecimalEdit)gvDeadlines.Rows[e.RowIndex].FindControl("decNewHours"); if (dc.AircraftHours > 0) { dc.AircraftHours = dc.NewHoursBasedOnHours(typeinNewHours.Value); } else { dc.Expiration = dc.NewDueDateBasedOnDate(typeinNew.Date); } if (dc.IsValid() && dc.FCommit()) { gvDeadlines.EditIndex = -1; ForceRefresh(); DeadlineUpdated?.Invoke(this, new DeadlineEventArgs(dcOriginal, dc)); } }
protected string TemplateText() { StringBuilder sb = new StringBuilder(); foreach (Control c in plcTemplateForm.Controls) { LiteralControl l = c as LiteralControl; TextBox t = c as TextBox; Controls_mfbTypeInDate d = c as Controls_mfbTypeInDate; DropDownList dd = c as DropDownList; if (l != null) { sb.Append(l.Text); } else if (t != null) { sb.Append(t.Text); } else if (d != null) { sb.Append(d.Date.ToShortDateString()); } else if (dd != null) { sb.Append(dd.SelectedValue); } } return(sb.ToString()); }
protected void gvDeadlines_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } DeadlineCurrency dc = UserDeadlines[e.RowIndex]; DeadlineCurrency dcOriginal = new DeadlineCurrency(); util.CopyObject(dc, dcOriginal); Controls_mfbTypeInDate typeinNew = (Controls_mfbTypeInDate)gvDeadlines.Rows[e.RowIndex].FindControl("mfbUpdateDeadlineDate"); Controls_mfbDecimalEdit typeinNewHours = (Controls_mfbDecimalEdit)gvDeadlines.Rows[e.RowIndex].FindControl("decNewHours"); if (dc.AircraftHours > 0) { dc.AircraftHours = dc.NewHoursBasedOnHours(typeinNewHours.Value); } else { dc.Expiration = dc.NewDueDateBasedOnDate(typeinNew.Date); } if (dc.IsValid() && dc.FCommit()) { gvDeadlines.EditIndex = -1; ForceRefresh(); if (dc.AircraftID > 0) { string szDiff = dc.DifferenceDescription(dcOriginal); if (!String.IsNullOrEmpty(szDiff)) { MaintenanceLog ml = new MaintenanceLog() { AircraftID = dc.AircraftID, ChangeDate = DateTime.Now, User = UserName, Description = szDiff, Comment = string.Empty }; ml.FAddToLog(); } } if (DeadlineUpdated != null) { DeadlineUpdated(this, new DeadlineEventArgs(dcOriginal, dc)); } } }
protected void gvDeadlines_RowDataBound(object sender, GridViewRowEventArgs e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Row.RowType == DataControlRowType.DataRow) { if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) { Controls_mfbTypeInDate typeindate = (Controls_mfbTypeInDate)e.Row.FindControl("mfbUpdateDeadlineDate"); Controls_mfbDecimalEdit decEdit = (Controls_mfbDecimalEdit)e.Row.FindControl("decNewHours"); DeadlineCurrency dc = UserDeadlines[e.Row.RowIndex]; if (dc.UsesHours) { decEdit.Value = dc.AircraftHours; } else { typeindate.Date = typeindate.DefaultDate = dc.Expiration.LaterDate(DateTime.Now); } } } }
protected void UpdateFormForTemplate(int id, bool fResetTitle) { EndorsementType et = EndorsementType.GetEndorsementByID(id); if (et == null) { throw new MyFlightbookException(String.Format(CultureInfo.InvariantCulture, "EndorsementTemplate with ID={0} not found", id)); } plcTemplateForm.Controls.Clear(); plcValidations.Controls.Clear(); // don't change the title unless we're changing from a prior template. if (fResetTitle) { txtTitle.Text = et.Title; } lblEndorsementFAR.Text = et.FARReference; // Find each of the substitutions Regex r = new Regex("\\{[^}]*\\}"); MatchCollection matches = r.Matches(et.BodyTemplate); int cursor = 0; foreach (Match m in matches) { // compute the base ID for a control that we create here, before anything gets added, since the result depends on how many controls are in the placeholder already string idNewControl = ctlIDPrefix + plcTemplateForm.Controls.Count.ToString(CultureInfo.InvariantCulture); if (m.Index > cursor) // need to catch up on some literal text { LiteralControl lt = new LiteralControl(); plcTemplateForm.Controls.Add(lt); lt.Text = et.BodyTemplate.Substring(cursor, m.Index - cursor); lt.ID = "ltCatchup" + idNewControl; } string szMatch = m.Captures[0].Value; switch (szMatch) { case "{Date}": { Controls_mfbTypeInDate tid = (Controls_mfbTypeInDate)LoadControl("~/Controls/mfbTypeInDate.ascx"); plcTemplateForm.Controls.Add(tid); tid.Date = DateTime.Now; tid.ID = idNewControl; tid.TextControl.BorderColor = System.Drawing.Color.Black; tid.TextControl.BorderStyle = BorderStyle.Solid; tid.TextControl.BorderWidth = Unit.Pixel(1); } break; case "{FreeForm}": NewTextBox(plcTemplateForm, idNewControl, "", true, true, "Free-form text"); break; case "{Student}": NewTextBox(plcTemplateForm, idNewControl, TargetUser == null ? Resources.SignOff.EditEndorsementStudentNamePrompt : TargetUser.UserFullName, false, true, Resources.SignOff.EditEndorsementStudentNamePrompt); break; default: // straight textbox, unless it is strings separated by slashes, in which case it's a drop-down { string szMatchInner = szMatch.Substring(1, szMatch.Length - 2); // get the inside bits - i.e., strip off the curly braces if (szMatchInner.Contains("/")) { string[] rgItems = szMatchInner.Split('/'); DropDownList dl = new DropDownList(); plcTemplateForm.Controls.Add(dl); foreach (string szItem in rgItems) { dl.Items.Add(new ListItem(szItem, szItem)); } dl.ID = idNewControl; dl.BorderColor = System.Drawing.Color.Black; dl.BorderStyle = BorderStyle.Solid; dl.BorderWidth = Unit.Pixel(1); } else { NewTextBox(plcTemplateForm, idNewControl, String.Empty, false, true, szMatchInner); } } break; } cursor = m.Captures[0].Index + m.Captures[0].Length; } if (cursor < et.BodyTemplate.Length) { LiteralControl lt = new LiteralControl(); plcTemplateForm.Controls.Add(lt); lt.Text = et.BodyTemplate.Substring(cursor); lt.ID = "ltEnding"; } }