Пример #1
0
        public List <Cajero> ListarCajeros(string usuario, string clave)
        {
            List <Cajero> _cajeros = new List <Cajero>();

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ListarCajeros", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    try
                    {
                        cnn.Open();
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    Cajero _cajero = new Cajero(Convert.ToInt32(reader["Ci"]), (string)reader["Usuario"], (string)reader["Clave"], (string)reader["NomCompleto"], (string)reader["HoraInicio"], (string)reader["HoraFin"]);

                                    _cajeros.Add(_cajero);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(_cajeros);
        }
Пример #2
0
        public void BajaEmpresa(Empresa empresa, string usuario, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("BajaEmpresa", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int);
                    retorno.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retorno);

                    cmd.Parameters.AddWithValue("@Codigo", empresa.Codigo);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();

                        if ((int)retorno.Value == -1)
                        {
                            throw new Exception("No existe la Empresa");
                        }
                        if ((int)retorno.Value == -2)
                        {
                            throw new Exception("Error en la DB");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Пример #3
0
        public Cajero BuscarCajeroLogueo(string usuario, string clave)
        {
            Cajero cajero = null;

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("BuscarCajeroLogueo", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@Usuario", usuario);
                    try
                    {
                        cnn.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();

                                cajero = new Cajero(Convert.ToInt32(reader["Ci"]), (string)reader["Usuario"], (string)reader["Clave"], (string)reader["NomCompleto"], (string)reader["HoraInicio"], (string)reader["HoraFin"]);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(cajero);
        }
Пример #4
0
        public void AltaCajero(Cajero _cajero, string usuario, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("AltaCajero", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int);
                    retorno.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retorno);

                    cmd.Parameters.AddWithValue("@Usuario", _cajero.Usu);
                    cmd.Parameters.AddWithValue("@Clave", _cajero.Clave);
                    cmd.Parameters.AddWithValue("@CI", _cajero.Ci);
                    cmd.Parameters.AddWithValue("@NomCompleto", _cajero.NomCompleto);
                    cmd.Parameters.AddWithValue("@HoraInicio", _cajero.HoraInicio);
                    cmd.Parameters.AddWithValue("@HoraFin", _cajero.HoraFin);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();

                        if ((int)retorno.Value == -1)
                        {
                            throw new Exception("El usuario " + _cajero.Usu + " ya existe.");
                        }
                        if ((int)retorno.Value == -2)
                        {
                            throw new Exception("Ya existe el usuario de cedula: " + _cajero.Ci + ".");
                        }
                        if ((int)retorno.Value == -3)
                        {
                            throw new Exception("Error.");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Пример #5
0
        public void ModEmpresa(Empresa _empresa, string usuario, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ModEmpresa", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int);
                    retorno.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retorno);

                    cmd.Parameters.AddWithValue("@Codigo", _empresa.Codigo);
                    cmd.Parameters.AddWithValue("@Rut", _empresa.Rut);
                    cmd.Parameters.AddWithValue("@DirFiscal", _empresa.DirFiscal);
                    cmd.Parameters.AddWithValue("@Nombre", _empresa.Nombre);
                    cmd.Parameters.AddWithValue("@Tel", _empresa.Tel);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();

                        if ((int)retorno.Value == -1)
                        {
                            throw new Exception("La Empresa no existe.");
                        }
                        if ((int)retorno.Value == -2)
                        {
                            throw new Exception("Ya existe la Empresa de Rut: " + _empresa.Rut + " .");
                        }
                        if ((int)retorno.Value == -3)
                        {
                            throw new Exception("Error.");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Пример #6
0
        public List <LineaPago> ListarFacturas(int _NumeroInterno, string usuario, string clave)
        {
            List <LineaPago> listaFacturas = null;

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ListarFacturas", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@NumeroInterno", _NumeroInterno);

                    try
                    {
                        cnn.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                listaFacturas = new List <LineaPago>();
                                while (reader.Read())
                                {
                                    LineaPago _LineaPago = new LineaPago(Convert.ToInt32(reader["Monto"]),
                                                                         Convert.ToDateTime(reader["FechaVencimiento"]),
                                                                         Convert.ToInt32(reader["CodCliente"]),
                                                                         PContrato.GetInstancia().BuscarContrato(Convert.ToInt32(reader["CodigoEmpresa"]),
                                                                                                                 Convert.ToInt32(reader["TipoContrato"]), usuario, clave));

                                    listaFacturas.Add(_LineaPago);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(listaFacturas);
        }
Пример #7
0
        public List <Gerente> ListarGerentes(string usuario, string clave)
        {
            List <Gerente> _gerentes = null;

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ListarGerentes", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    try
                    {
                        cnn.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                _gerentes = new List <Gerente>();

                                while (reader.Read())
                                {
                                    Gerente _gerente = new Gerente(Convert.ToInt32(reader["Ci"]),
                                                                   (string)reader["Usuario"],
                                                                   (string)reader["Clave"],
                                                                   (string)reader["NomCompleto"],
                                                                   (string)reader["Email"]);

                                    _gerentes.Add(_gerente);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }

                    return(_gerentes);
                }
            }
        }
Пример #8
0
        public List <Contrato> ListarContrato(int CodEmpresa, string usuario, string clave)
        {
            List <Contrato> _Contratos = null;

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ListarContrato", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@CodEmpresa", CodEmpresa);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();
                        SqlDataReader reader = cmd.ExecuteReader();

                        if (reader.HasRows)
                        {
                            _Contratos = new List <Contrato>();
                            while (reader.Read())
                            {
                                Contrato _Contrato = new Contrato();
                                _Contrato.Empresa     = FabricaP.GetPEmpresa().BuscarEmpresa(CodEmpresa);
                                _Contrato.CodContrato = Convert.ToInt32(reader["CodTipo"]);
                                _Contrato.NomContrato = (string)reader["Nombre"];

                                _Contratos.Add(_Contrato);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(_Contratos);
        }
Пример #9
0
        public List <Pago> ListarPagos(string usuario, string clave)
        {
            List <Pago> listaPagos = null;

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ListarPagos", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    try
                    {
                        cnn.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                listaPagos = new List <Pago>();

                                while (reader.Read())
                                {
                                    Pago _Pago = new Pago((int)reader["NumInterno"],
                                                          (DateTime)reader["Fecha"], (int)reader["Monto"],
                                                          PCajero.GetInstancia().BuscarCajero(Convert.ToInt32(reader["Cajero"]), usuario, clave),
                                                          ListarFacturas(Convert.ToInt32(reader["NumInterno"]), usuario, clave));

                                    listaPagos.Add(_Pago);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(listaPagos);
        }
Пример #10
0
        public int Logueo(string usuario, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("Logueo", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@Usuario", usuario);
                    cmd.Parameters.AddWithValue("@Clave", clave);

                    SqlParameter retorno = new SqlParameter("@retorno", SqlDbType.Int);
                    retorno.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retorno);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();

                        if ((int)retorno.Value == 1)
                        {
                            return(1);
                        }
                        else if ((int)retorno.Value == 2)
                        {
                            return(2);
                        }
                        else
                        {
                            throw new Exception("Usuario o Contraseña incorrectos.");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Пример #11
0
        public List <Empresa> ListarEmpresa(string usuario, string clave)
        {
            List <Empresa> _Empresas = new List <Empresa>();

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ListarEmpresas", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    try
                    {
                        cnn.Open();
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    Empresa _empresa = new Empresa((long)reader["Rut"],
                                                                   Convert.ToInt32(reader["Codigo"]),
                                                                   (string)reader["Nombre"],
                                                                   (string)reader["DirFiscal"],
                                                                   Convert.ToInt64(reader["Tel"]));

                                    _Empresas.Add(_empresa);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(_Empresas);
        }
Пример #12
0
        public Contrato BuscarContrato(int CodEmpresa, int CodTipo, string usuario, string clave)
        {
            Contrato _Contrato = null;

            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("BuscarContrato", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@CodEmpresa", CodEmpresa);
                    cmd.Parameters.AddWithValue("@CodTipo", CodTipo);

                    try
                    {
                        cnn.Open();

                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();
                                _Contrato             = new Contrato();
                                _Contrato.Empresa     = FabricaP.GetPEmpresa().BuscarEmpresa((int)reader["CodEmpresa"]);
                                _Contrato.CodContrato = CodTipo;
                                _Contrato.NomContrato = (string)reader["Nombre"];
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }

            return(_Contrato);
        }
Пример #13
0
        public void AltaGerente(Gerente Gerente, string usuario, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("AltaGerente", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int);
                    retorno.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retorno);

                    cmd.Parameters.AddWithValue("@Usuario", Gerente.Usu);
                    cmd.Parameters.AddWithValue("@Clave", Gerente.Clave);
                    cmd.Parameters.AddWithValue("@Ci", Gerente.Ci);
                    cmd.Parameters.AddWithValue("@NomCompleto", Gerente.NomCompleto);
                    cmd.Parameters.AddWithValue("@Email", Gerente.Email);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();
                        if ((int)retorno.Value == -1)
                        {
                            throw new Exception("Este usuario ya existe.");
                        }
                        if ((int)retorno.Value == -2)
                        {
                            throw new Exception("Error en la base de datos");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Пример #14
0
        public void ModContrato(Contrato _contrato, string usuario, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ModContrato", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int);
                    retorno.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retorno);

                    cmd.Parameters.AddWithValue("@CodEmpresa", _contrato.Empresa.Codigo);
                    cmd.Parameters.AddWithValue("@CodTipo", _contrato.CodContrato);
                    cmd.Parameters.AddWithValue("@Nombre", _contrato.NomContrato);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();

                        if ((int)retorno.Value == -1)
                        {
                            throw new Exception("No existe este Contrato en esta Empresa.");
                        }
                        if ((int)retorno.Value == -2)
                        {
                            throw new Exception("Error en la DB.");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Пример #15
0
        public void ModificarClave(Gerente gerente, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(gerente.Usu, gerente.Clave)))
            {
                using (SqlCommand cmd = new SqlCommand("ModClave", cnn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int);
                    retorno.Direction = ParameterDirection.ReturnValue;
                    cmd.Parameters.Add(retorno);

                    cmd.Parameters.AddWithValue("@Usuario", gerente.Usu);
                    cmd.Parameters.AddWithValue("@Clave", clave);

                    try
                    {
                        cnn.Open();
                        cmd.ExecuteNonQuery();
                        if ((int)retorno.Value == -1)
                        {
                            throw new Exception("No existe el Usuario.");
                        }

                        if ((int)retorno.Value == -2)
                        {
                            throw new Exception("Error en la DB.");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }
Пример #16
0
        public void AltaPago(Pago _pago, string usuario, string clave)
        {
            using (SqlConnection cnn = new SqlConnection(Conexion.Cnn(usuario, clave)))
            {
                try
                {
                    cnn.Open();

                    using (SqlCommand cmd = new SqlCommand("AltaPago", cnn))
                    {
                        cmd.Parameters.AddWithValue("@Fecha", _pago.Fecha);
                        cmd.Parameters.AddWithValue("@Monto", _pago.Monto);
                        cmd.Parameters.AddWithValue("@Cajero", _pago.Cajero.Ci);

                        cmd.CommandType = CommandType.StoredProcedure;

                        SqlParameter retorno = new SqlParameter("@Retorno", SqlDbType.Int);
                        retorno.Direction = ParameterDirection.ReturnValue;
                        cmd.Parameters.Add(retorno);

                        try
                        {
                            cmd.ExecuteNonQuery();

                            //Verifico que el primer SP no haya dado error
                            switch ((int)retorno.Value)
                            {
                            case -1:
                                throw new Exception("Error al ingresar pago, intente nuevamente más tarde.");

                            case -2:
                                throw new Exception("No existe el usuario cajero que está ejecutando esta operación.");

                            default:
                                foreach (LineaPago factura in _pago.LineasPago)
                                {
                                    cmd.Parameters.Clear();
                                    cmd.CommandText = "RegistrarFacturaEnPago";

                                    cmd.Parameters.Add(retorno);
                                    cmd.Parameters.AddWithValue("@CodigoEmpresa", factura.Contrato.Empresa.Codigo);
                                    cmd.Parameters.AddWithValue("@TipoContrato", factura.Contrato.CodContrato);
                                    cmd.Parameters.AddWithValue("@CodCliente", factura.CodigoCliente);
                                    cmd.Parameters.AddWithValue("@FechaVencimiento", factura.FechaVencimiento);
                                    cmd.Parameters.AddWithValue("@Monto", factura.Monto);

                                    cmd.ExecuteNonQuery();
                                    //Verifico que cada ingreso de factura no de error
                                    switch ((int)retorno.Value)
                                    {
                                    case -1:
                                        throw new Exception("Error al registrar factura, intente nuevamente más tarde.");

                                    case -2:
                                        throw new Exception("Error al registrar factura, no existe el tipo de contrato de la factura.\r\nPor favor verifique que el tipo de contrato exista y que no haya más de una factura para el mismo contrato.");

                                    default:
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                { throw new Exception(ex.Message); }
            }
        }