Exemplo n.º 1
0
        private void txtID_Validated(object sender, EventArgs e)
        {
            if (this.txtID.Text.Trim() == "" || this.txtID.Text == "Nueva")
            {
                this.txtID.Text = "Nueva";
                cotizacionesDS.ProductosDT.Rows.Clear();
                cotizacionesDS.DocumentosDT.Rows.Clear();
                chkActivo.Checked     = true;
                chkVendida.Checked    = false;
                txtFecha.Text         = DateTime.Now.ToString();
                txtNombre.Text        = "";
                txtTotal.Text         = "0.00";
                txtNombreCliente.Text = "";
                txtIDCliente.Text     = "";
                Client = null;
                btnAgregarProducto.Visible  = true;
                btnAgregarDocumento.Visible = true;
            }
            else
            {
                int id = 0;
                if (!int.TryParse(this.txtID.Text.Trim(), out id))
                {
                    MessageBox.Show("El id no es un valor entero.", "Usuarios", MessageBox.Botones.Aceptar);
                    Limpiar();
                    return;
                }
                Quotation quotation = Quotations.GetQuotation(id);
                if (quotation == null)
                {
                    MessageBox.Show("La cotización no existe.", "Usuarios", MessageBox.Botones.Aceptar);
                    Limpiar();
                }
                else
                {
                    cotizacionesDS.ProductosDT.Rows.Clear();
                    cotizacionesDS.DocumentosDT.Rows.Clear();
                    txtFecha.Text         = quotation.date.ToString();
                    chkActivo.Checked     = quotation.active;
                    chkVendida.Checked    = quotation.sold;
                    txtNombre.Text        = quotation.name;
                    txtTotal.Text         = quotation.total.ToString();
                    txtIDCliente.Text     = quotation.Cliente.idClient.ToString();
                    txtNombreCliente.Text = quotation.Cliente.name;
                    Client = quotation.Cliente;
                    foreach (QuotationProduct quotationProduct in quotation.CotizacionesProductos)
                    {
                        cotizacionesDS.ProductosDT.AddProductosDTRow(quotationProduct.idProduct, quotationProduct.row, quotationProduct.Producto.name, quotationProduct.quantity, quotationProduct.price);
                    }

                    foreach (Document document in quotation.Documentos)
                    {
                        cotizacionesDS.DocumentosDT.AddDocumentosDTRow(document.id, document.description, document.dataFile);
                    }
                    btnAgregarProducto.Visible  = false;
                    btnAgregarDocumento.Visible = false;
                }
            }
        }