public agency Insert(agency id) { string ConnectionString = IDManager.connection(); SqlConnection con = new SqlConnection(ConnectionString); try { con.Open(); SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_AGENCY", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@address_id", id.address_id); cmd.Parameters.AddWithValue("@agency_name", id.agency_name); cmd.Parameters.AddWithValue("@primary_fName", id.primary_fName); cmd.Parameters.AddWithValue("@primary_lName", id.primary_lName); cmd.Parameters.AddWithValue("@primary_phone", id.primary_phone); cmd.Parameters.AddWithValue("@sec_fName", id.sec_fName); cmd.Parameters.AddWithValue("@sec_lName", id.sec_lName); cmd.Parameters.AddWithValue("@sec_phone", id.sec_phone); cmd.ExecuteReader(); con.Close(); con.Open(); cmd = new SqlCommand("SP_DMCS_GET_AGENCY", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@address_id", id.address_id); cmd.Parameters.AddWithValue("@agency_name", id.agency_name); cmd.Parameters.AddWithValue("@primary_fName", id.primary_fName); cmd.Parameters.AddWithValue("@primary_lName", id.primary_lName); cmd.Parameters.AddWithValue("@primary_phone", id.primary_phone); cmd.Parameters.AddWithValue("@sec_fName", id.sec_fName); cmd.Parameters.AddWithValue("@sec_lName", id.sec_lName); cmd.Parameters.AddWithValue("@sec_phone", id.sec_phone); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { rdr.Read(); id.agency_id = rdr.GetInt32(0); } } catch (Exception ex) { id.SetColumnDefaults(); } finally { con.Close(); } return(id); }
public agency Insert(agency id) { string ConnectionString = IDManager.connection(); SqlConnection con = new SqlConnection(ConnectionString); try { con.Open(); SqlCommand cmd = new SqlCommand("SP_DMCS_INSERT_AGENCY", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@address_id", id.address_id); cmd.Parameters.AddWithValue("@agency_name", id.agency_name); cmd.Parameters.AddWithValue("@primary_fName", id.primary_fName); cmd.Parameters.AddWithValue("@primary_lName", id.primary_lName); cmd.Parameters.AddWithValue("@primary_phone", id.primary_phone); cmd.Parameters.AddWithValue("@sec_fName", id.sec_fName); cmd.Parameters.AddWithValue("@sec_lName", id.sec_lName); cmd.Parameters.AddWithValue("@sec_phone", id.sec_phone); cmd.ExecuteReader(); con.Close(); con.Open(); cmd = new SqlCommand("SP_DMCS_GET_AGENCY", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@address_id", id.address_id); cmd.Parameters.AddWithValue("@agency_name", id.agency_name); cmd.Parameters.AddWithValue("@primary_fName", id.primary_fName); cmd.Parameters.AddWithValue("@primary_lName", id.primary_lName); cmd.Parameters.AddWithValue("@primary_phone", id.primary_phone); cmd.Parameters.AddWithValue("@sec_fName", id.sec_fName); cmd.Parameters.AddWithValue("@sec_lName", id.sec_lName); cmd.Parameters.AddWithValue("@sec_phone", id.sec_phone); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { rdr.Read(); id.agency_id = rdr.GetInt32(0); } } catch (Exception ex) { id.SetColumnDefaults(); } finally { con.Close(); } return id; }
public agency Select(int id) { agency agency = new agency(); string ConnectionString = IDManager.connection(); SqlConnection con = new SqlConnection(ConnectionString); try { con.Open(); SqlCommand cmd = new SqlCommand("SP_DMCS_SELECT_AGENCY", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@agency_id", id); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { rdr.Read(); if (!rdr.IsDBNull(0)) { agency.agency_id = rdr.GetInt32(0); } else { agency.agency_id = 0; } if (!rdr.IsDBNull(1)) { agency.address_id = rdr.GetInt32(1); } else { agency.address_id = 0; } if (!rdr.IsDBNull(2)) { agency.agency_name = rdr.GetString(2); } else { agency.agency_name = " "; } if (!rdr.IsDBNull(3)) { agency.primary_fName = rdr.GetString(3); } else { agency.primary_fName = " "; } if (!rdr.IsDBNull(4)) { agency.primary_lName = rdr.GetString(4); } else { agency.primary_lName = " "; } if (!rdr.IsDBNull(5)) { agency.primary_phone = rdr.GetString(5); } else { agency.primary_phone = " "; } if (!rdr.IsDBNull(6)) { agency.sec_fName = rdr.GetString(6); } else { agency.sec_fName = " "; } if (!rdr.IsDBNull(7)) { agency.sec_lName = rdr.GetString(7); } else { agency.sec_lName = " "; } if (!rdr.IsDBNull(8)) { agency.sec_phone = rdr.GetString(8); } else { agency.sec_phone = " "; } } else { agency.SetColumnDefaults(); } } catch (Exception ex) { agency.SetColumnDefaults(); return agency; } finally { con.Close(); } return agency; }
public agency Select(int id) { agency agency = new agency(); string ConnectionString = IDManager.connection(); SqlConnection con = new SqlConnection(ConnectionString); try { con.Open(); SqlCommand cmd = new SqlCommand("SP_DMCS_SELECT_AGENCY", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@agency_id", id); SqlDataReader rdr = cmd.ExecuteReader(); if (rdr.HasRows) { rdr.Read(); if (!rdr.IsDBNull(0)) { agency.agency_id = rdr.GetInt32(0); } else { agency.agency_id = 0; } if (!rdr.IsDBNull(1)) { agency.address_id = rdr.GetInt32(1); } else { agency.address_id = 0; } if (!rdr.IsDBNull(2)) { agency.agency_name = rdr.GetString(2); } else { agency.agency_name = " "; } if (!rdr.IsDBNull(3)) { agency.primary_fName = rdr.GetString(3); } else { agency.primary_fName = " "; } if (!rdr.IsDBNull(4)) { agency.primary_lName = rdr.GetString(4); } else { agency.primary_lName = " "; } if (!rdr.IsDBNull(5)) { agency.primary_phone = rdr.GetString(5); } else { agency.primary_phone = " "; } if (!rdr.IsDBNull(6)) { agency.sec_fName = rdr.GetString(6); } else { agency.sec_fName = " "; } if (!rdr.IsDBNull(7)) { agency.sec_lName = rdr.GetString(7); } else { agency.sec_lName = " "; } if (!rdr.IsDBNull(8)) { agency.sec_phone = rdr.GetString(8); } else { agency.sec_phone = " "; } } else { agency.SetColumnDefaults(); } } catch (Exception ex) { agency.SetColumnDefaults(); return(agency); } finally { con.Close(); } return(agency); }