示例#1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (txtNombre.Text.Trim() == "")
            {
                MessageBox.Show("Escriba la descripción.", "Verifique", MessageBox.Botones.Aceptar);
                return;
            }
            if (cotizacionesDS.ProductosDT.Rows.Count == 0)
            {
                MessageBox.Show("Debe capturar al menos un producto", "Verifique", MessageBox.Botones.Aceptar);
                return;
            }
            if (Client == null)
            {
                MessageBox.Show("Capture el cliente", "Verifique", MessageBox.Botones.Aceptar);
                return;
            }
            if ((txtID.Text.Trim() == "" || txtID.Text == "Nueva"))
            {
                Quotation quotation = new Quotation();
                quotation.name     = txtNombre.Text.Trim();
                quotation.idClient = Client.idClient;
                quotation.sold     = chkVendida.Checked;
                quotation.active   = chkActivo.Checked;
                quotation.total    = decimal.Parse(txtTotal.Text);

                foreach (CotizacionesDS.ProductosDTRow row in cotizacionesDS.ProductosDT)
                {
                    QuotationProduct quotationProduct = new QuotationProduct();
                    quotationProduct.price     = row.precio;
                    quotationProduct.idProduct = row.idProducto;
                    quotationProduct.row       = row.renglon;
                    quotationProduct.quantity  = row.cantidad;
                    quotation.QuotationsProducts.Add(quotationProduct);
                }

                foreach (CotizacionesDS.DocumentosDTRow row in cotizacionesDS.DocumentosDT)
                {
                    Quotations.AgregarDocumento(ref quotation, row);
                }

                Quotations.CrearCotizacion(quotation);

                MessageBox.Show("Cotización creada correctamente.", "Usuario", MessageBox.Botones.Aceptar);
                Limpiar();
            }
            else
            {
                int id = 0;
                if (int.TryParse(txtID.Text.Trim(), out id) && id != 0)
                {
                    Quotation quotation = new Quotation();
                    quotation.id     = id;
                    quotation.sold   = chkVendida.Checked;
                    quotation.active = chkActivo.Checked;
                    Quotations.ActualizarCotizacion(quotation);
                    MessageBox.Show("Cotización Actualizada correctamente.", "Usuario", MessageBox.Botones.Aceptar);
                    Limpiar();
                }
            }
        }