예제 #1
0
 /// <summary>
 /// Adds a new validation test to the current instance.  The test is associated with a specific member of the
 /// target object being validated and will be performed against the value of that member.
 /// </summary>
 /// <returns>
 /// The current instance, permitting method-chaining (such as adding many tests together).
 /// </returns>
 /// <param name='member'>
 /// The member that this test is to be associated with.
 /// </param>
 /// <param name='test'>
 /// The test to add.
 /// </param>
 /// <param name='testIdentifier'>
 /// An identifier for the test, that allows it to be distinguished from other tests.
 /// </param>
 /// <typeparam name='TMember'>
 /// The output/return type of the <paramref name="member"/> that this test is associated with.
 /// </typeparam>
 public IValidator <TTarget> AddTest <TMember>(MemberInfo member,
                                               ValidationFunction <TMember> test,
                                               object testIdentifier)
 {
     this.Tests.Add(new ValidationTest <TTarget, TMember>(test, member, testIdentifier));
     return(this);
 }
예제 #2
0
        public static void Init(Vector2 centerPosition,
                                float width,
                                string title,
                                string description,
                                string text,
                                OnSetText setTextCallback,
                                ValidationFunction validateFunc,
                                string okButtonText,
                                Styling style)
        {
            var descContent = new GUIContent(description);
            var height      = GUI.skin.label.CalcHeight(descContent, width);

            if (height > EditorGUIUtility.singleLineHeight)
            {
                height -= EditorGUIUtility.singleLineHeight;
            }

            var win  = EditorWindow.CreateInstance <TextEditPopover>();
            var size = new Vector2(width, 90 + height);
            var rect = new Rect(centerPosition.x - size.x * 0.5f, centerPosition.y - size.y * 0.5f, 0, 0);

            win.Configure(title, description, text, setTextCallback, validateFunc, okButtonText, style);
            win.ShowAsDropDown(rect, size);
        }
