private bool validateInput()
        {
            StringBuilder builder = new StringBuilder();
            int           isError = 0;

            if (txt_name.Text.ToString().Length > 0)
            {
                if (this.IsDigitsOnly(txt_name.Text.ToString()))
                {
                    isError++;
                    builder.Append("Name must be alphabetic").AppendLine();
                }
                else
                {
                    if (txt_name.Text.ToString().Length > 191)
                    {
                        isError++;
                        builder.Append("Name is too long").AppendLine();
                    }
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_email.Text.ToString().Length > 0)
            {
                if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter  email").AppendLine();
            }

            Customer customer = new Customer();

            if (this.isCustomerEdit == true)
            {
                if (txt_phone.Text.ToString().Length > 0)
                {
                    if (this.IsDigitsOnly(txt_phone.Text.ToString()))
                    {
                        if (txt_phone.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("Phone number should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (!this.previous_phone.Equals(txt_phone.Text.ToString()))
                            {
                                if (customer.checkPhoneAlreadyExist(txt_phone.Text.ToString()))
                                {
                                    isError++;
                                    builder.Append("Phone number already exist").AppendLine();
                                }
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Phone must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter phone").AppendLine();
                }
            }
            else
            {
                if (txt_phone.Text.ToString().Length > 0)
                {
                    if (this.IsDigitsOnly(txt_phone.Text.ToString()))
                    {
                        if (txt_phone.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("Phone number should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (customer.checkPhoneAlreadyExist(txt_phone.Text.ToString()))
                            {
                                isError++;
                                builder.Append("Phone number already exist").AppendLine();
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Phone must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter phone").AppendLine();
                }
            }



            if (txt_address.Text.Length > 0)
            {
                if (txt_address.Text.Length > 191)
                {
                    isError++;
                    builder.Append("Address is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter address").AppendLine();
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 2
0
        private bool validateUser()
        {
            int isError = 0;

            StringBuilder builder = new StringBuilder();

            if (txt_email.Text.ToString().Length > 0)
            {
                if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter  email").AppendLine();
            }



            if (txt_name.Text.ToString().Length > 0)
            {
                if (Encrption.Is_Alphabetic(txt_name.Text.ToString()))
                {
                    if (txt_name.Text.ToString().Length > 191)
                    {
                        isError++;
                        builder.Append("Name is too long").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Name must be alphabetic").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_username.Text.ToString().Length > 0)
            {
                if (txt_username.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("Username is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter username").AppendLine();
            }

            if (txt_password.Text.ToString().Length > 0)
            {
                if (txt_password.Text.ToString().Length < 6 || txt_password.Text.ToString().Length > 20)
                {
                    isError++;
                    builder.Append("Password must be in between 6 to 20 characters").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter password").AppendLine();
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Esempio n. 3
0
        private bool validateInput()
        {
            StringBuilder builder = new StringBuilder();
            int           isError = 0;

            if (txt_name.Text.ToString().Length > 0)
            {
                if (!Encrption.Is_Alphabetic(txt_name.Text.ToString()))
                {
                    isError++;
                    builder.Append("Name must be alphabetic").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_fathername.Text.ToString().Length > 0)
            {
                if (!Encrption.Is_Alphabetic(txt_fathername.Text.ToString()))
                {
                    isError++;
                    builder.Append("Father name must be alphabetic").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter father name").AppendLine();
            }

            if (txt_email.Text.ToString().Length > 0)
            {
                if (!Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter email").AppendLine();
            }

            Employee employee = new Employee();

            if (this.isEditEmployee == true)
            {
                // Mobile
                if (txt_mobile.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_mobile.Text.ToString(), out double result))
                    {
                        if (txt_mobile.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("mobile lenght should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (!this.mobile_no.Equals(txt_mobile.Text.ToString()))
                            {
                                if (employee.checkPhoneAlreadyExist(txt_mobile.Text.ToString()))
                                {
                                    isError++;
                                    builder.Append("Mobile number already exists").AppendLine();
                                }
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Mobile number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("please enter mobile number").AppendLine();
                }

                // Nic
                if (txt_nic.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_nic.Text.ToString(), out double result))
                    {
                        if (txt_nic.Text.ToString().Length != 13)
                        {
                            isError++;
                            builder.Append("Nic lenght should be 13 digits").AppendLine();
                        }
                        else
                        {
                            if (!this.cnic_no.Equals(txt_nic.Text.ToString()))
                            {
                                if (employee.checkNicAlreadyExist(txt_nic.Text.ToString()))
                                {
                                    isError++;
                                    builder.Append("Nic number already exist").AppendLine();
                                }
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Nic number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter nic number").AppendLine();
                }
            }
            else
            {
                // Mobile
                if (txt_mobile.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_mobile.Text.ToString(), out double result))
                    {
                        if (txt_mobile.Text.ToString().Length != 11)
                        {
                            isError++;
                            builder.Append("mobile lenght should be 11 digits").AppendLine();
                        }
                        else
                        {
                            if (employee.checkPhoneAlreadyExist(txt_mobile.Text.ToString()))
                            {
                                isError++;
                                builder.Append("Mobile number already exists").AppendLine();
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Mobile number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("please enter mobile number").AppendLine();
                }

                // Nic
                if (txt_nic.Text.ToString().Length > 0)
                {
                    if (double.TryParse(txt_nic.Text.ToString(), out double result))
                    {
                        if (txt_nic.Text.ToString().Length != 13)
                        {
                            isError++;
                            builder.Append("Nic lenght should be 13 digits").AppendLine();
                        }
                        else
                        {
                            if (employee.checkNicAlreadyExist(txt_nic.Text.ToString()))
                            {
                                isError++;
                                builder.Append("Nic number already exist").AppendLine();
                            }
                        }
                    }
                    else
                    {
                        isError++;
                        builder.Append("Nic number must be numeric").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter nic number").AppendLine();
                }
            }

            if (txt_address.Text.Length > 0)
            {
                if (txt_address.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("Address is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("please enter address").AppendLine();
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }
        private bool validateUser()
        {
            int           isError = 0;
            StringBuilder builder = new StringBuilder();

            if (txt_name.Text.ToString().Length > 0)
            {
                if (txt_name.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("Name is too long").AppendLine();
                }
                else
                {
                    if (!Regex.IsMatch(txt_name.Text, @"^[A-Za-z ]+$"))
                    {
                        isError++;
                        builder.Append("Name contain only character").AppendLine();
                    }

                    //if(Regex.IsMatch(txt_name.Text, "^[0-9]+$"))
                    //{
                    //    isError++;
                    //    builder.Append("Name cannot contain digits").AppendLine();
                    //}
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter name").AppendLine();
            }

            if (txt_email.Text.ToString().Length > 0)
            {
                if (Encrption.IsValidEmailAddress(txt_email.Text.ToString()))
                {
                    if (txt_email.Text.ToString().Length > 191)
                    {
                        isError++;
                        builder.Append("Email is too long").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter valid email").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter  email").AppendLine();
            }

            if (txt_username.Text.ToString().Length > 0)
            {
                if (txt_username.Text.ToString().Length > 191)
                {
                    isError++;
                    builder.Append("login id is too long").AppendLine();
                }
            }
            else
            {
                isError++;
                builder.Append("Please enter login id").AppendLine();
            }

            if (!is_edit.Equals(true))
            {
                if (txt_password.Text.ToString().Length > 0)
                {
                    if (txt_password.Text.ToString().Length < 6 || txt_password.Text.ToString().Length > 20)
                    {
                        isError++;
                        builder.Append("Password must be in between 6 to 20 characters").AppendLine();
                    }
                }
                else
                {
                    isError++;
                    builder.Append("Please enter password").AppendLine();
                }
            }

            if (isError > 0)
            {
                MessageBox.Show(builder.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                return(true);
            }
        }