示例#1
0
        public int version; // current version of this control

        #endregion Fields

        #region Methods

        public void UpdateCommonProperties(FormControl newControlProperties)
        {
            // If passed values are blank, do not update
            if (newControlProperties.name != null) { name = newControlProperties.name; }
            if (newControlProperties.prompt != null) { prompt = newControlProperties.prompt; }
            if (newControlProperties.tip != null) { tip = newControlProperties.tip; }
            if (newControlProperties.ordernum != -1) { ordernum = newControlProperties.ordernum; }
        }
示例#2
0
文件: UIFS.cs 项目: jmptrader/UIFS
        public int version; // The current version of the form

        #endregion Fields

        #region Methods

        // ------------------------------------------------------------
        // Adds a control, and returns the index if not a new control
        public int AddControl(ControlType type, FormControl Control, bool newControl)
        {
            int iControl = 0, newControlListentry=this.controls;
            if (newControl) {
                // We need to create a ControlList entry
                this.controls += 1; // Update control count
                Array.Resize(ref ControlList, controls); // resize control list
                ControlList[newControlListentry] = new FormDataStruct.ControlListDetail();
                ControlList[newControlListentry].type = type;
                // get and assign needed vars
                Control.id = this.nextcontrolid; nextcontrolid += 1; // get an official control id and increase the count
                Control.ordernum = Get_NextOrderNum();
                ControlList[newControlListentry].ordernum = Control.ordernum; // New controls need an order num (will get sorted later if user dropped in a different order)
                ControlList[newControlListentry].id = Control.id; // this id assignment is temporary for new (unsaved) controls (when saved to db the id will get assigned)
                Control.version = 1; // new controls start with version 1
            }
            switch (type)
            {
                case ControlType.Textbox:
                    if (Textbox == null)
                    {
                        Array.Resize(ref Textbox, 1); // start new
                    }
                    else
                    {
                        Array.Resize(ref Textbox, Textbox.Length + 1);
                    }
                    iControl = Textbox.Length - 1;
                    Textbox[iControl] = (FormControl.Textbox)Control;
                    break;
                case ControlType.List:
                    if (List == null)
                    {
                        Array.Resize(ref List, 1);
                    }
                    else
                    {
                        Array.Resize(ref List, List.Length + 1);
                    }
                    iControl = List.Length - 1;
                    List[iControl] = (FormControl.List)Control;
                    break;
                case ControlType.Checkbox:
                    if (Checkbox == null)
                    {
                        Array.Resize(ref Checkbox, 1);
                    }
                    else
                    {
                        Array.Resize(ref Checkbox, Checkbox.Length + 1);
                    }
                    iControl = Checkbox.Length - 1;
                    Checkbox[iControl] = (FormControl.Checkbox)Control;
                    break;
                case ControlType.DateTime:
                    if (DateTime == null)
                    {
                        Array.Resize(ref DateTime, 1);
                    }
                    else
                    {
                        Array.Resize(ref DateTime, DateTime.Length + 1);
                    }
                    iControl = DateTime.Length - 1;
                    DateTime[iControl] = (FormControl.DateTime)Control;
                    break;
                case ControlType.Number:
                    if (Number == null)
                    { Array.Resize(ref Number, 1); }
                    else { Array.Resize(ref Number, Number.Length + 1); }
                    iControl = Number.Length - 1;
                    Number[iControl] = (FormControl.Number)Control;
                    break;
                case ControlType.Percentage:
                    if (Percentage == null)
                    { Array.Resize(ref Percentage, 1); }
                    else { Array.Resize(ref Percentage, Percentage.Length + 1); }
                    iControl = Percentage.Length - 1;
                    Percentage[iControl] = (FormControl.Percentage)Control;
                    break;
                case ControlType.Range:
                    if (Range == null)
                    { Array.Resize(ref Range, 1); }
                    else { Array.Resize(ref Range, Range.Length + 1); }
                    iControl = Range.Length - 1;
                    Range[iControl] = (FormControl.Range)Control;
                    break;
            }

            if (newControl)
            { // update index
                ControlList[newControlListentry].index = iControl; // index of new control
            }

            return iControl; // return the index of the added control
        }
示例#3
0
文件: UIFS.cs 项目: jmptrader/UIFS
        public void Update_ControlCommonProperties(int ControlID, FormControl ControlChanges, bool Controlrequiredchanged = false)
        {
            int iControlList = Find_ControlListEntry_byControlID(ControlID);
            int iControl = ControlList[iControlList].index;

            // Here is where we can check/filter the entered values: name, prompt, tip

            // Mark control as changed (if not just addded)
            if (!ControlList[iControlList].added) { ControlList[iControlList].controlchanged = true; }
            switch (ControlList[iControlList].type)
            {
                case ControlType.Textbox:
                    Textbox[iControl].UpdateCommonProperties(ControlChanges);
                    if (Controlrequiredchanged) { Textbox[iControl].required = ControlChanges.required; }
                    break;
                case ControlType.List:
                    List[iControl].UpdateCommonProperties(ControlChanges);
                    if (Controlrequiredchanged) { List[iControl].required = ControlChanges.required; }
                    break;
                case ControlType.Checkbox:
                    Checkbox[iControl].UpdateCommonProperties(ControlChanges);
                    if (Controlrequiredchanged) { Checkbox[iControl].required = ControlChanges.required; }
                    break;
                case ControlType.DateTime:
                    DateTime[iControl].UpdateCommonProperties(ControlChanges);
                    if (Controlrequiredchanged) { DateTime[iControl].required = ControlChanges.required; }
                    break;
                case ControlType.Number:
                    Number[iControl].UpdateCommonProperties(ControlChanges);
                    if (Controlrequiredchanged) { Number[iControl].required = ControlChanges.required; }
                    break;
                case ControlType.Percentage:
                    Percentage[iControl].UpdateCommonProperties(ControlChanges);
                    if (Controlrequiredchanged) { Percentage[iControl].required = ControlChanges.required; }
                    break;
                case ControlType.Range:
                    Range[iControl].UpdateCommonProperties(ControlChanges);
                    if (Controlrequiredchanged) { Range[iControl].required = ControlChanges.required; }
                    break;
                default:
                    // ERROR essentially - log it
                    break;
            }
        }
示例#4
0
文件: UIFS.cs 项目: jmptrader/UIFS
 /* Pass to this routine the controlid you want reordered and the new order number
  */
 public void Sort_ControlList(int Controlid, int newOrderNum)
 {
     int oldOrderNum = 0, lowOrderNum, highOrderNum, difference;
     int iControl = 0;
     // First, find original sort number and change to newordernum
     for (int t = 0; t < ControlList.Length; t++)
     {
         if (ControlList[t].id == Controlid)
         {
             iControl = t;
             oldOrderNum = ControlList[t].ordernum;  // capture old
             ControlList[t].ordernum = newOrderNum;  // assign new
             FormControl ControlChanges = new FormControl();
             ControlChanges.ordernum = ControlList[t].ordernum;
             Update_ControlCommonProperties(ControlList[t].id, ControlChanges);
         }
     }
     // Now find the lower/higher between the two values to re-order the controls in-between
     if (newOrderNum > oldOrderNum)
     {
         lowOrderNum = oldOrderNum; highOrderNum = newOrderNum; difference = -1;
     }
     else
     {
         highOrderNum = oldOrderNum; lowOrderNum = newOrderNum; difference = 1;
     }
     // walk through list and reorder the needed controls
     for (int t = 0; t < ControlList.Length; t++)
     { // only reorder if it falls in the correct range and IS NOT the control that is causing the reordereding (already changed)
         if (t != iControl && ControlList[t].ordernum >= lowOrderNum && ControlList[t].ordernum <= highOrderNum)
         { // if in our range, set new ordernum
             ControlList[t].ordernum = ControlList[t].ordernum + difference;
             FormControl ControlChanges = new FormControl();
             ControlChanges.ordernum = ControlList[t].ordernum;
             Update_ControlCommonProperties(ControlList[t].id, ControlChanges);
         }
     }
 }
示例#5
0
文件: UIFS.cs 项目: jmptrader/UIFS
 // ReOrder_ControlList :: just does a complete reorder mapped to control index
 public void ReOrder_ControlList()
 {
     for (int t = 0; t < ControlList.Length; t++)
     {
         ControlList[t].ordernum = t+1;
         FormControl ControlChanges = new FormControl();
         ControlChanges.ordernum = ControlList[t].ordernum;
         Update_ControlCommonProperties(ControlList[t].id, ControlChanges);
     }
 }
示例#6
0
        // First get the common (shared) properties for all control types
        public string ControlProperties(ControlType type, FormControl Control)
        {
            FormControl.Textbox ControlTextbox = new FormControl.Textbox();
            FormControl.List ControlList = new FormControl.List();
            FormControl.Checkbox ControlCheckbox = new FormControl.Checkbox();
            FormControl.DateTime ControlDateTime = new FormControl.DateTime();
            FormControl.Number ControlNumber = new FormControl.Number();
            FormControl.Percentage ControlPercentage = new FormControl.Percentage();
            FormControl.Range ControlRange = new FormControl.Range();

            string ControlRequired;

            // Now begin the table and show the shared/common properties
            html = "<table class='Properties'>";

            // Do not display our "toolbar" if a new control..
            if (Control.id != -1) {
                html = html + "<tr class='Toolbar'><td colspan='2'><button class='Button_RemoveControl' onclick=\"Form_RemoveControl('" + Control.id.ToString() + "')\">Remove Control</button></td></tr>";
            }
            if (Control.required) { ControlRequired = "checked='1'"; } else { ControlRequired = ""; }
            // Common Properties
            html = html + "<tr class='CommonProp'><td title='The name of the control'>Name: </td><td><input type='text' id='" + Control.id.ToString() + "_Name' size='50' value='" + Control.name + "' onkeypress=\"Button_Enable('" + Control.id.ToString() + "_SaveB','Unsaved Changes!'); \"/></td></tr>" +
                "<tr class='CommonProp'><td title='The prompt the user will see'>Prompt: </td><td><textarea id='" + Control.id.ToString() + "_Prompt' rows='3' cols='50' onkeypress=\"Button_Enable('" + Control.id.ToString() + "_SaveB','Unsaved Changes!'); \">" + Control.prompt + "</textarea></td></tr>" +
                "<tr class='CommonProp'><td title='The help message that will appear when the user moves the mouse over this control'>Tip: </td><td><textarea id='" + Control.id.ToString() + "_Tip' rows='2' cols='50' onkeypress=\"Button_Enable('" + Control.id.ToString() + "_SaveB','Unsaved Changes!'); \">" + Control.tip + "</textarea></td></tr>" +
                "<tr class='CommonProp'><td title='Requires the control to be completed before submitting form'>Required: </td><td><input type='checkbox' "+ControlRequired+" id='" + Control.id.ToString() + "_Req' onclick=\"Button_Enable('" + Control.id.ToString() + "_SaveB','Unsaved Changes!'); \" /></td></tr>" +
                "<tr class='CommonProp'><td colspan='2' class='CommonProp_Submit'><span id='" + Control.id.ToString() + "_Save' ><input type='submit' id='" + Control.id.ToString() + "_SaveB' value='no changes' disabled='true' onclick=\"CommonProperties_Update('" + Control.id.ToString() + "')\" /></span></td>" +
                "<tr><td colspan='2' class='Table_SeparatorRow' /></tr>";

            // Cycle through each type again and display control properties
            switch (type)
            {
                case ControlType.Textbox:
                    ControlTextbox = (FormControl.Textbox)Control;
                    string fulltext;

                    html = html + "<tr><td colspan='2' class='Table_SeparatorRow_SectionHeader'>Textbox Properties</td></tr>";
                    // # of lines
                    html = html + "<tr><td colspan='2'>Lines: <select id='" + Control.id.ToString() + "_Lines' onChange=\"Button_Enable('" + Control.id.ToString() + "_TextboxSaveB','Unsaved Changes!'); \">";
                    for (int a = 1; a < 4; a++)
                    {
                        if (a == ControlTextbox.lines)
                        { html = html + "<option selected='1'>" + a.ToString() + "</option>"; }
                        else { html = html + "<option>" + a.ToString() + "</option>"; }
                    }
                    html = html + "</select>";
                    // # of columns
                    html = html + "&nbsp;&nbsp;&nbsp; Width: <select id='" + Control.id.ToString() + "_Width' onChange=\"Button_Enable('" + Control.id.ToString() + "_TextboxSaveB','Unsaved Changes!'); \">";
                    for (int a = 20; a < 61; a+=5)
                    {
                        if (a == ControlTextbox.width)
                        { html = html + "<option selected='1'>" + a.ToString() + "</option>"; }
                        else { html = html + "<option>" + a.ToString() + "</option>"; }
                    }
                    html = html + "</select>" +
                        "<span class='Button_floatRight' id='" + Control.id.ToString() + "_TextboxSave'><input type='submit' id='" + Control.id.ToString() + "_TextboxSaveB' value='no changes' disabled='true' onclick=\"Textbox_UpdateProperties('" + Control.id.ToString() + "')\" /></span></td>" +
                    "</tr>";
                    // Fulltext or not
                    if (ControlTextbox.FullText)
                    { fulltext = " checked='true' "; }
                    else { fulltext = ""; }
                    html = html + "<tr><td colspan='2'><input type='checkbox' id='" + Control.id.ToString() + "_fulltext'" + fulltext + " onClick=\"Button_Enable('" + Control.id.ToString() + "_TextboxSaveB','Unsaved Changes!'); \"/>Full Textbox (no length limits)</td></tr>";

                    ControlTextbox = null;
                    break;

                case ControlType.List:
                    ControlList = (FormControl.List)Control;
                    html = html + "<tr><td colspan='2' class='Table_SeparatorRow_SectionHeader'>List Properties</td></tr>" +
                        "<tr><td colspan='2'><table class='List_Options'>";
                // begin list options table
                    if (Control.id != -1)
                    { // Do not display if a new control
                        html = html + "<tr><th colspan='2'>List Options</th></tr>" +
                        // NOTE: Removed because the average user DOES NOT UNDERSTAND why they would need two values
                        // The DB now stores the "name" as both name and value
                        // The DB will still contain all the possibility for having different values..but it is up to the advanced user to implement
                        //"<tr><td>Name:<br/><input type='text' id='" + Control.id.ToString() + "_Opt_Name' /><br/>Value:<br/><input type='text' id='" + Control.id.ToString() + "_Opt_Value' />" +
                        "<tr><td>Name:<br/><input type='text' id='" + Control.id.ToString() + "_Opt_Name' />" +
                        "<br/><input type='button' name='Add New' value='Add New' onclick=\"javascript:List_AddOption('" + ControlList.id + "')\" /></td>" +
                        "<td><div class='List_Options_List'><ul id='" + Control.id.ToString() + "_sortable'>"; 
                        if (ControlList.Items != null)
                        { // If there are any items...list them
                            for (int a = 0; a < ControlList.Items.Length; a++)
                            {
                                html = html + "<li class='ui-state-default' value='" + a.ToString() + "'>"
                                    + "<img border='0' src='Images/x.png' title='Delete Item' onclick=\"javascript:List_RemoveOption('" + ControlList.id + "','" + a.ToString() + "')\" />"
                                    + ControlList.Items[a].name + "</li>"; //+ " : " + ControlList.Items[a].value (removed, see above)
                            }
                        }
                        html = html + "</ul></div></td></tr>";
                    }
                    // List type selection
                    html = html + "<tr><td colspan='2'>Type: <select id='" + Control.id.ToString() + "_type' onChange=\"Button_Enable('" + Control.id.ToString() + "_ListSaveB','Unsaved Changes!'); \">";
                    switch (ControlList.type)
                    {
                        case FormControl.List.listtype.radio:
                            html = html + "<option selected='1' value='0'>radio</option><option value='1'>dropdown</option><option value='2'>slider</option>";
                            break;
                        case FormControl.List.listtype.dropdown:
                            html = html + "<option value='0'>radio</option><option selected='1' value='1'>dropdown</option><option value='2'>slider</option>";
                            break;
                        case FormControl.List.listtype.slider:
                            html = html + "<option value='0'>radio</option><option value='1'>dropdown</option><option selected='1' value='2'>slider</option>";
                            break;
                    }
                    html = html + "</select></td></tr>";

                    // Save button
                    html = html + "<tr><td colspan='2'><span class='Button_floatRight' id='" + Control.id.ToString() + "_ListSave'><input type='submit' id='" + Control.id.ToString() + "_ListSaveB' value='no changes' disabled='true' onclick=\"List_UpdateProperties('" + Control.id.ToString() + "')\" /></span></td></tr>";

                    html=html+"</table></td></tr>"; // close out list options table
                    ControlList = null;
                    break;

                case ControlType.Checkbox:
                    ControlCheckbox = (FormControl.Checkbox)Control;
                    string initialstate, hasinput;

                    html = html + "<tr><td colspan='2' class='Table_SeparatorRow_SectionHeader'>Checkbox Properties</td></tr>";
                    
                    // checkbox type selection
                    html = html + "<tr><td colspan='2'>Type: <select id='" + Control.id.ToString() + "_type' onChange=\"Button_Enable('" + Control.id.ToString() + "_CheckboxSaveB','Unsaved Changes!'); \">";
                    switch (ControlCheckbox.type)
                    {
                        case FormControl.Checkbox.checkboxtype.standard:
                            html = html + "<option selected='1' value='0'>Standard</option><option value='1'>Yes/No</option><option value='2'>On/Off</option>";
                            break;
                        case FormControl.Checkbox.checkboxtype.YesNo:
                            html = html + "<option value='0'>Standard</option><option selected='1' value='1'>Yes/No</option><option value='2'>On/Off</option>";
                            break;
                        case FormControl.Checkbox.checkboxtype.OnOff:
                            html = html + "<option value='0'>Standard</option><option value='1'>Yes/No</option><option selected='1' value='2'>On/Off</option>";
                            break;
                    }
                    html = html + "</select></td></tr>";
                
                    // initialstate checked or not
                    if (ControlCheckbox.initialstate){ initialstate = " checked='true' "; } else { initialstate = ""; }
                    // has input?
                    if (ControlCheckbox.hasinput) { hasinput = " checked='true' "; } else { hasinput = ""; }
                    // options
                    html = html + "<tr><td colspan='2'><input type='checkbox' id='" + Control.id.ToString() + "_initialstate'" + initialstate + " onClick=\"Button_Enable('" + Control.id.ToString() + "_CheckboxSaveB','Unsaved Changes!'); \"/>Initial State of checkbox</td></tr>";
                    html = html + "<tr><td colspan='2'><input type='checkbox' id='" + Control.id.ToString() + "_hasinput'" + hasinput + " onClick=\"Button_Enable('" + Control.id.ToString() + "_CheckboxSaveB','Unsaved Changes!'); \"/>Include text entry alongside checkbox</td></tr>";
                    // Save button
                    html = html + "<tr><td colspan='2'><span class='Button_floatRight' id='" + Control.id.ToString() + "_CheckboxSave'><input type='submit' id='" + Control.id.ToString() + "_CheckboxSaveB' value='no changes' disabled='true' onclick=\"Checkbox_UpdateProperties('" + Control.id.ToString() + "')\" /></span></td></tr>";

                    ControlCheckbox = null;
                    break;

                case ControlType.DateTime:
                    ControlDateTime = (FormControl.DateTime)Control;
                    html = html + "<tr><td colspan='2' class='Table_SeparatorRow_SectionHeader'>DateTime Properties</td></tr>";

                    //  type selection
                    html = html + "<tr><td colspan='2'>Type: <select id='" + Control.id.ToString() + "_type' onChange=\"Button_Enable('" + Control.id.ToString() + "_DateTimeSaveB','Unsaved Changes!'); \">";
                    switch (ControlDateTime.type)
                    {
                        case FormControl.DateTime.datetimetype.datetime:
                            html = html + "<option selected='1' value='0'>Date and Time</option><option value='1'>just Date</option><option value='2'>just Time</option>";
                            break;
                        case FormControl.DateTime.datetimetype.date:
                            html = html + "<option value='0'>Date and Time</option><option value='1' selected='1'>just Date</option><option value='2'>just Time</option>";
                            break;
                        case FormControl.DateTime.datetimetype.time:
                            html = html + "<option value='0'>Date and Time</option><option value='1'>just Date</option><option value='2' selected='1'>just Time</option>";
                            break;
                    }
                    html = html + "</select></td></tr>";

                    html = html + "<tr><td colspan='2'><span class='Button_floatRight' id='" + Control.id.ToString() + "_DateTimeSave'><input type='submit' id='" + Control.id.ToString() + "_DateTimeSaveB' value='no changes' disabled='true' onclick=\"DateTime_UpdateProperties('" + Control.id.ToString() + "')\" /></span></td></tr>";

                    ControlDateTime = null;
                    break;

                case ControlType.Number:
                    ControlNumber = (FormControl.Number)Control;
                    string slider;

                    html = html + "<tr><td colspan='2' class='Table_SeparatorRow_SectionHeader'>Number Properties</td></tr>";

                    // Min, Max, Interval
                    html = html + "<tr><td>Minimum Value: </td><td><input type='text' id='" + Control.id.ToString() + "_min' size='50' value='" + ControlNumber.min + "' onChange=\"Button_Enable('" + Control.id.ToString() + "_NumberSaveB','Unsaved Changes!'); \"/></td></tr>" +
                        "<tr><td>Maximum Value: </td><td><input type='text' id='" + Control.id.ToString() + "_max' size='50' value='" + ControlNumber.max + "' onChange=\"Button_Enable('" + Control.id.ToString() + "_NumberSaveB','Unsaved Changes!'); \"></td></tr>" +
                        "<tr><td>Interval: </td><td><input type='text' id='" + Control.id.ToString() + "_interval' size='50' value='" + ControlNumber.interval + "' onChange=\"Button_Enable('" + Control.id.ToString() + "_NumberSaveB','Unsaved Changes!'); \"></td></tr>";

                    // slider checked or not
                    if (ControlNumber.slider) { slider = " checked='true' "; } else { slider = ""; }
                    // Slider option
                    html = html + "<tr><td colspan='2'><input type='checkbox' id='" + Control.id.ToString() + "_slider'" + slider + " onClick=\"Button_Enable('" + Control.id.ToString() + "_NumberSaveB','Unsaved Changes!'); \"/>use slider for selection</td></tr>";
                    // Save button
                    html = html + "<tr><td colspan='2'><span class='Button_floatRight' id='" + Control.id.ToString() + "_NumberSave'><input type='submit' id='" + Control.id.ToString() + "_NumberSaveB' value='no changes' disabled='true' onclick=\"Number_UpdateProperties('" + Control.id.ToString() + "')\" /></span></td></tr>";

                    ControlNumber = null;
                    break;

                case ControlType.Percentage:
                    ControlPercentage = (FormControl.Percentage)Control;
                    html = html + "<tr><td colspan='2' class='Table_SeparatorRow_SectionHeader'>Percentage Properties</td></tr>";

                    // Interval
                    html = html + "<tr><td>Interval: </td><td><input type='text' id='" + Control.id.ToString() + "_interval' size='5' value='" + ControlPercentage.interval + "' onChange=\"Button_Enable('" + Control.id.ToString() + "_PercentageSaveB','Unsaved Changes!'); \"></td></tr>";

                    // Save button
                    html = html + "<tr><td colspan='2'><span class='Button_floatRight' id='" + Control.id.ToString() + "_PercentageSave'><input type='submit' id='" + Control.id.ToString() + "_PercentageSaveB' value='no changes' disabled='true' onclick=\"Percentage_UpdateProperties('" + Control.id.ToString() + "')\" /></span></td></tr>";

                    ControlNumber = null;
                    break;

                case ControlType.Range:
                    ControlRange = (FormControl.Range)Control;
                    string RangeTypeName="", RangeTypeDesc="";
                    html = html + "<tr><td colspan='2' class='Table_SeparatorRow_SectionHeader'>Range Properties</td></tr>";
                    //  type selection
                    html = html + "<tr><td colspan='2'>Type: <select id='" + Control.id.ToString() + "_type' onChange=\"Button_Enable('" + Control.id.ToString() + "_RangeSaveB','Unsaved Changes!'); \">";
                    FormControl.Range RangeTypes = new FormControl.Range();
                    foreach (FormControl.Range.Rangetype RangeType in Enum.GetValues(typeof(UIFS.FormControl.Range.Rangetype)))
                    {
                        switch (RangeType) {
                            case FormControl.Range.Rangetype.TimeRange:
                                RangeTypeName="Time Range";
                                RangeTypeDesc = "start/end time values (min and max are irrelevant here)";
                                break;
                            case FormControl.Range.Rangetype.DateRange:
                                RangeTypeName="Date Range";
                                RangeTypeDesc="start/end date values (min and max are irrelevant here)";
                                break;
                            case FormControl.Range.Rangetype.DateTimeRange:
                                RangeTypeName="DateTime Range";
                                RangeTypeDesc="start/end date and time values (min and max are irrelevant here)";
                                break;
                            case FormControl.Range.Rangetype.Currency:
                                RangeTypeName="Currency Range";
                                RangeTypeDesc="a currency range according to min and max";
                                break;
                            case FormControl.Range.Rangetype.MinMax:
                                RangeTypeName="Number Range";
                                RangeTypeDesc="a range according to min and max";
                                break;
                        }
                        if (ControlRange.type == RangeType) {
                            html = html + "<option selected='1' value='"+ Convert.ToInt32(RangeType) +"' title='"+RangeTypeDesc+"'>"+RangeTypeName+"</option>";
                        }
                        else {
                            html = html + "<option value='" + Convert.ToInt32(RangeType) + "' title='" + RangeTypeDesc + "'>" + RangeTypeName + "</option>";
                        }
                    }
                    html = html + "</select></td></tr>";

                    // Min and Max
                    html = html + "<tr><td>Minimum Value: </td><td><input type='text' id='" + Control.id.ToString() + "_min' size='50' value='" + ControlRange.min + "' onChange=\"Button_Enable('" + Control.id.ToString() + "_RangeSaveB','Unsaved Changes!'); \"/></td></tr>" +
                        "<tr><td>Maximum Value: </td><td><input type='text' id='" + Control.id.ToString() + "_max' size='50' value='" + ControlRange.max + "' onChange=\"Button_Enable('" + Control.id.ToString() + "_RangeSaveB','Unsaved Changes!'); \"></td></tr>";

                    // Save button
                    html = html + "<tr><td colspan='2'><span class='Button_floatRight' id='" + Control.id.ToString() + "_RangeSave'><input type='submit' id='" + Control.id.ToString() + "_RangeSaveB' value='no changes' disabled='true' onclick=\"Range_UpdateProperties('" + Control.id.ToString() + "')\" /></span></td></tr>";

                    ControlNumber = null;
                    break;
            }

            html = html + "</table>"; // End of Properties table

            return html;
        }
