private void btnAdd_Click(object sender, EventArgs e) { u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; bool success = dal.Insert(u); if (success == true) { MessageBox.Show("ทำการบันทึกข้อมูลผู้ใช้งานเรียบร้อยแล้ว"); clear(); } else { MessageBox.Show("ไม่สามารถทำการบันทึกข้อมูลผู้ใช้งานได้! กรุณาลองใหม่อีกครั้ง"); } DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void btnAdd_Click(object sender, EventArgs e) { //get the values from the UI u.full_name = textBoxFullName.Text; u.email = textBoxEmail.Text; u.username = textBoxUsername.Text; u.password = textBoxPassword.Text; u.contact = textBoxContact.Text; u.address = textBoxAddress.Text; u.added_date = DateTime.Now; u.image_name = imageName; //adding the values from the UI to database //boolean variable to check wether the data is inserted successfully or not bool success = dal.Insert(u); //check wether the data is inserted successfully or not if (success == true) { //data or user added successfully MessageBox.Show("New user added successfully."); //display the user in data grid view DataTable dt = dal.Select(); dgvUsers.DataSource = dt; //clear textboxes Clear(); } else { //failed to add a new user MessageBox.Show("Failed to add new user."); } }
private void btnAdd_Click(object sender, EventArgs e) { u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; string loggedInUser = Login.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedInUser); u.added_by = usr.id; bool success = dal.Insert(u); if (success == true) { MessageBox.Show("User created Successfully."); clear(); } else { MessageBox.Show("Failed to add new User!!"); } DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
//BUTTON ADD #region Button Add Click private void addBtn_Click(object sender, EventArgs e) { //Step 1 get the values from UI u.full_name = txtBoxFullName.Text; u.email = txtBoxEmail.Text; u.username = txtBoxUserName.Text; u.password = txtBoxPwd.Text; u.contact = txtBoxContact.Text; u.address = txtBoxAddress.Text; u.address = txtBoxAddress.Text; u.added_date = DateTime.Now; u.image_name = imageName; //Step 2 Adding into DB //Create a bool var to check success bool success = dal.Insert(u); //step 3 Check if it was inserted successfully or not if (success == true) { //Data or user added Successfully MessageBox.Show("New user has been added"); } else { MessageBox.Show("Failed to add"); } }
private void btnCadastro_Click(object sender, EventArgs e) { u.pr_nome = txtFirstName.Text; u.sb_nome = txtLastName.Text; u.email = txtEmail.Text; u.user_name = txtUserName.Text; u.password = txtSenha.Text; u.contato = txtContato.Text; u.nm_endereco = txtEndereco.Text; u.sexo = cbxSexo.Text; u.user_type = cbxTpUser.Text; u.data = DateTime.Now; u.add_por = 1; bool sucess = dal.Insert(u); if (sucess = true) { MessageBox.Show("Usuário cadastrado com sucesso"); Limpar(); } else { MessageBox.Show("Não foi possivel cadastrar esse usuário"); } DataTable dt = dal.Select(); dgvUser.DataSource = dt; }
private void buttonCadastrar_Click(object sender, EventArgs e) { u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUserName.Text; u.password = txtPassword.Text; u.contact = txtContato.Text; u.address = txtAddress.Text; u.genero = cmbGenero.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; bool success = dal.Insert(u); if (success == true) { MessageBox.Show("USUÁRIO CADASTRADO COM SUCESSO!"); Limpar(); } else { MessageBox.Show("NÃO FOI POSSÍVEL CADASTRAR USUÁRIO!"); } DataTable dt = dal.Select(); dgvUser.DataSource = dt; }
private void btnAdd_Click(object sender, EventArgs e) { u.ime_i_prezime = txtFullName.Text; u.email = txtEmail.Text; u.korisnicko_ime = txtUsername.Text; u.lozinka = txtPassword.Text; u.kontakt = txtContact.Text; u.adresa = txtAddress.Text; u.datum_dodavanja = DateTime.Now; u.slika_korisnika = slikaKorisnika; bool success = dal.Insert(u); if (success == true) { MessageBox.Show("Novi korisnik uspješno dodan. "); DataTable dt = dal.Select(); dgvUsers.DataSource = dt; Clear(); } else { MessageBox.Show("Bezuspješno dodavanje korisnika"); } }
private void btnAdd_Click(object sender, EventArgs e) { //Step 1: Get the Values from UI u.full_name = txtFullName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.added_date = DateTime.Now; u.image_name = imageName; //Step2: Adding the Values from UI to the Database //Create a Boolean Variable to check whether the data is inserted successfully or not bool success = dal.Insert(u); //Step 3: Check whether the Data is Inserted Successfully or Not if (success == true) { //Data or User Added Successfully MessageBox.Show("New User added Successfully."); //Display the user in DataGrid View DataTable dt = dal.Select(); dgvUsers.DataSource = dt; //Clear TextBoxes Clear(); } else { //Failed to Add User MessageBox.Show("Failed to Add New User."); } }
private void btnAdd_Click(object sender, EventArgs e) { u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUserName.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; bool success = dal.Insert(u); if (success) { clearFields(); } MessageBox.Show(success ? "User-i eshte krijuar me sukses" : "Krijimi i User-it Deshtoi"); refreshDataGridView(); }
private void btnAdd_Click(object sender, EventArgs e) { u.FirstName = txtFirstname.Text; u.LastName = txtLastname.Text; u.Username = txtUsername.Text; u.Password = txtPassword.Text; u.Email = txtEmail.Text; u.Contact = Convert.ToInt32(txtContact.Text); u.Gender = cmbGender.Text; u.Address = txtAddress.Text; u.UserType = cmbUserType.Text; u.DateTime = DateTime.Now; // Inserting in to database bool success = dal.Insert(u); // If the data is successfully inserted then the value of success will be true else it will be false if (success == true) { //Data successfully inserted MessageBox.Show("User successfully Added."); Clear(); } else { //Fail to insert Data MessageBox.Show("Fail To Add User Try Again."); } //Refresh Data grid View DataTable dt = dal.Select(); dgvUser.DataSource = dt; }
private void button2_Click(object sender, EventArgs e) { if (lblUserType.Text == "Student") { userType = "Student"; } else if (lblUserType.Text == "Tutor") { userType = "Tutor"; } if (txtpassword.Text == txtrepassword.Text) { u.fullname = txtFullName.Text; u.address = txtAddress.Text; u.dob = dateTimePicker1.Value; u.parentName = txtParentName.Text; u.tell = txtTel.Text; u.username = txtusername.Text; u.password = txtpassword.Text; u.userType = lblUserType.Text; bool success = dal.Insert(u); if (success == true) { MessageBox mb = new MessageBox("User Added Successfully!!!", sampleframe.cs.MessageBox.MsgType.success); mb.Show(); clear(); Login f4 = new Login(); f4.Show(); this.Visible = false; } else { MessageBox mb = new MessageBox("Fail to Added!!!", sampleframe.cs.MessageBox.MsgType.retry); mb.Show(); } DataTable dt = dal.Select(); } else { MessageBox mb = new MessageBox("Passwords are not matched!!!", sampleframe.cs.MessageBox.MsgType.retry); mb.Show(); } }
private void BtnSave_Click(object sender, EventArgs e) { //Get the username of the logged in User string loggedUser = Login.loggedIn; //get the user details from UI u.firstName = tbFirstName.Text; u.lastName = tbLastName.Text; u.emailAddress = tbEmail.Text; u.gender = cbGender.Text; u.address = tbAddress.Text; u.phoneNumber = tbTelephone.Text; u.activity = cbActivity.Text; u.username = tbUsername.Text; u.password = tbPassword.Text; u.userType = cbUserType.Text; u.dateCreated = DateTime.Now; u.dateOfBirth = dpDOB.Value; //Get the username of the logged in User for adding to the added by field of the database string logggedUser = Login.loggedIn; userBLL usr = d.GetIDFromUsername(logggedUser); u.addedBy = usr.id; u.subscription = cbSubscription.Text; u.status = cbSubscriptionStatus.Text; //Auto generate Password int lengthOfPassword = 9; string valid = "abcdefghijklmnozABCDEFGHIJKLMNOZ1234567890&%$#@!"; StringBuilder strB = new StringBuilder(100); Random random = new Random(); while (0 < lengthOfPassword--) { strB.Append(valid[random.Next(valid.Length)]); } u.password = strB.ToString(); //Insert data into database bool success = d.Insert(u); if (success == true) { MessageBox.Show("User Successfully Created"); } else { MessageBox.Show("Failed to add user"); } Clear(); //refresh the datagrid view DataTable dt = d.SelectM(); dgvAdduser.DataSource = dt; }
private void btnAdd_Click(object sender, EventArgs e) { //empty form error message if (txtFirstName.Text == "" || txtLastName.Text == "" || txtEmail.Text == "" || txtUsername.Text == "" || txtPassword.Text == "" || txtContact.Text == "" || txtAddress.Text == "") { MessageBox.Show("Please fill your detail first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { //Gettting Data FRom UI u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; //Getting Username of the logged in user string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; //Inserting Data into DAtabase bool success = dal.Insert(u); //If the data is successfully inserted then the value of success will be true else it will be false if (success == true) { //Data Successfully Inserted MessageBox.Show("User successfully created."); clear(); } else { //Failed to insert data MessageBox.Show("Failed to add new user"); } //Refreshing Data Grid View DataTable dt = dal.Select(); dgvUsers.DataSource = dt; } }
private void btnAdd_Click(object sender, EventArgs e) { if (cmbUserType.Text == "") { MessageBox.Show("Vui lòng điền mục 'Loại' tài khoản"); } else { //Getting Username of the logged in user string logged_in_user = fLogin.logged_in; //Getting data from UI userBLL.first_name = txtBoxFirstName.Text; userBLL.last_name = txtBoxLastName.Text; userBLL.email = txtBoxEmail.Text; userBLL.username = txtBoxUsername.Text; userBLL.password = txtBoxPassword.Text; userBLL.contact = txtBoxContact.Text; userBLL.address = txtBoxAddress.Text; userBLL.gender = cmbGender.Text; userBLL.user_type = cmbUserType.Text; userBLL.added_date = DateTime.Now; userBLL usr = userDAL.GetIDFromUsername(logged_in_user); userBLL.added_by = usr.username; //Inserting data into database bool success = userDAL.Insert(userBLL); //If data is succesfully insertted then the value of sucess will be true if (success == true) { //Data successfully inserted MessageBox.Show("User successfully created."); clear(); } else { //Failed MessageBox.Show("Failed to add new user."); } //refreshing data grid view DataTable dataTable = userDAL.Select(); dgvUser.DataSource = dataTable; } }
private void buttonAdd_Click(object sender, EventArgs e) { //on add get the text input u.username = textBoxUsername.Text; u.first_name = textBoxFirstName.Text; u.last_name = textBoxLastName.Text; u.email = textBoxEmail.Text; u.address = textBoxAddress.Text; u.mobile = textBoxMobile.Text; switch (comboBoxGender.SelectedIndex) { case 0: u.gender = "Male"; break; case 1: u.gender = "Female"; break; case 2: u.gender = "Others"; break; } u.enrolled_date = dateTimePickerEnrolledDate.Value; u.membership_expiry_date = dateTimePickerExpiryDate.Value; u.num_books_borrowed = int.Parse(textBoxBooksBorrowed.Text); bool success = dal.Insert(u); if (success) { MessageBox.Show("New User Added Successfully"); //display the user in DataGrid view DataTable dt = dal.Select(); dataGridViewUsers.DataSource = dt; //clear the text inputs Clear(); } else { MessageBox.Show("Failed to Add New User"); } }
private void btnAdd_Click(object sender, EventArgs e) { //getting data from UI u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; ///getting username of logged in user string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; //inserting data into database bool success = dal.Insert(u); //if the data is successfully inserted then value of success will be true or else false if (success == true) { //data successfully inserted MessageBox.Show("User account successfully created!"); Clear(); } else { //failed inserting data MessageBox.Show("Failed to create the account!"); } //refreshing data grid view DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void btnAdd_Click(object sender, EventArgs e) { //Getting username of the logged in user string loggedUser = frmLogin.loggedIn; //Getting Data from UI u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; //Getting Username of the logged in user string loggeduser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; //Inserting Data into Database bool success = dal.Insert(u); //If the data is successfully inserted then the value will be true else it will be false if (success == true) { //Data Successfully Inserted MessageBox.Show("User Suuccessfully Created"); clear(); } else { //Failed to Insert Data MessageBox.Show("Failed to Add New User"); } //Refresing DatagridView DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void btnAdd_Click(object sender, EventArgs e) { u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUserName.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = comboGender.Text; u.user_type = comboUserType.Text; u.added_date = DateTime.Now; string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIdFromUsername(loggedUser); u.added_by = loggedUser; if (u.user_type == "") { MassageBox mb = new MassageBox("Added Failed", MsgType.retry); mb.Show(); } else { bool success = dal.Insert(u); if (success == true) { MassageBox mb = new MassageBox("Added Success", MsgType.success); mb.Show(); //MessageBox.Show("User Added Successfully!!!"); clear(); } else { MassageBox mb = new MassageBox("Added Failed", MsgType.retry); mb.Show(); //MessageBox.Show("Fail to Added!!!"); } } DataTable dt = dal.Select(); dgvUser.DataSource = dt; }
private void btnAdd_Click(object sender, EventArgs e) { //Getting Username of the logged in user string loggedUser = frmLogin.loggedIn; // Getting Data From UI // We will use BLL Object here u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; // This DateTime.Now will show the current date when user adds data userBLL usr = dal.GetIDFromUsername((loggedUser)); u.added_by = usr.id; // currently we don't have user id so we wil put it later ***** We have fixed it and we have user id now //Inserting Data into Database bool sucess = dal.Insert(u); // If the data is sucessfully inserted then the value will be true else it will be false if (sucess == true) { //Data Sucessfully Inserted MessageBox.Show("User Sucessfully Added"); clear(); } else { // Failed to insert data MessageBox.Show("Failed to Add New User"); } //Refreshing Data Grid View DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void button1_Click(object sender, EventArgs e) { // Getting userID //update string loggedUser = frmLogin.loggedIn; // Geting data from UI u.first_name = textBox1.Text; u.last_name = textBox2.Text; u.email = textBox3.Text; u.username = textBox4.Text; u.password = textBox5.Text; u.contact = textBox6.Text; u.address = textBox7.Text; u.gender = comboBox1.Text; u.user_type = comboBox2.Text; u.added_date = DateTime.Now; // String loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIdFromUsername(loggedUser); u.added_by = usr.id; //Inserting data into database bool success = dal.Insert(u); if (success == true) { //data inserted sucesfully MessageBox.Show("User Added Succesfully"); clear(); } else { //error occured MessageBox.Show("Sorry..!! , Failed to add user"); } DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void BtnSave_Click(object sender, EventArgs e) { u.firstName = tbFirstName.Text; u.lastName = tbLastName.Text; u.address = tbAddress.Text; u.activity = cbActivity.Text; u.dateOfBirth = dpDOB.Value; u.gender = cbGender.Text; u.emailAddress = tbEmail.Text; u.username = tbUsername.Text; u.phoneNumber = tbTelephone.Text; u.userType = cbUserType.Text; u.dateCreated = DateTime.Now; u.addedBy = 1; int lengthOfPassword = 9; string valid = "abcdefghijklmnozABCDEFGHIJKLMNOZ1234567890&%$#@!"; StringBuilder strB = new StringBuilder(100); Random random = new Random(); while (0 < lengthOfPassword--) { strB.Append(valid[random.Next(valid.Length)]); } u.password = strB.ToString(); //Insert data into database bool success = d.Insert(u); if (success == true) { MessageBox.Show("User Successfully Created"); } else { MessageBox.Show("Failed to add user"); } Clear(); }
private void BtnAdd_Click(object sender, EventArgs e) { string loggedUser = frmLogin.loggedIn; //getting data from UI u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; userBLL usr = dal.GetIDFromUsername(loggedUser); // get username of the logged in user u.added_by = usr.id; //inserting data into database bool success = dal.Insert(u); //if data is successfully inserted,then value will be true if (success == true) { //data inserted MessageBox.Show("User successfully created."); clear(); } else { //data insertion failed MessageBox.Show("Failed to add new user"); } DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void btnAdd_Click(object sender, EventArgs e) { //..........................................Getting Data from UI......................................... u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.user_type = cnbUserType.Text; u.added_date = DateTime.Now; u.gender = cnbGender.Text; //Getting User Name From Logged In User string LoggedInUser = frmLogin.LoggedIn; userBLL usr = daL.GetIDFromUserName(LoggedInUser); u.added_by = usr.id; //Inserting Data into Database bool success = daL.Insert(u); //if data is successfully inserted value of success will be true if (success == true) { MessageBox.Show("User succesfully created."); clear(); } else { MessageBox.Show("Failed to create user"); } //Refreshing Data Grid View DataTable dt = daL.Select(); dgvUsers.DataSource = dt; }
private void button1_Click(object sender, EventArgs e) { if (validation() == true) { //getting data from UI u.first_name = first_name.Text; u.last_name = last_name.Text; u.email = email.Text; u.username = username.Text; u.password = password.Text; u.contact = contact.Text; u.address = address.Text; u.gender = gender.Text; u.user_type = userType.Text; u.added_date = DateTime.Now; u.added_by = 1; bool success1 = userdal.Insert(u); //bool success1 = true; if (success1 = true) { MessageBox.Show("User succesfully created"); } else { MessageBox.Show("User not succesfully created"); } DataTable dt = userdal.Select(); dgv.DataSource = dt; clear(); } else { clear(); MessageBox.Show("Please fill the form correctly"); } }
private void btnAdd_Click(object sender, EventArgs e) { //Getting UserName of the loggedIn User string loggedUser = frmLogin.LoggedInUserName; //Getting the UserID basedon the UserNAme UserBll usr = userDl.GetIDFromUsername(loggedUser); //Getting data from UI userBl.firstName = txtFirstName.Text; userBl.lastName = txtLastName.Text; userBl.email = txtEmail.Text; userBl.userName = txtUserName.Text; userBl.passWord = txtpassword.Text; userBl.Contact = txtContact.Text; userBl.address = txtAdress.Text; userBl.gender = cmbGender.Text; userBl.user_type = cmbUserType.Text; userBl.addedDate = DateTime.Now; userBl.addedBy = usr.id; //inserting Data into DATABASE bool success = userDl.Insert(userBl); //if the data SuccessFully inserted then Success will be True if (success == true) { MessageBox.Show("User SuccessFully Created"); clear(); } else { MessageBox.Show("Failed!!!! to Add User"); } //Refreshing Data Grid View DataTable DT = userDl.Select(); dgvUsers.DataSource = DT; }
private void btnAdd_Click(object sender, EventArgs e) { string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUSername(loggedUser); //Getting data from UI u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAdress.Text; u.gender = cmbGender.Text; u.user_type = cmbUsertype.Text; u.added_date = DateTime.Now; u.added_by = usr.id; //Inserting data in to DB bool success = dal.Insert(u); if (success == true) { MessageBox.Show("User succesfully created"); clear(); } else { MessageBox.Show("Failed to add new user"); } //Refreshing Data Grid View DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void Form1_Load(object sender, EventArgs e) { bool bit = true; if (bit) { tbl_users u = new tbl_users { first_name = "name", last_name = "name" }; dal.Insert(u); List <tbl_users> query = dal.Select(); foreach (var item in query) { textBox1.Text = textBox1.Text + Environment.NewLine + item.Id + " " + item.first_name; } } else { var user = new tbl_users { first_name = "firstname2" }; db.tbl_users.Add(user); db.SaveChanges(); // Display all Blogs from the database var query = from b in db.tbl_users orderby b.first_name select b; foreach (var item in query) { textBox1.Text = textBox1.Text + Environment.NewLine + item.Id + " " + item.first_name; } } }
private void btnAdd_Click(object sender, EventArgs e) { #region Throw Erroe Message if (txtFirstName.Text == "" && txtLastName.Text == "" && txtEmail.Text == "" && txtUsername.Text == "" && txtPassword.Text == "" && txtContact.Text == "" && txtAddress.Text == "" && cmbGender.Text == "" && cmbUserType.Text == "") { MessageBox.Show(" Please Fill All The Details .... !! "); } else if (txtFirstName.Text == "") { MessageBox.Show(" Please Enter First Name ... !! "); } else if (txtLastName.Text == "") { MessageBox.Show(" Please Enter Last Name ... !! "); } else if (txtEmail.Text == "") { MessageBox.Show(" Please Enter Email Id ... !! "); } else if (txtUsername.Text == "") { MessageBox.Show(" Please Enter User Name ... !! "); } else if (txtPassword.Text == "") { MessageBox.Show(" Please Enter Password ... !! "); } else if (txtContact.Text == "") { MessageBox.Show(" Please Enter Contact No ... !! "); } else if (txtAddress.Text == "") { MessageBox.Show(" Please Enter Address ... !! "); } else if (cmbGender.Text == "") { MessageBox.Show(" Please Select Gender ... !! "); } else if (cmbUserType.Text == "") { MessageBox.Show(" Please Select UserType ... !! "); } #endregion else { //Getting data from UI u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.email = txtEmail.Text; u.username = txtUsername.Text; u.password = txtPassword.Text; u.contact = txtContact.Text; u.address = txtAddress.Text; u.gender = cmbGender.Text; u.user_type = cmbUserType.Text; u.added_date = DateTime.Now; //Getting username of loggedin user string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; //Inserting data into Database bool success = dal.Insert(u); //IF the data is successfully inserted then the value of success will be true else it will be false if (success == true) { MessageBox.Show("User Successfully Created."); clear(); } else { MessageBox.Show("Failed to add new user"); } //refreshing data grid view DataTable dt = dal.select(); dgvUsers.DataSource = dt; error(); } }