Exemple #1
0
 public void WriteLog(string Msg)
 {
     string username = WindowsIdentity.GetCurrent().Name;
     SQL ErrSQL = new SQL(ConfigurationManager.AppSettings["UIFS.Log"].ToString());
     ErrSQL.OpenDatabase();
     ErrSQL.Query = string.Format(ErrSQL.SQLQuery.WriteLOG, 0, ErrSQL.ParseInput(Msg), username);
     ErrSQL.cmd = ErrSQL.Command(ErrSQL.Data);
     ErrSQL.cmd.ExecuteNonQuery();
     ErrSQL.CloseDatabase();
     ErrSQL = null;
 }
Exemple #2
0
            /* /---[ Subject_Set       ]--------------------------------------------------------------------\
             * | Loads all the ReportConditions based on Subject (does not matter if a new report or existing one)
             * |
             * \-------------------------------------------------------------------/
             * isnew    =   false if loading/editing an existing RD  (otherwise if a new Subject is chosen, TRUE to rebuild)
             *
             */
            public bool Subject_Set(bool isnew, ref FormLink Formlinks, ReportingSubject RS, ref SQL SQL, ref ReportingSubject[] ReportingSubjects)
            {
                bool exists = false;
                ReportingSubject.Detail RSdetail;
                ReportDefinition.Detail existingRDdetail = new ReportDefinition.Detail();
                FormControl UIFSFormControl;
                if (isnew || this.ReportConditions == null)
                {
                    this.ReportConditions = new ReportCondition[0]; // starting over fresh...should this be possible?
                }

                //. setup [globals]
                foreach (FormLink.Detail FLdetail in Formlinks.Details) {
                    int iRDDd=-1; // holds the index of the RD.Desc.detail for linking the ReportCondition to the actual RD.Description...
                    switch (FLdetail.type)
                    {
                        // -[ Global Subject ]-
                        // this behaves as a "pointer"/collection of id(s) to reference a Subject or set of Subjects to filter by...
                        // this is a UIFS standard, but for UX simplification (This "subject" has a corresponding id field that is unique to each form created)
                        case "Subject":
                            if (!isnew) { // check to see if exists in current RD
                                for (int t=0;t<RD.Description.Details.Length;t++) {
                                    if ("[global]"+FLdetail.name == RD.Description.Details[t].name)
                                    {
                                        existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                        exists = true; break;
                                    }
                                }
                            }
                            RSdetail = new ReportingSubject.Detail();
                            RSdetail.db = FLdetail.field;
                            RSdetail.name = "[global]" + FLdetail.name;
                            RSdetail.type = "id"; // this basically tells the application that this is a linked *Subject
                            Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                            ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                            if (exists)
                            {
                                ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                exists = false; // reset
                            }
                            //. Load subject selection data
                            int pscount=0; int iRS;
                            //. Find reporting subject
                            for (iRS = 0; iRS < ReportingSubjects.Length; iRS++)
                            {
                                if (ReportingSubjects[iRS].name == FLdetail.name) { break; }
                            }
                            SQL.Query = ReportingSubjects[iRS].BuildQuery_IDList(); // dynamic build...
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader();
                            while (SQL.sdr.Read())
                            {
                                Array.Resize(ref ReportConditions[ReportConditions.Length - 1].PossibleValues, pscount+1);
                                ReportConditions[ReportConditions.Length - 1].PossibleValues[pscount] = new FormControl.List.Item();
                                ReportConditions[ReportConditions.Length - 1].PossibleValues[pscount].value = SQL.sdr[0].ToString();
                                ReportConditions[ReportConditions.Length - 1].PossibleValues[pscount].name = SQL.sdr[1].ToString();
                                pscount += 1;
                            }
                            SQL.sdr.Close();
                            // Report Show possibility
                            ReportShow_Add(RSdetail.db, RSdetail.name, RSdetail.type);
                            break;
                        case "Detail":
                            if (!isnew)
                            { // check to see if exists in current RD
                                for (int t = 0; t < RD.Description.Details.Length; t++)
                                {
                                    if ("[global]" + FLdetail.name == RD.Description.Details[t].name)
                                    {
                                        existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                        exists = true; break;
                                    }
                                }
                            }
                            RSdetail = new ReportingSubject.Detail();
                            RSdetail.db = FLdetail.field;
                            RSdetail.name = "[global]" + FLdetail.name;
                            RSdetail.type = FLdetail.datatype;
                            Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                            ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                            if (exists)
                            {
                                ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                exists = false; // reset
                            }
                            // Report Show possibility
                            ReportShow_Add(RSdetail.db, RSdetail.name, RSdetail.type);
                            break;
                    }

                } // end globals

                // NOTE: Right now, reporting is based off of having a UIFS.Form selection as the MAIN SUBJECT
                //    This means we are not setup to handle any generic *Subject as the main...here and in BuildReport()

                // ONLY when a SINGLE *Form* is chosen can we use its details
                if (RD.Description.lang == "singular")
                {
                    exists = false;
                    //. Now we walk through our chosen "Subject"'s Details
                    // this is a UIFS.Form
                    if (RD.Description.name == "Form")
                    {
                        //. need to get data from UIFS.Form for advanced functionality
                        UIFS.Form UIFSForm = new Form(ref SQL);
                        UIFS.FormDataStruct UIFSFormData = new FormDataStruct();
                        DataType UIFSConvertDT = new DataType();
                        // TODO: diff form ver
                        if (!UIFSForm.Load(Convert.ToInt32(RD.Description.selection),-1, ref UIFSFormData))
                        {
                            SQL.WriteLog_Error(UIFSForm.ErrorEx, "Error loading form:" + RD.Description.selection, "UIFS.Reporting.GraphicalUserInterface.Subject_Set()");
                            return false;
                        }
                        //. walk through all form controls...
                        foreach (FormDataStruct.ControlListDetail CLD in UIFSFormData.ControlList)
                        {
                            int iRDDd = -1;
                            UIFSFormControl = UIFSFormData.Get_Control(CLD.id);
                            switch (CLD.type) {
                                case ControlType.Range: // Range Controls have 2 values
                                    FormControl.Range Ctrl_Range = (FormControl.Range)UIFSFormControl;
                                    //. create Start option
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString()+"_Start";
                                    RSdetail.name = UIFSFormControl.name+" START";
                                    RSdetail.type = UIFSConvertDT.convertUIFS(Ctrl_Range.type.ToString());
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    //. create End option
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString()+"_End";
                                    RSdetail.name = UIFSFormControl.name +" END";
                                    RSdetail.type = UIFSConvertDT.convertUIFS(Ctrl_Range.type.ToString());
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    // Report Show possibility
                                    switch (Ctrl_Range.type)
                                    {
                                        case FormControl.Range.Rangetype.DateRange:
                                        case FormControl.Range.Rangetype.TimeRange:
                                        case FormControl.Range.Rangetype.DateTimeRange:
                                            ReportShow_Add(CLD.id.ToString(), UIFSFormControl.name, "Range_DateTime");
                                            break;
                                        case FormControl.Range.Rangetype.MinMax:
                                        case FormControl.Range.Rangetype.Currency:
                                            ReportShow_Add(CLD.id.ToString(),UIFSFormControl.name,"Range_Number");//UIFSFormControl.name
                                            break;
                                    }
                                    break;
                                case ControlType.DateTime:
                                    FormControl.DateTime Ctrl_DateTime = (FormControl.DateTime)UIFSFormControl;
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString();
                                    RSdetail.name = UIFSFormControl.name;
                                    RSdetail.type = UIFSConvertDT.convertUIFS(Ctrl_DateTime.type.ToString().ToLower()); // UIFS.ControlType..
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl = true;
                                    ReportConditions[ReportConditions.Length - 1].UIFSControl = UIFSFormControl;
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl_type = CLD.type;
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    // Report Show possibility
                                    ReportShow_Add(RSdetail.db, RSdetail.name, RSdetail.type);
                                    break;
                                default:
                                    RSdetail = new ReportingSubject.Detail();
                                    RSdetail.db = CLD.id.ToString();
                                    RSdetail.name = UIFSFormControl.name;
                                    RSdetail.type = UIFSConvertDT.convertUIFS(CLD.type.ToString().ToLower()); // UIFS.ControlType..
                                    if (!isnew) { // check to see if exists in current RD
                                        for (int t = 0; t < RD.Description.Details.Length; t++) {
                                            if (RSdetail.db == RD.Description.Details[t].name){
                                                existingRDdetail = RD.Description.Details[t]; iRDDd = t;
                                                exists = true; break;
                                            }
                                        }
                                    }
                                    Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                                    ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSdetail, ReportConditions.Length - 1);
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl = true;
                                    ReportConditions[ReportConditions.Length - 1].UIFSControl = UIFSFormControl;
                                    ReportConditions[ReportConditions.Length - 1].UIFSFormControl_type = CLD.type;
                                    if (exists)
                                    {
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = existingRDdetail;
                                        ReportConditions[ReportConditions.Length - 1].iRDDdetail = iRDDd;
                                        exists = false; // reset
                                    }
                                    // Report Show possibility
                                    ReportShow_Add(RSdetail.db,RSdetail.name,RSdetail.type);

                                    break;
                            }
                        }
                    }

                    // NOT IMPLEMENTED
                    else
                    { // generic Subject, use the Reporting DB
                        foreach (ReportingSubject.Detail RSd in RS.Details)
                        {
                            Array.Resize(ref ReportConditions, ReportConditions.Length + 1);
                            ReportConditions[ReportConditions.Length - 1] = new ReportCondition(RSd, ReportConditions.Length - 1);
                            if (!isnew)
                            { // check to see if exists in current RD
                                foreach (ReportDefinition.Detail RDdetail in RD.Description.Details)
                                {
                                    if (RSd.name == RDdetail.name)
                                    { // if an RD is loaded, this gives us the selection details
                                        ReportConditions[ReportConditions.Length - 1].RDdetail = RDdetail;
                                        break;
                                    }
                                }
                            }
                        }

                    }
                }

                // END of Subject_Set()
                return true;
            }
Exemple #3
0
 // Logging routines are specific to UIFS of course.  As long as the user has provided the "UIFS.Log" appsetting in web.config, the errors
 // will be logged in the user's database of choice.
 public void WriteLog_Error(Exception ex, string ErrorMsg, string CodeLocation)
 {
     string username =  WindowsIdentity.GetCurrent().Name;
     SQL ErrSQL = new SQL(ConfigurationManager.AppSettings["UIFS.Log"].ToString());
     ErrSQL.OpenDatabase();
     ErrSQL.Query = string.Format(ErrSQL.SQLQuery.WriteLOG_AppError, -1, ErrSQL.ParseInput(ErrorMsg), username, ErrSQL.ParseInput(ex.Message), ErrSQL.ParseInput(ex.Source), ErrSQL.ParseInput(ex.StackTrace), CodeLocation);
     ErrSQL.cmd = ErrSQL.Command(ErrSQL.Data);
     ErrSQL.cmd.ExecuteNonQuery();
     ErrSQL.CloseDatabase();
     ErrSQL = null;
 }
Exemple #4
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
            {
            }
        }