private void saveButton_Click(object sender, EventArgs e) { if (companyCreated) { MessageBox.Show(@"Already a Company Created", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CompanyNametextBox.Clear(); AddressrichTextBox.Clear(); return; } if (string.IsNullOrEmpty(CompanyNametextBox.Text)) { MessageBox.Show(@"Please Enter Company Name", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CompanyNametextBox.Focus(); return; } if (string.IsNullOrEmpty(AddressrichTextBox.Text)) { MessageBox.Show(@"Please Enter Company Address", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CompanyNametextBox.Focus(); } else { try { con = new SqlConnection(cs.DBConn); con.Open(); string query = "INSERT INTO Companies (CompanyName,CompanyAddress,UserId) VALUES (@d1,@d2,@d3)" + "SELECT CONVERT(int, SCOPE_IDENTITY())"; cmd = new SqlCommand(query, con); cmd.Parameters.AddWithValue("@d1", CompanyNametextBox.Text); cmd.Parameters.AddWithValue("@d2", AddressrichTextBox.Text); cmd.Parameters.AddWithValue("@d3", user_id); currentCompanyId = (int)(cmd.ExecuteScalar()); con.Close(); MessageBox.Show(@"Company Registered successfully", @"Record", MessageBoxButtons.OK, MessageBoxIcon.Information); CompanyNametextBox.Clear(); AddressrichTextBox.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void saveButton_Click(object sender, EventArgs e) { SetupCompanyManager setupCompanyManager = new SetupCompanyManager(); if (CompanyNametextBox.Text != "") { MessageBox.Show(setupCompanyManager.AddComapny(CompanyNametextBox.Text)); } else { MessageBox.Show("Required any Company Name"); } CompanyNametextBox.Clear(); SetDatainListView(); }