示例#7
0
        // ---------------------------------------------------------------------------------------------------------------
        /* -- Form.Save --
        // ---------------------------------------------------------------------------------------------------------------
        /* -- This routine is run after form controls have been changed via the designer and the user chooses the 'Save' option
         * -- It can be an initial save or an update
         *
         * -- Designed to build a Query, test it in a controlled transaction first, then committ
         */
        public bool Save(ref FormDataStruct FormData)
        {
            FormControl Control = new FormControl();
            bool increaseVersion = false;
            string DBSaveQuery = "";

            // 1) Check to see if form has been created: if zero, this is a new form
            if (FormData.id != 0)
            { // form exists
                // 1a) Cycle through all controls and see which ones have changed
                for (int t = 0; t < FormData.ControlList.Length; t++)
                {
                    // 1a.1) Update changed controls (not new/added controls)
                    if (FormData.ControlList[t].controlchanged && !FormData.ControlList[t].added && !FormData.ControlList[t].removed)
                    {
                        // DB_UpdateControl will perform the functions needed
                        Control = FormData.Get_Control(FormData.ControlList[t].id);
                        // Add Control update routine to query
                        DBSaveQuery = DBSaveQuery + DB_UpdateControl(FormData.ControlList[t].type, Control, FormData.ControlList[t].newversionneeded, FormData.id) + "\n";
                        if (FormData.ControlList[t].newversionneeded) { increaseVersion = true; }
                    }
                }
                // 2a) Cycle through all controls...find additions...find deletions
                for (int t = 0; t < FormData.ControlList.Length; t++)
                {
                    Control = FormData.Get_Control(FormData.ControlList[t].id);
                    // 2a.1) New Controls!
                    if (FormData.ControlList[t].added)
                    {
                        increaseVersion = true;
                        // Query to add FormControl data
                        DBSaveQuery = DBSaveQuery + DB_FormControl_AddQuery(Control, FormData.ControlList[t].type, FormData.id) + "\n";
                        // Query to update form table by adding a new column for this control
                        DBSaveQuery = DBSaveQuery + string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnAdd, FormData.id, DB_FormControl_ColumnCreation(FormData.ControlList[t].type, Control)) + "\n";
                    }
                    else
                    {
                        // 2a.2) Removed Controls
                        if (FormData.ControlList[t].removed)
                        {
                            increaseVersion = true;
                            // Build query and execute
                            DBSaveQuery = DBSaveQuery + string.Format(SQL.SQLQuery.Form_UpdateControl_Deactivate,
                                FormData.id, FormData.ControlList[t].id, Control.version)+"\n";
                        }
                    }
                }

                // TEST SAVE
                try
                {
                    //BEGIN TRAN UIFS_Update \n BEGIN TRY " + Query_NewControlVersion + "\n" + Query_OldControlDeactivate + "\n" + Query_DataTableUpdate + "\n COMMIT TRAN UIFS_Update \n END TRY \n BEGIN CATCH\nROLLBACK TRAN UIFS_Update\nDECLARE @ErrMsg NVARCHAR(4000);DECLARE @ErrSev INT;DECLARE @ErrState INT; SELECT @ErrMsg = ERROR_MESSAGE(),@ErrSev = ERROR_SEVERITY(),@ErrState = ERROR_STATE(); RAISERROR (@ErrMsg,@ErrSev,@ErrState); \n END CATCH ";

                    SQL.Query = "BEGIN TRAN UIFS_Update \n BEGIN TRY " +DBSaveQuery+
                        "\n COMMIT TRAN UIFS_Update \n END TRY \n BEGIN CATCH\nROLLBACK TRAN UIFS_Update\nDECLARE @ErrMsg NVARCHAR(4000);DECLARE @ErrSev INT;DECLARE @ErrState INT; SELECT @ErrMsg = ERROR_MESSAGE(),@ErrSev = ERROR_SEVERITY(),@ErrState = ERROR_STATE(); RAISERROR (@ErrMsg,@ErrSev,@ErrState); \n END CATCH ";
                    SQL.cmd = SQL.Command(SQL.Data);
                    SQL.cmd.ExecuteNonQuery();
                    //-- SUCCESS! --
                    try
                    {
                        // if a version change is required:
                        if (increaseVersion) { FormData.version += 1; }
                        // Update the main form details: name, version, lastmodifiedby
                        SQL.Query = string.Format(SQL.SQLQuery.Form_Update, FormData.id, SQL.ParseInput(FormData.name), SQL.ParseInput(FormData.description), FormData.version, WindowsIdentity.GetCurrent().Name);
                        SQL.cmd = SQL.Command(SQL.Data);
                        SQL.cmd.ExecuteNonQuery();
                        // This runs last, if version changed
                        if (increaseVersion)
                        {
                            // Create version history..(This is created immediately after form changes to preserve a record of form and form control's states)
                            SQL.Query = string.Format(SQL.SQLQuery.Form_VersionHistory_Create, FormData.id);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.cmd.ExecuteNonQuery();
                        }
                        SQL.WriteLog("Saved changes to form: "+FormData.id.ToString());
                    }
                    catch (Exception ex)
                    {
                        SQL.WriteLog_Error(ex, "Failed to update version and/or version history...", "UIFS.Form.Save()");
                    }
                }
                catch (Exception ex) { // -- SAVE FAILED :( boo
                    SQL.WriteLog_Error(ex,"SAVING FORM FAILED: "+DBSaveQuery,"UIFS.Form.Save()");
                    return false;
                }

            }
            else
            { // 1b.1) New Form, create db entries for the form and its controls, create a table for the data
                try
                {
                    if (!DB_CreateForm(ref FormData)) { return false; }
                    if (!DB_CreateDataTable(FormData)) { return false; }

                    // Create version history..
                    SQL.Query = string.Format(SQL.SQLQuery.Form_VersionHistory_Create, FormData.id);
                    SQL.cmd = SQL.Command(SQL.Data);
                    SQL.cmd.ExecuteNonQuery();
                    SQL.WriteLog("Created new form!");
                }
                catch (Exception ex)
                {
                    SQL.WriteLog_Error(ex,"Failed to create a new form! ","UIFS.Form.Save()");
                }
            }

            // update any other components, layout,etc.

            return true;
        }
示例#8
0
        // ---------------------------------------------------------------------------------------------------------------
        /* -- Form.DB_CreateForm --
        // ---------------------------------------------------------------------------------------------------------------
            Creates the new form adding appropriate db entries
        */
        public bool DB_CreateForm(ref FormDataStruct FormData)
        {
            FormControl Control = new FormControl();

            try
            {
                // Create new Form entry
                SQL.Query = string.Format(SQL.SQLQuery.Form_Create, 1, SQL.ParseInput(FormData.name), SQL.ParseInput(FormData.description), WindowsIdentity.GetCurrent().Name);
                SQL.cmd = SQL.Command(SQL.Data);
                // Assign the new form its id
                FormData.id = Convert.ToInt32(SQL.cmd.ExecuteScalar());

                // create all the controls
                for (int t = 0; t < FormData.ControlList.Length; t++)
                {
                    switch (FormData.ControlList[t].type)
                    {
                        case ControlType.Textbox:
                            Control = FormData.Textbox[FormData.ControlList[t].index];
                            break;
                        case ControlType.List:
                            Control = FormData.List[FormData.ControlList[t].index];
                            break;
                        case ControlType.Checkbox:
                            Control = FormData.Checkbox[FormData.ControlList[t].index];
                            break;
                        case ControlType.DateTime:
                            Control = FormData.DateTime[FormData.ControlList[t].index];
                            break;
                        case ControlType.Number:
                            Control = FormData.Number[FormData.ControlList[t].index];
                            break;
                        case ControlType.Percentage:
                            Control = FormData.Percentage[FormData.ControlList[t].index];
                            break;
                        case ControlType.Range:
                            Control = FormData.Range[FormData.ControlList[t].index];
                            break;
                    }
                    // Get query and execute
                    SQL.Query = DB_FormControl_AddQuery(Control, FormData.ControlList[t].type, FormData.id);
                    SQL.cmd = SQL.Command(SQL.Data);
                    SQL.cmd.ExecuteNonQuery();
                }

                return true;
            }
            catch (Exception ex)
            {
                SQL.WriteLog_Error(ex, "Could not create a new form: " + SQL.Query, "UIFS.Form.DB_CreateForm");
                return false;
            }
        }
