コード例 #1
0
        public void llenaCampos()
        {
            txtNombre.Text = p.getNombre();
            txtPrecio.Text = p.getPrecio();
            txtStock.Text  = p.getStock();
            //cbTipo1.SelectedText = p.getT1().ToUpper();
            //cbTipo2.SelectedText = p.getT2().ToUpper();

            //Producto pro = new Producto();
            //String t1Texto = pro.getGestor().getUnString("select id from productos_tipo1 where tipo = '" + cbTipo1.SelectedItem.ToString() + "'");
            //String t2Texto = pro.getGestor().getUnString("select id from productos_tipo2 where tipo = '" + cbTipo2.SelectedItem.ToString() + "'");
            //int t1 = Int16.Parse(t1Texto);
            //int t2 = Int16.Parse(t2Texto);
        }
コード例 #2
0
        private void btnAñadir_Click(object sender, EventArgs e)
        {
            this.t = 0;
            Pedido o     = new Pedido();
            int    stock = (prod != null) ? Int32.Parse(o.getGestor().getUnString("Select stock from productos where id_producto=" + prod.getId())) : -1;

            if (nudAmount.Value <= stock && stock != -1)
            {
                if (!String.IsNullOrEmpty(txtProduct.Text.Replace("'", "")))
                {
                    bool seguir = true;

                    for (int i = 0; i < dgvNuevoPedido.RowCount && seguir; i++)
                    {
                        if (dgvNuevoPedido.RowCount > 0)
                        {
                            String nombre = dgvNuevoPedido.Rows[i].Cells[0].Value.ToString();
                            int    amount = Int32.Parse(dgvNuevoPedido.Rows[i].Cells[1].Value.ToString());

                            if (String.Equals(nombre, txtProduct.Text.Replace("'", "")))
                            {
                                seguir = false;
                                int newamount = amount + Int32.Parse(nudAmount.Value.ToString());
                                dgvNuevoPedido.Rows[i].Cells[1].Value = newamount;
                                for (int j = 0; j < dgvNuevoPedido.RowCount; j++)
                                {
                                    this.t = this.t + (float.Parse(dgvNuevoPedido.Rows[j].Cells[1].Value.ToString()) * float.Parse(dgvNuevoPedido.Rows[j].Cells[2].Value.ToString()));
                                }
                                Math.Round(t, 2);
                                txtTotal.Text = Convert.ToString(t);
                                dgvNuevoPedido.ClearSelection();
                                txtProduct.Text = "";
                            }
                        }
                    }
                    if (seguir)
                    {
                        dgvNuevoPedido.Rows.Add(txtProduct.Text.Replace("'", ""), nudAmount.Value.ToString().Replace("'", ""), prod.getPrecio().Replace("'", ""));

                        for (int i = 0; i < dgvNuevoPedido.RowCount; i++)
                        {
                            this.t = this.t + (float.Parse(dgvNuevoPedido.Rows[i].Cells[1].Value.ToString()) * float.Parse(dgvNuevoPedido.Rows[i].Cells[2].Value.ToString()));
                        }
                        Math.Round(t, 2);
                        txtTotal.Text = Convert.ToString(t);
                        dgvNuevoPedido.ClearSelection();
                        txtProduct.Text = "";
                    }
                }
                else
                {
                    MessageBox.Show("Debes seleccionar un producto", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (stock != -1)
                {
                    MessageBox.Show("No queda stock suficiente de este producto", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Debes seleccionar un producto", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }