Example #1
0
        protected void RefreshTemplateList()
        {
            List <EndorsementType> lst = new List <EndorsementType>(EndorsementType.LoadTemplates(mfbSearchTemplates.SearchText));

            if (lst.Count == 0) // if nothing found, use the custom template
            {
                lst.Add(EndorsementType.GetEndorsementByID(1));
            }

            cmbTemplates.DataSource     = lst;
            cmbTemplates.DataValueField = "id";
            cmbTemplates.DataTextField  = "FullTitle";
            cmbTemplates.DataBind();

            int currentEndorsementID = mfbEditEndorsement1.EndorsementID;

            if (lst.Find(et => et.ID == currentEndorsementID) == null)  // restricted list doesn't have active template - select the first one.
            {
                cmbTemplates.SelectedIndex = 0;
                UpdateTemplate();
            }
            else if (currentEndorsementID.ToString(CultureInfo.InvariantCulture) != cmbTemplates.SelectedValue)
            {
                UpdateTemplate();
            }

            hdnLastTemplate.Value = cmbTemplates.SelectedValue;
        }
Example #2
0
        protected void UpdateFormForTemplate(int id, bool fResetTitle, string defaultText = null)
        {
            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 = HttpUtility.HtmlEncode(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, defaultText ?? string.Empty, 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";
            }
        }