示例#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>"; }
                }
示例#2
0
        // First get the common (shared) properties for all control types
        public string ControlProperties(ControlType type, FormControl Control)
        {
            FormControl.Textbox ControlTextbox = new FormControl.Textbox();
            FormControl.List ControlList = new FormControl.List();
            FormControl.Checkbox ControlCheckbox = new FormControl.Checkbox();
            FormControl.DateTime ControlDateTime = new FormControl.DateTime();
            FormControl.Number ControlNumber = new FormControl.Number();
            FormControl.Percentage ControlPercentage = new FormControl.Percentage();
            FormControl.Range ControlRange = new FormControl.Range();

            string ControlRequired;

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

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

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

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

                    ControlTextbox = null;
                    break;

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

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

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

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

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

                    ControlCheckbox = null;
                    break;

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

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

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

                    ControlDateTime = null;
                    break;

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

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

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

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

                    ControlNumber = null;
                    break;

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

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

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

                    ControlNumber = null;
                    break;

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

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

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

                    ControlNumber = null;
                    break;
            }

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

            return html;
        }
示例#3
0
        // -- This routine will load the form data from the db and put it in the referenced FormData
        // formversion :: set to -1 to get LATEST version
        public bool Load(int formid, int formversion, ref FormDataStruct FormData)
        {
            try
            {
                FormData = null; // Clear out just in case
                FormData = new FormDataStruct();
                int iControl = 0;
                bool reOrderControls = false; // set to true to perform a complete reordering of control order#s

                //: 1) Load main form data
                SQL.Query = string.Format(SQL.SQLQuery.Form_Load, formid);
                SQL.cmd = SQL.Command(SQL.Data);
                SQL.sdr = SQL.cmd.ExecuteReader();
                SQL.sdr.Read();
                FormData.id = formid;
                FormData.version = SQL.sdr.GetInt16(0);
                FormData.name = SQL.sdr.GetString(1);
                FormData.description = SQL.sdr.GetString(2);
                FormData.created = SQL.sdr.GetDateTime(3);
                SQL.sdr.Close();

                //: 2) Load controls list
                if (formversion != -1)
                { // retrieves the controls for a specific version of the form
                    // required: reordering!
                    reOrderControls = true;
                    SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControlList_byversion, formid, formversion);
                }
                else { // retrieves the latest version of this form
                    SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControlList, formid);
                }
                // This query actually only returns the common control data which we will use to create the control list.
                //  With the list we will then walk through all control types with specific control type queries to load the control data.
                SQL.cmd = SQL.Command(SQL.Data);
                SQL.sdr = SQL.cmd.ExecuteReader();
                while (SQL.sdr.Read())
                {
                    FormData.controls += 1;
                    Array.Resize(ref FormData.ControlList, FormData.controls);
                    FormData.ControlList[FormData.controls - 1] = new FormDataStruct.ControlListDetail();
                    FormData.ControlList[FormData.controls - 1].id = SQL.sdr.GetInt16(0);
                    FormData.ControlList[FormData.controls - 1].type = (ControlType)SQL.sdr.GetInt32(1);
                    FormData.ControlList[FormData.controls - 1].ordernum = SQL.sdr.GetInt16(2);
                    FormData.ControlList[FormData.controls - 1].version = SQL.sdr.GetInt16(3);
                }
                SQL.sdr.Close();

                //: 3) Load Controls
                for (int i = 0; i < FormData.ControlList.Length; i++)
                {
                    switch (FormData.ControlList[i].type)
                    {
                        case ControlType.Textbox:
                            FormControl.Textbox newTextBox = new FormControl.Textbox();
                            newTextBox.id = FormData.ControlList[i].id; // copy id
                            newTextBox.version = FormData.ControlList[i].version;
                            // Load rest of data from db
                            SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControl_Textbox, formid, FormData.ControlList[i].id, FormData.ControlList[i].version);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                            newTextBox.name = SQL.sdr.GetString(0);
                            newTextBox.prompt = SQL.sdr.GetString(1);
                            if (!SQL.sdr.IsDBNull(2)) { newTextBox.tip = SQL.sdr.GetString(2); }
                            newTextBox.ordernum = SQL.sdr.GetInt16(3);
                            newTextBox.required = SQL.sdr.GetBoolean(4);
                            newTextBox.lines = SQL.sdr.GetInt32(5);
                            newTextBox.width = SQL.sdr.GetInt32(6);
                            newTextBox.FullText = SQL.sdr.GetBoolean(7);
                            SQL.sdr.Close();
                            // Add new control to control array and get index
                            iControl = FormData.AddControl(ControlType.Textbox, newTextBox, false);
                            FormData.ControlList[i].index = iControl; // record index
                            break;
                        case ControlType.List:
                            string ListOptions = "";
                            string[] ListOption;
                            int iItem; // index of current item...
                            FormControl.List newList = new FormControl.List();

                            newList.id = FormData.ControlList[i].id; // copy id
                            newList.version = FormData.ControlList[i].version;
                            SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControl_List, formid, FormData.ControlList[i].id, FormData.ControlList[i].version);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                            newList.name = SQL.sdr.GetString(0);
                            newList.prompt = SQL.sdr.GetString(1);
                            if (!SQL.sdr.IsDBNull(2)) { newList.tip = SQL.sdr.GetString(2); }
                            newList.ordernum = SQL.sdr.GetInt16(3);
                            newList.required = SQL.sdr.GetBoolean(4);
                            ListOptions = SQL.sdr.GetString(5);
                            newList.type = (FormControl.List.listtype)SQL.sdr.GetByte(6);
                            SQL.sdr.Close();
                            // Load Option names/values
                            ListOption = ListOptions.Split(new char[] { ',' });
                            Array.Resize(ref newList.Items, ListOption.Length);
                            for (int t = 0; t < ListOption.Length; t++)
                            {
                                newList.Items[t] = new FormControl.List.Item();
                                iItem = ListOption[t].IndexOf(":");
                                newList.Items[t].name = ListOption[t].Substring(0, iItem);
                                newList.Items[t].value = ListOption[t].Substring(iItem + 1);
                            }
                            iControl = FormData.AddControl(ControlType.List, newList, false);
                            FormData.ControlList[i].index = iControl; // Set index value in control list for faster search/display
                            break;
                        case ControlType.Checkbox:
                            FormControl.Checkbox newCheckbox = new FormControl.Checkbox();
                            newCheckbox.id = FormData.ControlList[i].id; // copy id
                            newCheckbox.version = FormData.ControlList[i].version;
                            // Load rest of data from db
                            SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControl_Checkbox, formid, FormData.ControlList[i].id, FormData.ControlList[i].version);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                            newCheckbox.name = SQL.sdr.GetString(0);
                            newCheckbox.prompt = SQL.sdr.GetString(1);
                            if (!SQL.sdr.IsDBNull(2)) { newCheckbox.tip = SQL.sdr.GetString(2); }
                            newCheckbox.ordernum = SQL.sdr.GetInt16(3);
                            newCheckbox.required = SQL.sdr.GetBoolean(4);
                            newCheckbox.type = (FormControl.Checkbox.checkboxtype)SQL.sdr.GetByte(5);
                            newCheckbox.initialstate = SQL.sdr.GetBoolean(6);
                            newCheckbox.hasinput = SQL.sdr.GetBoolean(7);
                            SQL.sdr.Close();
                            // Add new control to control array and get index
                            iControl = FormData.AddControl(ControlType.Checkbox, newCheckbox, false);
                            FormData.ControlList[i].index = iControl; // record index
                            break;
                        case ControlType.DateTime:
                            FormControl.DateTime newDateTime = new FormControl.DateTime();
                            newDateTime.id = FormData.ControlList[i].id; // copy id
                            newDateTime.version = FormData.ControlList[i].version;
                            // Load rest of data from db
                            SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControl_DateTime, formid, FormData.ControlList[i].id, FormData.ControlList[i].version);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                            newDateTime.name = SQL.sdr.GetString(0);
                            newDateTime.prompt = SQL.sdr.GetString(1);
                            if (!SQL.sdr.IsDBNull(2)) { newDateTime.tip = SQL.sdr.GetString(2); }
                            newDateTime.ordernum = SQL.sdr.GetInt16(3);
                            newDateTime.required = SQL.sdr.GetBoolean(4);
                            newDateTime.type = (FormControl.DateTime.datetimetype)SQL.sdr.GetByte(5);
                            SQL.sdr.Close();
                            // Add new control to control array and get index
                            iControl = FormData.AddControl(ControlType.DateTime, newDateTime, false);
                            FormData.ControlList[i].index = iControl; // record index
                            break;
                        case ControlType.Number:
                            FormControl.Number newNumber = new FormControl.Number();
                            newNumber.id = FormData.ControlList[i].id; // copy id
                            newNumber.version = FormData.ControlList[i].version;
                            // Load rest of data from db
                            SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControl_Number, formid, FormData.ControlList[i].id, FormData.ControlList[i].version);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                            newNumber.name = SQL.sdr.GetString(0);
                            newNumber.prompt = SQL.sdr.GetString(1);
                            if (!SQL.sdr.IsDBNull(2)) { newNumber.tip = SQL.sdr.GetString(2); }
                            newNumber.ordernum = SQL.sdr.GetInt16(3);
                            newNumber.required = SQL.sdr.GetBoolean(4);
                            newNumber.min = (decimal)SQL.sdr[5];
                            newNumber.max = (decimal)SQL.sdr[6];
                            newNumber.interval = (decimal)SQL.sdr[7];
                            newNumber.slider = SQL.sdr.GetBoolean(8);
                            SQL.sdr.Close();
                            // Add new control to control array and get index
                            iControl = FormData.AddControl(ControlType.Number, newNumber, false);
                            FormData.ControlList[i].index = iControl; // record index
                            break;
                        case ControlType.Percentage:
                            FormControl.Percentage newPercentage = new FormControl.Percentage();
                            newPercentage.id = FormData.ControlList[i].id; // copy id
                            newPercentage.version = FormData.ControlList[i].version;
                            // Load rest of data from db
                            SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControl_Percentage, formid, FormData.ControlList[i].id, FormData.ControlList[i].version);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                            newPercentage.name = SQL.sdr.GetString(0);
                            newPercentage.prompt = SQL.sdr.GetString(1);
                            if (!SQL.sdr.IsDBNull(2)) { newPercentage.tip = SQL.sdr.GetString(2); }
                            newPercentage.ordernum = SQL.sdr.GetInt16(3);
                            newPercentage.required = SQL.sdr.GetBoolean(4);
                            newPercentage.interval = SQL.sdr.GetInt32(5);
                            SQL.sdr.Close();
                            // Add new control to control array and get index
                            iControl = FormData.AddControl(ControlType.Percentage, newPercentage, false);
                            FormData.ControlList[i].index = iControl; // record index
                            break;
                        case ControlType.Range:
                            FormControl.Range newRange = new FormControl.Range();
                            newRange.id = FormData.ControlList[i].id; // copy id
                            newRange.version = FormData.ControlList[i].version;
                            // Load rest of data from db
                            SQL.Query = string.Format(SQL.SQLQuery.Form_LoadControl_Range, formid, FormData.ControlList[i].id, FormData.ControlList[i].version);
                            SQL.cmd = SQL.Command(SQL.Data);
                            SQL.sdr = SQL.cmd.ExecuteReader(); SQL.sdr.Read();
                            newRange.name = SQL.sdr.GetString(0);
                            newRange.prompt = SQL.sdr.GetString(1);
                            if (!SQL.sdr.IsDBNull(2)) { newRange.tip = SQL.sdr.GetString(2); }
                            newRange.ordernum = SQL.sdr.GetInt16(3);
                            newRange.required = SQL.sdr.GetBoolean(4);
                            newRange.type = (FormControl.Range.Rangetype)SQL.sdr.GetByte(5);
                            newRange.min = (decimal)SQL.sdr[6];
                            newRange.max = (decimal)SQL.sdr[7];
                            SQL.sdr.Close();
                            // Add new control to control array and get index
                            iControl = FormData.AddControl(ControlType.Range, newRange, false);
                            FormData.ControlList[i].index = iControl; // record index
                            break;
                    }
                }

                //: 4) Get next available control id
                SQL.Query = string.Format(SQL.SQLQuery.Form_GetNextAvailableControlID, formid);
                SQL.cmd = SQL.Command(SQL.Data);
                FormData.nextcontrolid = Convert.ToInt32(SQL.cmd.ExecuteScalar());

                //: 5) reorder Control list if needed
                if (reOrderControls)
                {
                    FormData.ReOrder_ControlList();
                }
                //: ?) what is next?

                FormData.newform = false; // This is not a new form.

            }
            catch (Exception ex)
            { // Failed to load form
                ErrorEx = ex;
                return false;
            }
            return true;
        }