private void Admcli_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == Convert.ToChar(Keys.Enter))
            {
                if (txtnombre.Text == "")
                {
                    MessageBox.Show("Alguno de los Campos esta Vacio, Favor llenar", "Atencion!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (txtrnc.Text == "")
                {
                    MessageBox.Show("Alguno de los Campos esta Vacio, Favor llenar", "Atencion!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                else if (txtdirecc.Text == "")
                {
                    MessageBox.Show("Alguno de los Campos esta Vacio, Favor llenar", "Atencion!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                else if (txttel.Text == "")
                {
                    MessageBox.Show("Alguno de los Campos esta Vacio, Favor llenar", "Atencion!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                else
                {
                    //primero buscame si el cliente existe
                    try
                    {
                        string  CMD = string.Format("SELECT * FROM Clientes WHERE Nombre = '{0}'  AND RNC_No = '{1}'", txtnombre.Text.Trim(), txtrnc.Text.Trim());
                        DataSet ds  = ConsultasSQL.Ejecutar(CMD);
                        string  cli = ds.Tables[0].Rows[0]["Nombre"].ToString().Trim();
                        string  rn  = ds.Tables[0].Rows[0]["RNC_No"].ToString().Trim();

                        if (cli == txtnombre.Text.Trim() && rn == txtrnc.Text.Trim())
                        {
                            MessageBox.Show("EL Cliente ya esta registrado...", "Lo siento", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception)
                    {
                        try
                        {
                            string  cmd = "INSERT INTO Clientes VALUES ('" + txtnombre.Text + "', '" + txtrnc.Text + "', '" + txtdirecc.Text + "', '" + txttel.Text + "')";
                            DataSet ds  = ConsultasSQL.Ejecutar(cmd);

                            MessageBox.Show("Cliente Registrado Con Exito", "Datos Guardados", MessageBoxButtons.OK, MessageBoxIcon.Information);


                            Nuevo();
                        }
                        catch (Exception llll)
                        {
                            MessageBox.Show("Algo va Mal..." + llll);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (con_filas == 0)
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtcliente.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtRNC.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtdireccion.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txttelefono.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            //dtalles
            else if (txtrets.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtvalid.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtfe.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtor.Text == "")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtfor.Text == "Forma")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (lblcant.Text == "Existencia")
            {
                MessageBox.Show("Debe de llenar todos los Campos", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                try
                {
                    //generame el ret
                    conexion.Open();
                    SqlCommand lopo = new SqlCommand("INSERT INTO Regimenes values('" + txtrets.Text + "')", conexion);
                    lopo.ExecuteNonQuery();
                    conexion.Close();

                    maxregimenesesp lp = new maxregimenesesp();


                    lp.ShowDialog();

                    if (lp.DialogResult == DialogResult.OK)
                    {
                        txtrets.Text  = lp.dgv.Rows[lp.dgv.CurrentRow.Index].Cells[0].Value.ToString();
                        txtvalid.Text = lp.dgv2.Rows[lp.dgv2.CurrentRow.Index].Cells[0].Value.ToString();
                    }
                    //continua con la factura
                }
                catch (Exception l)
                {
                    MessageBox.Show("" + l.Message);
                }



                if (con_filas != 0)
                {
                    try
                    {
                        //llenar reistros
                        string  cmd = "INSERT INTO Fac VALUES ('" + txtfe.Text + "', '" + txtvalid.Text + "', '" + txtor.Text + "', '" + txtfor.Text + "', '" + lbltip.Text + "')";
                        DataSet ds  = ConsultasSQL.Ejecutar(cmd);



                        //fin llenar registro



                        Ganancia  = 0;
                        Ganancia0 = 0;
                        decimal precio_c;
                        decimal precio_v;
                        int     Cant_Tomada;

                        //llenar fac && fin llenar registro
                        foreach (DataGridViewRow Fila in dgv.Rows)
                        {
                            cmd = "INSERT INTO DEfac VALUES  ( '" + txtrets.Text + "','" + Fila.Cells[0].Value.ToString() + "', '" + Fila.Cells[1].Value.ToString() + "', '" + Fila.Cells[2].Value.ToString() + "', '" + Fila.Cells[3].Value.ToString() + "', '" + Fila.Cells[4].Value.ToString() + "', 'NULL', 'NULL', '" + txttotalll.Text + "' )";
                            ds  = ConsultasSQL.Ejecutar(cmd);

                            //Buscame algunos campos necesarios PARA EL RPORTE

                            SqlCommand comando = new SqlCommand("SELECT * FROM Productos WHERE Codigo = @Cod", conexion);
                            comando.Parameters.AddWithValue("@Cod", Fila.Cells[0].Value.ToString());
                            conexion.Open();


                            SqlDataReader regsitro = comando.ExecuteReader();
                            if (regsitro.Read())
                            {
                                LOTEee           = regsitro["Lote"].ToString();
                                lblpreventa.Text = regsitro["Precio_Compra"].ToString();
                            }
                            conexion.Close();

                            //primer calculo de cantidad por precio

                            precio_c    = Convert.ToDecimal(lblpreventa.Text);
                            Cant_Tomada = Convert.ToInt32(Fila.Cells[1].Value.ToString());



                            Ganancia0 = precio_c * Cant_Tomada;//ya tengo mi ganancia 0


                            //calcular utilidad


                            precio_c = Convert.ToDecimal(lblpreventa.Text);
                            precio_v = Convert.ToDecimal(Fila.Cells[5].Value.ToString());
                            if (precio_v < Ganancia0)
                            {
                                Ganancia = 0;
                            }

                            else if (precio_v == Ganancia0)
                            {
                                Ganancia = 0;
                            }
                            else
                            {
                                Ganancia = precio_v - Ganancia0;
                            }

                            //actualiza cantidad
                            double exi;
                            double to;
                            int    cant;

                            exi  = Convert.ToInt32(lblcant.Text);
                            cant = Convert.ToInt32(Fila.Cells[1].Value.ToString());

                            to = exi - cant;

                            conexion.Open();
                            SqlCommand raro = new SqlCommand(@"update Productos set Existencia = '" + to.ToString() + "' where Codigo = @toma ", conexion);
                            raro.CommandType = CommandType.Text;
                            raro.Parameters.AddWithValue(@"toma", Fila.Cells[0].Value.ToString());
                            raro.ExecuteNonQuery();
                            to = 0;
                            conexion.Close();



                            //actualizar cantidad


                            //registrame la factura
                            conexion.Open();                                                           //Fecha_Factura          //Num_Fac                 //Codigo_Producto                         //Descripcion                           //Lote_Producto                     //presentacion                                //Cant_Tomada                           //Costo                     //CostoTotal                   //Precio                             //Precio_Total
                            SqlCommand comand = new SqlCommand("INSERT INTO Registros VALUES ('" + fechaa4.ToString() + "', '" + txtrets.Text + "', '" + Fila.Cells[0].Value.ToString() + "', '" + Fila.Cells[3].Value.ToString() + "', '" + LOTEee.ToString() + "', '" + Fila.Cells[2].Value.ToString() + "' ,'" + Fila.Cells[1].Value.ToString() + "', '" + lblpreventa.Text + "', '" + Ganancia0.ToString("N2", new CultureInfo("en-US")) + "', '" + Fila.Cells[4].Value.ToString() + "', '" + Fila.Cells[5].Value.ToString() + "', '" + Ganancia.ToString("N2", new CultureInfo("en-US")) + "' )", conexion);
                            comand.ExecuteNonQuery();
                            conexion.Close();
                        }



                        //calculame la Utilidad



                        //continua

                        ReporteRegimenesESP rp = new ReporteRegimenesESP();



                        //detalles fac


                        for (int i = 0; i < dgv.Rows.Count; i++)
                        {
                            report datos = new report();

                            datos.Cliente   = txtcliente.Text;
                            datos.RNC       = txtRNC.Text;
                            datos.direccion = txtdireccion.Text;
                            datos.telefono  = txttelefono.Text;

                            //datos del tipo fac

                            datos.RET   = txtrets.Text;
                            datos.VALID = txtvalid.Text;
                            datos.FECHA = txtfe.Text;
                            datos.ORDEN = txtor.Text;
                            datos.FORMA = txtfor.Text;

                            datos.CODIGO       = (string)this.dgv.Rows[i].Cells[0].Value;
                            datos.CANTIDAD     = (string)this.dgv.Rows[i].Cells[1].Value;
                            datos.PRESENTACION = (string)this.dgv.Rows[i].Cells[2].Value;
                            datos.DESCRPP      = (string)this.dgv.Rows[i].Cells[3].Value;
                            datos.PRECIOU      = (string)this.dgv.Rows[i].Cells[4].Value;


                            datos.PRECIOT = txttotalll.Text;


                            rp.DatosRE.Add(datos);
                        }



                        rp.ShowDialog();
                        Nuevo();
                    }



                    catch (Exception error)
                    {
                        MessageBox.Show("Algo Va mal...  " + error);
                    }
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (txtcodigo.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtdescripc.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtexistencia.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtprecon.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            else if (txtcatiui.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (combouni.Text == "Seleccione una Unidad")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtbodega.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else if (txtlote.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }



            else if (txtmarca.Text == "")
            {
                MessageBox.Show("Debe de Llenar los Campos Faltantes", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                try
                {
                    //verificame si existe la descrpcion y el lote

                    string CMD = string.Format("Select * FROM Productos WHERE Descripcion = '{0}' AND Lote='{1}'", txtdescripc.Text.Trim(), txtlote.Text.Trim());

                    DataSet ds     = ConsultasSQL.Ejecutar(CMD);
                    string  descri = ds.Tables[0].Rows[0]["Descripcion"].ToString().Trim();
                    string  lote   = ds.Tables[0].Rows[0]["Lote"].ToString().Trim();


                    if (descri == txtdescripc.Text.Trim() && lote == txtlote.Text.Trim())
                    {
                        //YA QUE EXISTE JALAME LA CANTIDAD EXISTENTE

                        SqlCommand comando = new SqlCommand("SELECT * FROM Productos WHERE Descripcion = @Cod", conexion);
                        comando.Parameters.AddWithValue("@Cod", txtdescripc.Text);
                        conexion.Open();

                        SqlDataReader regsitro = comando.ExecuteReader();
                        if (regsitro.Read())
                        {
                            txtid.Text = regsitro["ID"].ToString();
                            txtex.Text = regsitro["Existencia"].ToString();
                        }
                        conexion.Close();

                        //ya que tengo la cantidad hago el calculo

                        int CantiExi  = 0;
                        int CantToma  = 0;
                        int CantFinal = 0;

                        CantToma = Convert.ToInt32(txtexistencia.Text);
                        CantiExi = Convert.ToInt32(txtex.Text);

                        CantFinal = CantiExi + CantToma;

                        //ya que tengo en calculo procedo a modificar

                        conexion.Open();
                        SqlCommand raro = new SqlCommand(@"UPDATE Productos SET Existencia = '" + CantFinal + "' WHERE ID = @toma ", conexion);
                        raro.CommandType = CommandType.Text;
                        raro.Parameters.AddWithValue(@"toma", txtid.Text);
                        raro.ExecuteNonQuery();


                        MessageBox.Show("Registo Existoso", "Atencion!!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Nuevo();
                        conexion.Close();


                        CantFinal = 0;
                    }
                }
                catch (Exception)
                {
                    //si no existe insertame normalmente



                    string agregar = "Insert into Productos  Values('" + txtcodigo.Text + "','" + txtdescripc.Text + "','" + txtexistencia.Text + "',  '" + txtcatiui.Text + "','" + combouni.Text + "', '" + txtbodega.Text + "' , '" + txtlote.Text + "', '" + txtprecon.Text + "', '" + date12.Text + "', '" + txtmarca.Text + "')";

                    DataSet ds = ConsultasSQL.Ejecutar(agregar);
                    MessageBox.Show("Se Ha agregado un Producto", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Nuevo();
                }
            }
        }