public static bool Update(Registered_Company rc) { int result = 0; SqlConnection conn = DBUtil.CreateConnection(); if (conn == null) { return(false); } try { SqlCommand cmd = new SqlCommand("usp_Update_A_RegisteredCompany", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@RegComp_Id", SqlDbType.Int).Value = rc.RegComp_Id; cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = rc.Name; cmd.Parameters.Add("@BranschId", SqlDbType.Int).Value = rc.BranschId; result = cmd.ExecuteNonQuery(); } catch (Exception e) { throw e; } finally { DBUtil.CloseConnection(conn); } if (result == 0) { return(false); } return(true); }
public static DataTable ReadAllEmployeesForACompany(Registered_Company rc) { DataTable rcs = new DataTable(); SqlConnection conn = DBUtil.CreateConnection(); if (conn == null) { return(rcs); } try { SqlCommand cmd = new SqlCommand("usp_Info_About_Company_Employees", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CompanyId", rc.RegComp_Id); SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(rcs); } catch (Exception e) { throw e; } finally { DBUtil.CloseConnection(conn); } return(rcs); }
private void dgvCompanies_CellClick(object sender, DataGridViewCellEventArgs e) { try { CompanyClear(); int companyId = Int32.Parse(dgvCompanies.CurrentRow.Cells[0].Value.ToString()); currentCompany = CompanyController.FindById(companyId); txtCompanyId.Text = currentCompany.RegComp_Id.ToString(); txtCompanyName.Text = currentCompany.Name; cmbCompanyBranch.SelectedText = currentCompany.BranschId.ToString(); dgvCompaniesEmployees.DataSource = CompanyController.ReadAllEmployeesForACompany(currentCompany); } catch (Exception ex) { lblresponse.Text = ErrorHandlern.HandleExceptions(ex); } }
private void btnCompanyCreate_Click(object sender, EventArgs e) { try { String tempId = txtCompanyId.Text; tempId = tempId.Trim(); if (String.IsNullOrEmpty(tempId)) { lblresponse.Text = "Id box is empty"; return; } Registered_Company rc = new Registered_Company(); rc.RegComp_Id = Int32.Parse(tempId); rc.Name = txtCompanyName.Text; rc.BranschId = Int32.Parse(cmbCompanyBranch.SelectedItem.ToString()); if (rc.BranschId < 0) { lblresponse.Text = "Id is less than 0"; return; } if (String.IsNullOrEmpty(rc.Name)) { lblresponse.Text = "You need to write a name"; return; } bool success = CompanyController.CreateRegistered_Company(rc); if (success) { lblresponse.Text = "Company Created"; } else { lblresponse.Text = "Failed to create company"; } } catch (Exception ex) { lblresponse.Text = ErrorHandlern.HandleExceptions(ex); } FillListWithAllCompanies(); }
public static Registered_Company FindById(int id) { Registered_Company rc = null; SqlConnection conn = DBUtil.CreateConnection(); if (conn == null) { return(null); } try { SqlCommand cmd = new SqlCommand("usp_Find_A_RegComp_By_ID", conn); cmd.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter idParam = new SqlParameter("@RegComp_Id", id); cmd.Parameters.Add(idParam); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { rc = new Registered_Company(); rc.RegComp_Id = reader.GetInt32(reader.GetOrdinal("RegComp_Id")); rc.Name = reader["Name"].ToString(); rc.BranschId = Int32.Parse(reader["BranschId"].ToString()); } } catch (Exception e) { throw e; } finally { DBUtil.CloseConnection(conn); } return(rc); }
public static bool Update(Registered_Company rc) { return(Registred_CompanyAccess.Update(rc)); }
public static bool CreateRegistered_Company(Registered_Company rc) { return(Registred_CompanyAccess.CreateRegistered_Company(rc)); }
public static DataTable ReadAllEmployeesForACompany(Registered_Company rc) { return(Registred_CompanyAccess.ReadAllEmployeesForACompany(rc)); }