Example #1
0
        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    int   rowIndex = dataGridView1.CurrentCell.RowIndex;
                    int   Cantidad = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells[1].Value);
                    float precio   = float.Parse(dataGridView1.Rows[rowIndex].Cells[5].Value.ToString().Replace("$", ""));
                    if (Cantidad > 0)
                    {
                        dataGridView1.Rows[rowIndex].Cells[1].Value = (Cantidad + 1).ToString();
                        dataGridView1.Rows[rowIndex].Cells[6].Value = ((Cantidad + 1) * -precio).ToString("$0.00");
                        chequeartotal();
                    }
                }
            }
            if (e.KeyCode == Keys.Left)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    int   rowIndex = dataGridView1.CurrentCell.RowIndex;
                    int   Cantidad = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells[1].Value);
                    float precio   = float.Parse(dataGridView1.Rows[rowIndex].Cells[5].Value.ToString().Replace("$", ""));

                    if (Cantidad > 1)
                    {
                        dataGridView1.Rows[rowIndex].Cells[1].Value = (Cantidad - 1).ToString();
                        dataGridView1.Rows[rowIndex].Cells[6].Value = ((Cantidad - 1) * -precio).ToString("$0.00");
                        chequeartotal();
                    }
                }
            }

            if (e.KeyCode == Keys.Up)
            {
                try
                {
                    int rowIndex = dataGridView1.CurrentCell.RowIndex;
                    dataGridView1.Rows[rowIndex - 1].Cells[1].Selected = true;
                }
                catch (Exception)
                {
                }
            }
            if (e.KeyCode == Keys.Down)
            {
                try
                {
                    int rowIndex = dataGridView1.CurrentCell.RowIndex;
                    dataGridView1.Rows[rowIndex + 1].Cells[1].Selected = true;
                }
                catch (Exception)
                {
                }
            }
            if (e.KeyCode == Keys.Escape)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    DialogResult result = MessageBox.Show("Está seguro de cancelar la venta?", "Atención",
                                                          MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.Yes)
                    {
                        this.Close();
                        NotaDeCredito frm = new NotaDeCredito();
                        frm.Show();
                        frm.Focus();
                    }
                }
                else
                {
                    this.Close();
                }
            }
            if (e.KeyCode == Keys.Enter)
            {
                if (dataGridView1.Rows.Count < 1 && textBox4.Text.Length == 0)
                {
                    MessageBox.Show("No hay ningún artículo vendido");
                }
                if (dataGridView1.Rows.Count > 0 && textBox4.Text.Length == 0)
                {
                    DataTable dt = new DataTable(); //agarramos el gridview y le metemos los datos a un datatable.
                    //no hay forma mejor que hacerlo de esta manera porque no funciona referenciando el DT del dgridview

                    for (int i = 0; i < dataGridView1.Columns.Count; i++)
                    {
                        dt.Columns.Add("column" + i.ToString());
                    }
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        DataRow dr = dt.NewRow();
                        for (int j = 0; j < dataGridView1.Columns.Count; j++)
                        {
                            dr["column" + j.ToString()] = row.Cells[j].Value;
                        }

                        dt.Rows.Add(dr);
                    }
                    totalventa.detallenotacred = dt;


                    totalventa.totnotacred = textBox5.Text;
                    Total total = new Total();
                    total.Show();
                }//mostrar la pantalla que ingresa plata clente
                if (textBox4.Text.Length > 0)
                {
                    Conexion.abrir();
                    SqlCeCommand metocodigo = new SqlCeCommand();
                    metocodigo.Parameters.AddWithValue("@cod", textBox4.Text);
                    DataTable producto = Conexion.Consultar("idarticulo,codigoart,descripcion,marca,precio", "Articulos", "WHERE codigoart = @cod", "", metocodigo);
                    Conexion.cerrar();
                    if (producto.Rows.Count > 0)
                    {
                        int    cantidad   = 1;
                        string idproducto = producto.Rows[0][0].ToString();
                        string codigo     = producto.Rows[0][1].ToString();
                        string desc       = producto.Rows[0][2].ToString();
                        string mca        = producto.Rows[0][3].ToString();
                        float  prec       = float.Parse(producto.Rows[0][4].ToString());
                        float  total      = prec * -cantidad;
                        dataGridView1.Rows.Add(idproducto, cantidad, codigo, desc, mca, prec.ToString("$0.00"), total.ToString("$0.00"));
                        textBox4.Text = "";
                        dataGridView1.Rows[(dataGridView1.Rows.Count - 1)].Cells[1].Selected = true;
                    }
                    else
                    {
                        MessageBox.Show("No se ha encontrado el artículo");
                        textBox4.Text = "";
                    }
                }//chequear si existe el codigo de ese producto y de ser asi agregarlo al DGV.
            }
            if (e.KeyCode == Keys.F5)
            {
                //abrir busqueda de articulo
                Buscarticulo bus = new Buscarticulo();
                bus.ShowDialog();
                if (totalventa.codprodbuscado != "")
                {
                    Conexion.abrir();
                    SqlCeCommand metocodigo = new SqlCeCommand();
                    metocodigo.Parameters.AddWithValue("@cod", totalventa.codprodbuscado);
                    DataTable producto = Conexion.Consultar("idarticulo,codigoart,descripcion,marca,precio", "Articulos", "WHERE codigoart = @cod", "", metocodigo);
                    Conexion.cerrar();
                    if (producto.Rows.Count > 0)
                    {
                        int    cantidad   = 1;
                        string idproducto = producto.Rows[0][0].ToString();
                        string codigo     = producto.Rows[0][1].ToString();
                        string desc       = producto.Rows[0][2].ToString();
                        string mca        = producto.Rows[0][3].ToString();
                        float  prec       = float.Parse(producto.Rows[0][4].ToString());
                        float  total      = -prec * cantidad;
                        dataGridView1.Rows.Add(idproducto, cantidad, codigo, desc, mca, prec.ToString("$0.00"), total.ToString("$0.00"));
                        textBox4.Text = "";
                        dataGridView1.Rows[(dataGridView1.Rows.Count - 1)].Cells[1].Selected = true;
                    }
                }
            }
            if (e.KeyCode == Keys.F4 && dataGridView1.Rows.Count > 0)
            {
                //abrir busqueda de articulo
                IngreseUnidades ing = new IngreseUnidades();
                ing.ShowDialog();
                int     rowIndex = dataGridView1.CurrentCell.RowIndex;
                decimal Cantidad = totalventa.cantidad;
                float   precio   = float.Parse(dataGridView1.Rows[rowIndex].Cells[5].Value.ToString().Replace("$", ""));
                if (Cantidad > 0)
                {
                    dataGridView1.Rows[rowIndex].Cells[1].Value = Cantidad.ToString();
                    dataGridView1.Rows[rowIndex].Cells[6].Value = ((float.Parse(Cantidad.ToString()) * -precio).ToString("$0.00"));
                    chequeartotal();
                }
            }
            if (e.KeyCode == Keys.Delete)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    int rowIndex = dataGridView1.CurrentCell.RowIndex;

                    dataGridView1.Rows.Remove(dataGridView1.Rows[rowIndex]);
                }
            }
        }
