Пример #1
0
        public bool Insertar(ref BE.Empresa empresa)
        {
            try
            {
                string sp           = "SpTbEmpresaInsertar";
                int    rowsAffected = 0;

                using (var cnn = new SqlConnection(Conexion.strCnxBD))
                {
                    cnn.Open();

                    var cmd = new SqlCommand(sp, cnn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add(new SqlParameter("@IDEMPRESA", empresa.Id));
                    cmd.Parameters["@IDEMPRESA"].Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(new SqlParameter("@NOMBRE", empresa.Nombre));
                    cmd.Parameters.Add(new SqlParameter("@DESCRIPCION", empresa.Descripcion));

                    rowsAffected = cmd.ExecuteNonQuery();
                    empresa.Id   = int.Parse(cmd.Parameters["@IDEMPRESA"].Value.ToString());
                }

                return(rowsAffected > 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public BE.Empresa Obtener(int id)
        {
            BE.Empresa beEmpresa = null;
            try
            {
                string sp = "SpTbEmpresaObtener";

                using (var cnn = new SqlConnection(Conexion.strCnxBD))
                {
                    cnn.Open();

                    var cmd = new SqlCommand(sp, cnn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@IDEMPRESA", id));

                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        beEmpresa = new BE.Empresa();

                        beEmpresa.Id          = int.Parse(reader["idEmpresa"].ToString());
                        beEmpresa.Nombre      = reader["nombre"].ToString();
                        beEmpresa.Descripcion = reader["descripcion"].ToString();
                    }

                    cnn.Close();
                }

                return(beEmpresa);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public BE.Configuracion Obtener(BE.Empresa empresa)
        {
            BE.Configuracion beConfiguracion = null;
            try
            {
                string sp = "SpTbConfiguracionObtener";

                using (var cnn = new SqlConnection(Conexion.strCnxBD))
                {
                    cnn.Open();

                    var cmd = new SqlCommand(sp, cnn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@IDEMPRESA", empresa.Id));

                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        beConfiguracion = new BE.Configuracion();

                        beConfiguracion.Id          = int.Parse(reader["IdConfiguracion"].ToString());
                        beConfiguracion.Empresa     = empresa;
                        beConfiguracion.Servidor    = reader["servidor"].ToString();
                        beConfiguracion.BaseDatos   = reader["baseDatos"].ToString();
                        beConfiguracion.TipoBD      = int.Parse(reader["tipoBD"].ToString());
                        beConfiguracion.UsuarioBD   = reader["usuarioBD"].ToString();
                        beConfiguracion.ClaveBD     = reader["claveBD"].ToString();
                        beConfiguracion.LicenciaSAP = reader["licenciaSAP"].ToString();
                        beConfiguracion.UsuarioSAP  = reader["usuarioSAP"].ToString();
                        beConfiguracion.ClaveSAP    = reader["claveSAP"].ToString();
                    }

                    cnn.Close();
                }

                return(beConfiguracion);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        public List <BE.Empresa> Listar()
        {
            var lstEmpresa = new List <BE.Empresa>();

            try
            {
                string sp = "SpTbEmpresaListar";

                using (var cnn = new SqlConnection(Conexion.strCnxBD))
                {
                    cnn.Open();

                    var cmd = new SqlCommand(sp, cnn);
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var beEmpresa = new BE.Empresa();

                        beEmpresa.Id          = int.Parse(reader["idEmpresa"].ToString());
                        beEmpresa.Nombre      = reader["nombre"].ToString();
                        beEmpresa.Descripcion = reader["descripcion"].ToString();

                        lstEmpresa.Add(beEmpresa);
                    }

                    cnn.Close();
                }

                return(lstEmpresa);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }