private void Btn_Guardar_Click(object sender, EventArgs e) { if (Txt_Cedula.Text.Trim() == "") { MessageBox.Show("Proporcione la cédula"); Txt_Cedula.Focus(); return; } if (Txt_Cliente.Text.Trim() == "") { MessageBox.Show("Proporcione el cliente"); Txt_Cliente.Focus(); return; } if (detallesProductos.Count == 0) { MessageBox.Show("Debe de agregar productos al listado"); Txt_Codigo.Focus(); return; } decimal total = 0; decimal.TryParse(Txt_Total.Text.Replace(",", ""), out total); if (total <= 0) { MessageBox.Show("El importe total no puede ser cero ni menor que cero"); Txt_Codigo.Focus(); return; } Alta_Factura(); }
private void limpiar() { Txt_Cedula.Text = ""; Txt_Nombre.Text = ""; Txt_Apellido.Text = ""; Txt_Fijo.Text = ""; Txt_Celular.Text = ""; newDatos = true; Txt_Cedula.Focus(); }
private async void Alta_Factura() { this.Cursor = Cursors.WaitCursor; typeFactura factura = new typeFactura(); factura.Fecha = Dtp_Fecha.Value; factura.Cedula = Txt_Cedula.Text.Trim(); factura.Cliente = Txt_Cliente.Text.Trim(); decimal Subtotal = 0; decimal.TryParse(Txt_Subtotal.Text.Replace(",", ""), out Subtotal); factura.Subtotal = Subtotal; decimal Descuento = 0; decimal.TryParse(Txt_Descuento.Text.Replace(",", ""), out Descuento); factura.Descuento = Descuento; decimal Total = 0; decimal.TryParse(Txt_Total.Text.Replace(",", ""), out Total); factura.Total = Total; factura.Detalles = detallesProductos; using (var client = new HttpClient()) { var serializedProduct = JsonConvert.SerializeObject(factura); var content = new StringContent(serializedProduct, Encoding.UTF8, "application/json"); using (var response = await client.PostAsync(Globales.Url_API + "facturacion/agregafactura", content)) { if (response.IsSuccessStatusCode) { var a = response.Content.ReadAsStringAsync(); var contents = JsonConvert.DeserializeObject <typeResponse>(response.Content.ReadAsStringAsync().Result); Txt_Numero_Comprobante.Text = contents.Message; DsFactura dsFactura = new DsFactura(); DataRow Registro; Registro = dsFactura.Tables["Encabezado"].NewRow(); Registro["Numero_Documento"] = Txt_Numero_Comprobante.Text; Registro["Fecha"] = Dtp_Fecha.Value; Registro["Cedula"] = Txt_Cedula.Text; Registro["Cliente"] = Txt_Cliente.Text; Registro["SubTotal"] = Subtotal; Registro["Descuento"] = Descuento; Registro["Total"] = Total; dsFactura.Tables["Encabezado"].Rows.Add(Registro); foreach (var detalle in detallesProductos) { Registro = dsFactura.Tables["Detalles"].NewRow(); Registro["Cantidad"] = detalle.Cantidad; Registro["Codigo"] = detalle.Codigo; Registro["Nombre"] = detalle.Nombre; Registro["Precio"] = detalle.Precio; Registro["Importe"] = detalle.Importe; dsFactura.Tables["Detalles"].Rows.Add(Registro); } FrmVisorReporte frm = new FrmVisorReporte(); ReportDocument rpt = new ReportDocument(); rpt.Load(AppDomain.CurrentDomain.BaseDirectory + "\\Reportes\\RptFormatoFactura.rpt"); rpt.SetDataSource(dsFactura); frm.crViewer.ReportSource = rpt; frm.crViewer.RefreshReport(); frm.Show(); this.Cursor = Cursors.Default; MessageBox.Show("Factura registrada"); Dtp_Fecha.Value = DateTime.Now; Txt_Numero_Comprobante.Text = "Consecutivo se obtiene al guardar"; Txt_Cedula.Text = ""; Txt_Cliente.Text = ""; Txt_Subtotal.Text = "0.00"; Txt_Descuento.Text = "0.00"; Txt_Total.Text = "0.00"; detallesProductos.Clear(); Grid_Productos.DataSource = null; Grid_Productos.DataSource = detallesProductos; Txt_Codigo.Text = ""; Txt_Cedula.Focus(); } else { this.Cursor = Cursors.Default; var contents = JsonConvert.DeserializeObject <typeResponse>(response.Content.ReadAsStringAsync().Result); MessageBox.Show(contents.Message); } } } }