Example #2
0
        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    int   rowIndex = dataGridView1.CurrentCell.RowIndex;
                    int   Cantidad = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells[1].Value);
                    float costo    = float.Parse(dataGridView1.Rows[rowIndex].Cells[7].Value.ToString().Replace("$", ""));
                    if (Cantidad > 0)
                    {
                        dataGridView1.Rows[rowIndex].Cells[1].Value = (Cantidad + 1).ToString();
                        dataGridView1.Rows[rowIndex].Cells[6].Value = ((Cantidad + 1) * costo).ToString("$0.00");
                        chequeartotal();
                    }
                }
            }
            if (e.KeyCode == Keys.Left)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    int   rowIndex = dataGridView1.CurrentCell.RowIndex;
                    int   Cantidad = Convert.ToInt32(dataGridView1.Rows[rowIndex].Cells[1].Value);
                    float costo    = float.Parse(dataGridView1.Rows[rowIndex].Cells[7].Value.ToString().Replace("$", ""));

                    if (Cantidad > 1)
                    {
                        dataGridView1.Rows[rowIndex].Cells[1].Value = (Cantidad - 1).ToString();
                        dataGridView1.Rows[rowIndex].Cells[6].Value = ((Cantidad - 1) * costo).ToString("$0.00");
                        chequeartotal();
                    }
                }
            }

            if (e.KeyCode == Keys.Up)
            {
                try
                {
                    int rowIndex = dataGridView1.CurrentCell.RowIndex;
                    dataGridView1.Rows[rowIndex - 1].Cells[1].Selected = true;
                }
                catch (Exception)
                {
                }
            }
            if (e.KeyCode == Keys.Down)
            {
                try
                {
                    int rowIndex = dataGridView1.CurrentCell.RowIndex;
                    dataGridView1.Rows[rowIndex + 1].Cells[1].Selected = true;
                }
                catch (Exception)
                {
                }
            }

            if (e.KeyCode == Keys.Enter)
            {
                if (dataGridView1.Rows.Count < 1 && textBox4.Text.Length == 0)
                {
                    MessageBox.Show("No hay ningún artículo para comprar");
                }
                if (dataGridView1.Rows.Count > 0 && textBox4.Text.Length == 0)
                {
                    DataTable dt = new DataTable(); //agarramos el gridview y le metemos los datos a un datatable.
                    //no hay forma mejor que hacerlo de esta manera porque no funciona referenciando el DT del dgridview

                    for (int i = 0; i < dataGridView1.Columns.Count; i++)
                    {
                        dt.Columns.Add("column" + i.ToString());
                    }
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        DataRow dr = dt.NewRow();
                        for (int j = 0; j < dataGridView1.Columns.Count; j++)
                        {
                            dr["column" + j.ToString()] = row.Cells[j].Value;
                        }

                        dt.Rows.Add(dr);
                    }
                    totalventa.detallecompra = dt;
                    totalventa.totcompra     = textBox5.Text;
                    totalventa.fechacompra   = dateTimePicker1.Value.ToShortDateString() + " " + dateTimePicker1.Value.ToShortTimeString();
                    Total total = new Total();
                    total.Show();
                }//mostrar la pantalla que ingresa plata clente
                if (textBox4.Text.Length > 0)
                {
                    if (comboBox1.SelectedIndex >= 0)
                    {
                        totalventa.proveedcompra = comboBox1.SelectedItem.ToString();
                        Conexion.abrir();
                        SqlCeCommand metocodigo = new SqlCeCommand();
                        metocodigo.Parameters.AddWithValue("@cod", textBox4.Text);
                        metocodigo.Parameters.AddWithValue("@pro", totalventa.proveedcompra);
                        DataTable producto = Conexion.Consultar("*", "Articulos", "WHERE codigoart = @cod and proveedor = @pro", "", metocodigo);
                        Conexion.cerrar();
                        bool yaesta = false;
                        if (producto.Rows.Count > 0)
                        {
                            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                            {
                                if (dataGridView1.Rows[i].Cells[0].Value.ToString() == producto.Rows[0][0].ToString())
                                {
                                    dataGridView1.Rows[i].Cells[1].Value = int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) + 1;
                                    dataGridView1.Rows[i].Cells[6].Value = (float.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) * float.Parse(dataGridView1.Rows[i].Cells[7].Value.ToString().Replace("$", ""))).ToString("$0.00");
                                    yaesta        = true;
                                    textBox4.Text = "";
                                    chequeartotal();
                                }
                            }
                            if (yaesta == false)
                            {
                                int    cantidad   = 1;
                                string idproducto = producto.Rows[0][0].ToString();
                                string codigo     = producto.Rows[0][1].ToString();
                                string desc       = producto.Rows[0][11].ToString();
                                string mca        = producto.Rows[0][2].ToString();
                                float  prec       = float.Parse(producto.Rows[0][4].ToString());
                                float  costo      = float.Parse(producto.Rows[0][5].ToString());
                                float  iva        = float.Parse(producto.Rows[0][6].ToString());
                                float  porcentaje = float.Parse(producto.Rows[0][12].ToString());
                                //añadir al table el costo y porcentaje y esconderlos, para asi poder hacer el porcentaje de mierda ese.
                                float total = costo * cantidad;
                                dataGridView1.Rows.Add(idproducto, cantidad, codigo, desc, mca, prec.ToString("$0.00"), total.ToString("$0.00"), costo.ToString("$0.00"), iva.ToString(), porcentaje.ToString());
                                textBox4.Text = "";
                                dataGridView1.Rows[(dataGridView1.Rows.Count - 1)].Cells[1].Selected = true;
                                //MessageBox.Show(costo.ToString() + "-" + porcentaje.ToString() );
                            }
                        }
                        else
                        {
                            MessageBox.Show("No se ha encontrado el artículo");
                            textBox4.Text = "";
                        }
                    }
                    else
                    {
                        MessageBox.Show("Debe seleccionar proveedor primero");
                        textBox4.Text = "";
                        comboBox1.Select();
                        comboBox1.DroppedDown = true;
                    }
                }//chequear si existe el codigo de ese producto y de ser asi agregarlo al DGV.
            }
            if (e.KeyCode == Keys.F5)
            {
                //abrir busqueda de articulo
                if (comboBox1.SelectedIndex >= 0)
                {
                    totalventa.proveedcompra  = comboBox1.SelectedItem.ToString();
                    totalventa.codprodbuscado = "";
                    Buscarticulo bus = new Buscarticulo();
                    bus.ShowDialog();
                    if (totalventa.codprodbuscado != "")
                    {
                        Conexion.abrir();
                        SqlCeCommand metocodigo = new SqlCeCommand();
                        metocodigo.Parameters.AddWithValue("@cod", totalventa.codprodbuscado);
                        DataTable producto = Conexion.Consultar("idarticulo,codigoart,descripcion,marca,precio,costo,iva,porcentaje", "Articulos", "WHERE codigoart = @cod", "", metocodigo);
                        Conexion.cerrar();
                        bool yaesta = false;
                        if (producto.Rows.Count > 0)
                        {
                            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                            {
                                if (dataGridView1.Rows[i].Cells[0].Value.ToString() == producto.Rows[0][0].ToString())
                                {
                                    dataGridView1.Rows[i].Cells[1].Value = int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) + 1;
                                    dataGridView1.Rows[i].Cells[6].Value = (float.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) * float.Parse(dataGridView1.Rows[i].Cells[7].Value.ToString().Replace("$", ""))).ToString("$0.00");
                                    yaesta        = true;
                                    textBox4.Text = "";
                                    chequeartotal();
                                }
                            }
                            if (yaesta == false)
                            {
                                int    cantidad   = 1;
                                string idproducto = producto.Rows[0][0].ToString();
                                string codigo     = producto.Rows[0][1].ToString();
                                string desc       = producto.Rows[0][2].ToString();
                                string mca        = producto.Rows[0][3].ToString();
                                float  prec       = float.Parse(producto.Rows[0][5].ToString());
                                float  total      = prec * cantidad;
                                float  costo      = float.Parse(producto.Rows[0][5].ToString());
                                float  iva        = float.Parse(producto.Rows[0][6].ToString());
                                float  porcentaje = float.Parse(producto.Rows[0][7].ToString());
                                dataGridView1.Rows.Add(idproducto, cantidad, codigo, desc, mca, prec.ToString("$0.00"), total.ToString("$0.00"), costo.ToString("$0.00"), iva.ToString(), porcentaje.ToString());
                                textBox4.Text = "";
                                dataGridView1.Rows[(dataGridView1.Rows.Count - 1)].Cells[1].Selected = true;
                                chequeartotal();
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Para cargar articulos, debe seleccionar un proveedor");
                    comboBox1.DroppedDown = true;
                }
            }
            if (e.KeyCode == Keys.F4 && dataGridView1.Rows.Count > 0)
            {
                //abrir busqueda de articulo
                IngreseUnidades ing = new IngreseUnidades();
                ing.ShowDialog();
                int     rowIndex = dataGridView1.CurrentCell.RowIndex;
                decimal Cantidad = totalventa.cantidad;
                float   costo    = float.Parse(dataGridView1.Rows[rowIndex].Cells[7].Value.ToString().Replace("$", ""));
                if (Cantidad > 0)
                {
                    dataGridView1.Rows[rowIndex].Cells[1].Value = Cantidad.ToString();
                    dataGridView1.Rows[rowIndex].Cells[6].Value = ((float.Parse(Cantidad.ToString()) * costo).ToString("$0.00"));
                    chequeartotal();
                }
            }
            if (e.KeyCode == Keys.F3 && dataGridView1.Rows.Count > 0)
            {
                //abrir busqueda de articulo
                IngreseMonto ing = new IngreseMonto();
                ing.ShowDialog();
                int   rowIndex = dataGridView1.CurrentCell.RowIndex;
                float Monto    = totalventa.montocompra;

                if (Monto > 0)
                {
                    float Cantidad = float.Parse(dataGridView1.Rows[rowIndex].Cells[1].Value.ToString());
                    dataGridView1.Rows[rowIndex].Cells[6].Value = ((Cantidad * Monto).ToString("$0.00"));
                    dataGridView1.Rows[rowIndex].Cells[7].Value = Monto.ToString("$0.00");
                    chequeartotal();
                }
            }
            if (e.KeyCode == Keys.Delete)
            {
                if (dataGridView1.Rows.Count > 0)
                {
                    int rowIndex = dataGridView1.CurrentCell.RowIndex;

                    dataGridView1.Rows.Remove(dataGridView1.Rows[rowIndex]);
                }
            }
        }