예제 #3
0
        //Generic Function to take inputs, validate and return.
        private static T ReadAndValidateInput <T>(T OldValue,
                                                  String promptString, IsEmpty <T> isEmpty,
                                                  ValidationFunction <T> validationFunction, String invalidPrompt)
        {
            T    readValue;
            bool isReadDone;

            do
            {
                Console.Write(promptString);
                if (!isEmpty(OldValue))
                {
                    Console.Write($" ({OldValue}) ");
                }

                readValue  = (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
                readValue  = isEmpty(readValue) ? OldValue : readValue;
                isReadDone = validationFunction(readValue);
                if (!isReadDone)
                {
                    Console.WriteLine("\n" + invalidPrompt + "\n");
                }
            } while (!isReadDone);
            return(readValue);
        }
예제 #4
0
        public ActionResult ThemThongTin(string TenKhachHang, string SoDienThoai, string Email, string DiaChi)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrEmpty(TenKhachHang))
                    {
                        throw new Exception("Lỗi Tên khách hàng");
                    }

                    if (!ValidationFunction.IsValidEmail(Email))
                    {
                        throw new Exception("Email không hợp lệ");
                    }

                    if (!SoDienThoai.ValidatePhoneNumber(true))
                    {
                        throw new Exception("Số điện thoại không hợp lệ");
                    }
                }
                catch (Exception e)
                {
                    Response.StatusCode = 400;
                    return(Json(new { msg = e.Message }, JsonRequestBehavior.AllowGet));
                }

                var identity = _db.IdentityTraces.Find(1);

                identity.KhachHangIdentity++;
                var khachHang = new KhachHang
                {
                    MaKhachHang     = "KHACHHANG" + identity.KhachHangIdentity.ToString("00"),
                    Email           = Email,
                    Ten             = TenKhachHang,
                    DiaChi          = DiaChi,
                    MaLoaiKhachHang = "KHACHHANGTHUONG",
                    ThoiGianDangKi  = DateTime.Now,
                    SoDienThoai     = SoDienThoai
                };
                _db.KhachHangs.Add(khachHang);
                _db.SaveChanges();
                Session["MaKhachHangVangLai"] = khachHang.MaKhachHang;
                Response.StatusCode           = 200;
                return(Json(new { msg = "Thành Công" }, JsonRequestBehavior.AllowGet));
            }

            Response.StatusCode = 400;
            return(Json(new { msg = "Lỗi ! Hãy Thử trong vài giây nữa" }, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
파일: Types.cs 프로젝트: ardud/ClassLibrary
        public void GetValues(ref List <string> takenValues)
        {
#if DEBUG
            GeneralClass.CheckNotNull(takenValues);
#endif
            takenValues.Clear();
            takenValues.Add(ID.ToString());
            takenValues.Add(NameOfType.ToString());
            takenValues.Add(Format.ToString());
            takenValues.Add(Parse.ToString());
            takenValues.Add(IfEnum.ToString());
            takenValues.Add(ValidationFunction.ToString());
            takenValues.Add(DefaultValue.ToString());
        }
예제 #6
0
 void Configure(string popoverTitle,
                string description,
                string text,
                OnSetText setTextCallback,
                ValidationFunction validateFunc,
                string okButtonText,
                Styling style)
 {
     _title        = popoverTitle;
     _description  = description;
     _originalText = _text = text;
     _onSetText    = setTextCallback;
     _validateFunc = validateFunc;
     _okButton     = okButtonText;
     _style        = style;
 }
예제 #7
0
        public static void Validate <T>(this ValidationResultsBuilder validationResultsBuilder,
                                        ValidationFunction <T> validationFunction,
                                        T value,
                                        string member)
        {
            if (validationResultsBuilder == null)
            {
                throw new ArgumentNullException(nameof(validationResultsBuilder));
            }

            if (validationFunction == null)
            {
                throw new ArgumentNullException(nameof(validationFunction));
            }

            if (!validationFunction(value, out var message))
            {
                validationResultsBuilder.AddValidationResult(member, message);
            }
        }
예제 #8
0
 /// <summary>
 /// Initializes a new validation test instance.
 /// </summary>
 /// <param name='test'>
 /// The test function that this instance performs.
 /// </param>
 /// <param name='member'>
 /// The member that this test is associated with.
 /// </param>
 /// <param name='identifier'>
 /// The identifier for this test, to distinguish it from other tests.
 /// </param>
 public ValidationTest(ValidationFunction <TValue> test,
                       MemberInfo member,
                       object identifier) : base(identifier, member)
 {
     this.Test = test;
 }
예제 #9
0
        public ActionResult Register(string TenNhanVien, string Email, string TaiKhoanDangNhap, string MatKhau,
                                     string pass,
                                     string DiaChi, string SoDienThoai, int Gender, string NgaySinh, double Luong)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (_context.TaiKhoans.Find(TaiKhoanDangNhap) != null)
                    {
                        throw new Exception("Tài khoản này đã được đăng kí ! Vui lòng chọn tên đăng nhập khác");
                    }

                    if (string.IsNullOrEmpty(TaiKhoanDangNhap))
                    {
                        throw new Exception("Lỗi Tài khoản đăng nhập");
                    }

                    if (string.IsNullOrEmpty(TenNhanVien))
                    {
                        throw new Exception("Lỗi Tên khách hàng");
                    }

                    if (!SoDienThoai.ValidatePhoneNumber(true))
                    {
                        throw new Exception("Số điện thoại không hợp lệ");
                    }

                    if (!ValidationFunction.IsValidEmail(Email))
                    {
                        throw new Exception("Email không hợp lệ");
                    }

                    if (!ValidationFunction.IsValidPassword(MatKhau))
                    {
                        throw new Exception(
                                  "Mật khẩu không hợp lệ ! Hãy nhập ít nhất 1 chữ số , một chữ cái viết hoa , dài ít nhất 8 kí tự");
                    }

                    if (string.Compare(MatKhau, pass) != 0)
                    {
                        throw new Exception("Hãy nhập mật khẩu khớp nhau");
                    }


                    if (Gender > 1 || Gender < 0)
                    {
                        throw new Exception("Lỗi thông tin giới tính");
                    }

                    try
                    {
                        DateTime.Parse(NgaySinh);
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                }
                catch (Exception e)
                {
                    Response.StatusCode = 400;
                    return(Json(new { msg = e.Message }, JsonRequestBehavior.AllowGet));
                }

                var identity = _context.IdentityTraces.Find(1);

                identity.NhanVienIdentity++;
                var nhanVien = new NhanVien()
                {
                    MaNhanVien     = "NHANVIEN" + identity.KhachHangIdentity.ToString("00"),
                    Email          = Email,
                    Ten            = TenNhanVien,
                    DiaChi         = DiaChi,
                    GioiTinh       = Gender == 1 ? true : false,
                    MaLoaiNhanVien = "NHANVIEN0",
                    NgaySinh       = DateTime.Parse(NgaySinh),
                    NgayVaoLam     = DateTime.Now,
                    SoDienThoai    = SoDienThoai,
                    Luong          = Luong,
                };
                _context.NhanViens.Add(nhanVien);
                _context.SaveChanges();

                var taiKhoan = new TaiKhoan
                {
                    MaTaiKhoan       = nhanVien.MaNhanVien,
                    TaiKhoanDangNhap = TaiKhoanDangNhap,
                    MatKhau          = MatKhau
                };

                _context.TaiKhoans.Add(taiKhoan);
                _context.SaveChanges();

                Response.StatusCode = 200;
                return(Json(new { msg = "Thành Công" }, JsonRequestBehavior.AllowGet));
            }

            Response.StatusCode = 400;
            return(Json(new { msg = "Lỗi ! Hãy Thử trong vài giây nữa" }, JsonRequestBehavior.AllowGet));
        }
