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 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) { //Datta Successfully Inserted MessageBox.Show("User successfully created"); Clear(); } else { //Data Failed Inserted MessageBox.Show("Failed to add new user"); } //Refreshing Data Grid View DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
public bool Insert(userBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstring); try { string sql = "INSERT INTO tbl_users (first_name, last_name, email, username, password, contact, address, gender, user_type, added_date, added_by) VALUES (@first_name, @last_name, @email, @username, @password, @contact, @address, @gender, @user_type, @added_date, @added_by)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@first_name", u.first_name); cmd.Parameters.AddWithValue("@last_name", u.last_name); cmd.Parameters.AddWithValue("@email", u.email); cmd.Parameters.AddWithValue("@username", u.username); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@contact", u.contact); cmd.Parameters.AddWithValue("@address", u.address); cmd.Parameters.AddWithValue("@gender", u.gender); cmd.Parameters.AddWithValue("@user_type", u.user_type); cmd.Parameters.AddWithValue("@added_by", u.added_by); cmd.Parameters.AddWithValue("@added_date", u.added_date); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void btnAdd_Click(object sender, EventArgs e) { //getting data from UI u.first_name = txtFirstName.Text; u.last_name = txtLastName.Text; u.Email_id = txtEmail_id.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 trueelse it will be false if (success == true) { //data successfully inserted MessageBox.Show("user successfully created"); clear(); } else { //failed to inserted data MessageBox.Show("failed to add new user"); } //refreshing data grid view DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
private void btnUpdate_Click(object sender, EventArgs e) { // Get the Values from the Category form c.id = int.Parse(txtCatgoryID.Text); c.title = txtTitle.Text; c.description = txtDescription.Text; c.added_date = DateTime.Now; // we will copy the code from ADD and Paste here // Getting ID in Added by Field. This will give name of laogged in use string loggedUser = frmLogin.loggedIn; // we need to convert this into user id userBLL usr = udal.GetIDFromUsername(loggedUser); // passing the id of logged in user in added by field c.added_by = usr.id; // Creating Boolean Variable to update Categories and Check bool success = dal.Update(c); // if the category is updated successfully, then the value of success will be true else it will be flase if (success == true) { // category updated successfully MessageBox.Show("Updated Successfully"); Clear(); // refresh data grid view DataTable dt = dal.Select(); dgvCategories.DataSource = dt; } else { // not updated MessageBox.Show("Not Updated. try"); } }
private void btnUpdate_Click(object sender, EventArgs e) { //add the functionality to update donors //get the values from form d.donor_id = int.Parse(textBoxDonorId.Text); d.first_name = textBoxFirstName.Text; d.last_name = textBoxLastName.Text; d.email = textBoxEmail.Text; d.gender = comboBoxGender.Text; d.blood_group = comboBoxBloodGroup.Text; d.contact = textBoxContact.Text; d.address = textBoxAddress.Text; //get the logged in user id string loggedInUser = frmLogin.loggedInUser; userBLL usr = udal.GetIDFromUsername(loggedInUser); d.added_by = usr.user_id; d.image_name = imageName; //create a boolean variable to check whether the data updated successfully bool isSuccess = dal.Update(d); //if the data updated successfully then the value of isSuccess will be true if (isSuccess == true) { //donor updated MessageBox.Show("Donor updated successfully!"); Clear(); //refresh data grid view DataTable dt = dal.Select(); dgvDonors.DataSource = dt; } else { //failed to update MessageBox.Show("Failed to update."); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (txtDeaCustID.Text == "") { MessageBox.Show("Please select a record"); } else { //Get the values from Form dc.id = int.Parse(txtDeaCustID.Text); dc.type = cmbDeaCust.Text; dc.name = txtName.Text; dc.email = txtEmail.Text; dc.contact = txtContact.Text; dc.address = txtAddress.Text; dc.added_date = DateTime.Now; //Getting the ID to Logged in user and passign its value in dealer or cutomer module string loggedUsr = frmLogin.loggedIn; userBLL usr = uDal.GetIDFromUsername(loggedUsr); dc.added_by = usr.id; //create boolean variable to check whether the dealer or customer is updated or not bool success = dcDal.Update(dc); if (success == true) { //Dealer and Customer update Successfully MessageBox.Show("Dealer or Customer updated Successfully"); Clear(); //Refresh the Data Grid View DataTable dt = dcDal.Select(); dgvDeaCust.DataSource = dt; } else { //Failed to udate Dealer or Customer MessageBox.Show("Failed to Udpate Dealer or Customer"); } } }
private void btnAdd_Click(object sender, EventArgs e) { dc.type = cmbDlrCust.Text; dc.name = txtName.Text; dc.email = txtEmail.Text; dc.contact = txtContact.Text; dc.address = txtAddress.Text; dc.added_date = DateTime.Now; string loggedUsr = frmLogin.loggedIn; userBLL usr = uDal.GetIdFromUsername(loggedUsr); dc.added_by = loggedUsr; if (cmbDlrCust.Text == "") { MassageBox mb = new MassageBox("Added Failed", MsgType.retry); mb.Show(); } else { bool success = dcdal.Insert(dc); if (success == true) { MassageBox mb = new MassageBox("Added Success", MsgType.success); mb.Show(); //MessageBox.Show("Dealer/Customer Added Successfully..."); Clear(); DataTable dt = dcdal.Select(); dgvDlr_Customer.DataSource = dt; } else { MassageBox mb = new MassageBox("Added Failed", MsgType.retry); mb.Show(); //MessageBox.Show("Failed to ADD Dealer/Customer...!!! Try Again.."); } } }
public bool Update(userBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "UPDATE tbl_users SET first_name=@first_name, last_name=@last_name, " + "email=@email, username=@username, password=@password, " + "contact=@contact, address=@address, gender=@gender, user_type=@user_type, " + "added_date=@added_date, added_by=@added_by" + " WHERE id=@id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@first_name", u.first_name); cmd.Parameters.AddWithValue("@last_name", u.last_name); cmd.Parameters.AddWithValue("@email", u.email); cmd.Parameters.AddWithValue("@username", u.username); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@contact", u.contact); cmd.Parameters.AddWithValue("@address", u.address); cmd.Parameters.AddWithValue("@gender", u.gender); cmd.Parameters.AddWithValue("@user_type", u.user_type); cmd.Parameters.AddWithValue("@added_date", u.added_date); cmd.Parameters.AddWithValue("@added_by", u.added_by); cmd.Parameters.AddWithValue("@id", u.id); conn.Open(); int rows = cmd.ExecuteNonQuery(); isSuccess = rows > 0; //Kallxon nese Query eshte ekzekutuar me sukses } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool update(userBLL u) { bool isSucess = false; SqlConnection conn = new SqlConnection(myconnstring); try { string sql = "UPDATE tbl_usuario SET pr_nome=@pr_nome,sb_nome=@sb_nome,email=@email,user_name=@user_name,password=@password,contato=@contato,nm_endereco=@nm_endereco,sexo=@sexo,user_type=@user_type,data=@data,add_por=@add_por WHERE id=@id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@pr_nome", u.pr_nome); cmd.Parameters.AddWithValue("@sb_nome", u.sb_nome); cmd.Parameters.AddWithValue("@email", u.email); cmd.Parameters.AddWithValue("@user_name", u.user_name); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@contato", u.contato); cmd.Parameters.AddWithValue("@nm_endereco", u.nm_endereco); cmd.Parameters.AddWithValue("@sexo", u.sexo); cmd.Parameters.AddWithValue("@user_type", u.user_type); cmd.Parameters.AddWithValue("@data", u.data); cmd.Parameters.AddWithValue("@add_por", u.add_por); cmd.Parameters.AddWithValue("@id", u.id); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucess = true; } else { isSucess = false; } } catch (Exception e) { MessageBox.Show(e.Message); } finally { conn.Close(); } return(isSucess); }
private void btnAdd_Click(object sender, EventArgs e) { try { //get all the values from product form p.name = txtName.Text; p.category = cmbCategory.Text; p.description = txtDescription.Text; p.rate = decimal.Parse(txtRate.Text); p.qty = 0; p.added_date = DateTime.Now; //getting user name of logged in user string loggedUser = frmLogin.loggedIn; userBLL usr = udal.GetIDFromUsername(loggedUser); p.added_by = usr.id; //create variable to check if product added successfully or not bool success = pdal.Insert(p); //if the product is succssesfully added then the value of success is true else false if (success == true) { //product inserted successfully MessageBox.Show("Product Added Successfully!"); //calling clear method to clear all fields Clear(); //refresh the datagrid view DataTable dt = pdal.Select(); dgvProducts.DataSource = dt; } else { //product inserting failed MessageBox.Show("Product Adding Failed!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (txtID.Text == "") { MessageBox.Show("Please select a record to update"); } else { //Get the Values from UI or Product Form p.id = int.Parse(txtID.Text); p.name = txtName.Text; p.category = cmbCategory.Text; p.description = txtDescription.Text; p.rate = decimal.Parse(txtRate.Text); p.added_date = DateTime.Now; //Getting Username of logged in user for added by String loggedUsr = frmLogin.loggedIn; userBLL usr = udal.GetIDFromUsername(loggedUsr); p.added_by = usr.id; //Create a boolean variable to check if the product is updated or not bool success = pdal.Update(p); //If the prouct is updated successfully then the value of success will be true else it will be false if (success == true) { //Product updated Successfully MessageBox.Show("Product Successfully Updated"); Clear(); //REfresh the Data Grid View DataTable dt = pdal.Select(); dgvProducts.DataSource = dt; } else { //Failed to Update Product MessageBox.Show("Failed to Update Product"); } } }
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 username string loggedUser = frmLogin.loggedIn; userBLL usr = dal.GetIDFromUsername(loggedUser); u.added_by = usr.id; //Inserting Data into Datebase bool success = dal.Insert(u); //If data is successfully inserted the value of success will be true else it will be false if (success == true) { //Data successfully Inserted MessageBox.Show("Successfully user created."); clear(); } else { //Data failed to insert MessageBox.Show("Failed to create user."); } //Refreshing data in Grid view DataTable dt = dal.Select(); dgvUsers.DataSource = dt; }
public bool update(userBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "UPDATE tbl_users SET first_name=@first_name,last_name=@last_name,user_name=@user_name,password=@password,user_type=@user_type where id=@id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id", u.id); cmd.Parameters.AddWithValue("@first_name", u.first_name); cmd.Parameters.AddWithValue("@last_name", u.last_name); cmd.Parameters.AddWithValue("@user_name", u.username); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@user_type", u.user_type); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
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; }
public bool Insert(userBLL u) { bool isSucess = false; SqlConnection conn = new SqlConnection(myconnstring); try { String sql = "INSERT INTO tbl_usuario(pr_nome,sb_nome,email,user_name,password,contato,nm_endereco,sexo,user_type,data,add_por) VALUES (@pr_nome,@sb_nome,@email,@user_name,@password,@contato,@nm_endereco,@sexo,@user_type,@data,@add_por)"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@pr_nome", u.pr_nome); cmd.Parameters.AddWithValue("@sb_nome", u.sb_nome); cmd.Parameters.AddWithValue("@email", u.email); cmd.Parameters.AddWithValue("@user_name", u.user_name); cmd.Parameters.AddWithValue("@password", u.password); cmd.Parameters.AddWithValue("@contato", u.contato); cmd.Parameters.AddWithValue("@nm_endereco", u.nm_endereco); cmd.Parameters.AddWithValue("@sexo", u.sexo); cmd.Parameters.AddWithValue("@user_type", u.user_type); cmd.Parameters.AddWithValue("@data", u.data); cmd.Parameters.AddWithValue("@add_por", u.add_por); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucess = true; } else { isSucess = false; } } catch (Exception e) { MessageBox.Show(e.Message); } finally { conn.Close(); } return(isSucess); }
private void BtnUpdate_Click(object sender, EventArgs e) { //Get the Values From User Interface u.id = Convert.ToInt32(tbaddUserId.Text); 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; //Update data in database bool success = d.Update(u); //if data is not updated successfully change value to true else false if (success == true) { MessageBox.Show("User Successfully updated"); Clear(); } else { MessageBox.Show("Failed to update User"); } }
private void btnUpdate_Click(object sender, EventArgs e) { //Add the Functionality to Update the Donors //1. Get the Values from Form d.donor_id = int.Parse(txtDonorID.Text); d.first_name = txtFirstName.Text; d.last_name = txtLastName.Text; d.email = txtEmail.Text; d.gender = cmbGender.Text; d.blood_group = cmbBloodGroup.Text; d.contact = txtContact.Text; d.address = txtAddress.Text; //Get The ID of Logged In USer string loggedInUser = frmLogin.loggedInUser; userBLL usr = udal.GetIDFromUsername(loggedInUser); d.added_by = usr.user_id; d.image_name = imageName; //Create a Boolean Variable to Check whether the data updated successfully or not bool isSuccess = dal.Update(d); //If the data updated successfully then the value of isSuccess will be true else it will be false if (isSuccess == true) { //Donor Updated Successfully MessageBox.Show("Donor updated Successfully."); Clear(); //Refresh Datagridview DataTable dt = dal.Select(); dgvDonors.DataSource = dt; } else { //Failed to Update MessageBox.Show("Failed to update donors."); } }
public bool Delete(userBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { String sql = "DELETE FROM tbl_user WHERE user_id=@user_id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@user_id", u.user_id); conn.Open(); int rows = cmd.ExecuteNonQuery(); //if the query is executed successfully then the rows' value = 0 if (rows > 0) { //query successful isSuccess = true; } else { //Query falled isSuccess = false; } } catch (Exception ex) { Module.Tool tool = new Module.Tool(); tool.saveToText(ex); } finally { conn.Close(); } return(isSuccess); }
public bool Delete(userBLL u) { //Create a Boolean Variable and set its default value to false bool isSuccess = false; try { var erg = from user in db.tbl_users where user.Id == u.id select user; db.tbl_users.Remove(erg.FirstOrDefault()); db.SaveChanges(); isSuccess = true; } catch (Exception ex) { MessageBox.Show(ex.Message); isSuccess = false; } return(isSuccess); }
private void btnADD_Click(object sender, EventArgs e) { if (txtTitle.Text == "" || txtDescription.Text == "") { MessageBox.Show("Please add the records first"); } else { //Get the values from Categroy Form c.title = txtTitle.Text; c.description = txtDescription.Text; c.added_date = DateTime.Now; //Getting ID in Added by field string loggedUser = frmLogin.loggedIn; userBLL usr = udal.GetIDFromUsername(loggedUser); //Passign the id of Logged in User in added by field c.added_by = usr.id; //Creating Boolean Method To insert data into database bool success = dal.Insert(c); //If the category is inserted successfully then the value of the success will be true else it will be false if (success == true) { //NewCAtegory Inserted Successfully MessageBox.Show("New Category Inserted Successfully."); Clear(); //Refresh Data Grid View DataTable dt = dal.Select(); dgvCategories.DataSource = dt; } else { //FAiled to Insert New Category MessageBox.Show("Failed to Insert New CAtegory."); } } }
public bool Insert(userBLL c) { bool isSuccess = false; SqlConnection Conn = new SqlConnection(myconnstring); try { String sql = "INSERT INTO tbl_stusers (fullname,address,dob,parentName,tellnumber,username,password,userType) VALUES (@fullname,@address,@dob,@parentName,@tellnumber,@username,@password,@userType)"; SqlCommand cmd = new SqlCommand(sql, Conn); cmd.Parameters.AddWithValue("@fullname", c.fullname); cmd.Parameters.AddWithValue("@address", c.address); cmd.Parameters.AddWithValue("@dob", c.dob); cmd.Parameters.AddWithValue("@parentName", c.parentName); cmd.Parameters.AddWithValue("@tellnumber", c.tell); cmd.Parameters.AddWithValue("@username", c.username); cmd.Parameters.AddWithValue("@password", c.password); cmd.Parameters.AddWithValue("@userType", c.userType); Conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = true; } } catch (Exception ex) { MessageBox mb = new MessageBox(ex.Message, sampleframe.cs.MessageBox.MsgType.success); } finally { Conn.Close(); } return(isSuccess); }
private void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text == "" || cmbCategory.Text == "" || txtDescription.Text == "" || txtRate.Text == "") { MessageBox.Show("Please fill all the fields"); } else { //Get All the Values from Product Form p.name = txtName.Text; p.category = cmbCategory.Text; p.description = txtDescription.Text; p.rate = decimal.Parse(txtRate.Text); p.qty = 0; p.added_date = DateTime.Now; //Getting username of logged in user String loggedUsr = frmLogin.loggedIn; userBLL usr = udal.GetIDFromUsername(loggedUsr); p.added_by = usr.id; //Create Boolean variable to check if the product is added successfully or not bool success = pdal.Insert(p); //if the product is added successfully then the value of success will be true else it will be false if (success == true) { MessageBox.Show("Product Added Successfully"); Clear(); //Refreshing DAta Grid View DataTable dt = pdal.Select(); dgvProducts.DataSource = dt; } else { MessageBox.Show("Failed to Add New Product"); } } }
} // This Method is used to Create roe header active-------When you click oon row header then all the Data is shown in text fiedls private void btnUpdate_Click(object sender, EventArgs e) { //Get the values from Form dc.id = int.Parse(txtDeaCustID.Text); dc.type = cmbDeaCust.Text; dc.name = txtName.Text; dc.email = txtEmail.Text; dc.contact = txtContact.Text; dc.address = txtAddress.Text; dc.added_date = DateTime.Now; //Getting the ID to Logged of logged in user and passing its value in dealer string loggedUsr = frmLogin.loggedIn; userBLL usr = uDal.GetIDFromUsername(loggedUsr); dc.added_by = usr.id; //Create boolean variable to check whether the dealer or customer is updated or not bool success = dcDal.Update(dc); if (success == true) { //Dealer and Customer update Successfully MessageBox.Show("Dealer or Customer updated successfully"); //To clear the Text Fields Clear(); //Refresh the Data Grid View DataTable dt = dcDal.Select(); dgvDeaCust.DataSource = dt; } else { //Dealer and Customer failed to Updated MessageBox.Show("Failed to Update Dealer or Customer"); } } // This method is created to Update the Data in the DataGrid View or We can say Table
public bool Delete(userBLL u) { bool isSuccess = false; SQLiteConnection conn = new SQLiteConnection(myconnstrng); try { //Database Connection Open conn.Open(); string sql = "DELETE FROM tbl_users WHERE id=@id"; SQLiteCommand cmd = new SQLiteCommand(sql, conn); cmd.Parameters.AddWithValue("@id", u.id); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { //Query Successfull isSuccess = true; } else { //Query Failed isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void btnUpdate_Click(object sender, EventArgs e) { try { dc.Id = int.Parse(txtDlr_CustID.Text); dc.type = cmbDlrCust.Text; dc.name = txtName.Text; dc.email = txtEmail.Text; dc.contact = txtContact.Text; dc.address = txtAddress.Text; dc.added_date = DateTime.Now; string loggedUser = frmLogin.loggedIn; userBLL usr = uDal.GetIdFromUsername(loggedUser); dc.added_by = loggedUser; bool succes = dcdal.Update(dc); if (succes == true) { MassageBox mb = new MassageBox("Updated", MsgType.update); mb.Show(); // MessageBox.Show("Dealer and Customer Updated Succesfully"); Clear(); DataTable dt = dcdal.Select(); dgvDlr_Customer.DataSource = dt; } else { MassageBox mb = new MassageBox("Update Failed", MsgType.retry); mb.Show(); //MessageBox.Show("Failed To Update Dealer and Customer!!!...Try Again"); } } catch (Exception) { MassageBox mb = new MassageBox("Update Failed", MsgType.retry); mb.Show(); } }
private void btnUpdate_Click(object sender, EventArgs e) { //Get the values from the UI userBLL.id = Convert.ToInt32(txtBoxUserID.Text); 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; String logged_in_user = fLogin.logged_in; userBLL user = userDAL.GetIDFromUsername(logged_in_user); userBLL.added_by = user.username; //Updating data into database bool success = userDAL.Update(userBLL); if (success == true) { MessageBox.Show("User " + txtBoxFirstName.Text + " is updated successfully"); clear(); } else { MessageBox.Show("Can not update user " + txtBoxFirstName.Text); } //refreshing data grid view DataTable dataTable = userDAL.Select(); dgvUser.DataSource = dataTable; }
private void btnUpdate_Click(object sender, EventArgs e) { if (txtCategoryID.Text == "") { MessageBox.Show("Please select a record"); } else { //Get the Values from the CAtegory form c.id = int.Parse(txtCategoryID.Text); c.title = txtTitle.Text; c.description = txtDescription.Text; c.added_date = DateTime.Now; //Getting ID in Added by field string loggedUser = frmLogin.loggedIn; userBLL usr = udal.GetIDFromUsername(loggedUser); //Passign the id of Logged in User in added by field c.added_by = usr.id; //Creating Boolean variable to update categories and check bool success = dal.Update(c); //If the cateory is updated successfully then the value of success will be true else it will be false if (success == true) { //CAtegory updated Successfully MessageBox.Show("Category Updated Successfully"); Clear(); //Refresh Data Gid View DataTable dt = dal.Select(); dgvCategories.DataSource = dt; } else { //FAiled to Update Category MessageBox.Show("Failed to Update Category"); } } }
public bool Delete(userBLL u) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "DELETE FROM tbl_korisnici WHERE korisnik_id=@korisnik_id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@korisnik_id", u.korisnik_id); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void btnAdd_Click(object sender, EventArgs e) { if (txtName.Text == "" || txtEmail.Text == "" || txtContact.Text == "" || txtAddress.Text == "") { MessageBox.Show("Fill all the fields"); } else { //Get the Values from Form dc.type = cmbDeaCust.Text; dc.name = txtName.Text; dc.email = txtEmail.Text; dc.contact = txtContact.Text; dc.address = txtAddress.Text; dc.added_date = DateTime.Now; //Getting the ID to Logged in user and passign its value in dealer or cutomer module string loggedUsr = frmLogin.loggedIn; userBLL usr = uDal.GetIDFromUsername(loggedUsr); dc.added_by = usr.id; //Creating boolean variable to check whether the dealer or cutomer is added or not bool success = dcDal.Insert(dc); if (success == true) { //Dealer or Cutomer inserted successfully MessageBox.Show("Dealer or Customer Added Successfully"); Clear(); //Refresh Data Grid View DataTable dt = dcDal.Select(); dgvDeaCust.DataSource = dt; } else { //failed to insert dealer or customer } } }
private void btnADD_Click(object sender, EventArgs e) { //getting data from UI u.title = txtTitle.Text; u.description = txtDescription.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("Category successfully added!"); Clear(); } else { //failed inserting data MessageBox.Show("Failed to create the category!"); } //refreshing data grid view DataTable dt = dal.Select(); dgvCategories.DataSource = dt; }