Ejemplo n.º 1
0
                // For Editing:
                // RDdetail     =   need to know what is selected (if anything yet)
                public string Edit()
                {
                    string prompt="",html="", js="", phraseselect="";
                    string[] phrases;
                    DataType datatype = new DataType();
                    UIFS.Form_Output FormOut = new Form_Output();

                    FormControl.Checkbox Ctrl_Checkbox;
                    FormControl.DateTime Ctrl_DateTime;
                    FormControl.Number Ctrl_Number;
                    FormControl.Percentage Ctrl_Percentage;
                    FormControl.List Ctrl_List;
                    FormControl.Range Ctrl_Range;
                    FormControl.Textbox Ctrl_Textbox;

                    // Load Phrases for this datatype, if phrase selection data does not exist ... set to default
                    phrases = datatype.Phrases(detail.type).Split(new char[] { ',' });
                    if (RDdetail == null)
                    {
                        RDdetail = new ReportDefinition.Detail();
                        RDdetail.lang = phrases[0]; // first language phrase
                    }
                    prompt = "<span class=\"name\">" + detail.name + "</span> ";
                    // Language selection
                    //: currently based on datatype
                    prompt = prompt + "<select id=\""+this.id.ToString()+"_phrase\" onchange=\"Option_Redraw('"+this.id.ToString()+"'); \">";
                    foreach (string phrase in phrases)
                    {
                        if (RDdetail.lang == phrase) { phraseselect = " selected=\"1\" "; } else { phraseselect = ""; }
                        prompt = prompt + "<option value=\"" + phrase + "\" " + phraseselect + ">" + phrase + "</option>";
                    }
                    prompt = prompt + "</select>";

                    // --[  Builds a dynamic UIFS.FormControl we use to get input needed to build form  ]
                    // entry type...based on language, then datatype
                    string CtrlEntryType = datatype.FormEntryType(detail.type, RDdetail.lang);
                    switch (CtrlEntryType)
                    {
                        // possibly have two different methods
                        // 1: for getting data specific to UIFS.Form (this way we can mirror our control properties)
                        // 2: for generic Subject-Detail

                        case "id":
                        case "list_id":
                            // GLOBAL identifiers are user defined formlinks to id lists of this Subject type...
                            //. Use a list control
                            if (detail.name.StartsWith("[global]")) {
                                Ctrl_List = new FormControl.List();
                                Ctrl_List.id = this.id;
                                Ctrl_List.prompt = prompt;
                                Ctrl_List.tip = "Please choose your Subject";
                                Ctrl_List.type = FormControl.List.listtype.dropdown;
                                Ctrl_List.Items = PossibleValues;
                                FormOut.HTML_FormControl(ControlType.List, Ctrl_List, ref html, ref js);
                                Control = Ctrl_List; Control_type = ControlType.List;
                            }
                            break;
                        case "checkbox":
                            if (UIFSFormControl) {
                                Ctrl_Checkbox = (FormControl.Checkbox)UIFSControl;
                                Ctrl_Checkbox.hasinput = false; // we do not want this
                            }
                            else {
                                Ctrl_Checkbox = new FormControl.Checkbox(); }
                            Ctrl_Checkbox.id = this.id;
                            Ctrl_Checkbox.prompt = prompt; //TEST: we want to use this as part of our Control div if possible
                            Ctrl_Checkbox.tip = "Choose one or the other";
                            FormOut.HTML_FormControl(ControlType.Checkbox, Ctrl_Checkbox, ref html, ref js); // builds html for control
                            Control = Ctrl_Checkbox; Control_type = ControlType.Checkbox;
                            break;
                        case "number":
                            if (UIFSFormControl){Ctrl_Number = (FormControl.Number)UIFSControl; }
                            else { Ctrl_Number = new FormControl.Number(); }
                            Ctrl_Number.id = this.id; Ctrl_Number.prompt = prompt;
                            Ctrl_Number.tip = "Please choose a number between: " + Ctrl_Number.min.ToString() + " AND " + Ctrl_Number.max.ToString();
                            FormOut.HTML_FormControl(ControlType.Number, Ctrl_Number, ref html, ref js);
                            Control = Ctrl_Number; Control_type = ControlType.Number;
                            break;
                        case "datetime":
                        case "date":
                        case "time":
                            if (UIFSFormControl) {Ctrl_DateTime = (FormControl.DateTime)UIFSControl; }
                            else { Ctrl_DateTime = new FormControl.DateTime();}
                            Ctrl_DateTime.id = this.id;
                            Ctrl_DateTime.prompt = prompt;
                            Ctrl_DateTime.tip = "Please select a date/time";
                            switch (CtrlEntryType)
                            {
                                case "datetime":
                                    Ctrl_DateTime.type = FormControl.DateTime.datetimetype.datetime;
                                    break;
                                case "date":
                                    Ctrl_DateTime.type = FormControl.DateTime.datetimetype.date;
                                    break;
                                case "time":
                                    Ctrl_DateTime.type = FormControl.DateTime.datetimetype.time;
                                    break;
                            }
                            FormOut.HTML_FormControl(ControlType.DateTime, Ctrl_DateTime, ref html, ref js);
                            Control = Ctrl_DateTime; Control_type = ControlType.DateTime;
                            break;
                        case "text":
                            if (UIFSFormControl)
                            { // if
                                switch (UIFSFormControl_type)
                                {
                                    case ControlType.List: // List Controls are basically text field values; which is what the input value is
                                        Ctrl_List = (FormControl.List)UIFSControl;
                                        Ctrl_List.id = this.id;
                                        Ctrl_List.prompt = prompt;
                                        FormOut.HTML_FormControl(ControlType.List, Ctrl_List, ref html, ref js);
                                        Control = Ctrl_List; Control_type = ControlType.List;
                                        break;
                                    case ControlType.Textbox:
                                        Ctrl_Textbox = (FormControl.Textbox)UIFSControl;
                                        Ctrl_Textbox.id = this.id;
                                        Ctrl_Textbox.prompt = prompt;
                                        FormOut.HTML_FormControl(ControlType.Textbox, Ctrl_Textbox, ref html, ref js);
                                        Control = Ctrl_Textbox; Control_type = ControlType.Textbox;
                                        break;
                                }
                            }
                            else
                            { // default
                                Ctrl_Textbox = new FormControl.Textbox();
                                Ctrl_Textbox.id = this.id;
                                Ctrl_Textbox.prompt = prompt;
                                Ctrl_Textbox.tip = "value to look for...";
                                FormOut.HTML_FormControl(ControlType.Textbox, Ctrl_Textbox, ref html, ref js);
                                Control = Ctrl_Textbox; Control_type = ControlType.Textbox;
                            }
                            break;
                        //NOTE: should this be allowed to be a generic?
                        case "percentage":
                            if (UIFSFormControl) { Ctrl_Percentage = (FormControl.Percentage)UIFSControl; }
                            else { Ctrl_Percentage = new FormControl.Percentage(); }
                            Ctrl_Percentage.id = this.id;
                            Ctrl_Percentage.prompt = prompt;
                            Ctrl_Percentage.interval = 1; // allow to select all values
                            Ctrl_Percentage.tip = "select a percentage value";
                            FormOut.HTML_FormControl(ControlType.Percentage, Ctrl_Percentage, ref html, ref js);
                            Control = Ctrl_Percentage; Control_type = ControlType.Percentage;
                            break;
                        case "range_number":
                        case "range_percentage":
                            Ctrl_Range = new FormControl.Range();
                            if (CtrlEntryType == "range_percentage")
                            {
                                Ctrl_Range.min = 0; Ctrl_Range.max = 100;
                                Ctrl_Range.tip = "Please choose your percentage range";
                            }
                            else
                            {
                                if (UIFSFormControl)
                                {
                                    if (this.UIFSFormControl_type == ControlType.Number)
                                    {
                                        Ctrl_Number = (FormControl.Number)UIFSControl;
                                        Ctrl_Range.min = Ctrl_Number.min; Ctrl_Range.max = Ctrl_Number.max; // get values from UIFS control properties
                                        Ctrl_Range.tip = Ctrl_Number.tip;
                                    }
                                }
                                else
                                {
                                    Ctrl_Range.min = 0; Ctrl_Range.max = 1000; // default
                                    Ctrl_Range.tip = "Please choose your range";
                                }
                            }
                            Ctrl_Range.id = this.id; Ctrl_Range.prompt = prompt;
                            Ctrl_Range.type = FormControl.Range.Rangetype.MinMax;
                            FormOut.HTML_FormControl(ControlType.Range, Ctrl_Range, ref html, ref js);
                            Control = Ctrl_Range; Control_type = ControlType.Range;
                            break;
                        case "range_time":
                        case "range_date":
                        case "range_datetime":
                            Ctrl_Range = new FormControl.Range();
                            if (UIFSFormControl) {
                                if (this.UIFSFormControl_type == ControlType.DateTime)
                                {
                                    Ctrl_DateTime = (FormControl.DateTime)UIFSControl;
                                    Ctrl_Range.tip = Ctrl_DateTime.tip;
                                    switch (Ctrl_DateTime.type)
                                    {
                                        case FormControl.DateTime.datetimetype.time:
                                            Ctrl_Range.type = FormControl.Range.Rangetype.TimeRange;
                                            break;
                                        case FormControl.DateTime.datetimetype.date:
                                            Ctrl_Range.type = FormControl.Range.Rangetype.DateRange;
                                            break;
                                        case FormControl.DateTime.datetimetype.datetime:
                                            Ctrl_Range.type = FormControl.Range.Rangetype.DateTimeRange;
                                            break;
                                    }
                                }
                            }
                            else{ // non-UIFS control
                                Ctrl_Range.tip = "Please choose your range";
                                switch (CtrlEntryType)
                                {
                                    case "range_time":
                                        Ctrl_Range.type = FormControl.Range.Rangetype.TimeRange;
                                        break;
                                    case "range_date":
                                        Ctrl_Range.type = FormControl.Range.Rangetype.DateRange;
                                        break;
                                    case "range_datetime":
                                        Ctrl_Range.type = FormControl.Range.Rangetype.DateTimeRange;
                                        break;
                                }
                            }
                            Ctrl_Range.id = this.id; Ctrl_Range.prompt = prompt;
                            FormOut.HTML_FormControl(ControlType.Range, Ctrl_Range, ref html, ref js);
                            Control = Ctrl_Range; Control_type = ControlType.Range;
                            break;
                        case "list_number":
                            break;
                        default:
                            return "";
                    }
                    Control.id = this.id; // mirror for simplification in ajax routines

                    //TODO: temp to show what exists if it does not find its way through
                    if (html == "") { html = "<div id='"+detail.name+"'>"+prompt+"</div>"; }
                    // USE button
                    html = "<table class='selection' onMouseover=\"ToggleButton(this,1);\" onMouseout=\"ToggleButton(this,0);\" ><tr><td class='input'>" + html + "</td>" +
                        "<td class='buttons'><div class='button' onMousedown=\"ToggleButton(this.parentNode,2);\" onMouseup=\"ToggleButton(this.parentNode,3);\" onclick=\"Option_Use(" + this.id + ",'" + Control_type.ToString() + "');\">USE</div></td>" +
                        "</tr></table>";

                    // return combined (if js exists)
                    if (js == "") { return html; }
                    else { return html + "<script type='text/javascript'>" + js + "</script>"; }
                }
Ejemplo n.º 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;
            }