private void radButton1_Click(object sender, EventArgs e) { var userName = txtUserName.Text; if (string.IsNullOrEmpty(userName)) { MessageBox.Show(this, "Type User Name!", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var pass = txtPass.Text; if (string.IsNullOrEmpty(pass)) { MessageBox.Show(this, "Type Password!", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } var dbContext = new VgmsDbContext(); var user = dbContext.UserInfo.SingleOrDefault(x => x.UserName == userName); if (user != null) { if (user.Password == pass) { //success login _App.UserFullName = user.FullName; _App.UserName = user.UserName; FrmMain main = new FrmMain(); main.Show(this); this.Hide(); } else { MessageBox.Show(this, "Invalid Password!", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(this, "Invalid User Name!", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtName.Text == "") { MessageBox.Show("Type Name!"); return; } if (txtEmail.Text == "") { MessageBox.Show("Type Email!"); return; } if (!txtEmail.Text.Contains("@") || !txtEmail.Text.Contains(".")) { MessageBox.Show("Invalid Email!"); return; } if (txtPass.Text == "") { MessageBox.Show("Type Password!"); return; } if (txtPass.Text != txtRePass.Text) { MessageBox.Show("Password not matched!!"); return; } if (txtMobile.Text == "") { MessageBox.Show("Type Mobile number!"); return; } if (dtpDob.Value >= DateTime.Now) { MessageBox.Show("Invalid DOB!"); return; } //data save to userinfo UserInfo userInfo = new UserInfo(); userInfo.FullName = txtName.Text; userInfo.UserName = txtUserName.Text; userInfo.Password = txtPass.Text; userInfo.Email = txtEmail.Text; userInfo.Mobile = txtMobile.Text; userInfo.Dob = dtpDob.Value; GenderEnum gender = (GenderEnum)ddlGender.SelectedItem; userInfo.GenderEnumId = (int)gender; //data save to database VgmsDbContext vgmsDb = new VgmsDbContext(); vgmsDb.UserInfo.Add(userInfo); vgmsDb.SaveChanges(); MessageBox.Show("Saved"); }