예제 #10
0
 /// <summary>
 /// Initializes a new validation test instance.
 /// </summary>
 /// <param name='test'>
 /// The test function that this instance performs.
 /// </param>
 /// <param name='identifier'>
 /// The identifier for this test, to distinguish it from other tests.
 /// </param>
 public ValidationTest(ValidationFunction <TTarget> test, object identifier) : this(identifier, null)
 {
     this.Test = test;
 }
예제 #11
0
 /// <summary>
 /// Adds a new validation test to the current instance.  The test will validate an object in general terms, without
 /// an association to a particular member of the instance.
 /// </summary>
 /// <returns>
 /// The current instance, permitting method-chaining (such as adding many tests together).
 /// </returns>
 /// <param name='test'>
 /// The test to add.
 /// </param>
 public IValidator <TTarget> AddTest(ValidationFunction <TTarget> test)
 {
     return(this.AddTest(test, null));
 }
예제 #12
0
 /// <summary>
 /// Adds a new validation test to the current instance.  The test is associated with a specific member of the
 /// target object being validated and will be performed against the value of that member.
 /// </summary>
 /// <returns>
 /// The current instance, permitting method-chaining (such as adding many tests together).
 /// </returns>
 /// <param name='member'>
 /// The member that this test is to be associated with.
 /// </param>
 /// <param name='test'>
 /// The test to add.
 /// </param>
 /// <param name='testIdentifier'>
 /// An identifier for the test, that allows it to be distinguished from other tests.
 /// </param>
 /// <typeparam name='TMember'>
 /// The output/return type of the <paramref name="member"/> that this test is associated with.
 /// </typeparam>
 public IValidator <TTarget> AddTest <TMember>(Expression <Func <TTarget, TMember> > member,
                                               ValidationFunction <TMember> test,
                                               object testIdentifier)
 {
     return(this.AddTest <TMember>(Reflect.Member <TTarget, TMember>(member), test, testIdentifier));
 }
예제 #13
0
 /// <summary>
 /// Adds a new validation test to the current instance.  The test is associated with a specific member of the
 /// target object being validated and will be performed against the value of that member.
 /// </summary>
 /// <returns>
 /// The current instance, permitting method-chaining (such as adding many tests together).
 /// </returns>
 /// <param name='member'>
 /// The member that this test is to be associated with.
 /// </param>
 /// <param name='test'>
 /// The test to add.
 /// </param>
 /// <typeparam name='TMember'>
 /// The output/return type of the <paramref name="member"/> that this test is associated with.
 /// </typeparam>
 public IValidator <TTarget> AddTest <TMember>(MemberInfo member,
                                               ValidationFunction <TMember> test)
 {
     return(this.AddTest <TMember>(member, test, null));
 }
예제 #14
0
 /// <summary>
 /// Adds a new validation test to the current instance.  The test is associated with a specific member of the
 /// target object being validated and will be performed against the value of that member.
 /// </summary>
 /// <returns>
 /// The current instance, permitting method-chaining (such as adding many tests together).
 /// </returns>
 /// <param name='member'>
 /// The member that this test is to be associated with.
 /// </param>
 /// <param name='test'>
 /// The test to add.
 /// </param>
 /// <typeparam name='TMember'>
 /// The output/return type of the <paramref name="member"/> that this test is associated with.
 /// </typeparam>
 public IValidator <TTarget> AddTest <TMember>(Expression <Func <TTarget, TMember> > member,
                                               ValidationFunction <TMember> test)
 {
     return(this.AddTest <TMember>(member, test, null));
 }
예제 #15
0
 /// <summary>
 /// Adds a new validation test to the current instance.  The test will validate an object in general terms, without
 /// an association to a particular member of the instance.
 /// </summary>
 /// <returns>
 /// The current instance, permitting method-chaining (such as adding many tests together).
 /// </returns>
 /// <param name='test'>
 /// The test to add.
 /// </param>
 /// <param name='testIdentifier'>
 /// An identifier for the test, that allows it to be distinguished from other tests.
 /// </param>
 public IValidator <TTarget> AddTest(ValidationFunction <TTarget> test,
                                     object testIdentifier)
 {
     this.Tests.Add(new ValidationTest <TTarget>(test, testIdentifier));
     return(this);
 }
예제 #16
0
 public PropertyValidated(String name, T initval, ValidationFunction <T> fnValidation)
     : base(name, initval)
 {
     this.fnValidation = fnValidation;
 }