private bool checkData() { if (string.IsNullOrWhiteSpace(tb_student_id.Text)) { MessageBox.Show("Bạn chưa nhập mã sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_student_id.Focus(); return(false); } else { if (!MyValidate.validateID(tb_student_id.Text)) { MessageBox.Show("Mã sinh viên phải gồm 8 kí tự", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_student_id.Focus(); return(false); } } if (string.IsNullOrWhiteSpace(tb_student_name.Text)) { MessageBox.Show("Bạn chưa nhập tên sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_student_name.Focus(); return(false); } if (string.IsNullOrWhiteSpace(tb_student_group.Text)) { MessageBox.Show("Bạn chưa nhập điểm toán của sinh viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_student_group.Focus(); return(false); } return(true); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; MyValidate validateCode = new MyValidate(); string code = validateCode.CreateValidateCode(4); context.Session["code"] = code;//保存到session中 validateCode.CreateValidateGraphic(code, context); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); //创建生成2维图的对象 MyValidate validateCode = new MyValidate(); //调用CreateValidateCode方法,传入参数5 表示生成一个5位数的验证码 string code = validateCode.CreateValidateCode(4); //并且返回此验证码中的数字 context.Session["code"] = code; //验证码图片中的数字保存到Session会话作用域中 validateCode.CreateValidateGraphic(code, context); //将最终的图片输出到网页中去 }
private void btn_save_student_Click(object sender, EventArgs e) { if (flag.Equals("add")) { if (checkData()) { string id = tb_student_id.Text; string name = tb_student_name.Text; string group = tb_student_group.Text; Student itemStudent = new Student(name, id, group); if (MyValidate.isStudentExists(itemStudent, listStudent)) { MessageBox.Show("Sinh viên đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); unlockControl(); } else { studentTable.Rows.Add(id, name, group, itemStudent.getPoint() + ""); dataGridStudent.DataSource = studentTable; listStudent.Add(itemStudent); List <Student> itemList = new List <Student>(); itemList.Add(itemStudent); IOStream.writeLineStudent(pathDataSource, itemList, true); dataGridStudent.RefreshEdit(); } } } if (flag.Equals("edit")) { if (checkData()) { studentTable.Rows[indexSelectionTable][0] = tb_student_id.Text; studentTable.Rows[indexSelectionTable][1] = tb_student_name.Text; studentTable.Rows[indexSelectionTable][2] = tb_student_group.Text; dataGridStudent.DataSource = studentTable; dataGridStudent.RefreshEdit(); lockControl(); } } }
public ActionResult Create(User user) { context = new ShopLaptionDbContextDataContext(); if (ModelState.IsValid) { var check_user = context.Users.Any(a => a.UserName.Equals(user.UserName)); var check_email = context.Users.Any(a => a.Email.Equals(user.Email)); var res_val = new MyValidate(); if (check_user) { ModelState.AddModelError("", "Tài khoản đã tồn tại !"); return(View()); } else if (check_email) { ModelState.AddModelError("", "Email đã tồn tại !"); return(View()); } else if (res_val.isEmail(user.Email) == false) { ModelState.AddModelError("", "Email không đúng định dạng !"); return(View()); } else if (res_val.IsValidPhone(user.Phone) == false) { ModelState.AddModelError("", "Số điện thoại không đúng !"); return(View()); } else { user.CreatedBy = Session[CommonConstants.NAME_SESSION].ToString(); user.CreatedDate = DateTime.Now; context.Users.InsertOnSubmit(user); context.SubmitChanges(); return(RedirectToAction("Index")); } } return(RedirectToAction("Index")); }
public MyValidateTests() { myValidate = new MyValidate(); }
public ActionResult DatHang(FormCollection collection) { context = new ShopLaptionDbContextDataContext(); SetViewbag(); SetListOrder(); ViewBag.TongTien = TongTien(); var res = new MyValidate(); Order order = new Order(); List <GioHang> gioHangs = GetOrders(); order.MaDH = "HD" + DateTime.Now.ToString("yyyyMMddHHmmsss"); order.TenKH = collection["tenKH"]; order.Sdt = collection["sdt"]; order.DiaChi = collection["diachi"]; order.NgayDat = DateTime.Now; order.GhiChu = collection["ghichu"]; order.TinhTrang = false; //bool v = res.IsValidPhone(order.Sdt); if (String.IsNullOrEmpty(order.TenKH)) { ViewData["err1"] = "Vui lòng nhập họ tên của bạn !"; } else if (String.IsNullOrEmpty(order.Sdt)) { ViewData["err2"] = "Vui lòng nhập số điện thoại liên lạc !"; } else if (res.IsValidPhone(order.Sdt) == false) { ViewData["err3"] = "Số điện thoại bạn nhập không đúng định dạng!"; } else if (String.IsNullOrEmpty(order.DiaChi)) { ViewData["err4"] = "Vui lòng nhập địa chỉ giao hàng !"; } else { context.Orders.InsertOnSubmit(order); context.SubmitChanges(); foreach (var item in gioHangs) { OrderDetail orderDetail = new OrderDetail(); orderDetail.MaDH = order.MaDH; orderDetail.MaSP = item.masp; orderDetail.TenSP = item.tensp; orderDetail.Soluong = item.sl; orderDetail.DonGia = (decimal)item.gia; orderDetail.Tong = (decimal)TongTien(); var pro = context.Products.SingleOrDefault(x => x.Code == orderDetail.MaSP); pro.Quantity = pro.Quantity - orderDetail.Soluong; context.OrderDetails.InsertOnSubmit(orderDetail); context.SubmitChanges(); } context.SubmitChanges(); Session["order"] = null; return(RedirectToAction("XacNhanDonHang", "Card")); } return(View()); }
private void button4_Click(object sender, EventArgs e) { MyValidate.T(); }
private bool register() { if (string.IsNullOrWhiteSpace(tb_register_name.Text)) { MessageBox.Show("Bạn chưa nhập tên đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_name.Focus(); return(false); } if (string.IsNullOrWhiteSpace(tb_register_password.Text)) { MessageBox.Show("Bạn chưa nhập mật khẩu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password.Focus(); return(false); } else { if (!MyValidate.validatePassword(tb_register_password.Text)) { MessageBox.Show("Mật khẩu không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password.Focus(); return(false); } } if (string.IsNullOrWhiteSpace(tb_register_password_validate.Text)) { MessageBox.Show("Bạn chưa xác nhận mật khẩu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password_validate.Focus(); return(false); } else { if (!MyValidate.validatePassword(tb_register_password_validate.Text)) { MessageBox.Show("Mật khẩu xác nhận không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password_validate.Focus(); return(false); } } if (!tb_register_password.Text.ToString().Equals(tb_register_password_validate.Text.ToString())) { MessageBox.Show("Xác nhận mật khẩu không trùng khớp" + tb_register_password.Text + tb_register_password_validate.Text, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_password_validate.Focus(); return(false); } User user = new User(tb_register_name.Text, tb_register_password.Text); if (MyValidate.isUserExists(user, listUser)) { MessageBox.Show("Tài khoản đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_register_name.Focus(); tb_register_password_validate.Text = ""; tb_register_password.Text = ""; return(false); } else { List <User> list = new List <User>(); list.Add(user); IOStream.writeLineUser(pathDataSource, list, true); return(true); } }