//Guardar datos de factura, cliente y detalle factura private void btn_guardar_Click(object sender, EventArgs e) { try { Factura fac = new Factura(); CapaDatos nuev = new CapaDatos(); //formato para los datatimepicker dtp_fecha.Format = DateTimePickerFormat.Custom; dtp_fecha.CustomFormat = "yyyy-MM-dd"; if (!String.IsNullOrEmpty(txt_nombre.Text.Trim()) && !String.IsNullOrEmpty(txt_apellido.Text.Trim()) && cmb_pago.SelectedIndex != -1) { CapaDatos db = new CapaDatos(); //Manejo db = new Manejo(); string formaPago = cmb_pago.SelectedItem.ToString(); double sumaTotal = Convert.ToDouble(txt_total.Text.Trim()); int IdCliente = Convert.ToInt32(txt_temporal.Text.Trim()); string empleados = Convert.ToString(cmb_empleado.SelectedValue.ToString()); string BodegaID = Convert.ToString(cmb_bodega.SelectedValue.ToString()); db.GuardarFacturaEncabezado(dtp_fecha.Text.Trim(), formaPago, sumaTotal, IdCliente, empleados, BodegaID); int codigoAutoIncrement = CapaDatos.ConsultaUatoIncrementFactura(); CapaDatos v = new CapaDatos(); /*DataTable dt1 = CapaDatos.CargarGridAutoIncrement("select AUTO_INCREMENT from information_schema.TABLES where TABLE_SCHEMA='prueba' and TABLE_NAME='factura_encabezado';"); DataRow rows = dt1.Rows[0]; int codigoObtenido = Convert.ToInt32(rows[0]);*/ int MiBodega2 = Convert.ToInt32(BodegaID); foreach (DataGridViewRow row in dgv_facturaDetalle.Rows) { int codigo_facturaM = codigoAutoIncrement - 1; int codigo_productoM = Convert.ToInt32(row.Cells[0].Value); int idMarca = Convert.ToInt32(row.Cells[2].Value); int Existencia2 = Convert.ToInt32(CapaDatos.ConsultaExistenciav1(Convert.ToString(codigo_productoM), BodegaID)); int cantidadM = Convert.ToInt32(row.Cells[4].Value); int existenciaNueva = Existencia2 - cantidadM; double precioM = Convert.ToDouble(row.Cells[5].Value); double subtotalM = Convert.ToDouble(row.Cells[6].Value); v.ActualziarExistencia(existenciaNueva, codigo_productoM, idMarca, MiBodega2); v.insertar_detalle_factura(codigo_facturaM, codigo_productoM, idMarca, cantidadM, precioM, subtotalM); } //termina mi foreach MessageBox.Show("Se Actualizo Existencia"); } if (chb_habilita.Checked) { CapaDatos nuevo = new CapaDatos(); string temporales = cmb_cotizaciones.SelectedValue.ToString(); nuevo.ActualizaEstadoPedidoCotizacion(temporales); } MessageBox.Show(" Se Guardo Factura Exitosamente "); this.Close(); } catch { MessageBox.Show("Error al Guardar datos de insercion"); } }
//Guardar datos de factura, cliente y detalle factura private void btn_guardar_Click(object sender, EventArgs e) { try { //formato para los datatimepicker dtp_fecha.Format = DateTimePickerFormat.Custom; dtp_fecha.CustomFormat = "yyyy-MM-dd"; if (!String.IsNullOrEmpty(txt_nombre.Text.Trim()) && !String.IsNullOrEmpty(txt_apellido.Text.Trim()) && !String.IsNullOrEmpty(txt_direccion.Text.Trim()) && !String.IsNullOrEmpty(txt_telefono.Text.Trim()) && cmb_pago.SelectedIndex != -1) { CapaDatos db = new CapaDatos(); //Manejo db = new Manejo(); string temp = cmb_pago.SelectedItem.ToString(); double temp1 = Convert.ToDouble(txt_total.Text.Trim()); int temp3 = Convert.ToInt32(txt_temporal.Text.Trim()); db.GuardarFacturaEncabezado(dtp_fecha.Text.Trim(), temp, temp1, temp3); CapaDatos v = new CapaDatos(); DataTable dt1 = CapaDatos.CargarGridAutoIncrement("select AUTO_INCREMENT from information_schema.TABLES where TABLE_SCHEMA='crmbd' and TABLE_NAME='factura_encabezado';"); DataRow rows = dt1.Rows[0]; int id_req = Convert.ToInt32(rows[0]); foreach (DataGridViewRow row in dgv_facturaDetalle.Rows) { int codigo_facturaM = id_req - 1; int codigo_productoM = Convert.ToInt32(row.Cells[0].Value); int cantidadM = Convert.ToInt32(row.Cells[3].Value); double subtotalM = Convert.ToDouble(row.Cells[4].Value); v.insertar_detalle_factura(codigo_facturaM, codigo_productoM, cantidadM, subtotalM); } //termina mi foreach } if (chb_habilita.Checked) { CapaDatos nuevo = new CapaDatos(); string temporales = cmb_cotizaciones.SelectedValue.ToString(); nuevo.ActualizaEstadoPedidoCotizacion(temporales); } } catch { MessageBox.Show("Error al Guardar datos de insercion"); } }