public static void RegistrarDepartamento(DepartamentoEn _departamento) { try { ConsultasAd.RegistrarDepartamento(_departamento); } catch (Exception ex) { throw ex; } }
public UsuariosEn() { user_name = string.Empty; id_usuario = 0; nombre = string.Empty; apellido1 = string.Empty; apellido2 = string.Empty; password = string.Empty; estado = string.Empty; fec_ultimo_cambio = DateTime.MinValue; departamento = new DepartamentoEn(); }
private void btnGuardar_Click(object sender, EventArgs e) { try { DepartamentoEn dep = new DepartamentoEn(); dep.Desc_departamento = txtDepartamento.Text; UsuarioLn.RegistrarDepartamento(dep); } catch (Exception ex) { MessageBox.Show("Se produjo un error al ingresar el departamento. " + ex.Message); } }
public static void RegistrarDepartamento(DepartamentoEn _departamento) { try { using (SqlConnection con = DataBaseManager.OpenSqlDatabase(user, pass, servidor, baseDatos)) { using (SqlCommand command = con.CreateCommand()) { command.CommandText = "sp_departamento"; command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ID_DEPARTAMENTO", _departamento.Id_departamento); command.Parameters.AddWithValue("@DESC_DEPARTAMENTO",_departamento.Desc_departamento); command.ExecuteNonQuery(); } } } catch (Exception ex) { throw ex; } }
public static List<DepartamentoEn> ConsultaDepartamentos() { List<DepartamentoEn> response = new List<DepartamentoEn>(); try { using (SqlConnection con = DataBaseManager.OpenSqlDatabase(user, pass, servidor, baseDatos)) { using (SqlCommand command = con.CreateCommand()) { command.CommandText = "sp_consulta_departamentos"; command.CommandType = System.Data.CommandType.StoredProcedure; using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { DepartamentoEn tmp = new DepartamentoEn(); tmp.Desc_departamento = dr["DESC_DEPARTAMENTO"].ToString() ?? string.Empty; tmp.Id_departamento = dr["ID_DEPARTAMENTO"] != DBNull.Value ? Convert.ToInt32(dr["ID_DEPARTAMENTO"]) : 0; response.Add(tmp); } } } } } catch (Exception ex) { throw ex; } return response; }