Example #1
0
 protected void btnIngresar_Click(object sender, EventArgs e)
 {
     try
     {
         if (_Conexion.conectar())
         {
             DataTable dtUsuario = new DataTable();
             dtUsuario = _Conexion.CargarDatos("select usuario from usuario where usuario = '" + txtUsuario.Text.Trim() + "' and contraseña = '" + txtContrasena.Text.Trim() + "'");
             if (dtUsuario.Rows.Count > 0)
             {
                 _MensajeSatisfactorio = "Usuario correcto";
                 HttpCookie _IdUsuario = new HttpCookie("idusuario");
                 _IdUsuario.Value   = txtUsuario.Text;
                 _IdUsuario.Expires = DateTime.Now.AddHours(1);
                 Response.Cookies.Add(_IdUsuario);
                 Response.Redirect("Default.aspx");
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
Example #2
0
 private void CargarDatos()
 {
     try
     {
         if (_Conexion.conectar())
         {
             DataTable dtRoles = new DataTable();
             dtRoles = _Conexion.CargarDatos("select id_rol, rol from rol order by id_rol");
             if (dtRoles.Rows.Count > 0)
             {
                 ListItem _PrimeraOpcionRol = new ListItem("Seleccione rol", "0");
                 cmbRole.DataSource     = dtRoles;
                 cmbRole.DataValueField = "id_rol";
                 cmbRole.DataTextField  = "rol";
                 cmbRole.DataBind();
                 cmbRole.Items.Insert(0, _PrimeraOpcionRol);
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
Example #3
0
        public bool ValidarDisponibilidadArticulo()
        {
            bool _resultado = true;

            try
            {
                FerreteriaPro1.conexion.conexion _Conexion = new FerreteriaPro1.conexion.conexion();
                if (_Conexion.conectar())
                {
                    DataTable dtDatos = new DataTable();
                    dtDatos = _Conexion.CargarDatos("select cantidad_articulo_ferreteria, precio_articulo from articulos art inner join articulo_ferreteria arf on art.id_articulo = arf.id_articulo where arf.id_ferreteria = " + cmbFerreteria.SelectedValue + " and art.id_articulo = " + cmbArticulos.SelectedValue.ToString());
                    if (dtDatos.Rows.Count > 0)
                    {
                        int stockArticulo = int.Parse(dtDatos.Rows[0][0].ToString());
                        int cantidadProductosAgregados = 0;
                        cantidadProductosAgregados = ObtenerCantidadArticuloEnGrid();
                        if ((int.Parse(txtCantidad.Text) + cantidadProductosAgregados) > stockArticulo)
                        {
                            _resultado    = false;
                            _MensajeError = "La cantidad ingresada es mayor al stock del producto";
                        }
                        else
                        {
                            _PrecioArticulo = dtDatos.Rows[0][1].ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _MensajeError = ex.Message;
                return(false);
            }
            return(_resultado);
        }
Example #4
0
 private void ObtenerDatosArticulo()
 {
     try
     {
         if (!IsPostBack)
         {
             string idArticulos = Request.QueryString["ida"];
             string operacion   = Request.QueryString["op"];
             if (operacion == null || operacion == "" || idArticulos == null || idArticulos == "")
             {
                 _MensajeError = "Debe ingresar operacion y codigo de articulos";
             }
             else
             {
                 if (operacion == "4")
                 {
                     if (_Conexion.conectar())
                     {
                         DataTable dtArticulos = new DataTable();
                         dtArticulos = _Conexion.CargarDatos("select * from articulos where id_articulos = " + idArticulos);
                         foreach (DataRow _Ferreteria in dtArticulos.Rows)
                         {
                             txtNombreArticulo.Text        = _Ferreteria["nombre_articulo"].ToString();
                             txtDescripcionArticulo.Text   = _Ferreteria["descripcion_articulo"].ToString();
                             txtPrecioArticulo.Text        = _Ferreteria["precio_articulo"].ToString();
                             txtStockArticulo.Text         = _Ferreteria["stock_articulo"].ToString();
                             cmbUnidadMedida.SelectedValue = _Ferreteria["id_unidad_medida"].ToString();
                             cmbProveedor.SelectedValue    = _Ferreteria["id_proveedor"].ToString();
                         }
                         btnGuardar.Enabled = false;
                     }
                     else
                     {
                         _MensajeError = _Conexion.Mensaje;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
 private void CargarDatos()
 {
     try
     {
         DataTable dtDatos = new DataTable();
         if (_Conexion.conectar())
         {
             dtDatos = _Conexion.CargarDatos("select id_articulo, nombre_articulo from articulos order by id_articulo");
             if (dtDatos.Rows.Count > 0)
             {
                 ListItem _PrimeraOpcion = new ListItem("Seleccione artículo", "0");
                 cmbArticulos.DataSource     = dtDatos;
                 cmbArticulos.DataValueField = "id_articulo";
                 cmbArticulos.DataTextField  = "nombre_articulo";
                 cmbArticulos.DataBind();
                 cmbArticulos.Items.Insert(0, _PrimeraOpcion);
             }
             if (_Conexion.conectar())
             {
                 dtDatos = new DataTable();
                 dtDatos = _Conexion.CargarDatos("select id_ferreteria, nombre from ferreteria order by id_ferreteria");
                 if (dtDatos.Rows.Count > 0)
                 {
                     ListItem _PrimeraOpcion = new ListItem("Seleccione ferretería", "0");
                     cmbIdFerreteria.DataSource     = dtDatos;
                     cmbIdFerreteria.DataValueField = "id_ferreteria";
                     cmbIdFerreteria.DataTextField  = "nombre";
                     cmbIdFerreteria.DataBind();
                     cmbIdFerreteria.Items.Insert(0, _PrimeraOpcion);
                 }
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
 private void ObtenerDatosFerreteria()
 {
     try
     {
         if (!IsPostBack)
         {
             string idFerreteria = Request.QueryString["idf"];
             string operacion    = Request.QueryString["op"];
             if (operacion == null || operacion == "" || idFerreteria == null || idFerreteria == "")
             {
                 //_MensajeError = "Debe ingresar operacion y codigo de ferreteria";
             }
             else
             {
                 if (operacion == "4")
                 {
                     if (_Conexion.conectar())
                     {
                         DataTable dtFerreteria = new DataTable();
                         dtFerreteria = _Conexion.CargarDatos("select * from ferreteria where id_ferreteria = " + idFerreteria);
                         foreach (DataRow _Ferreteria in dtFerreteria.Rows)
                         {
                             txtNombres.Text  = _Ferreteria["nombre"].ToString();
                             txtTelefono.Text = _Ferreteria["telefono"].ToString();
                             cmbTipoFerreteria.SelectedValue = _Ferreteria["id_tipoferreteria"].ToString();
                         }
                         btnGuardar.Enabled = false;
                     }
                     else
                     {
                         _MensajeError = _Conexion.Mensaje;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
        private bool ValidarDatos()
        {
            bool _Resultado = true;

            try
            {
                if (_IdArticulo == "")
                {
                    _Mensaje += "Debe ingresar el articulo"; _Resultado = false;
                }
                if (_Cantidad == "")
                {
                    _Mensaje += "Debe ingresar la cantidad"; _Resultado = false;
                }
                else
                {
                    int cantidad = 0;
                    if (!int.TryParse(_Cantidad, out cantidad))
                    {
                        _Mensaje += "Debe ingresar la cantidad con valores numéricos"; _Resultado = false;
                    }
                    else
                    {
                        FerreteriaPro1.conexion.conexion _Conexion = new FerreteriaPro1.conexion.conexion();
                        if (_Conexion.conectar())
                        {
                            DataTable dtDatos = new DataTable();
                            dtDatos = _Conexion.CargarDatos("select stock_articulo from articulos where id_articulo = " + _IdArticulo);
                            if (dtDatos.Rows.Count > 0)
                            {
                                int stockArticulo = int.Parse(dtDatos.Rows[0][0].ToString());
                                if (int.Parse(_Cantidad) > stockArticulo)
                                {
                                    _Mensaje += "La cantidad ingresada es mayor al stock disponible del artículo."; _Resultado = false;
                                }
                            }
                        }
                    }
                }
                if (_IdFerreteria == "")
                {
                    _Mensaje += "Debe ingresar la ferretería"; _Resultado = false;
                }
            }
            catch (Exception ex)
            {
                _Mensaje   = ex.Message;
                _Resultado = false;
            }
            return(_Resultado);
        }
        private void ObtenerDatosProveedor()
        {
            try
            {
                if (!IsPostBack)
                {
                    string idProveedor = Request.QueryString["idp"];
                    string operacion   = Request.QueryString["op"];
                    if (operacion == null || operacion == "" || idProveedor == null || idProveedor == "")
                    {
                        //_MensajeError = "Debe ingresar operacion y codigo del proveedor";
                    }
                    else
                    {
                        if (operacion == "4")
                        {
                            if (_Conexion.conectar())
                            {
                                DataTable dtProveedor = new DataTable();
                                dtProveedor = _Conexion.CargarDatos("select * from proveedor where id_proveedor = " + idProveedor);
                                foreach (DataRow _FilaProveedor in dtProveedor.Rows)
                                {
                                    txtNombreProveedor.Text    = _FilaProveedor["nombre_proveedor"].ToString();
                                    txtTelefonoProveedor.Text  = _FilaProveedor["telefono_proveedor"].ToString();
                                    txtDireccionProveedor.Text = _FilaProveedor["direccion_proveedor"].ToString();
                                }
                            }
                            btnGuardar.Enabled = false;
                        }
                        else
                        {
                            _MensajeError = _Conexion.Mensaje;
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                _MensajeError = ex.Message;
            }
        }
Example #9
0
        public bool ObtenerPrecioArticulo()
        {
            bool _resultado = true;

            try
            {
                FerreteriaPro1.conexion.conexion _Conexion = new FerreteriaPro1.conexion.conexion();
                if (_Conexion.conectar())
                {
                    DataTable dtDatos = new DataTable();
                    dtDatos = _Conexion.CargarDatos("select precio_articulo from articulos where id_articulo = " + cmbArticulos.SelectedValue.ToString());
                    if (dtDatos.Rows.Count > 0)
                    {
                        _PrecioArticulo = dtDatos.Rows[0][0].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                _MensajeError = ex.Message;
                return(false);
            }
            return(_resultado);
        }
 private void ObtenerProveedores()
 {
     try
     {
         if (_Conexion.conectar())
         {
             DataTable dtUsuario = new DataTable();
             dtUsuario = _Conexion.CargarDatos("select * from proveedor");
             if (dtUsuario.Rows.Count > 0)
             {
                 dgvListado.DataSource = dtUsuario;
                 dgvListado.DataBind();
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
Example #11
0
 private void ObtenerFerreteria()
 {
     try
     {
         if (_Conexion.conectar())
         {
             DataTable dtFerreteria = new DataTable();
             dtFerreteria = _Conexion.CargarDatos("select * from ferreteria fer inner join TIPO_FERRETERIA tip on fer.id_tipoferreteria=tip.id_tipoferreteria");
             if (dtFerreteria.Rows.Count > 0)
             {
                 dgvListado.DataSource = dtFerreteria;
                 dgvListado.DataBind();
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
 private void ObtenerArticulos()
 {
     try
     {
         if (_Conexion.conectar())
         {
             DataTable dtArticulos = new DataTable();
             dtArticulos = _Conexion.CargarDatos("select * from articulos fer inner join PROVEEDOR pro on fer.id_proveedor=pro.id_proveedor inner join unidad_medida ume on fer.id_unidad_medida = ume.id_unidad_medida");
             if (dtArticulos.Rows.Count > 0)
             {
                 dgvListado.DataSource = dtArticulos;
                 dgvListado.DataBind();
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
 private void ObtenerCompras()
 {
     try
     {
         if (_Conexion.conectar())
         {
             DataTable dtArticulos = new DataTable();
             dtArticulos = _Conexion.CargarDatos("select com.id_compra,com.fecha_compra,pro.nombre_proveedor,sum(cod.total_compra_detalle) as monto_total_compra from compra com inner join compra_detalle cod on com.id_compra = cod.id_compra inner join PROVEEDOR pro on com.id_proveedor=pro.id_proveedor group by com.id_compra,com.fecha_compra,pro.nombre_proveedor");
             if (dtArticulos.Rows.Count > 0)
             {
                 dgvListado.DataSource = dtArticulos;
                 dgvListado.DataBind();
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
Example #14
0
 private void ObtenerVentas()
 {
     try
     {
         if (_Conexion.conectar())
         {
             DataTable dtArticulos = new DataTable();
             dtArticulos = _Conexion.CargarDatos("select VEN.ID_VENTA, VEN.FECHA_VENTA, CLI.nombre_cliente, FER.nombre as nombre_ferreteria, SUM(VED.total_venta_detalle) as monto_total_venta from VENTA VEN INNER JOIN CLIENTES CLI ON VEN.id_cliente = CLI.id_cliente INNER JOIN FERRETERIA FER ON FER.id_ferreteria = VEN.ID_FERRETERIA INNER JOIN VENTA_DETALLE VED ON VEN.ID_VENTA = VED.ID_VENTA group by VEN.ID_VENTA , VEN.FECHA_VENTA, CLI.nombre_cliente, FER.nombre");
             if (dtArticulos.Rows.Count > 0)
             {
                 dgvListado.DataSource = dtArticulos;
                 dgvListado.DataBind();
             }
         }
         else
         {
             _MensajeError = _Conexion.Mensaje;
         }
     }
     catch (Exception ex)
     {
         _MensajeError = ex.Message;
     }
 }
Example #15
0
        public bool OperarVenta()
        {
            bool _Resultado = true;

            try
            {
                _Resultado = ValidarDatos();
                if (_Resultado)
                {
                    int _IdVenta = 0;
                    FerreteriaPro1.conexion.conexion _Conexion = new FerreteriaPro1.conexion.conexion();
                    if (_Conexion.conectar())
                    {
                        DataTable dtDatos = new DataTable();
                        dtDatos = _Conexion.CargarDatos("select isnull(max(id_venta),0) + 1 from venta");
                        if (dtDatos.Rows.Count > 0)
                        {
                            _IdVenta = int.Parse(dtDatos.Rows[0][0].ToString());
                        }
                        string consulta = "insert into venta values ("
                                          + "" + _IdVenta + ", "
                                          + "" + _IdCliente + ", "
                                          + "" + _IdFerreteria + ", "
                                          + "getdate()"
                                          + ")";
                        if (_Conexion.EjecutarComandoSql(consulta) > 0)
                        {
                            foreach (DataRow _Detalle in dtDetalleVenta.Rows)
                            {
                                consulta = "insert into venta_detalle values ("
                                           + "" + _IdVenta + ", "
                                           + "" + _Detalle["id_articulo"] + ", "
                                           + "" + _Detalle["cantidad_articulo"] + ", "
                                           + "" + float.Parse(_Detalle["cantidad_articulo"].ToString()) * float.Parse(_Detalle["precio_articulo"].ToString())
                                           + ")";
                                if (_Conexion.EjecutarComandoSql(consulta) > 0)
                                {
                                    consulta = "update articulos set stock_articulo = stock_articulo - " + _Detalle["cantidad_articulo"] + " where id_articulo = " + _Detalle["id_articulo"];
                                    if (_Conexion.EjecutarComandoSql(consulta) > 0)
                                    {
                                        _Resultado = true;
                                    }
                                    else
                                    {
                                        _Resultado = false;
                                    }
                                }
                                else
                                {
                                    _Resultado = false;
                                }
                            }
                        }
                        else
                        {
                            _Resultado = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Mensaje    = ex.Message;
                _Resultado = false;
            }
            return(_Resultado);
        }
Example #16
0
        private void ObtenerDatosCliente()
        {
            try
            {
                string idCliente = Request.QueryString["idc"];
                _TipoOperacion = Request.QueryString["op"];

                if (_TipoOperacion == null || _TipoOperacion == "")
                {
                    _MensajeError = "Debe ingresar operacion";
                }
                else
                {
                    if (_TipoOperacion != "1")
                    {
                        if (idCliente == null || idCliente == "")
                        {
                            _MensajeError = "Debe ingresar id del cliente";
                        }
                        else
                        {
                            if (_TipoOperacion == "2")
                            {
                                _Operacion = "Modificar";
                            }
                            if (_TipoOperacion == "3")
                            {
                                _Operacion = "Eliminar";
                            }
                            if (_TipoOperacion == "4")
                            {
                                _Operacion         = "Consultar";
                                btnGuardar.Enabled = false;
                            }
                            if (!IsPostBack)
                            {
                                if (_Conexion.conectar())
                                {
                                    DataTable dtClientes = new DataTable();
                                    dtClientes = _Conexion.CargarDatos("select * from clientes where id_cliente = " + idCliente);
                                    foreach (DataRow _Cliente in dtClientes.Rows)
                                    {
                                        txtIdCliente.Text         = _Cliente["id_cliente"].ToString();
                                        txtNombreCliente.Text     = _Cliente["nombre_cliente"].ToString();
                                        txtDireccionClientes.Text = _Cliente["direccion_cliente"].ToString();
                                        txtTelefonoClientes.Text  = _Cliente["telefono_cliente"].ToString();
                                    }
                                }
                                else
                                {
                                    _MensajeError = _Conexion.Mensaje;
                                }
                            }
                        }
                    }
                    else if (_TipoOperacion == "1")
                    {
                        _Operacion = "Agregar";
                    }
                    btnGuardar.Text = _Operacion;
                }
            }
            catch (Exception ex)
            {
                _MensajeError = ex.Message;
            }
        }