public void Saves() { using (var BH = new Models.BanLapTopEntities()) { var sql = BH.CaiDats.Where(m => m.STT == 1).Single() as CaiDat; sql.FullScreen = SetFull(); sql.font = SetFont(); sql.Back = SetLight(); BH.SaveChanges();//lưu thay doi } }
private void btnReset_Click(object sender, RoutedEventArgs e) { Settings?.Invoke("Reset"); using (var BH = new Models.BanLapTopEntities()) { var sql = BH.CaiDats.Where(m => m.STT == 1).Single() as CaiDat; sql.FullScreen = "Windows"; sql.font = "Default"; sql.Back = "Dark"; BH.SaveChanges();//lưu thay doi } }
private void SavePasswd_Click(object sender, RoutedEventArgs e) { string oldpass = md5(pOldPass.Password); string newpass = md5(pNewPass.Password); string ConfigPass = md5(pPass.Password); using (Models.BanLapTopEntities db = new Models.BanLapTopEntities()) { var mh = db.TaiKhoans.Where(m => m.IdNguoiDung == txtID.Text).Single() as TaiKhoan; if (mh == null) { MessageBox.Show("Fail!"); return; } if (string.IsNullOrEmpty(pOldPass.Password) || string.IsNullOrEmpty(pNewPass.Password) || string.IsNullOrEmpty(pPass.Password)) { error.Content = ("Not fully entered!"); return; } else { var password = (from h in BLT.TaiKhoans where h.IdNguoiDung == txtID.Text select h.PassND).SingleOrDefault(); if (oldpass != password) { error.Content = "Wrong password"; return; } if (newpass != ConfigPass) { error.Content = "Confirm password must be same as password."; return; } else { mh.PassND = newpass; if (db.SaveChanges() > 0) { MessageBox.Show("Done!"); error.Content = ""; Expan.IsExpanded = false; } } } } }
private void Button_Click(object sender, RoutedEventArgs e) { if (udSL.Value < 0) { MessageBox.Show("Why is " + udSL.Value + " ?", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { using (var BH = new Models.BanLapTopEntities()) { var sql = BH.SanPhams.Where(m => m.MaSP == MaSP).Single() as SanPham; sql.SoLuongTon += (int)udSL.Value; BH.SaveChanges(); this.Close(); } } }
private void btnSave_Click(object sender, RoutedEventArgs e) { string email = txtEmail.Text; string Hoten = txtName.Text; string sex = txtSex.Text; string diachi = txtDiaChi.Text; string sdt = txtSDT.Text; using (Models.BanLapTopEntities db = new Models.BanLapTopEntities()) { var mh = db.TaiKhoans.Where(m => m.IdNguoiDung == txtID.Text).Single() as TaiKhoan; if (mh == null) { MessageBox.Show("Fail!"); return; } if (SinhNhat.SelectedDate == null || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(Hoten) || string.IsNullOrEmpty(sex) || string.IsNullOrEmpty(diachi) || string.IsNullOrEmpty(sdt)) { errorInfo.Text = ("Chưa nhập đầy đủ thông tin!"); return; } if (txtSex.Text != "Nam" && txtSex.Text != "Nữ") { errorInfo.Text = ("Giới tình phải là [Nam] Hoặc [Nữ]!"); txtSex.Focus(); return; } if (!Regex.IsMatch(email, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { errorInfo.Text = ("Email không hợp lệ"); txtEmail.Focus(); return; } if (sdt.Length > 12 || sdt.Length < 10) { errorInfo.Text = ("SĐT Phải từ 10 đến 11 số"); txtSDT.Focus(); return; } long sdtparse; if (!long.TryParse(txtSDT.Text, out sdtparse)) { errorInfo.Text = ("SĐT không hợp lệ"); txtSDT.Focus(); return; } else { mh.Email = email; mh.GioiTinh = sex; mh.HoTen = Hoten; mh.DiaChi = diachi; mh.SoDT = sdt; mh.NgaySinh = SinhNhat.SelectedDate.Value; if (File.Exists(DuongDan)) { FileStream Stream = new FileStream(DuongDan, FileMode.Open, FileAccess.Read); StreamReader Reader = new StreamReader(Stream); Byte[] ImgData = new Byte[Stream.Length - 1]; Stream.Read(ImgData, 0, (int)Stream.Length - 1); mh.Avatar = ImgData; } if (db.SaveChanges() > 0) { MessageBox.Show("Done!"); IsReadOnlyTextBox(true); errorInfo.Text = (""); InfoUser?.Invoke("1"); } } } }
private void Submit_Click(object sender, RoutedEventArgs e) { if (textBoxUser.Text.Length == 0) { errormessage.Text = "Please Enter a Username "; textBoxUser.Focus(); return; } else if (textBoxUser.Text.Length < 4) { errormessage.Text = "Please Enter a Username Length >= 5 character!"; textBoxUser.Focus(); return; } BanLapTopEntities BLT = new BanLapTopEntities(); int DK = BLT.TaiKhoans.Where(m => m.IdNguoiDung == textBoxUser.Text).Count(); if (DK > 0) { errormessage.Text = "The username already exists!"; textBoxUser.Focus(); return; } //---------- if (textBoxLastName.Text.Length == 0) { errormessage.Text = "Please Enter at your full name !"; textBoxLastName.Focus(); return; } else if (textBoxLastName.Text.Length < 5) { errormessage.Text = "Enter a valid your name!"; textBoxLastName.Focus(); return; } //------------- if (textBoxEmail.Text.Length == 0) { errormessage.Text = "Please Enter an email !"; textBoxEmail.Focus(); return; } else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { errormessage.Text = "Enter a valid email."; textBoxEmail.Select(0, textBoxEmail.Text.Length); textBoxEmail.Focus(); return; } //---------- if (passwordBox1.Password.Length == 0) { errormessage.Text = "Please Enter password !"; passwordBox1.Focus(); return; } if (passwordBoxConfirm.Password.Length == 0) { errormessage.Text = "Please Enter Confirm password."; passwordBoxConfirm.Focus(); return; } if (passwordBox1.Password != passwordBoxConfirm.Password) { errormessage.Text = "Confirm password must be same as password."; passwordBoxConfirm.Focus(); return; } if (textBoxAddress.Text.Length == 0) { errormessage.Text = "Please Enter Address...."; textBoxAddress.Focus(); return; } string Username = textBoxUser.Text; string lastname = textBoxLastName.Text; string email = textBoxEmail.Text; string password = md5(passwordBox1.Password); string address = ""; address = textBoxAddress.Text; errormessage.Text = ""; var TK = new TaiKhoan { IdNguoiDung = Username, PassND = password, HoTen = lastname, Email = email, DiaChi = address, MaLoaiTK = 0 }; using (var BanHang = new Models.BanLapTopEntities()) { int n = BanHang.TaiKhoans.Where(m => m.IdNguoiDung == TK.IdNguoiDung).Count(); if (n > 0) { errormessage.Text = "Username is Exist"; } else { BanHang.TaiKhoans.Add(TK); if (BanHang.SaveChanges() > 0) { MessageBox.Show("Success!"); Reset(); } else { MessageBox.Show("Error Please record"); } } } }