private void button1_Click_1(object sender, EventArgs e) { //try //{ SistemaInventarioDatos sd = new SistemaInventarioDatos(); char delimitador = '-'; bool vacia = ValidarBodegaVacia(); if (vacia == false) { foreach (DataGridViewRow fila in dgw_entradas.Rows) { //desaparecer orden if (fila.Cells["Codigo"].Value != null) { //------------OBTENER BODEGA, CANTIDAD Y BIEN int cantidad = Convert.ToInt32(fila.Cells["Cant_recibida"].Value); //string bodega = fila.Cells["bodega"].Value.ToString(); DataGridViewComboBoxCell CboBodega = fila.Cells["bodega"] as DataGridViewComboBoxCell; string bodega = CboBodega.Value.ToString(); //string codigo = fila.Cells["Descripcion"].Value.ToString(); DataGridViewComboBoxCell CboBienes = fila.Cells["Descripcion"] as DataGridViewComboBoxCell; string codigo = CboBienes.Value.ToString(); string[] codigo_separado = codigo.Split(delimitador); string categoria = codigo_separado[0].Trim(); string id_bien = codigo_separado[1].Trim(); //-----------VALIDAR SI YA EXISTE LA TUPLA int y = sd.ValidarExistenciaDeProducto(id_bien, categoria, bodega); if (y == 1) { int existencias = sd.ObtenerExistenciasEnBodega(id_bien, categoria, bodega); int nueva_existencia = existencias + cantidad; sd.ActualizarExistenciasEnBodega(id_bien, categoria, bodega, nueva_existencia); } else { sd.InsertarProductoEnBodega(id_bien, categoria, bodega, cantidad); } } } MessageBox.Show("Orden ingresada con exito"); if (radioButton2.Checked) { //<<<<<<<<<<<<<<INGRESAR DOCUMENTO<<<<<<<<<<<<<<<<<<<<< //ENC string id_orden = cbo_orden.SelectedValue.ToString(); DataTable dt_orden = sd.ObtenerDatosOrdenDeCompra(id_orden); DataRow rowk = dt_orden.Rows[0]; string proveedor = rowk[0].ToString(); DateTime fecha = Convert.ToDateTime(rowk[1]); string fechaS = fecha.ToString("yyyy-MM-dd"); string empresa = rowk[2].ToString(); sd.InsertarDocInv(id_orden, fechaS, empresa, proveedor); //DET IngresarDetalleOrden(id_orden, empresa); //<<<<<<<<<<<<REGISTRAR MOVIMIENTO<<<<<<<<<<<<<<<<<<<<< RegistrarMovimiento(id_orden, empresa); //<<<<<<<DESAPARECER ORDEN<<<<<<< sd.OrdenProcesada(id_orden); cbo_orden.DataSource = sd.ObtenerOrden(); /*OC*/ cbo_orden.ValueMember = "id_factura_compra_pk"; cbo_orden.DisplayMember = "id_factura_compra_pk"; } } else { MessageBox.Show("Debe seleccionar una ubicación (bodega) para todos los productos"); } //} //catch(Exception ex) { MessageBox.Show(ex.Message); } }
private void btn_crear_Click(object sender, EventArgs e) { //crear la venta, crear la factura y registrarlas //try //{ SistemaInventarioDatos sd = new SistemaInventarioDatos(); char delimitador = '-'; string bodega = cbo_bodega.SelectedValue.ToString(); bool y = ValidarExistenciaProd(); if (y == true) { bool x = ValidarCantidadDelProducto(); if (x == true) { foreach (DataGridViewRow fila in dgw_requisicion.Rows) { if (fila.Cells["Codigo"].Value != null) { //------------OBTENER CANTIDAD Y BIEN int cantidad = Convert.ToInt32(fila.Cells["Cant_devuelta"].Value); DataGridViewComboBoxCell CboBienes = fila.Cells["Descripcion"] as DataGridViewComboBoxCell; string codigo = CboBienes.Value.ToString(); string[] codigo_separado = codigo.Split(delimitador); string categoria = codigo_separado[0].Trim(); string id_bien = codigo_separado[1].Trim(); int existencias = sd.ObtenerExistenciasEnBodega(id_bien, categoria, bodega); int nueva_existencia = existencias - cantidad; sd.ActualizarExistenciasEnBodega(id_bien, categoria, bodega, nueva_existencia); //0000000000000000000000000000000000000 } } SumarFactura(); MessageBox.Show("factura procesada con exito"); //----INSERTAR ENCABEZADO string nit = txt_nit.Text.Trim(); DateTime f = Convert.ToDateTime(dtp_fecha_dev.Value); string fecha = f.ToString("yyyy-MM-dd"); string nombre = txt_nom_cliente.Text.Trim(); string apellido = txt_apellido_cliente.Text.Trim(); string direccion = txt_direccion.Text.Trim(); sd.InsertarFacturaEncabezado(nit, nombre, apellido, direccion); //--DETALLE int id_fac = sd.ObtenerUltimaFact(); InsertarDetalleDevolucion(id_fac); //--INSERTAR DOC INV sd.InsertarDocInvDin(id_fac.ToString(), "-", "Factura", fecha, "-", "procesado", "0"); //--DETALLE DOC INV InsertarDetalleDocInv(id_fac); //--REGISTRAR MOV RegistrarMovimiento(id_fac); } else { MessageBox.Show("Hay menos existenicas de las que pretende vender"); } } else { MessageBox.Show("Alguno de los productos de la factura no existe en la bodega indicada"); } //} //catch { MessageBox.Show("No se pudo realizar la devolución"); } }