Ejemplo n.º 1
0
        /// <summary>
        /// Adds all the exam fields to the search.
        /// </summary>
        public static void SetExtraExam(bool persist)
        {
            if (!persist)
            {
                ExtraList.Clear();
            }
            DataDesc tmpData = new DataDesc();

            tmpData.IdData        = SearchEnum.EXAM_NAME;
            tmpData.Name          = Text.Exam;
            tmpData.Kind          = Data.OPTIONS;
            tmpData.AuxValues     = Common.GetBDList("Exam", "SELECT Exam FROM Exam WHERE Status = " + ExamStatus.ACTIVE, false).ToString().Replace(",", "|");
            tmpData.CustomQuery   = "IdExam IN (SELECT IdExam FROM Exam WHERE Exam = '#SEARCH_VALUE#')";
            tmpData.IdDataGroup   = SearchEnum.EXAMS;
            tmpData.DataGroupName = Text.Exams;
            ExtraList.Add(tmpData);

            tmpData        = new DataDesc();
            tmpData.IdData = SearchEnum.EXAM_SCORE;
            tmpData.Name   = Text.Score;
            NumberJSON numberJSON = new NumberJSON();

            numberJSON.from      = 0;
            numberJSON.to        = 100;
            numberJSON.maxLength = "4";
            tmpData.AuxValues    = JsonConvert.SerializeObject(numberJSON);
            tmpData.Kind         = Data.FLOAT;
            tmpData.CustomQuery  = "CAST(Score AS Float) >= '#SEARCH_VALUE#' AND CAST(Score AS Float) <= '#SEARCH_VALUE2#'";
            tmpData.IdDataGroup  = SearchEnum.EXAMS;
            ExtraList.Add(tmpData);

            tmpData           = new DataDesc();
            tmpData.IdData    = SearchEnum.EXAM_STATUS;
            tmpData.Name      = Text.Status;
            tmpData.Kind      = Data.OPTIONS;
            tmpData.AuxValues = Text.Exam_Failed + "|" + Text.Exam_Incomplete + "|" + Text.Exam_Passed + "|" + Text.Exam_Pending;
            Dictionary <string, string> userStatusFriendly = new Dictionary <string, string>();

            userStatusFriendly.Add(Text.Exam_Failed, UserExamStatus.FAILED.ToString());
            userStatusFriendly.Add(Text.Exam_Incomplete, UserExamStatus.INCOMPLETE.ToString());
            userStatusFriendly.Add(Text.Exam_Passed, UserExamStatus.PASSED.ToString());
            userStatusFriendly.Add(Text.Exam_Pending, UserExamStatus.PENDING.ToString());
            tmpData.FriendlyOptions = userStatusFriendly;
            tmpData.CustomQuery     = "Status IN (#SEARCH_VALUE#)";
            tmpData.IdDataGroup     = SearchEnum.EXAMS;
            tmpData.DataGroupName   = Text.Exams;
            ExtraList.Add(tmpData);

            tmpData             = new DataDesc();
            tmpData.IdData      = SearchEnum.EXAM_DATE_COMPLETED;
            tmpData.Name        = Text.DateCompleted;
            tmpData.Kind        = Data.DATE;
            tmpData.CustomQuery = "CONVERT(DATETIME, DateComplete, 103) BETWEEN CONVERT(DATETIME, '#SEARCH_VALUE#', 103) AND CONVERT(DATETIME, '#SEARCH_VALUE2#', 103)";
            tmpData.IdDataGroup = SearchEnum.EXAMS;
            ExtraList.Add(tmpData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves the HTML for the current field.
        /// </summary>
        /// <returns>An HTML String.</returns>
        public string GetSearchHTML()
        {
            string retval             = "";
            string fieldId            = "data_" + IdData.ToString();
            string validationFunction = "";

            switch (Kind)
            {
            case Data.SIMPLE_TEXT:
            case Data.YES_NO:
            case Data.OPTIONS:
            case Data.CHECKBOX:
            case Data.TREE:
            case Data.EMAIL:
                retval = GetFieldHTML();
                break;

            case Data.MULTI_TEXT:
                retval = DrawInput.InputTextField(fieldId, SearchValue, "", "", "", "", "");
                break;

            case Data.INTEGER:
            case Data.FLOAT:
                NumberJSON numberJSON = JsonConvert.DeserializeObject <NumberJSON>(AuxValues);
                if ((numberJSON.from == numberJSON.to) && (numberJSON.to == 0))
                {
                    numberJSON.maxLength = "10";
                }
                if (Kind == Data.FLOAT)
                {
                    validationFunction = "validateFloat($(this), event);";
                }
                else
                {
                    validationFunction = "validateInt($(this), event);";
                }
                retval  = Text.Between + "&nbsp";
                retval += DrawInput.InputTextField(fieldId, SearchValue, numberJSON.maxLength, "", validationFunction, "width: 50px;", "title=\"" + Common.StrLang(Text.EnterValueBetweenXandY, numberJSON.from + "," + numberJSON.to) + "\" onKeyUp=\"" + validationFunction + "\"");
                retval += "&nbsp;" + Text.And + "&nbsp;";
                retval += DrawInput.InputTextField(fieldId + "_aux", SearchValueAux, numberJSON.maxLength, "", validationFunction, "width: 50px;", "title=\"" + Common.StrLang(Text.EnterValueBetweenXandY, numberJSON.from + "," + numberJSON.to) + "\" onKeyUp=\"" + validationFunction + "\"");
                break;

            case Data.SLIDER:
                validationFunction = "validateInt($(this), event);";
                retval             = Text.Between + "&nbsp";
                retval            += DrawInput.InputTextField(fieldId, SearchValue, "10", "", validationFunction, "width: 50px;", "onKeyUp=\"" + validationFunction + "\"");
                retval            += "&nbsp;" + Text.And + "&nbsp;";
                retval            += DrawInput.InputTextField(fieldId + "_aux", SearchValueAux, "10", "", validationFunction, "width: 50px;", "onKeyUp=\"" + validationFunction + "\"");
                break;

            case Data.DATE:
                retval  = Text.Between + "&nbsp";
                retval += DrawInput.InputTextField(fieldId, SearchValue, "", "datePicker", "", "width: 85px;", "");
                retval += "&nbsp;" + Text.And + "&nbsp;";
                retval += DrawInput.InputTextField(fieldId + "_aux", SearchValueAux, "", "datePicker", "", "width: 85px;", "");
                break;

            default:
                break;
            }
            return(retval);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validates the given Value.
        /// </summary>
        /// <returns>True if valid, false otherwise.</returns>
        public bool IsValid(string newValue)
        {
            bool retval = false;

            Value = newValue;
            Regex regEx;

            if (!String.IsNullOrEmpty(Value))
            {
                switch (Kind)
                {
                case Data.SIMPLE_TEXT:
                    if (RegExValidation != "")
                    {
                        regEx = new Regex(RegExValidation, RegexOptions.IgnoreCase);
                        if (regEx.IsMatch(Value))
                        {
                            retval = true;
                        }
                        else
                        {
                            ErrorMessage = Name + ": " + Text.InvalidData;
                        }
                    }
                    else
                    {
                        retval = true;
                    }
                    break;

                case Data.YES_NO:
                    if ((Value == Text.Yes) || (Value == Text.No))
                    {
                        retval = true;
                    }
                    else
                    {
                        ErrorMessage = Name + ": " + Text.InvalidData;
                    }
                    break;

                case Data.OPTIONS:
                    string[] values = Common.CSVToArray('|', "|" + AuxValues);
                    foreach (string val in values)
                    {
                        if (Value == val)
                        {
                            retval = true;
                            break;
                        }
                    }
                    if (!retval)
                    {
                        ErrorMessage = Name + ": " + Text.InvalidData;
                    }
                    break;

                case Data.INTEGER:
                case Data.FLOAT:
                    NumberJSON numberJSON = JsonConvert.DeserializeObject <NumberJSON>(AuxValues);
                    if ((numberJSON.from == numberJSON.to) && (numberJSON.to == 0))
                    {
                        retval = true;
                    }
                    else
                    {
                        if ((Convert.ToDouble(Value) >= Convert.ToDouble(numberJSON.from)) && (Convert.ToDouble(Value) <= Convert.ToDouble(numberJSON.to)))
                        {
                            retval = true;
                        }
                        else
                        {
                            ErrorMessage = Name + ": " + Common.StrLang(Text.EnterValueBetweenXandY, numberJSON.from + "," + numberJSON.to);
                        }
                    }
                    break;

                case Data.DATE:
                    retval = true;
                    break;

                case Data.CHECKBOX:
                    if ((Value == "1") || (Value == "0"))
                    {
                        retval = true;
                    }
                    break;

                case Data.TREE:
                    retval = true;
                    break;

                case Data.MULTI_TEXT:
                    retval = true;
                    break;

                case Data.SLIDER:
                    retval = true;
                    break;

                case Data.EMAIL:
                    string pattern = @"[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}";
                    regEx = new Regex(pattern, RegexOptions.IgnoreCase);
                    if (regEx.IsMatch(Value))
                    {
                        retval = true;
                    }
                    else
                    {
                        ErrorMessage = Name + ": " + Text.InvalidEmail;
                    }
                    break;

                case Data.LABEL:
                    retval = true;
                    break;

                default:
                    break;
                }
            }
            else if (Required == 1)
            {
                ErrorMessage = Name + ": " + Text.MissingFields;
            }
            else
            {
                retval = true;
            }
            return(retval);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Builds the HTML code for a given field.
        /// </summary>
        /// <returns>The HTML string of the field.</returns>
        public string GetFieldHTML()
        {
            string retval             = "";
            string fieldId            = "data_" + IdData.ToString();
            string validationFunction = "";

            switch (Kind)
            {
            case Data.SIMPLE_TEXT:
                retval = DrawInput.InputTextField(fieldId, Value, "", "", "", "", "");
                break;

            case Data.YES_NO:
                retval = DrawInput.InputSelect(fieldId, Value, Common.CSVToArray("," + Text.Yes + "," + Text.No), "", "", "", "");
                break;

            case Data.OPTIONS:
                retval = DrawInput.InputSelect(fieldId, Value, Common.CSVToArray('|', "|" + AuxValues), "", "", "", "");
                break;

            case Data.INTEGER:
                NumberJSON numberJSON = JsonConvert.DeserializeObject <NumberJSON>(AuxValues);
                if ((numberJSON.from == numberJSON.to) && (numberJSON.to == 0))
                {
                    validationFunction   = "validateInt($(this), event);";
                    numberJSON.maxLength = "10";
                }
                else
                {
                    validationFunction = "validateInt($(this), event, " + numberJSON.from + ", " + numberJSON.to + ");";
                }
                retval = DrawInput.InputTextField(fieldId, Value, numberJSON.maxLength, "", validationFunction, "width: 50px;", "title=\"" + Common.StrLang(Text.EnterValueBetweenXandY, numberJSON.from + "," + numberJSON.to) + "\" onKeyUp=\"validateInt($(this), event);\"");
                break;

            case Data.FLOAT:
                NumberJSON numberJSONf = JsonConvert.DeserializeObject <NumberJSON>(AuxValues);
                if ((numberJSONf.from == numberJSONf.to) && (numberJSONf.to == 0))
                {
                    validationFunction    = "validateFloat($(this), event);";
                    numberJSONf.maxLength = "10";
                }
                else
                {
                    validationFunction = "validateFloat($(this), event, " + numberJSONf.from + ", " + numberJSONf.to + ");";
                }
                retval = DrawInput.InputTextField(fieldId, Value, numberJSONf.maxLength, "", validationFunction, "width: 50px;", "title=\"" + Common.StrLang(Text.EnterValueBetweenXandY, numberJSONf.from + "," + numberJSONf.to) + "\" onKeyUp=\"validateFloat($(this), event);\"");
                break;

            case Data.DATE:
                retval = DrawInput.InputTextField(fieldId, Value, "", "datePicker", "", "width: 85px;", "");
                break;

            case Data.CHECKBOX:
                retval = DrawInput.InputCheckbox(fieldId, Value, (Value == "1"), "", "", "", "onChange='toggleCheckbox($(this));'");
                break;

            case Data.TREE:
                retval  = DrawInput.InputHiddenField(fieldId, Value, "", "");
                retval += "<div id='tree_" + fieldId + "'></div>";
                retval += "<script language='JavaScript'>";
                retval += "$('#tree_" + fieldId + "').treeSelectJSON({";
                retval += "  source: " + AuxValues + ",";
                retval += "  target: '" + fieldId + "',";
                retval += "  defaultText: '- " + Common.SQSF(Text.Select) + " -',";
                retval += "  preselected: '" + Value + "'";
                retval += "});";
                retval += "</script>";
                break;

            case Data.MULTI_TEXT:
                retval = DrawInput.InputTextArea(fieldId, Value, "4", "", "", "", "width: 100%;", "");
                break;

            case Data.SLIDER:
                if (String.IsNullOrEmpty(Value))
                {
                    Value = "0";
                }
                retval  = DrawInput.InputHiddenField(fieldId, Value, "", "");
                retval += "<div id='" + fieldId + "_slider'></div>";
                retval += "<script language='JavaScript'>";
                retval += "$('#" + fieldId + "_slider').slider({ value: " + Value + ", max: " + AuxValues + ", change: function() { $('#" + fieldId + "').val($('#" + fieldId + "_slider').slider('option', 'value')) }});";
                retval += "</script>";
                break;

            case Data.EMAIL:
                retval = DrawInput.InputTextField(fieldId, Value, "", "", "validateEmail($(this));", "", "title=\"" + Text.InvalidEmail + "\" placeholder=\"[email protected]\"");
                break;

            case Data.LABEL:
                retval = "<div align='center'>" + AuxValues + "</div>";
                break;

            default:
                break;
            }
            return(retval);
        }