Beispiel #1
0
        public static void TestDateField()
        {
            int currentDay   = System.DateTime.Now.Day;
            int currentMonth = System.DateTime.Now.Month;
            int currentYear  = System.DateTime.Now.Year;

            var MonthLeadingZero = Regex.Replace((currentMonth + 1).ToString(), @"\d+", m => m.Value.PadLeft(2, '0'));
            var DayLeadingZero   = Regex.Replace((currentDay + 1).ToString(), @"\d+", m => m.Value.PadLeft(2, '0'));
            var currentMonthStr  = Regex.Replace((currentMonth).ToString(), @"\d+", m => m.Value.PadLeft(2, '0'));
            var currentDayStr    = Regex.Replace((currentDay).ToString(), @"\d+", m => m.Value.PadLeft(2, '0'));

            var test_nonNumber             = TreatFields.DateField("aa/bb/19cD");
            var test_impossibleOld         = TreatFields.DateField("01/01/1500");
            var test_terminatorMcFly       = TreatFields.DateField(string.Format("01/01/{0}", (currentYear + 1)));
            var test_carnivalTillEndOfYear = TreatFields.DateField("30/02/2018");
            var test_whatMonth             = TreatFields.DateField("01/13/1930");
            var test_whatDay         = TreatFields.DateField("32/01/1930");
            var test_negativeDay     = TreatFields.DateField("-01/01/1930");
            var test_negativeMonth   = TreatFields.DateField("01/-2/1930");
            var test_negativeYear    = TreatFields.DateField("01/01/-1930");
            var test_shortenedDate   = TreatFields.DateField("01/1930");
            var test_extendedDate    = TreatFields.DateField("101/01/1930");
            var test_emptyDate       = TreatFields.DateField("");
            var test_monthAhead      = TreatFields.DateField(string.Format("01/{0}/{1}", MonthLeadingZero, currentYear));
            var test_neutralDayMonth = TreatFields.DateField("00/00/2015");
            var test_dayAhead        = TreatFields.DateField(string.Format("{0}/{1}/{2}", DayLeadingZero, currentMonthStr, currentYear));
            var test_Today           = TreatFields.DateField(string.Format("{0}/{1}/{2}", currentDayStr, currentMonthStr, currentYear));
            var test_Normal          = TreatFields.DateField("01/04/1997");

            var nonNumeric   = "Data deve conter apenas números!|";
            var invalidDay   = "Dia inválido!|";
            var invalidMonth = "Mês inválido!|";
            var invalidYear  = "Ano inválido!|";
            var wrongFormat  = "Insira uma data válida! Formato dia/mes/ano|";

            Assert.AreEqual(test_nonNumber, nonNumeric);
            Assert.AreEqual(test_impossibleOld, invalidYear);
            Assert.AreEqual(test_terminatorMcFly, invalidYear);
            Assert.AreEqual(test_carnivalTillEndOfYear, invalidDay);
            Assert.AreEqual(test_whatMonth, invalidMonth);
            Assert.AreEqual(test_whatDay, invalidDay);
            Assert.AreEqual(test_negativeDay, nonNumeric);
            Assert.AreEqual(test_negativeMonth, nonNumeric);
            Assert.AreEqual(test_negativeYear, nonNumeric);
            Assert.AreEqual(test_shortenedDate, wrongFormat);
            Assert.AreEqual(test_extendedDate, wrongFormat);
            Assert.AreEqual(test_emptyDate, wrongFormat);
            Assert.AreEqual(test_monthAhead, invalidMonth);
            Assert.AreEqual(test_dayAhead, invalidDay);
            Assert.AreEqual(test_Today, "");
            Assert.AreEqual(test_neutralDayMonth, invalidDay + invalidMonth);
            Assert.AreEqual(test_Normal, "");

            return;
        }
    public bool ValidInput(List <InputField> inputs, List <Toggle> toggles)
    {
        bool valid = true;

        string treatName    = TreatFields.NameField(inputs[0].text);
        string treatDate    = TreatFields.DateField(outDate.text);
        string treatPhone1  = TreatFields.PhoneField(inputs[2].text);
        string treatLogin   = TreatFields.LoginField(inputs[3].text);
        string treatPass    = TreatFields.PasswordField(inputs[4].text);
        string treatConfirm = TreatFields.ConfirmPasswordField(inputs[5].text, inputs[4].text);
        string treatSex     = TreatFields.SexField(toggles[0].isOn, toggles[1].isOn);

        string treatCrefito  = "";
        string treatRegiao   = "";
        string treatUniqueCR = "";

        if (inputs[6].text != "" && inputs[7].text != "")
        {
            treatCrefito  = TreatFields.CrefitoField(inputs[6].text);
            treatRegiao   = TreatFields.RegionField(inputs[7].text);
            treatUniqueCR = TreatFields.UniqueCrefitoRegion(inputs[6].text, inputs[7].text);
        }

        string treatPhone2 = "";

        if (inputs[8].text != "")
        {
            treatPhone2 = TreatFields.PhoneField(inputs[8].text);
        }

        string treatUniqueLP = TreatFields.UniqueLoginPassword(inputs[3].text);

        if (treatName != "" || treatDate != "" || treatPhone1 != "" ||
            treatCrefito != "" || treatRegiao != "" || treatLogin != "" ||
            treatPass != "" || treatConfirm != "" || treatPhone2 != "" ||
            treatSex != "" || treatUniqueCR != "" || treatUniqueLP != "")
        {
            bool          flag      = true;
            StringBuilder fullerror = new StringBuilder();

            if ((treatName != "") && flag)
            {
                var splitBar = treatName.Split('|');
                fullerror.Append("[Nome]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[0], 0);
            }
            else if (treatName == "")
            {
                ApplyColor(inputs[0], 2);
            }

            if (treatSex != "" && flag)
            {
                var splitBar = treatSex.Split('|');
                fullerror.Append("[Sexo]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(toggles[0], 0);
                ApplyColor(toggles[1], 0);
            }
            else if (treatSex == "")
            {
                ApplyColor(toggles[0], 2);
                ApplyColor(toggles[1], 2);
            }

            if ((treatDate != "") && flag)
            {
                var splitBar = treatDate.Split('|');
                fullerror.Append("[Data de Nascimento]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[1], 0);
            }
            else if (treatDate == "")
            {
                ApplyColor(inputs[1], 2);
            }

            if ((treatPhone1 != "") && flag)
            {
                var splitBar = treatPhone1.Split('|');
                fullerror.Append("[Telefone1]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[2], 0);
            }
            else if (treatPhone1 == "")
            {
                ApplyColor(inputs[2], 2);
            }

            if ((treatLogin != "" || treatUniqueLP != "") && flag)
            {
                var splitBar = treatLogin.Split('|');
                fullerror.Append("[Login]: ");
                if (treatLogin != "")
                {
                    foreach (var erro in splitBar)
                    {
                        fullerror.Append(erro + '\n');
                    }
                }

                splitBar = treatUniqueLP.Split('|');
                if (treatUniqueLP != "")
                {
                    foreach (var erro in splitBar)
                    {
                        fullerror.Append(erro + '\n');
                    }
                }

                flag = false;
                ApplyColor(inputs[3], 0);
            }
            else if (treatLogin == "" && treatUniqueLP == "")
            {
                ApplyColor(inputs[3], 2);
            }

            if ((treatPass != "") && flag)
            {
                var splitBar = treatPass.Split('|');
                fullerror.Append("[Senha]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[4], 0);
            }
            else if (treatPass == "")
            {
                ApplyColor(inputs[4], 2);
            }

            if ((treatConfirm != "") && flag)
            {
                var splitBar = treatConfirm.Split('|');
                fullerror.Append("[Confirmar Senha]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[5], 0);
            }
            else if (treatConfirm == "")
            {
                ApplyColor(inputs[5], 2);
            }

            if ((treatCrefito != "" || treatUniqueCR != "") && flag)
            {
                var splitBar = treatCrefito.Split('|');
                fullerror.Append("[CREFITO]: ");
                if (treatCrefito != "")
                {
                    foreach (var erro in splitBar)
                    {
                        fullerror.Append(erro + '\n');
                    }
                }

                splitBar = treatUniqueCR.Split('|');
                if (treatUniqueCR != "")
                {
                    foreach (var erro in splitBar)
                    {
                        fullerror.Append(erro + '\n');
                    }
                }

                flag = false;
                ApplyColor(inputs[6], 0);
            }
            else if (treatCrefito == "" && treatUniqueCR == "")
            {
                ApplyColor(inputs[6], 2);
            }

            if ((treatRegiao != "" || treatUniqueCR != "") && flag)
            {
                var splitBar = treatRegiao.Split('|');
                fullerror.Append("[Regiao]: ");
                if (treatRegiao != "")
                {
                    foreach (var erro in splitBar)
                    {
                        fullerror.Append(erro + '\n');
                    }
                }

                splitBar = treatUniqueCR.Split('|');
                if (treatUniqueCR != "")
                {
                    foreach (var erro in splitBar)
                    {
                        fullerror.Append(erro + '\n');
                    }
                }

                flag = false;
                ApplyColor(inputs[7], 0);
            }
            else if (treatRegiao == "" && treatUniqueCR == "")
            {
                ApplyColor(inputs[7], 2);
            }

            if ((treatPhone2 != "") && flag)
            {
                var splitBar = treatPhone2.Split('|');
                fullerror.Append("[Telefone2]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[8], 0);
            }
            else if (treatPhone2 == "")
            {
                ApplyColor(inputs[8], 2);
            }

            helpPopUp.text = fullerror.ToString();
            int   count = fullerror.ToString().Count(f => f == '\n');
            int   top   = -90 + (count * 30);
            float right = 300.0f - helpPopUp.preferredWidth;

            helpPopUp.transform.localPosition = new Vector3(helpPopUp.transform.localPosition.x, 0, helpPopUp.transform.localPosition.z);

            helpPopUp.transform.parent.gameObject.GetComponent <RectTransform>().offsetMin = new Vector2(right, -top);
            helpPopUp.transform.parent.gameObject.GetComponent <RectTransform>().offsetMax = new Vector2(-right, top);
            helpPopUp.transform.parent.gameObject.SetActive(true);

            valid = false;
        }

        return(valid);
    }
Beispiel #3
0
    public bool ValidInput(List <InputField> inputs, List <Toggle> toggles)
    {
        bool valid = true;

        string treatName   = TreatFields.NameField(inputs[0].text);
        string treatDate   = TreatFields.DateField(outDate.text);
        string treatPhone1 = TreatFields.PhoneField(inputs[2].text);
        string treatSex    = TreatFields.SexField(toggles[0].isOn, toggles[1].isOn);

        string treatPhone2 = "";

        if (inputs[3].text != "")
        {
            treatPhone2 = TreatFields.PhoneField(inputs[3].text);
        }

        if (treatName != "" || treatDate != "" || treatPhone1 != "" ||
            treatPhone2 != "" || treatSex != "")
        {
            bool          flag      = true;
            StringBuilder fullerror = new StringBuilder();

            if (treatName != "" && flag)
            {
                var splitBar = treatName.Split('|');
                fullerror.Append("[Nome]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[0], 0);
            }
            else if (treatName == "")
            {
                ApplyColor(inputs[0], 2);
            }

            if (treatDate != "" && flag)
            {
                var splitBar = treatDate.Split('|');
                fullerror.Append("[Data de Nascimento]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[1], 0);
            }
            else if (treatDate == "")
            {
                ApplyColor(inputs[1], 2);
            }

            if (treatPhone1 != "" && flag)
            {
                var splitBar = treatPhone1.Split('|');
                fullerror.Append("[Telefone1]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[2], 0);
            }
            else if (treatPhone1 == "")
            {
                ApplyColor(inputs[2], 2);
            }

            if (treatSex != "" && flag)
            {
                var splitBar = treatSex.Split('|');
                fullerror.Append("[Sexo]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(toggles[0], 0);
                ApplyColor(toggles[1], 0);
            }
            else if (treatSex == "")
            {
                ApplyColor(toggles[0], 2);
                ApplyColor(toggles[1], 2);
            }

            if (treatPhone2 != "" && flag)
            {
                var splitBar = treatPhone2.Split('|');
                fullerror.Append("[Telefone2]: ");
                foreach (var erro in splitBar)
                {
                    fullerror.Append(erro + '\n');
                }

                flag = false;
                ApplyColor(inputs[3], 0);
            }
            else if (treatPhone2 == "")
            {
                ApplyColor(inputs[3], 2);
            }

            helpPopUp.text = fullerror.ToString();
            int   count = fullerror.ToString().Count(f => f == '\n');
            int   top   = -90 + (count * 30);
            float right = 300.0f - helpPopUp.preferredWidth;

            helpPopUp.transform.localPosition = new Vector3(helpPopUp.transform.localPosition.x, 0, helpPopUp.transform.localPosition.z);

            helpPopUp.transform.parent.gameObject.GetComponent <RectTransform>().offsetMin = new Vector2(right, -top);
            helpPopUp.transform.parent.gameObject.GetComponent <RectTransform>().offsetMax = new Vector2(-right, top);
            helpPopUp.transform.parent.gameObject.SetActive(true);

            valid = false;
        }

        return(valid);
    }