示例#9
0
        // ---------------------------------------------------------------------------------------------------------------
        /* -- Form.DB_UpdateControl --
        // ---------------------------------------------------------------------------------------------------------------
        /*  Updates a single control with the new properties, makes changes to necessary tables
         */
        public string DB_UpdateControl(ControlType type, FormControl NewControl, bool newversion, int Formid)
        {
            string TheQuery = "";
            // The ONLY row updating that will be done is for COMMON properties, everything else requires a new version = new row

            if (!newversion)
            { // just update the common properties
                TheQuery = string.Format(SQL.SQLQuery.Form_UpdateControl_CommonProperties, Formid, NewControl.id, SQL.ParseInput(NewControl.name), SQL.ParseInput(NewControl.prompt), SQL.ParseInput(NewControl.tip), NewControl.ordernum, SQL.BoolValue(NewControl.required));
            }
            else
            { // updating to new version!
                string Query_NewControlVersion = "", Query_DataTableUpdate = "", Query_OldControlDeactivate = "";

                // Increase version #
                NewControl.version += 1;

                /* New Version Steps
                 *  1) new row: UIFS.FormControls
                 *  1a) mark old version (row) as inactive
                 *  2) update/modify: the form's table column(s)
                 *
                 * NOTE: really, we just create a new row with the new version # in the [UIFS.FormControls] table
                 *       then, rename the Control's column(s) in the form's data table and create new ones
                 */

                // Update a single control with the new properties, makes changes to necessary tables
                // Step #1
                Query_NewControlVersion = DB_FormControl_AddQuery(NewControl, type, Formid);
                // Step #1a
                Query_OldControlDeactivate = string.Format(SQL.SQLQuery.Form_UpdateControl_Deactivate, Formid, NewControl.id, NewControl.version - 1);
                // Step #2
                Query_DataTableUpdate = DB_FormControl_UpdateColumnQuery(NewControl, type, Formid);

                TheQuery = Query_NewControlVersion + "\n" + Query_OldControlDeactivate + "\n" + Query_DataTableUpdate + "\n";
            }
            return TheQuery;
        }
示例#10
0
        // ---------------------------------------------------------------------------------------------------------------
        /* -- Form.DB_FormControl_UpdateColumnQuery --
        // ---------------------------------------------------------------------------------------------------------------
        /*  Updates a control's column(s) in the Form's data table
         */
        public string DB_FormControl_UpdateColumnQuery(FormControl Control, ControlType type, int Formid)
        {
            string UpdateColumnQuery = "";
            /*  -- STEPS --
             *  1) rename old column(s)
             *  2) create new column(s)
             */

            //:: the different control types have different # of columns
            // Step #1
            switch (type)
            {
                case ControlType.Textbox: // single value
                case ControlType.List: // single value
                case ControlType.DateTime: // single value
                case ControlType.Number: // single value
                case ControlType.Percentage: // single value
                    UpdateColumnQuery = string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnRename, Formid, Control.id, Control.id + "_" + (Control.version - 1)) + "\n";
                    break;
                case ControlType.Checkbox: // can have a text entry box
                    FormControl.Checkbox CB = (FormControl.Checkbox)Control;
                    if (CB.hasinput)
                    { // two values
                        UpdateColumnQuery = string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnRename, Formid, Control.id, Control.id + "_" + (Control.version - 1)) + "\n";
                        // we use a different query struct here because if the control did not have text input this column will not exist and not need to be renamed..
                        UpdateColumnQuery = UpdateColumnQuery + string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnRename_ifexists, Formid, Control.id + "_text", Control.id +"_"+ (Control.version - 1) + "_text") + "\n";
                    }
                    else
                    { // single value
                        UpdateColumnQuery = string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnRename, Formid, Control.id, Control.id + "_" + (Control.version - 1)) + "\n";
                    }
                    break;
                case ControlType.Range: // Ranges have two values...
                    UpdateColumnQuery = string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnRename, Formid,Control.id + "_Start", Control.id + "_" + (Control.version - 1) + "_Start", Control.id) + "\n";
                    UpdateColumnQuery = UpdateColumnQuery + string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnRename, Formid, Control.id + "_End", Control.id + "_" + (Control.version - 1) + "_End") + "\n";
                    break;
            }

            // Step #2 (this step does not require an individual control breakout because it uses the columncreation routine that returns ALL needed column query language
            UpdateColumnQuery = UpdateColumnQuery + string.Format(SQL.SQLQuery.Form_UpdateControl_ColumnAdd, Formid, DB_FormControl_ColumnCreation(type, Control)) + "\n";

            return UpdateColumnQuery;
        }
示例#11
0
        // ---------------------------------------------------------------------------------------------------------------
        /* -- Form.DB_FormControl_ColumnCreation --
        // ---------------------------------------------------------------------------------------------------------------
        /* -- This encapsulates the sql column creation language so that it can be accessed by individual control
         */
        public string DB_FormControl_ColumnCreation(ControlType type, FormControl Control)
        {
            string ColumnCreation = "";
            string ControlID = Control.id.ToString(); // This is what we use to name/identify the columns.
            // DEVEL NOTE: if you decide to go by control names in the future OR offer it as an option, this is now setup for that

            switch (type)
            {
                case ControlType.Textbox:
                    // The textbox control only needs one column for its data
                    FormControl.Textbox TB = (FormControl.Textbox)Control;
                    if (TB.FullText)
                    { // MAX for fulltext
                        ColumnCreation = "[" + ControlID + "] VARCHAR(MAX) NULL";
                    }
                    else
                    { // 255 length
                        ColumnCreation = "[" + ControlID + "] VARCHAR(255) NULL";
                    }
                    break;
                case ControlType.List:
                    // The list stores the option chosen, single value
                    ColumnCreation = "[" + ControlID + "] VARCHAR(255) NULL";
                    break;
                case ControlType.Checkbox:
                    // CHECKBOX: Can have an optional text input (which will be 256 chars)
                    FormControl.Checkbox CB = (FormControl.Checkbox)Control;
                    if (CB.hasinput)
                    { // two values
                        ColumnCreation = "[" + ControlID + "] BIT NULL, [" + ControlID + "_text] VARCHAR(255) NULL";
                    }
                    else
                    { // single value
                        ColumnCreation = "[" + ControlID + "] BIT NULL";
                    }
                    break;
                case ControlType.DateTime:
                    // yah self splanitory yo
                    ColumnCreation = "[" + ControlID + "] DATETIME NULL";
                    break;
                case ControlType.Number:
                    // NUMBER: Set to 19 places and 4 decimals (stores as 9 bytes)
                    ColumnCreation = "[" + ControlID + "] NUMERIC(19, 4) NULL";
                    break;
                case ControlType.Percentage:
                    // PERCENTAGE: this can be a tinyint(256) since it is 0 - 100
                    ColumnCreation = "[" + ControlID + "] TINYINT NULL";
                    break;
                case ControlType.Range:
                    // RANGE: Depends on the type of range!
                    FormControl.Range RG = (FormControl.Range)Control;
                    switch (RG.type)
                    {
                        case FormControl.Range.Rangetype.TimeRange:
                        case FormControl.Range.Rangetype.DateRange:
                        case FormControl.Range.Rangetype.DateTimeRange:
                            // : stores as 2 datetimes
                            ColumnCreation = "[" + ControlID + "_Start] DATETIME NULL, [" + ControlID + "_End] DATETIME NULL";
                            break;
                        case FormControl.Range.Rangetype.Currency:
                        case FormControl.Range.Rangetype.MinMax:
                            // CURRENCY & MINMAX: These both will have a mininum number and a maximum numbered range.  We use our default numeric storage (9 bytes)
                            ColumnCreation = "[" + ControlID + "_Start] NUMERIC(19, 4) NULL, [" + ControlID + "_End] NUMERIC(19, 4) NULL";
                            break;
                    }
                    break;

                default:
                    break;
            }

            return ColumnCreation;
        }
示例#12
0
        // ---------------------------------------------------------------------------------------------------------------
        /* -- Form.DB_UpdateControl --
        // ---------------------------------------------------------------------------------------------------------------
        /*  Any controls that get "added" (insert cmds) can have their query created via this function
         */
        public string DB_FormControl_AddQuery(FormControl Control, ControlType type, int Formid)
        {
            string Query_NewControl = "";

            // Find the control type and build the query
            switch (type)
            {
                case ControlType.Textbox: // (formid, id, version, type, name, prompt, tip, textbox_lines, textbox_width)
                    FormControl.Textbox Control_TB = (FormControl.Textbox)Control;
                    Query_NewControl = string.Format(SQL.SQLQuery.Form_AddControl_Textbox, Formid, Control_TB.id, Control_TB.version, (int)type, SQL.ParseInput(Control.name), SQL.ParseInput(Control.prompt), SQL.ParseInput(Control.tip), Control.ordernum, SQL.BoolValue(Control.required), Control_TB.lines, Control_TB.width,SQL.BoolValue(Control_TB.FullText));
                    break;
                case ControlType.List: // (formid, id, version, type, name, prompt, tip, list_options, list_type)
                    FormControl.List Control_L = (FormControl.List)Control;
                    string ListOptions = "";
                    for (int t = 0; t < Control_L.Items.Length; t++)
                    {
                        ListOptions = ListOptions + Control_L.Items[t].name + ":" + Control_L.Items[t].value + ",";
                    }
                    ListOptions = ListOptions.Substring(0, ListOptions.Length - 1);
                    Query_NewControl = string.Format(SQL.SQLQuery.Form_AddControl_List, Formid, Control_L.id, Control_L.version, (int)type, SQL.ParseInput(Control.name), SQL.ParseInput(Control.prompt), SQL.ParseInput(Control.tip), Control.ordernum, SQL.BoolValue(Control.required), ListOptions, (int)Control_L.type);
                    break;
                case ControlType.Checkbox: // (formid, id, version, type, name, prompt, tip, checkbox_type, checkbox_initialstate, checkbox_hasinput)
                    FormControl.Checkbox Control_CB = (FormControl.Checkbox)Control;
                    Query_NewControl = string.Format(SQL.SQLQuery.Form_AddControl_Checkbox, Formid, Control_CB.id, Control_CB.version, (int)type, SQL.ParseInput(Control.name), SQL.ParseInput(Control.prompt), SQL.ParseInput(Control.tip), Control.ordernum, SQL.BoolValue(Control.required), (int)Control_CB.type, Convert.ToInt32(Control_CB.initialstate), Convert.ToInt32(Control_CB.hasinput));
                    break;
                case ControlType.DateTime: // (formid, id, version, type, name, prompt, tip, datetime_type)
                    FormControl.DateTime Control_DT = (FormControl.DateTime)Control;
                    Query_NewControl = string.Format(SQL.SQLQuery.Form_AddControl_DateTime, Formid, Control_DT.id, Control_DT.version, (int)type, SQL.ParseInput(Control.name), SQL.ParseInput(Control.prompt), SQL.ParseInput(Control.tip), Control.ordernum, SQL.BoolValue(Control.required), (int)Control_DT.type);
                    break;
                case ControlType.Number: // (formid, id, version, type, name, prompt, tip, number_min, number_max, number_interval, number_slider)
                    FormControl.Number Control_N = (FormControl.Number)Control;
                    Query_NewControl = string.Format(SQL.SQLQuery.Form_AddControl_Number, Formid, Control_N.id, Control_N.version, (int)type, SQL.ParseInput(Control.name), SQL.ParseInput(Control.prompt), SQL.ParseInput(Control.tip), Control.ordernum, SQL.BoolValue(Control.required), Control_N.min, Control_N.max, Control_N.interval, Convert.ToInt32(Control_N.slider));
                    break;
                case ControlType.Percentage: // (formid, id, version, type, name, prompt, tip, percentage_interval)
                    FormControl.Percentage Control_P = (FormControl.Percentage)Control;
                    Query_NewControl = string.Format(SQL.SQLQuery.Form_AddControl_Percentage, Formid, Control_P.id, Control_P.version, (int)type, SQL.ParseInput(Control.name), SQL.ParseInput(Control.prompt), SQL.ParseInput(Control.tip), Control.ordernum, SQL.BoolValue(Control.required), Control_P.interval);
                    break;
                case ControlType.Range: // (formid, id, version, type, name, prompt, tip, range_type, range_min, range_max)
                    FormControl.Range Control_Range = (FormControl.Range)Control;
                    Query_NewControl = string.Format(SQL.SQLQuery.Form_AddControl_Range, Formid, Control_Range.id, Control_Range.version, (int)type, SQL.ParseInput(Control.name), SQL.ParseInput(Control.prompt), SQL.ParseInput(Control.tip), Control.ordernum, SQL.BoolValue(Control.required), (int)Control_Range.type, Control_Range.min, Control_Range.max);
                    break;
            }
            return Query_NewControl;
        }
