Beispiel #1
0
        protected void CrearAgent_Click(object sender, ImageClickEventArgs e)
        {
            string validar = Session["Agentes"].ToString();



            if (validar == "SI")
            {
                Entidades.Gestion.CREARAGENTE CREARAGENTE = new Entidades.Gestion.CREARAGENTE();

                try
                {
                    CREARAGENTE.NOMBRE = txtnom.Text;
                    CREARAGENTE.CORREO = txtmail.Text;
                    CREARAGENTE.RUT    = txtrut.Text;

                    GestorGestion gestorgestion = new GestorGestion();
                    bool          result        = gestorgestion.CREARAGENTE(CREARAGENTE);
                    if (result == true)
                    {
                        lblmensaje.Text           = "Agente Registrado Correctamente";
                        this.lblmensaje.ForeColor = System.Drawing.Color.Green;
                        lblmensaje.Visible        = true;
                        txtnom.Text  = "";
                        txtmail.Text = "";
                        txtrut.Text  = "";
                        GVAgentes.DataBind();
                    }
                    else
                    {
                        lblmensaje.Text           = "No se Pudo Registrar Agente , Revisar Datos ";
                        this.lblmensaje.ForeColor = System.Drawing.Color.Red;
                        lblmensaje.Visible        = true;
                    }
                }
                catch (Exception) {
                    lblmensaje.Text           = "Error conexion a la Base de Datos , Favor Contactarse Con el Administrador de Sistemas ";
                    this.lblmensaje.ForeColor = System.Drawing.Color.Red;
                    lblmensaje.Visible        = true;
                }
            }
            else
            {
                lblmensaje.Text           = "Usuario sin privilegios para Crear Agentes";
                this.lblmensaje.ForeColor = System.Drawing.Color.Red;
                lblmensaje.Visible        = true;
            }
        }
        protected void btnRegistrar_Click(object sender, ImageClickEventArgs e)
        {
            string validar = Session["Usuarios"].ToString();

            if (validar == "SI")
            {
                SqlConnection Conn = new SqlConnection("Data Source=LocalHost;Initial Catalog=DBGestion;Persist Security Info=True;User ID=DBGestion;Password=123456");
                SqlCommand    cmd  = new SqlCommand();
                SqlDataReader dr;
                Conn.Open();
                cmd.Connection  = Conn;
                cmd.CommandText = "SELECT count(id_Usuario)as contador FROM Usuarios WITH(NOLOCK) where Usuario ='" + txtusuario.Text + "' or rut='" + txtrut.Text + "'";
                dr = cmd.ExecuteReader();
                dr.Read();
                int contador = int.Parse(dr["contador"].ToString());
                if (contador >= 1)
                {
                    lblmensaje.Text           = "Usuario o Rut ya existe";
                    this.lblmensaje.ForeColor = System.Drawing.Color.Red;
                    lblmensaje.Visible        = true;
                    Conn.Close();
                }
                else
                {
                    Entidades.Gestion.CREARUSUARIO CREARUSUARIO = new Entidades.Gestion.CREARUSUARIO();
                    try {
                        CREARUSUARIO.Usuario    = txtusuario.Text;
                        CREARUSUARIO.Contraseña = txtcontraseña.Text;
                        CREARUSUARIO.Nombre     = txtnombre.Text;
                        CREARUSUARIO.Apellido   = txtapellido.Text;
                        CREARUSUARIO.Rut        = txtrut.Text;
                        CREARUSUARIO.id_Perfil  = int.Parse(ddldepartamento.SelectedValue);
                        CREARUSUARIO.Modificar  = rbmod.SelectedValue.ToString();
                        CREARUSUARIO.Eliminar   = rbeliminar.SelectedValue.ToString();
                        CREARUSUARIO.Usuarios   = rbcuser.SelectedValue.ToString();
                        CREARUSUARIO.Perfiles   = rbcuser.SelectedValue.ToString();
                        CREARUSUARIO.Agentes    = rbcagentes.SelectedValue.ToString();
                        CREARUSUARIO.Registrar  = rbregistrar.SelectedValue.ToString();
                        GestorGestion gestorgestion = new GestorGestion();
                        bool          result        = gestorgestion.CREARUSUARIO(CREARUSUARIO);
                        if (result == true)
                        {
                            lblmensaje.Text           = "USUARIO CREADO CORRECTAMENTE";
                            this.lblmensaje.ForeColor = System.Drawing.Color.Green;
                            lblmensaje.Visible        = true;

                            gvuduarios.DataBind();
                            txtapellido.Text   = "";
                            txtcontraseña.Text = "";
                            txtnombre.Text     = "";
                            txtpass.Text       = "";
                            txtrut.Text        = "";
                            txtusuario.Text    = "";
                        }
                        else
                        {
                            lblmensaje.Text           = "Error al guardar los datos ....";
                            this.lblmensaje.ForeColor = System.Drawing.Color.Red;
                            lblmensaje.Visible        = true;
                        }
                    }catch (Exception) {
                        lblmensaje.Text           = "Error de proceso desconocido ....";
                        this.lblmensaje.ForeColor = System.Drawing.Color.Red;
                        lblmensaje.Visible        = true;
                    }
                }
                Conn.Close();
            }
            else
            {
                lblmensaje.Text           = "Usuario sin privilegios para Crear Cuentas";
                this.lblmensaje.ForeColor = System.Drawing.Color.Red;
                lblmensaje.Visible        = true;
            }
        }
        protected void btnRegistrar_ServerClick(object sender, EventArgs e)
        {
            SqlConnection Conn1 = new SqlConnection("Data Source=LocalHost;Initial Catalog=DBGestion;Persist Security Info=True;User ID=DBGestion;Password=123456");
            SqlCommand    cmd1  = new SqlCommand();
            SqlDataReader dr1;

            Conn1.Open();
            cmd1.Connection  = Conn1;
            cmd1.CommandText = "SELECT count(id_factura) as existe FROM Facturas2 where ninvoice ='" + txtninvoice.Text + "'";
            dr1 = cmd1.ExecuteReader();
            dr1.Read();
            string valor = dr1["existe"].ToString();

            //aqui revisar que tegistro no este
            if (valor == "0")
            {
                Conn1.Close();
                // de aqui hasta aqui
                Entidades.Gestion.INGRESARFACTURA INGRESARFACTURA = new Entidades.Gestion.INGRESARFACTURA();
                try{
                    INGRESARFACTURA.EMPRESA     = DDL_EMP.SelectedValue.ToString();
                    INGRESARFACTURA.AGENTE      = ddlagente.SelectedItem.ToString();
                    INGRESARFACTURA.NINVOICE    = txtninvoice.Text;
                    INGRESARFACTURA.FINVOICE    = txtfinvoice.Text;
                    INGRESARFACTURA.NUMERONC    = txtnnc.Text;
                    INGRESARFACTURA.VALORNC     = txtvnc.Text;
                    INGRESARFACTURA.FECHANC     = txtfnc.Text;
                    INGRESARFACTURA.MONEDA      = ddlmoneda.SelectedValue.ToString();
                    INGRESARFACTURA.TC          = txttc.Text;
                    INGRESARFACTURA.CONDICION   = ddlcp.SelectedValue.ToString();
                    INGRESARFACTURA.OBSERVACION = txtobservacion.Text;
                    INGRESARFACTURA.DETALLE     = txtdetalle.Text;
                    INGRESARFACTURA.USUARIO     = Session["Usuario"].ToString();
                    DateTime Hoy = DateTime.Today;
                    INGRESARFACTURA.FECHA_EMISION = Hoy.ToString("yyyy-MM-dd"); //FECHA DE INGRESO AUTOMATICA
                    INGRESARFACTURA.ESTADO        = "PENDIENTE";
                    INGRESARFACTURA.FECHAPAGO     = fpago.Text;                 //-----------------
                    if (IsPostBack)
                    {
                        Boolean fileOK = false;
                        String  path   = Server.MapPath("/Gestion2/PagoFacturas/PDF/");
                        if (fuinvoice.HasFile)
                        {
                            String   fileExtension     = System.IO.Path.GetExtension(fuinvoice.FileName).ToLower();
                            String[] allowedExtensions = { ".PDF", ".pdf" };//formatos admitidos
                            for (int i = 0; i < allowedExtensions.Length; i++)
                            {
                                if (fileExtension == allowedExtensions[i])
                                {
                                    fileOK = true;
                                }
                                else
                                {
                                    nook.Visible = true;
                                    ok.Visible   = false;
                                }
                            }
                            if (fileOK)
                            {
                                fuinvoice.PostedFile.SaveAs(path + "" + txtninvoice.Text + "" + fuinvoice.FileName);

                                //   lblmensaje.Text = "File uploaded!";
                                INGRESARFACTURA.LINKPDF = "/Gestion2/PagoFacturas/PDF/" + txtninvoice.Text + "" + fuinvoice.FileName + "";
                            }
                            else
                            {
                                nook.Visible = true;
                                ok.Visible   = false;
                            }
                        }
                    }


                    ////////////////////////////// aqui el duplicado



                    SqlConnection dupli    = new SqlConnection("Data Source=LocalHost;Initial Catalog=DBGestion;Persist Security Info=True;User ID=DBGestion;Password=123456");
                    SqlCommand    cmddupli = new SqlCommand();
                    SqlDataReader drdupli;
                    dupli.Open();
                    cmddupli.Connection  = dupli;
                    cmddupli.CommandText = "SELECT COUNT(linkpdf) as linkpdf FROM Facturas2 where linkpdf = '" + Session["buscarduplicado"] + "'";
                    drdupli = cmddupli.ExecuteReader();
                    drdupli.Read();

                    int val = int.Parse(drdupli["linkpdf"].ToString());

                    if (val >= 1)
                    {
                        string script = @"window.location.href = '#modalHtml';";
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", script, true);
                        nook.Visible     = true;
                        ok.Visible       = false;
                        duplimsj.Visible = false;
                        dupli.Close();
                    }
                    else
                    { // aquis e ejecuta el guardado
                        dupli.Close();


                        GestorGestion gestorgestion = new GestorGestion();
                        bool          result        = gestorgestion.INGRESARFACTURA(INGRESARFACTURA);
                        if (result == true)
                        {  // AQUI comienza a guardar en la tabla OP
                            SqlConnection Conn = new SqlConnection("Data Source=LocalHost;Initial Catalog=DBGestion;Persist Security Info=True;User ID=DBGestion;Password=123456");
                            SqlCommand    cmd  = new SqlCommand();
                            SqlDataReader dr;
                            Conn.Open();
                            cmd.Connection = Conn;
                            //  aqui se programa el switch para el ingreso de la op

                            int    num          = int.Parse(Session["contex"].ToString());
                            string maskValores0 = "###########.##";
                            string maskValores1 = "###########.##";
                            string maskValores2 = "###########.##";
                            string maskValores3 = "###########.##";
                            string maskValores4 = "###########.##";
                            string maskValores5 = "###########.##";
                            string formateado0  = Convert.ToDecimal(monto0.Text).ToString(maskValores0, CultureInfo.GetCultureInfo("en-US"));
                            string formateado1  = Convert.ToDecimal(monto1.Text).ToString(maskValores1, CultureInfo.GetCultureInfo("en-US"));
                            string formateado2  = Convert.ToDecimal(monto2.Text).ToString(maskValores2, CultureInfo.GetCultureInfo("en-US"));
                            string formateado3  = Convert.ToDecimal(monto3.Text).ToString(maskValores3, CultureInfo.GetCultureInfo("en-US"));
                            string formateado4  = Convert.ToDecimal(monto4.Text).ToString(maskValores4, CultureInfo.GetCultureInfo("en-US"));
                            string formateado5  = Convert.ToDecimal(monto5.Text).ToString(maskValores5, CultureInfo.GetCultureInfo("en-US"));

                            switch (num)
                            {
                            case 0:
                                cmd.CommandText = "INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op0.Text + "','" + formateado0 + "' ,'" + House0.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta0.Text + "')";
                                dr = cmd.ExecuteReader();
                                dr.Read();
                                Conn.Close();
                                nook.Visible     = false;
                                ok.Visible       = true;
                                duplimsj.Visible = false;
                                break;

                            case 1:
                                cmd.CommandText = "INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op0.Text + "','" + formateado0 + "' ,'" + House0.Text + "' ,'" + txtninvoice.Text + "'','" + txtF_Venta0.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op1.Text + "','" + formateado1 + "' ,'" + House1.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta1.Text + "')";
                                dr = cmd.ExecuteReader();
                                dr.Read();
                                Conn.Close();
                                nook.Visible     = false;
                                ok.Visible       = true;
                                duplimsj.Visible = false;
                                break;

                            case 2:
                                cmd.CommandText = "INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op0.Text + "','" + formateado0 + "' ,'" + House0.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta0.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op1.Text + "','" + formateado1 + "'  ,'" + House1.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta1.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op2.Text + "','" + formateado2 + "' ,'" + House2.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta2.Text + "')";
                                dr = cmd.ExecuteReader();
                                dr.Read();
                                Conn.Close();
                                nook.Visible     = false;
                                ok.Visible       = true;
                                duplimsj.Visible = false;
                                break;

                            case 3:
                                cmd.CommandText = "INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op0.Text + "','" + formateado0 + "' ,'" + House0.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta0.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op1.Text + "','" + formateado1 + "'  ,'" + House1.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta1.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op2.Text + "','" + formateado2 + "' ,'" + House2.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta2.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op3.Text + "','" + formateado3 + "' ,'" + House3.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta3.Text + "')";
                                dr = cmd.ExecuteReader();
                                dr.Read();
                                Conn.Close();
                                nook.Visible     = false;
                                ok.Visible       = true;
                                duplimsj.Visible = false;
                                break;

                            case 4:
                                cmd.CommandText = "INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op0.Text + "','" + formateado0 + "' ,'" + House0.Text + "','" + txtninvoice.Text + "','" + txtF_Venta0.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op1.Text + "','" + formateado1 + "'  ,'" + House1.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta1.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op2.Text + "','" + formateado2 + "' ,'" + House2.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta2.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op3.Text + "','" + formateado3 + "' ,'" + House3.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta3.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op4.Text + "','" + formateado4 + "' ,'" + House4.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta4.Text + "')";
                                dr = cmd.ExecuteReader();
                                dr.Read();
                                Conn.Close();
                                nook.Visible     = false;
                                ok.Visible       = true;
                                duplimsj.Visible = false;



                                break;

                            case 5:
                                cmd.CommandText = "INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op0.Text + "','" + formateado0 + "','" + House0.Text + "','" + txtninvoice.Text + "','" + txtF_Venta0.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op1.Text + "','" + formateado1 + "'  ,'" + House1.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta1.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op2.Text + "','" + formateado2 + "'  ,'" + House2.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta2.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op3.Text + "','" + formateado3 + "' ,'" + House3.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta3.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op4.Text + "','" + formateado4 + "','" + House4.Text + "'  ,'" + txtninvoice.Text + "','" + txtF_Venta4.Text + "')INSERT INTO Operaciones(numop,monto,House,ninvoice,Fventa)VALUES ('" + op5.Text + "','" + formateado5 + "' ,'" + House5.Text + "' ,'" + txtninvoice.Text + "','" + txtF_Venta5.Text + "')";
                                dr = cmd.ExecuteReader();
                                dr.Read();
                                Conn.Close();
                                nook.Visible     = false;
                                ok.Visible       = true;
                                duplimsj.Visible = false;
                                break;
                            }//cierre del switch

                            //aqui hay que programar el envio de correo avisando el ingreso

                            enviarmail();

                            //aqui hay que programar el envio de correo avisando el ingreso
                            Response.Redirect("~/pagos_agentes_Listado.aspx");
                        }
                        else
                        {
                            nook.Visible     = true;
                            ok.Visible       = false;
                            duplimsj.Visible = false;
                        }
                    }// aqui termina la validar dupli
                }
                catch (Exception)
                {
                    nook.Visible     = true;
                    ok.Visible       = false;
                    duplimsj.Visible = false;
                }


                // hasta aqui
            }
            else
            {
                Conn1.Close();
                nook.Visible = false;
                ok.Visible   = false;

                duplimsj.Visible = true;
            }//cierre del if de no repetir
        }
        protected void btnRegistrar_ServerClick(object sender, EventArgs e)
        {
            int usuario;

            usuario = (Convert.ToInt32(Session["id_Usuario"]));
            Entidades.Gestion.IngresarNC ingresarnc = new Entidades.Gestion.IngresarNC();
            try {
                ingresarnc.Empresa             = int.Parse(ddlEmpresa.SelectedValue.ToString());
                ingresarnc.Cliente             = txtCliente.Text;
                ingresarnc.RUT                 = txtRut.Text;
                ingresarnc.Motivo              = ddlmotivo.SelectedItem.ToString();
                ingresarnc.Detalle             = txtDetallemotivo.Text;
                ingresarnc.NOperación          = txtNOperacion.Text;
                ingresarnc.NFactura            = int.Parse(txtNFactura.Text);
                ingresarnc.FechaFactura        = DateTime.Parse(txtFechaFactura.Text);
                ingresarnc.idTipoFactura       = int.Parse(ddlTipoFact.SelectedValue.ToString());
                ingresarnc.MontoNetoFact       = txtMontoNetoFact.Text;
                ingresarnc.MontoIVAFact        = txtMontoIVAFact.Text;
                ingresarnc.MontoExentoFact     = txtMontoExentoFact.Text;
                ingresarnc.TotalFact           = txtTotalFact.Text;
                ingresarnc.MontoNetoNC         = txtMontoNetoNC.Text;
                ingresarnc.MontoIVANC          = txtMontoIVANC.Text;
                ingresarnc.MontoExentoNC       = txtMontoExentoNC.Text;
                ingresarnc.TotalNC             = txtTotalNC.Text;
                ingresarnc.id_Usuario          = usuario;
                ingresarnc.FechaRegistro       = DateTime.Today;
                ingresarnc.Vendedor            = txtNombreVendedor.Text;
                ingresarnc.FacturaReemplazante = txtnfacReemplazante.Text;
                ingresarnc.tiponota            = ddltiponota.SelectedValue.ToString();
                ingresarnc.fecha               = DateTime.Today.ToString();//revisa
                GestorGestion gestorgestion = new GestorGestion();
                bool          result        = gestorgestion.IngresarNC(ingresarnc);
                if (result == true)
                {
                    Alertaok.Visible = true;
                    NOOK.Visible     = false;
                    SinNC.Visible    = false;
                    gvnotacreditos.DataBind();
                    txtCliente.Text          = "";
                    txtDetallemotivo.Text    = "";
                    txtFechaFactura.Text     = "";
                    txtMontoExentoFact.Text  = "";
                    txtMontoExentoNC.Text    = "";
                    txtMontoIVAFact.Text     = "";
                    txtMontoIVANC.Text       = "";
                    txtMontoNetoFact.Text    = "";
                    txtMontoNetoNC.Text      = "";
                    txtNFactura.Text         = "";
                    txtNOperacion.Text       = "";
                    txtRut.Text              = "";
                    txtTotalFact.Text        = "";
                    txtTotalNC.Text          = "";
                    txtNombreVendedor.Text   = "";
                    txtnfacReemplazante.Text = "";
                    DateTime fecha = DateTime.Now;
                }
                else
                {
                    NOOK.Visible  = true;
                    SinNC.Visible = false;
                    NOOK.Visible  = false;
                }
            }
            catch (Exception)
            {
                NOOK.Visible  = true;
                SinNC.Visible = false;
                NOOK.Visible  = false;
            }
        }