private void ResetButton() { CustomerName.Clear(); CustomerAddress.Clear(); CustomerMobile.Clear(); CustomerName.Focus(); }
private void CustomerInsert_Click(object sender, EventArgs e) // Customer Insert Button(When I click on insert button the data will insert in Table) { con.Open(); // Connection Open comm = new SqlCommand("insert into Customer values('" + CustomerID.Text + "','" + CustomerName.Text + "','" + CustomerLastName.Text + "','" + CustomerAddress.Text + "','" + CustomerPhone.Text + "')", con); try { comm.ExecuteNonQuery(); MessageBox.Show("Customer Saved"); // Message Box (Its show the saved customers) con.Close(); // Connection Close ShowcustRecord(); CustomerID.Clear(); CustomerName.Clear(); CustomerLastName.Clear(); CustomerAddress.Clear(); CustomerPhone.Clear(); } catch (Exception) { MessageBox.Show("Customer Not Saved"); // Message Box } finally { con.Close(); // Connection Close } }
// Update Customer Button(This button used for update customer details private void UpdateCustomer_Click(object sender, EventArgs e) { con.Open();// Connection Open comm = new SqlCommand("update Customer set CId= '" + CustomerID.Text + "', FName= '" + CustomerName.Text + "', LName='" + CustomerLastName.Text + "', CAddress='" + CustomerAddress.Text + "', CPhoneNo='" + CustomerPhone.Text + "' where CId = '" + CustomerID.Text + "'", con); try { comm.ExecuteNonQuery(); MessageBox.Show("Customer Updated"); con.Close();// Connection Close ShowcustRecord(); CustomerID.Clear(); CustomerName.Clear(); CustomerLastName.Clear(); CustomerAddress.Clear(); CustomerPhone.Clear(); } catch (Exception) { MessageBox.Show("Customer Not Updated"); } finally { con.Close();// Connection Close } }
// Delete Customer Button(This button used for delete the customer) private void DeleteCustomer_Click(object sender, EventArgs e) { con.Open();// Connection Open comm = new SqlCommand("delete from Customer where CId = " + CustomerID.Text + " ", con); try { comm.ExecuteNonQuery(); MessageBox.Show("Customer Deleted"); con.Close();// Connection Close ShowcustRecord(); CustomerID.Clear(); CustomerName.Clear(); CustomerLastName.Clear(); CustomerAddress.Clear(); CustomerPhone.Clear(); CustomerID.Focus(); } catch (Exception x) { MessageBox.Show("Customer Not Deleted" + x.Message); } finally { con.Close();// Connection Close } }
private void clearButton_Click(object sender, EventArgs e) { CustomerName.Clear(); phno.Clear(); CustomerAddress.Clear(); CustomerEmail.Clear(); customerId.Clear(); }
private void Clear_Click(object sender, EventArgs e) { //Clear all the textboxes PhoneNo.Clear(); Address.Clear(); Email.Clear(); CustName.Clear(); CustomerName.Clear(); CustID.Clear(); }
// Button events private void ClearSearch_Click(object sender, EventArgs e) { StatusLabel.Text = ""; CustomerID.Clear(); CustomerName.Clear(); RefreshLookupOutput(); StatusLabel.Text = "Search cleared."; }
private void Clear() { ShipmentDate.Value = DateTime.Now; ItemName.Clear(); Remarks.Clear(); CourierName.SelectedIndex = -1; CourierName.Text = ""; TrackingId.Clear(); Register.Enabled = false; Prepaid.Checked = true; CODAmount.ResetText(); CustomerName.Clear(); CourierName.Focus(); }
private void Delete_Click(object sender, EventArgs e) { try { Connect connectObj = new Connect(); con = connectObj.connect(); SqlCommand cmd = new SqlCommand("DELETE FROM CUSTOMER WHERE C_ID = @cid", con); cmd.Parameters.AddWithValue("@cid", CustomerID.Text); int i = cmd.ExecuteNonQuery(); //If count is equal to 1, than show frmMain form if (i != 0) { MessageBox.Show("Customer Deletion Successful!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Customer Deletion Failed", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } CustomerName.Clear(); CustomerID.Clear(); } catch (Exception ex) { MessageBox.Show("Customer Not found", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { //Close the connection to DB if (con != null) { con.Close(); } } }
private void submitButton_Click(object sender, EventArgs e) { if (CustomerName.Text == "" || phno.Text == "" || CustomerAddress.Text == "" || CustomerEmail.Text == "" || customerId.Text == "") { MessageBox.Show("Please provide all the details", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (phno.Text.Length != 10) { MessageBox.Show("Enter valid Phone number", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { Connect connectObj = new Connect(); con = connectObj.connect(); SqlCommand cmd = new SqlCommand("customer_in", con); //To execute a stored procedure cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@cid", customerId.Text); cmd.Parameters.AddWithValue("@cname", CustomerName.Text); cmd.Parameters.AddWithValue("@phone_number", Convert.ToInt64(phno.Text)); cmd.Parameters.AddWithValue("@address", CustomerAddress.Text); cmd.Parameters.AddWithValue("@email", CustomerEmail.Text); cid += 1; int i = cmd.ExecuteNonQuery(); if (i != 0) { MessageBox.Show("Customer Insertion Successful!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Customer Insertion Failed", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error); } con.Close(); //Clear all the textboxes. CustomerName.Clear(); phno.Clear(); CustomerAddress.Clear(); CustomerEmail.Clear(); customerId.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (con != null) { con.Close(); } } }