示例#13
0
        protected void Page_PreRender()
        {
            try
            {
                // Prevent browser from caching pages!!!
                Response.Buffer = true;
                Response.ExpiresAbsolute = DateTime.Now;
                Response.Expires = 0;
                Response.CacheControl = "no-cache";

                // Get DB from session
                try
                {
                    SQL = (UIFS.SQL)Session["SQL"]; SQL.OpenDatabase(); // we expect to already be open, but check nonetheless
                }
                catch
                { // Session Expired
                    AJAXhtmloutput = "<input type='hidden' id='SystemAlert' value=\":SystemAlert: Your Session Expired\nPlease refresh the page\n :-/ :SystemAlertEnd:\" />";
                    return;
                }

                // As long as the Session is functioning normally and passing data, we can continue
                if (Session["KeepAlive"] != null)
                {

                    // Check query code to see what action we need to perform
                    switch (Request.QueryString["cmd"])
                    {
                        // TODO: we need to add security here or there

                        case "0": //kill session
                            Session.Clear();
                            Session.Abandon();
                            return;

                        case "TEST": // TEST

                            //Form_Output = new UIFS.Form_Output();
                            //Form_Input.InputValue[] FormValues = new Form_Input.InputValue[0];
                            //outputHTML = ""; outputJS = "";
                            //SQL = new SQL(ConfigurationManager.AppSettings["SQL_Default"]);
                            //SQL.OpenDatabase();
                            //UIFSForm = new Form(ref SQL);
                            //if (UIFSForm.Load(8, 1, ref FormData))
                            //{
                            //    Form_Output.HTML(FormData, ref outputHTML, ref outputJS);
                            //    FormValues = Form_Output.LoadData(FormData, SQL, 1);
                            //    if (FormValues != null)
                            //    {
                            //        outputJS = outputJS + Form_Output.PopulateForm_js(FormData, FormValues);
                            //    }
                            //    else
                            //    {
                            //        outputHTML = "ERROR: null returned";
                            //    }
                            //    outputJS = "<script type='text/javascript'>" + outputJS + "</script>"; // comes raw javascript
                            //    AJAXhtmloutput = outputHTML + outputJS;
                            //}
                            //SQL.CloseDatabase(); // close after all calls
                            break;

                    /*----/========================================================================================\----
                    * ---|                            COMMON Functionality SECTION                                  |----
                    * ----\========================================================================================/----

                    * */

                        case "300": // Outputs a datatable for choosing UIFS Forms: ALL, one, or multiple (singular or plural)

                            string html = "", js = "";
                            html = "<div id='FormSelect'><table cellpadding='0' cellspacing='0' border='0' class='display' id='DataTables_FormSelect'>" +
                                "<thead><tr><th>ID</th><th>Name</th><th>version</th><th>Created by</th><th>Description</th></tr></thead>" +
                                "<tbody></tbody></table></div>";

                            js = "<script type='text/javascript'>" +
                                    "$('#DataTables_FormSelect').dataTable( {" +
                                    "'aoColumnDefs': [ " +
                                        "{ 'bSearchable': false, 'bVisible': false, 'aTargets': [ 0 ] }]," +		// 0 would be the id field...
                                    "'bProcessing': false," + // *one-time* request for data
                                    "'bJQueryUI':true," + // use jquery ui theme
                                    "'sPaginationType': 'full_numbers'," + // for the paging navigation (either full or 2 arrows)
                                    "'aLengthMenu': [[50, 100, 200, -1], [50, 100, 200, 'All']],"+
                                    "'sScrollY': '250px'," + // MUST set our height to keep this thing under control!
                                    "'sScrollX':'100%',"+ // Set width to container size...add scrollbar in table
                                    "'sHeightMatch': 'none',"+ // do not let calculate row height...for faster display
                                    "'sAjaxSource': 'ajax.aspx?cmd=300.1',"+
                                    // The next line adds a row click function (allows selection multiple)
                                    //"'fnInitComplete': function () {$('tr').click(function () {if ($(this).hasClass('row_selected')) $(this).removeClass('row_selected'); else $(this).addClass('row_selected'); }); }"+
                                    "});" +
                                    "SubjectTable = $('#DataTables_FormSelect').dataTable();" +
                                    // Single row selection...(just copied code from site, it is very wasteful of resources..temp anyway)
                                    "$('#DataTables_FormSelect tbody').click(function(event) {$(SubjectTable.fnSettings().aoData).each(function (){ $(this.nTr).removeClass('row_selected'); }); $(event.target.parentNode).addClass('row_selected'); });" +
                                    "</script>";
                            AJAXhtmloutput= html+js;

                            break;

                        case "300.1": // outputs the datatable *data* in json format
                            string json = "{ \"aaData\": [";
                            string description = "",createdby="";
                            UIFSForm = new UIFS.Form(ref SQL);
                            // Get list of forms
                            UIFS.FormLIST[] FormsList = UIFSForm.List();
                            //. for each form, build array
                            for (int t = 0; t < FormsList.Length; t++)
                            {
                                //. needs to be filtered
                                createdby = Format4DataTablesJSON(FormsList[t].createdby);
                                description = Format4DataTablesJSON(FormsList[t].description);
                                //description = Newtonsoft.Json.JsonConvert.SerializeObject(FormsList[t].description);
                                json = json + "[\"" + FormsList[t].id + "\",\"" + FormsList[t].name + "\",\"" + FormsList[t].currentversion + "\",\""+createdby  + "\",\"" + description+"\"],";
                            }
                            json = json.Remove(json.Length - 1); //remove last comma
                            json = json + "]}";

                            AJAXhtmloutput = json;
                            break;

                        /*----/========================================================================================\----
                        * ---|                            REPORT DESIGNER SECTION                                       |----
                        * ----\========================================================================================/----

                        * */

                        case "800": // Ask to load existing or start new
                            break;
                        case "801": // Load Report Display
                            //. get list
                            SQL.Query = SQL.SQLQuery.Reporting_LoadReportList;
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader();
                            html = "<table>";
                            if (SQL.sdr.HasRows)
                            {
                                while (SQL.sdr.Read())
                                {
                                    html = html + "<tr onclick=\"OpenReport('" + Convert.ToDouble(SQL.sdr[0]) + "')\" onmouseover=\"$(this).find('.lang').show();\" onmouseout=\"$(this).find('.lang').hide();\" >" +
                                        "<td><div class='title'>" + SQL.sdr.GetString(1) + "</div><div class='lang ReportDefinitionLanguage'>" + SQL.sdr.GetString(2) + "</div></td></tr>";
                                }
                            }
                            SQL.sdr.Close();
                            html = html+"</table>";
                            AJAXhtmloutput = html;
                            break;
                        case "801.1": // Load existing report
                            Reporting = new Reporting(ref SQL);
                            Reporting.Load_ReportingSubjects();
                            ReportDefinition = Reporting.Load_ReportingDefinition(Convert.ToInt64(Request.QueryString["id"]));
                            int iRS = Reporting.Find_ReportingSubject(ReportDefinition.Description.name);
                            Reporting.GUI = new Reporting.GraphicalUserInterface(ReportDefinition);
                            Reporting.GUI.Subject_Set(false,ref Reporting.FormLinks,Reporting.ReportingSubjects[iRS],ref Reporting.SQL, ref Reporting.ReportingSubjects);
                            Session["Reporting"] = Reporting;
                            break;
                        case "802": // Start new from Subject Chosen (currently a UIFS Form)
                            Reporting = new Reporting(ref SQL);
                            Reporting.Load_ReportingSubjects();
                            ReportDefinition = new UIFS.ReportDefinition();
                            ReportDefinition.Description = new UIFS.ReportDefinition.Subject();
                            ReportDefinition.Description.lang = "singular"; // singular, plural, ALL
                            ReportDefinition.Description.name = "Form"; // this is a UIFS Form object/subject
                            ReportDefinition.Description.selection = Request.QueryString["id"]; //Form id(s)
                            ReportingSubject RS = new ReportingSubject();
                            Reporting.GUI = new Reporting.GraphicalUserInterface(ReportDefinition); // setup GUI
                            Reporting.GUI.Subject_Set(true, ref Reporting.FormLinks, RS, ref SQL, ref Reporting.ReportingSubjects); // load data
                            Session["Reporting"] = Reporting;
                            break;

                        case "803": // Save Report Display
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            Reporting.SQL.OpenDatabase();
                            if (Reporting.BuildReport(ref Reporting.GUI.RD))
                            {
                                html = "<div class='input'>Title: <input id='ReportTitle' type='text' value='" + Reporting.GUI.RD.title + "' size='66' /></div>";
                                html = html + "<div class='ReportLang'>" + Reporting.GUI.RD.language + "</div>";
                                Session["Reporting"] = Reporting;
                            }
                            else
                            {
                                html = "<input type='hidden' value=':SystemAlert: There was an error trying to BUILD the report :( :SystemAlertEnd:' />";
                            }
                            //Reporting.SQL.CloseDatabase();
                            AJAXhtmloutput = html;
                            break;
                        case "803.1": // SAVE REPORT
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            Reporting.SQL.OpenDatabase();
                            //. update title
                            Reporting.GUI.RD.title = Request.QueryString["title"];
                            if (Reporting.Save_ReportingDefinition(ref Reporting.GUI.RD,this.User.Identity.Name))
                            {
                                AJAXhtmloutput = " :SystemAlert: Report Saved! :) :SystemAlertEnd: ";
                            }
                            else
                            {
                                AJAXhtmloutput = " :SystemAlert: There was an error trying to save the report :( :SystemAlertEnd: ";
                            }
                            Session["Reporting"] = Reporting;
                            //Reporting.SQL.CloseDatabase();
                            break;
                        case "808": // Report Subject display
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            Reporting.aReportOn_UIFSForm(Convert.ToInt32(Reporting.GUI.RD.Description.selection));
                            AJAXhtmloutput = Reporting.aReportOn; //Reporting.GUI.RD.Description.name
                            break;
                        case "809": // Report Definition display
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            AJAXhtmloutput= Reporting.GUI.ReportDefinition_Where();
                            break;
                        case "810": // Report Options display
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            AJAXhtmloutput= Reporting.GUI.WHERE();
                            break;
                        case "810.1": // Report Options - single option redraw
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            Reporting.GUI.ReportConditions[Convert.ToInt32(Request.QueryString["id"])].RDdetail.lang = Request.QueryString["phrase"];
                            AJAXhtmloutput=Reporting.GUI.ReportConditions[Convert.ToInt32(Request.QueryString["id"])].Edit();
                            Session["Reporting"] = Reporting;
                            break;
                        case "810.2": // Report Option: USE - get value(s) of control (outputs js)
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            int Ctrlid = Convert.ToInt32(Request.QueryString["id"]);
                            FormControl FC = Reporting.GUI.ReportConditions[Ctrlid].Control;
                            ControlType CT = Reporting.GUI.ReportConditions[Ctrlid].Control_type;
                            FormData = new UIFS.FormDataStruct();
                            //. we have to manually add our control in to get parsed
                            Array.Resize(ref FormData.ControlList, 1);
                            FormData.ControlList[0] = new FormDataStruct.ControlListDetail();
                            FormData.ControlList[0].id = Ctrlid; FormData.ControlList[0].index = 0; FormData.ControlList[0].type = CT;
                            FormData.AddControl(CT,FC,false);
                            Form_Input = new Form_Input();
                            AJAXhtmloutput = Form_Input.GetInput_js(FormData); // comes raw javascript
                            Session["FormData"] = FormData;
                            break;
                        case "810.3": // Report Option: USE - passed in value(s)
                            int RCid = Convert.ToInt32(Request.QueryString["id"]);
                            int iRDDd = -1;
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            Form_Input = new Form_Input();
                            UIFS.Form_Input.InputValue[] IV = Form_Input.FilterInput(Request.QueryString, FormData);
                            //.  give this ReportCondition a selection value
                            if (IV[0].value == null)
                            { // use Start/End (From/To) values
                                Reporting.GUI.ReportConditions[RCid].RDdetail.selection = IV[0].Start + ',' + IV[0].End;
                            }
                            else
                            { // default to just returning a single value
                                Reporting.GUI.ReportConditions[RCid].RDdetail.selection = IV[0].value;
                            }
                            //. add a new ReportDefinition.Description.Detail
                            ReportDefinition.Detail detail = new UIFS.ReportDefinition.Detail();
                            if (Reporting.GUI.ReportConditions[RCid].detail.name.StartsWith("[global]")) {
                                detail.name = Reporting.GUI.ReportConditions[RCid].detail.name;
                            }
                            else {detail.name = Reporting.GUI.ReportConditions[RCid].detail.db;}
                            detail.lang = Reporting.GUI.ReportConditions[RCid].RDdetail.lang;
                            detail.selection = Reporting.GUI.ReportConditions[RCid].RDdetail.selection;
                            iRDDd = Reporting.GUI.RD.Description.AddDetail(detail); // already holds needed/updated information!
                            Reporting.GUI.ReportConditions[RCid].iRDDdetail = iRDDd;
                            Session["Reporting"] = Reporting;
                            break;
                        case "810.4": // Report Option: Remove
                            int RC_remove = Convert.ToInt32(Request.QueryString["id"]);
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            Reporting.GUI.RD.Description.DelDetail(Reporting.GUI.ReportConditions[RC_remove].RDdetail.name);
                            Reporting.GUI.ReportConditions[RC_remove].iRDDdetail = -1; // not being used anymore
                            Session["Reporting"] = Reporting;
                            break;

                        case "811": // Report Field Selection (THAT SHOWS) display
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            AJAXhtmloutput= Reporting.GUI.THATSHOWS();
                            break;
                        case "811.1": // Report (Field) selection (from js: Aggregate_Add)
                            ReportDefinition.Aggregate RDA = new UIFS.ReportDefinition.Aggregate();
                            int iShow_add = Convert.ToInt32(Request.QueryString["id"]); // our index
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));

                            Reporting.GUI.ReportShowing[iShow_add].manipulation = Request.QueryString["mani"];
                            RDA.db = Reporting.GUI.ReportShowing[iShow_add].db;
                            RDA.title = Reporting.GUI.ReportShowing[iShow_add].title;
                            RDA.datatype = Reporting.GUI.ReportShowing[iShow_add].datatype;
                            RDA.manipulation = Reporting.GUI.ReportShowing[iShow_add].manipulation;
                            Reporting.GUI.ReportShowing[iShow_add].iAggr = Reporting.GUI.RD.Description.AddAggregrate(RDA); // push our new aggr.
                            Session["Reporting"] = Reporting;
                            break;

                        case "890": // Preview Report (this outputs a datatables..)
                            Reporting = (Reporting)Convert.ChangeType(Session["Reporting"], typeof(Reporting));
                            Reporting.SQL.OpenDatabase();
                            //TODO: should check to see if built or not...save to session..
                            if (!Reporting.BuildReport(ref Reporting.GUI.RD)) {
                                //Reporting.SQL.CloseDatabase();
                                AJAXhtmloutput = " :SystemAlert: There was an error trying to process the report :( :SystemAlertEnd: ";
                                return;
                            }
                            string AggrOutput = Reporting.Output_Aggregation(Reporting.GUI.RD);
                            string DataTablesOutput = Reporting.Output_DataTables(Reporting.GUI.RD);
                            js = "";
                            filterJavascript(ref AggrOutput, ref js);
                            filterJavascript(ref DataTablesOutput, ref js);
                            AJAXhtmloutput =
                                "<div id='ReportLang'>" + Reporting.GUI.RD.language + "</div>" +
                                "<div id='ReportAggr'>" + AggrOutput + "</div>" +
                                "<div id='ReportData'>" + DataTablesOutput + "</div>" +
                                "<script type='text/javascript'>" + js + "</script>";
                            //Reporting.SQL.CloseDatabase();
                            break;

                        /* ----/========================================================================================\----
                         * ----|                                  DESIGNER SECTION                                      |----
                         * ----\========================================================================================/----
                         *
                         * */

                        case "900": // New Form
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            if (Convert.ToBoolean(Request.QueryString["confirmation"]))
                            { // Confirmation is TRUE, create new form
                                FormData = new UIFS.FormDataStruct();
                                FormData.newform = true; // not sure if we use this for anything...but it is functional
                                Session["FormData"] = FormData;
                                AJAXhtmloutput = "";
                            }
                            else { // if the confirmation variable is set to true, then we skip the check and start a new form
                                // First, run through current form and see if there are any unsaved changes
                                if (FormData.ControlList != null)
                                {
                                    for (int t = 0; t < FormData.ControlList.Length; t++)
                                    {
                                        if (FormData.ControlList[t].controlchanged || FormData.ControlList[t].added || FormData.ControlList[t].removed)
                                        { // If the current form has unsaved changes, tell the calling javascript with this msg
                                            AJAXhtmloutput = "UNSAVED CHANGES";
                                            break;
                                        }
                                    }
                                }
                            }

                            break;
                        case "901": // Load/Open Form Dialog
                            AJAXhtmloutput = Form_Open();
                            break;
                        case "901.1": // Actual Load Form data
                            UIFSForm = new UIFS.Form(ref SQL);
                            FormData = new UIFS.FormDataStruct();
                            if (!UIFSForm.Load(Convert.ToInt32(Request.QueryString["formid"]),-1, ref FormData))
                            { // failed to load
                                AJAXhtmloutput = " :SystemAlert: Failed to load form! ExMsg:" + UIFSForm.ErrorEx.Message + "\nStacktrace:" + UIFSForm.ErrorEx.StackTrace + " :SystemAlertEnd: ";
                                SQL.WriteLog_Error(UIFSForm.ErrorEx, "Failed to load form: " + Request.QueryString["formid"], "UIFS.ajax:901.1");
                                return;
                            }
                            Session["FormData"] = FormData; // Save to session
                            break;
                        case "901.2": // New Form based on...
                            //. load a form and clear out needed variables to make it a "new" form
                            UIFSForm = new UIFS.Form(ref SQL);
                            FormData = new UIFS.FormDataStruct();
                            if (!UIFSForm.Load(Convert.ToInt32(Request.QueryString["formid"]),-1, ref FormData))
                            { // failed to load
                                AJAXhtmloutput = " :SystemAlert: Failed to load form! ExMsg:" + UIFSForm.ErrorEx.Message + "\nStacktrace:" + UIFSForm.ErrorEx.StackTrace + " :SystemAlertEnd: ";
                                SQL.WriteLog_Error(UIFSForm.ErrorEx, "Failed to load form: " + Request.QueryString["formid"], "UIFS.ajax:901.2");
                                return;
                            }
                            // reset data for new form
                            FormData.name="";FormData.description="";FormData.id=0;FormData.version=0;FormData.newform=true;
                            Session["FormData"] = FormData; // Save to session
                            break;
                        case "903": // Save Dialog
                            AJAXhtmloutput = Form_Save();
                            break;
                        case "903.1": // Save Form
                            string ValidationMessage="";
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            if (FormData.ControlList == null) { AJAXhtmloutput = " :SystemAlert: No form to save, doh! :SystemAlertEnd: "; return; }
                            FormData.name = Request.QueryString["name"];
                            FormData.description = Request.QueryString["desc"];
                            UIFSForm = new UIFS.Form(ref SQL);
                            if (UIFSForm.Validate(ref FormData, ref ValidationMessage))
                            {
                                if (UIFSForm.Save(ref FormData))
                                {
                                    AJAXhtmloutput = " :SystemAlert: Form Saved! :SystemAlertEnd: ";
                                    // After form is saved, we need to reload it in order to properly get the changes
                                    // so, we will just clear out the Form here to act like a new form was started
                                    FormData = new UIFS.FormDataStruct();
                                    Session["FormData"] = FormData;
                                }
                                else
                                {
                                    AJAXhtmloutput = " :SystemAlert: Failed to save form :SystemAlertEnd: ";
                                }
                            }
                            else
                            {
                                AJAXhtmloutput = " :SystemAlert: " + ValidationMessage + " :SystemAlertEnd: ";
                            }
                            break;
                        case "904": // Form Settings dialog
                            AJAXhtmloutput = Form_Settings();
                            break;
                        case "904.1": // Form Settings SAVE
                            // TODO: should it just "save" to the session or the db too?
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            FormData.name = Request.QueryString["name"];
                            FormData.description = Request.QueryString["desc"];
                            //FormData.Layout.OutputFormat = (UIFS.Layout.Style)Convert.ToInt32(Request.QueryString["Layout_NumOfColumns"]);
                            Session["FormData"] = FormData;
                            AJAXhtmloutput = " :SystemAlert: Form Settings Saved! :SystemAlertEnd: ";
                            break;

                        case "910": // Live Preview
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.Form_Output FormPreview = new UIFS.Form_Output();
                            outputHTML=""; outputJS="";
                            FormPreview.HTML(FormData, ref outputHTML, ref outputJS);
                            // TOOLBAR: with buttons for testing/debugging
                            outputHTML = "<div id='FormPreview_HTML_Toolbar'><span class='submitvalues' onclick='FakeFormSubmit_GetValues()'>FakeSubmit</span>"+
                                "<span class='submitdata' onclick='FakeFormSubmit_SaveData()'>FakeSaveData</span>" +
                                "<span class='' onclick='FakeFormSubmit_Validate()'>FakeValidate</span>" +
                                "</div<div id='FormPreview_HTML_Toolbar_spacer' style='height:10px;'></div>"
                                + outputHTML;
                            outputJS = "<script type='text/javascript'>" + outputJS + "</script>"; // comes raw javascript
                            AJAXhtmloutput = outputHTML + outputJS;
                            FormPreview = null; FormData=null;
                            break;
                        case "910.1": // Live Preview: HTML Toolbar: getvalues (fake submit)
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.Form_Input FI_getvalues = new Form_Input();
                            //AJAXhtmloutput = "<script type='text/javascript'>" + Form_Input.GetInput_js(FormData) + "</script>"; // comes raw javascript
                            AJAXhtmloutput = FI_getvalues.GetInput_js(FormData); // comes raw javascript
                            FI_getvalues = null; FormData=null;
                            break;
                        case "910.2": // Live Preview: HTML Toolbar: formsave (Test Form saving data)
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.Form_Input FI_save = new Form_Input();
                            UIFS.Form_Input.InputValue[] InputValues = FI_save.FilterInput(Request.QueryString, FormData);
                            long formid = -1;
                            if (FI_save.Save(FormData, InputValues, ref SQL, true, ref formid))
                            { // successful
                                AJAXhtmloutput = "<input type='hidden' id='SystemAlert' value=\" :SystemAlert: Form Data Save: Successful! :SystemAlertEnd: \" />";
                            }
                            else { AJAXhtmloutput = "<input type='hidden' id='SystemAlert' value=\" :SystemAlert: Form Data Save: Failed! :SystemAlertEnd: \" />"; }
                            FI_save = null; FormData = null;
                            break;

                        case "1000": // Designer Main Screen Display
                            switch (Request.QueryString["Option"]){
                                case "Controls":
                                    int FormCnt_Textbox = 0, FormCnt_List = 0, FormCnt_Checkbox = 0, FormCnt_DateTime = 0, FormCnt_Number = 0, FormCnt_Percentage=0,FormCnt_Range=0;
                                    FormData = (UIFS.FormDataStruct)Session["FormData"];
                                    if (FormData.ControlList != null)
                                    { // get count of each # of controls
                                        foreach (UIFS.FormDataStruct.ControlListDetail cld in FormData.ControlList)
                                        {
                                            switch (cld.type)
                                            {
                                                case ControlType.Checkbox: FormCnt_Checkbox += 1; break;
                                                case ControlType.DateTime: FormCnt_DateTime += 1; break;
                                                case ControlType.Number: FormCnt_Number += 1; break;
                                                case ControlType.Percentage: FormCnt_Percentage += 1; break;
                                                case ControlType.List: FormCnt_List += 1; break;
                                                case ControlType.Range: FormCnt_Range += 1; break;
                                                case ControlType.Textbox: FormCnt_Textbox += 1; break;
                                            }
                                        }
                                    }
                                    html =
                                        "<div id='CTRL_Textbox' class='CTRL ui-widget-content'>Text Box (<span style='color:Blue;'>" + FormCnt_Textbox + "</span>)</div>" +
                                        "<div id='CTRL_List' class='CTRL ui-widget-content'>List (<span style='color:Blue;'>" + FormCnt_List + "</span>)</div>" +
                                        "<div id='CTRL_List_HourBlock' class='subCTRL ui-widget-content'>Hour Blocks [Time]</div>" +
                                        "<div id='CTRL_Checkbox' class='CTRL ui-widget-content'>Checkbox (<span style='color:Blue;'>" + FormCnt_Checkbox + "</span>)</div>" +
                                        "<div id='CTRL_DateTime' class='CTRL ui-widget-content'>Date/Time (<span style='color:Blue;'>" + FormCnt_DateTime + "</span>)</div>" +
                                        "<div id='CTRL_Number' class='CTRL ui-widget-content'>Number (<span style='color:Blue;'>" + FormCnt_Number + "</span>)</div>" +
                                        "<div id='CTRL_Percentage' class='CTRL ui-widget-content'>Percentage (<span style='color:Blue;'>" + FormCnt_Percentage + "</span>)</div>" +
                                        "<div id='CTRL_Range' class='CTRL ui-widget-content'>Range (<span style='color:Blue;'>" + FormCnt_Range + "</span>)</div>"
                                        ;
                                    AJAXhtmloutput = AJAXhtmloutput + html;
                                    FormData = null;
                                    break;
                                case "Form":
                                    Designer_FormTemplate();
                                    break;

                                case "Menu":
                                    html = "Save Form, New Form, Load Form, Full Preview";
                                    break;
                                default:
                                    break;
                            }
                            break;

                        case "1001": // DISPLAY Add/Create control dialog
                            CCDesigner = new UIFS.Designer();
                            switch (Request.QueryString["type"])
                            {
                                case "CTRL_Textbox":
                                    // create an empty control
                                    UIFS.FormControl.Textbox CTRL_TextBox = new UIFS.FormControl.Textbox();
                                    FormData = new UIFS.FormDataStruct(); // to use the jquery routines
                                    CTRL_TextBox.id = -1;
                                    js = FormData.jQuery.Textbox_AddNew(); // Remove save buttons
                                    AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.Textbox, CTRL_TextBox) + js;
                                    break;
                                case "CTRL_List":
                                    UIFS.FormControl.List CTRL_List = new UIFS.FormControl.List();
                                    FormData = new UIFS.FormDataStruct(); // to use the jquery routines
                                    CTRL_List.id = -1;
                                    js = FormData.jQuery.List_AddNew(); // Remove save buttons
                                    AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.List, CTRL_List) + js;
                                    break;
                                case "CTRL_Checkbox":
                                    UIFS.FormControl.Checkbox CTRL_Checkbox = new UIFS.FormControl.Checkbox();
                                    FormData = new UIFS.FormDataStruct(); // to use the jquery routines
                                    CTRL_Checkbox.id = -1;
                                    js = FormData.jQuery.Checkbox_AddNew(); // Remove save buttons
                                    AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.Checkbox, CTRL_Checkbox) + js;
                                    break;
                                case "CTRL_DateTime":
                                    UIFS.FormControl.DateTime CTRL_DateTime = new UIFS.FormControl.DateTime();
                                    FormData = new UIFS.FormDataStruct(); // to use the jquery routines
                                    CTRL_DateTime.id = -1;
                                    js = FormData.jQuery.DateTime_AddNew(); // Remove save buttons
                                    AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.DateTime, CTRL_DateTime) + js;
                                    break;
                                case "CTRL_Number":
                                    UIFS.FormControl.Number CTRL_Number = new UIFS.FormControl.Number();
                                    FormData = new UIFS.FormDataStruct(); // to use the jquery routines
                                    CTRL_Number.id = -1;
                                    js = FormData.jQuery.Number_AddNew(); // Remove save buttons
                                    AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.Number, CTRL_Number) + js;
                                    break;
                                case "CTRL_Percentage":
                                    UIFS.FormControl.Percentage CTRL_Percentage = new UIFS.FormControl.Percentage();
                                    FormData = new UIFS.FormDataStruct(); // to use the jquery routines
                                    CTRL_Percentage.id = -1;
                                    js = FormData.jQuery.Percentage_AddNew(); // Remove save buttons
                                    AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.Percentage, CTRL_Percentage) + js;
                                    break;
                                case "CTRL_Range":
                                    UIFS.FormControl.Range CTRL_Range = new UIFS.FormControl.Range();
                                    FormData = new UIFS.FormDataStruct(); // to use the jquery routines
                                    CTRL_Range.id = -1;
                                    js = FormData.jQuery.Range_AddNew(); // Remove save buttons
                                    AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.Range, CTRL_Range) + js;
                                    break;
                            }
                            break;

                        case "1002": // Remove Control
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            int iCtrl = FormData.Find_ControlListEntry_byControlID(Convert.ToInt32(Request.QueryString["id"]));
                            // reorder to last, so that active controls are ordered properly
                            FormData.Sort_ControlList(Convert.ToInt32(Request.QueryString["id"]), FormData.ControlList.Length);
                            // check if existing control or new control
                            if (FormData.ControlList[iCtrl].added)
                            { // This control was added during this session (not saved) - remove from existence!
                                FormData.RemoveControl(Convert.ToInt32(Request.QueryString["id"]));
                            }
                            else { // mark as removed (routines on Save)
                                FormData.ControlList[iCtrl].removed = true;
                            }
                            Session["FormData"] = FormData;
                            AJAXhtmloutput = "";
                            break;
                        case "1050": // Reorder controls
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            int Controlid = Convert.ToInt32(Request.QueryString["id"].Substring(Request.QueryString["id"].IndexOf("_")+1));
                            FormData.Sort_ControlList(Controlid, Convert.ToInt32(Request.QueryString["sortindex"]));
                            Session["FormData"] = FormData;
                            break;

                        /* ---------------------------------------------------------------------------------------------------
                         * -- Control Update/Addition Functions
                         * ---------------------------------------------------------------------------------------------------
                         */

                        // 1099 = Common Properties for all controls functions
                        case "1099": // Update
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            FormControl ControlChanges = new FormControl();
                            ControlChanges.name = Request.QueryString["name"];
                            ControlChanges.prompt = Request.QueryString["prompt"];
                            ControlChanges.tip = Request.QueryString["tip"];
                            ControlChanges.required = Convert.ToBoolean(Request.QueryString["req"]);
                            FormData.Update_ControlCommonProperties(Convert.ToInt32(Request.QueryString["id"]), ControlChanges,true);
                            Session["FormData"] = FormData;
                            break;

                        // 1100 = Textbox Control functions
                        case "1100": // Textbox Control - update properties
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            id = Convert.ToInt32(Request.QueryString["id"]); // control id
                            iControl = FormData.Find_Controlindex_byID(id);
                            FormData.Textbox[iControl].lines = Convert.ToInt32(Request.QueryString["lines"]);
                            FormData.Textbox[iControl].width = Convert.ToInt32(Request.QueryString["width"]);
                            FormData.Textbox[iControl].FullText = Convert.ToBoolean(Request.QueryString["fulltext"]);
                            // Control changed, mark for update
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].controlchanged = true;
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].newversionneeded = true;
                            Session["FormData"] = FormData;
                            break;

                        case "1100.1": // Textbox Control - ADD NEW
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.FormControl.Textbox newTBC = new UIFS.FormControl.Textbox();
                            newTBC.name = Request.QueryString["-1_Name"].ToString();
                            newTBC.prompt = Request.QueryString["-1_Prompt"].ToString();
                            newTBC.tip = Request.QueryString["-1_Tip"].ToString();
                            newTBC.required = Convert.ToBoolean(Request.QueryString["-1_Req"]);
                            newTBC.lines = Convert.ToInt32(Request.QueryString["-1_Lines"]);
                            newTBC.width = Convert.ToInt32(Request.QueryString["-1_Width"]);
                            newTBC.FullText = Convert.ToBoolean(Request.QueryString["-1_FullText"]);
                            iControl = FormData.AddControl(UIFS.ControlType.Textbox, newTBC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData;
                            break;
                        case "1100.2": // Textbox Control -

                            break;

                        // 1101 = List Control functions
                        case "1101": // List Control - Add Remove from Option List OR update properties
                            CCDesigner = new UIFS.Designer();
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            id = Convert.ToInt32(Request.QueryString["id"]); // List control id
                            iControl = FormData.Find_Controlindex_byID(id); // find List control
                            int iItem, newOrderNum;
                            bool reDraw = false;

                            switch (Request.QueryString["Option"])
                            {
                                case "Add":
                                    string name = Request.QueryString["name"].ToString();
                                    string value = Request.QueryString["value"].ToString();
                                    FormData.List[iControl].AddItem(name, value); // add this item
                                    reDraw = true;
                                    break;
                                case "Remove":
                                    iItem = Convert.ToInt32(Request.QueryString["i"]); // index of item
                                    FormData.List[iControl].RemoveItem(iItem); // remove this item
                                    reDraw = true;
                                    break;
                                case "ReOrder":
                                    iItem = Convert.ToInt32(Request.QueryString["item"]); // index of item
                                    newOrderNum = Convert.ToInt32(Request.QueryString["newindex"]); // new index#
                                    FormData.List[iControl].ReOrderItem(iItem, newOrderNum); // reorder
                                    reDraw = true; // We MUST redraw here because the remove buttons are indexed for each option
                                    break;
                                case "update":
                                    FormData.List[iControl].type = (FormControl.List.listtype)Convert.ToByte(Request.QueryString["type"]);
                                    break;
                            }
                            if (reDraw) {
                                // we need to reinitialize jquery (AJAX picks up java at end of output and executes it)
                                js = FormData.jQuery.List(FormData.List[iControl].id);
                                AJAXhtmloutput = CCDesigner.ControlProperties(UIFS.ControlType.List, FormData.List[iControl]) + js;
                            }
                            // Control changed, mark for update
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].controlchanged = true;
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].newversionneeded = true;
                            Session["FormData"] = FormData; // Push back to session
                            break;

                        case "1101.1": // List Control - Add New
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            newLC = new UIFS.FormControl.List();
                            newLC.name = Request.QueryString["-1_Name"].ToString();
                            newLC.prompt = Request.QueryString["-1_Prompt"].ToString();
                            newLC.tip = Request.QueryString["-1_Tip"].ToString();
                            newLC.required = Convert.ToBoolean(Request.QueryString["-1_Req"]);
                            newLC.type = (FormControl.List.listtype)Convert.ToByte(Request.QueryString["-1_type"]);
                            iControl = FormData.AddControl(UIFS.ControlType.List, newLC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData;
                            break;

                        case "1101.2": // List Control - (Predefined) Hour Blocks
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            newLC = new UIFS.FormControl.List();
                            newLC.name = "Hour Block Time Selection";
                            newLC.prompt = "Choose the time frame.";
                            newLC.tip = "Please select the correct hour time frame";
                            newLC.type = FormControl.List.listtype.slider;
                            newLC.Items = FormControl.List.HourBlocks; // use static (Predefined) values
                            iControl = FormData.AddControl(UIFS.ControlType.List, newLC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData;
                            break;

                        // Checkbox functions
                        case "1102": // Checkbox Control - update properties
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            id = Convert.ToInt32(Request.QueryString["id"]); // control id
                            iControl = FormData.Find_Controlindex_byID(id);
                            FormData.Checkbox[iControl].type = (UIFS.FormControl.Checkbox.checkboxtype)Convert.ToInt32(Request.QueryString["type"]);
                            FormData.Checkbox[iControl].initialstate = Convert.ToBoolean(Request.QueryString["initialstate"]);
                            FormData.Checkbox[iControl].hasinput = Convert.ToBoolean(Request.QueryString["hasinput"]);
                            // Control changed, mark for update
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].controlchanged = true;
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].newversionneeded = true;
                            Session["FormData"] = FormData;
                            break;
                        case "1102.1": // Add new checkbox control
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.FormControl.Checkbox newCbC = new UIFS.FormControl.Checkbox();
                            newCbC.name = Request.QueryString["-1_Name"].ToString();
                            newCbC.prompt = Request.QueryString["-1_Prompt"].ToString();
                            newCbC.tip = Request.QueryString["-1_Tip"].ToString();
                            newCbC.required = Convert.ToBoolean(Request.QueryString["-1_Req"]);
                            newCbC.type = (UIFS.FormControl.Checkbox.checkboxtype)Convert.ToInt32(Request.QueryString["-1_type"]);
                            newCbC.initialstate = Convert.ToBoolean(Request.QueryString["-1_initialstate"]);
                            newCbC.hasinput = Convert.ToBoolean(Request.QueryString["-1_hasinput"]);
                            iControl = FormData.AddControl(UIFS.ControlType.Checkbox, newCbC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData;
                            break;

                            // DateTime functions
                        case "1103": // DateTime Control - update properties
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            id = Convert.ToInt32(Request.QueryString["id"]); // control id
                            iControl = FormData.Find_Controlindex_byID(id);
                            FormData.DateTime[iControl].type = (UIFS.FormControl.DateTime.datetimetype)Convert.ToInt32(Request.QueryString["type"]);
                            // Control changed, mark for update
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].controlchanged = true;
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].newversionneeded = true;
                            Session["FormData"] = FormData;
                            break;
                        case "1103.1": // Add a new DateTime Control
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.FormControl.DateTime newDTC = new UIFS.FormControl.DateTime();
                            newDTC.name = Request.QueryString["-1_Name"].ToString();
                            newDTC.prompt = Request.QueryString["-1_Prompt"].ToString();
                            newDTC.tip = Request.QueryString["-1_Tip"].ToString();
                            newDTC.required = Convert.ToBoolean(Request.QueryString["-1_Req"]);
                            newDTC.type = (UIFS.FormControl.DateTime.datetimetype)Convert.ToInt32(Request.QueryString["-1_type"]);
                            iControl = FormData.AddControl(UIFS.ControlType.DateTime, newDTC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData;
                            break;

                        // 1104... = Number Control functions
                        case "1104": // Number Control - update properties
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            id = Convert.ToInt32(Request.QueryString["id"]); // control id
                            iControl = FormData.Find_Controlindex_byID(id);
                            FormData.Number[iControl].min = Convert.ToDecimal(Request.QueryString["min"]);
                            FormData.Number[iControl].max = Convert.ToDecimal(Request.QueryString["max"]);
                            FormData.Number[iControl].interval = Convert.ToDecimal(Request.QueryString["interval"]);
                            FormData.Number[iControl].slider = Convert.ToBoolean(Request.QueryString["slider"]);
                            // Control changed, mark for update
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].controlchanged = true;
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].newversionneeded = true;
                            Session["FormData"] = FormData; // save
                            break;
                        case "1104.1": // Add a new Number Control
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.FormControl.Number newNC = new UIFS.FormControl.Number();
                            newNC.name = Request.QueryString["-1_Name"].ToString();
                            newNC.prompt = Request.QueryString["-1_Prompt"].ToString();
                            newNC.tip = Request.QueryString["-1_Tip"].ToString();
                            newNC.required = Convert.ToBoolean(Request.QueryString["-1_Req"]);
                            newNC.min = Convert.ToDecimal(Request.QueryString["-1_min"]);
                            newNC.max = Convert.ToDecimal(Request.QueryString["-1_max"]);
                            newNC.interval = Convert.ToDecimal(Request.QueryString["-1_interval"]);
                            newNC.slider = Convert.ToBoolean(Request.QueryString["-1_slider"]);
                            iControl = FormData.AddControl(UIFS.ControlType.Number, newNC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData; // save
                            break;

                        // 1105... = Percentage Control functions
                        case "1105": // Percentage Control - update properties
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            id = Convert.ToInt32(Request.QueryString["id"]); // control id
                            iControl = FormData.Find_Controlindex_byID(id);
                            FormData.Percentage[iControl].interval = Convert.ToInt32(Request.QueryString["interval"]);
                            if (FormData.Percentage[iControl].interval <= 0) { FormData.Percentage[iControl].interval = 1; } // CANNOT BE ZERO
                            // Control changed, mark for update
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].controlchanged = true;
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].newversionneeded = true;
                            Session["FormData"] = FormData; // save
                            break;
                        case "1105.1": // Add a new Percentage Control
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.FormControl.Percentage newPC = new UIFS.FormControl.Percentage();
                            newPC.name = Request.QueryString["-1_Name"].ToString();
                            newPC.prompt = Request.QueryString["-1_Prompt"].ToString();
                            newPC.tip = Request.QueryString["-1_Tip"].ToString();
                            newPC.required = Convert.ToBoolean(Request.QueryString["-1_Req"]);
                            newPC.interval = Convert.ToInt32(Request.QueryString["-1_interval"]);
                            if (newPC.interval <= 0) { newPC.interval = 1; } // CANNOT BE ZERO
                            iControl = FormData.AddControl(UIFS.ControlType.Percentage, newPC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData; // save
                            break;

                        // 1106... = Range Control functions
                        case "1106": // Range Control - update properties
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            id = Convert.ToInt32(Request.QueryString["id"]); // control id
                            iControl = FormData.Find_Controlindex_byID(id);
                            FormData.Range[iControl].type = (UIFS.FormControl.Range.Rangetype)Convert.ToInt32(Request.QueryString["type"]);
                            FormData.Range[iControl].min = Convert.ToDecimal(Request.QueryString["min"]);
                            FormData.Range[iControl].max = Convert.ToDecimal(Request.QueryString["max"]);
                            // Control changed, mark for update
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].controlchanged = true;
                            FormData.ControlList[FormData.Find_ControlListEntry_byControlID(id)].newversionneeded = true;
                            Session["FormData"] = FormData; // save
                            break;
                        case "1106.1": // Add a new Range Control
                            FormData = (UIFS.FormDataStruct)Session["FormData"];
                            UIFS.FormControl.Range newRC = new UIFS.FormControl.Range();
                            newRC.name = Request.QueryString["-1_Name"].ToString();
                            newRC.prompt = Request.QueryString["-1_Prompt"].ToString();
                            newRC.tip = Request.QueryString["-1_Tip"].ToString();
                            newRC.required = Convert.ToBoolean(Request.QueryString["-1_Req"]);
                            newRC.type = (UIFS.FormControl.Range.Rangetype)Convert.ToInt32(Request.QueryString["-1_type"]);
                            newRC.min = Convert.ToDecimal(Request.QueryString["-1_min"]);
                            newRC.max = Convert.ToDecimal(Request.QueryString["-1_max"]);
                            iControl = FormData.AddControl(UIFS.ControlType.Range, newRC, true); // Add the new control
                            // New Control, mark for addition
                            FormData.ControlList[FormData.ControlList.Length - 1].added = true; // must be called before Sort_ControlList
                            FormData.Sort_ControlList(FormData.ControlList[FormData.ControlList.Length - 1].id, Convert.ToInt32(Request.QueryString["sortindex"])); // Reorder
                            Session["FormData"] = FormData; // save
                            break;

                        default: // THE querystring code did not check out, ignore
                            break;
                    }

                }

                else
                {
                    AJAXhtmloutput = "<input type='hidden' id='SystemAlert' value=\" :SystemAlert: Your Session has Expired!\n\nPlease exit the application :SystemAlertEnd: \" />";
                    //SQL.WriteLog(0, "Session Expired/No session data exists", this.User.Identity.Name);
                }

            }
            catch (Exception ex)
            {
                AJAXhtmloutput = "<input type='hidden' id='SystemAlert' value=\" :SystemAlert: An ERROR occured\r\nMessage:"+ex.Message+"\r\nStackTrace:"+ex.StackTrace+"<br/> :SystemAlertEnd: \" />";
            //    //SQL.WriteLog_AppError(0, "AJAX Routine Failed: " + SQL.ParseInput(Request.QueryString.ToString()), "PreRender", ex, this.User.Identity.Name);
            }
            finally
            {
            }
        }