private void btnGuardar_Click(object sender, EventArgs e) { if (cbOficinas.Text == "") { MessageBox.Show("Seleccione una sucursal", "Sucursal", MessageBoxButtons.OK, MessageBoxIcon.Error); cbOficinas.Focus(); } else { if (recuperado == false) { Models.Transfers transferencia = new Models.Transfers(); using (transferencia) { transferencia.Folio = Convert.ToInt16(txtFolios.Text); transferencia.Tipo_trapaso = "E"; transferencia.Sucursal = cbOficinas.SelectedValue.ToString(); transferencia.Subtotal = Convert.ToDouble(txtSubtotal.Text); transferencia.Iva = 0; transferencia.Total = 0; transferencia.Facturado = Convert.ToInt16(false); transferencia.CreateTransfer(); List <Models.Transfers> ultimo = transferencia.getTransferbyfolio(Convert.ToInt16(txtFolios.Text), "E"); Models.Det_transfers detalles = new Models.Det_transfers(); using (detalles) { detalles.Folio = Convert.ToInt16(txtFolios.Text); detalles.Tipo = "E"; Models.Product poductos = new Models.Product(); foreach (DataGridViewRow row in dtProductos.Rows) { detalles.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalles.Id_producto = Convert.ToInt16(row.Cells["id"].Value.ToString()); detalles.Precio = Convert.ToDouble(row.Cells["p_u"].Value.ToString()); detalles.CreateDet(); using (poductos) { List <Models.Product> producto = poductos.getProductById(Convert.ToInt16(row.Cells["id"].Value.ToString())); Models.Kardex kardex = new Models.Kardex(); using (kardex) { kardex.Id_producto = Convert.ToInt16(row.Cells["id"].Value.ToString()); kardex.Tipo = "T"; kardex.Id_documento = ultimo[0].Id; kardex.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); kardex.Antes = producto[0].Existencia; kardex.CreateKardex(); List <Models.Kardex> ultimo_kardez = kardex.getidKardex(Convert.ToInt16(row.Cells["id"].Value.ToString()), ultimo[0].Id, "T"); Models.Afecta_inv afecta = new Models.Afecta_inv(); using (afecta) { afecta.Disminuye(ultimo_kardez[0].Id); } } } } } } Models.Folios folio = new Models.Folios(); using (folio) { folio.Transferencia = (Convert.ToInt16(txtFolios.Text) + 1); folio.savenewTransfer(); } } else { Models.Transfers transferencia = new Models.Transfers(); using (transferencia) { transferencia.Folio = Convert.ToInt32(txtFolios.Text); transferencia.Tipo_trapaso = "E"; transferencia.Sucursal = cbOficinas.SelectedValue.ToString(); transferencia.Subtotal = Convert.ToDouble(txtSubtotal.Text); transferencia.Iva = 0; transferencia.Total = 0; transferencia.Facturado = Convert.ToInt16(false); transferencia.updateTrasfer(); } Models.Det_transfers detalles = new Models.Det_transfers(); using (detalles) { detalles.Folio = Convert.ToInt32(txtFolios.Text); detalles.delete_det(); detalles.Folio = Convert.ToInt16(txtFolios.Text); detalles.Tipo = "E"; Models.Product poductos = new Models.Product(); foreach (DataGridViewRow row in dtProductos.Rows) { detalles.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalles.Id_producto = Convert.ToInt16(row.Cells["id"].Value.ToString()); detalles.Precio = Convert.ToDouble(row.Cells["p_u"].Value.ToString()); detalles.CreateDet(); using (poductos) { List <Models.Product> producto = poductos.getProductById(Convert.ToInt16(row.Cells["id"].Value.ToString())); Models.Kardex kardex = new Models.Kardex(); using (kardex) { kardex.Id_producto = Convert.ToInt16(row.Cells["id"].Value.ToString()); kardex.Tipo = "T"; kardex.Id_documento = id_transfer; kardex.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); kardex.Antes = producto[0].Existencia; kardex.CreateKardex(); List <Models.Kardex> ultimo_kardez = kardex.getidKardex(Convert.ToInt16(row.Cells["id"].Value.ToString()), id_transfer, "T"); Models.Afecta_inv afecta = new Models.Afecta_inv(); using (afecta) { afecta.Disminuye(ultimo_kardez[0].Id); } } } } } } Models.Configuration configuracion = new Models.Configuration(); int cuantos = dtProductos.RowCount; int faltantes = 0; int valor; using (configuracion) { faltantes = cuantos - 1; valor = 110 * faltantes; valor = valor + 1150; PaperSize ps = new PaperSize("Custom", 300, valor); List <Models.Configuration> config = configuracion.getConfiguration(); printDocument1.DefaultPageSettings.PaperSize = ps; printDocument1.PrinterSettings.PrinterName = config[0].Impresora; printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage); printDocument1.Print(); } this.Close(); } }
private void button2_Click(object sender, EventArgs e) { bool valido = true; foreach (DataGridViewRow row in dtProductos.Rows) { if (row.DefaultCellStyle.BackColor.Name.ToString() == "Red") { valido = false; } } if (valido == false) { Autenficiar auto = new Autenficiar(); Autenficiar.origen = "Compras"; auto.ShowDialog(); Models.Log historial = new Models.Log(); using (historial) { foreach (DataGridViewRow row in dtProductos.Rows) { if (row.DefaultCellStyle.BackColor.Name.ToString() == "Red") { historial.Id_usuario = Autorizo; historial.Descripcion = "autorizo el ingreso de la compra de " + row.Cells["descripcion"].Value.ToString() + " que llego mas caro "; historial.createLog(); } } } valido = true; } if (valido == true) { int dias = 0; string fecha_credito = "0000-00-00"; string pagado = "SI"; if (chkContado.Checked != true) { dias = Convert.ToInt16(txtdias.Text); fecha_credito = dtVencimiento.Text; pagado = "NO"; } Models.Compras compra = new Models.Compras( 0, txtFolio.Text, dtFecha.Text, dtFechaDoc.Text, txtNumero.Text, "A", dias, fecha_credito, pagado, Convert.ToDouble(txtSubtotal.Text), Convert.ToDouble(txtiva.Text), Convert.ToDouble(txttotal.Text), Convert.ToDouble(txtdescuento.Text), dtRecepcion.Text, Autorizo ); using (compra) { compra.crateCompra(); Models.Log historial = new Models.Log(); using (historial) { historial.Id_usuario = Convert.ToInt32(Inicial.id_usario); historial.Descripcion = "agrego la compra " + txtFolio.Text + "del proveedor " + cbProveedor.Text + " por $ " + txttotal.Text; historial.createLog(); } List <Models.Compras> resultado = compra.GetlastCompras(dtFecha.Text, dtFechaDoc.Text, txtNumero.Text, Convert.ToDouble(txttotal.Text)); Models.Purchases detalles = new Models.Purchases(); detalles.Id = 0; detalles.Id_compra = resultado[0].Id; Models.Kardex kardex = new Models.Kardex(); Models.Product producto = new Models.Product(); Models.Afecta_inv afecta = new Models.Afecta_inv(); Models.Caducidades Caducida = new Models.Caducidades(); Models.prov_prod costos = new Models.prov_prod(); Caducida.Id = 0; Caducida.Id_compra = resultado[0].Id; double nuevo = 0; foreach (DataGridViewRow row in dtProductos.Rows) { using (producto) { List <Models.Product> prod = producto.getProductById(Convert.ToInt16(row.Cells["id_producto"].Value.ToString())); nuevo = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); while (prod[0].Parent != "0") { nuevo = nuevo * Convert.ToInt16(prod[0].C_unidad); prod = producto.getProductById(Convert.ToInt16(prod[0].Parent)); } detalles.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalles.Id_producto = Convert.ToInt32(row.Cells["id_producto"].Value.ToString()); detalles.P_u = Convert.ToDouble(row.Cells["p_u"].Value.ToString()); detalles.Total = Convert.ToDouble(row.Cells["total"].Value.ToString()); using (detalles) { using (costos) { List <Models.prov_prod> cost = costos.get_costobyproveedorandprodu(Convert.ToInt32(row.Cells["id_producto"].Value.ToString()), Convert.ToInt32(txtNumero.Text)); if (cost.Count > 0) { costos.Id_producto = Convert.ToInt32(row.Cells["id_producto"].Value.ToString()); costos.Id_proveedor = Convert.ToInt32(txtNumero.Text); costos.Cantidad = cost[0].Cantidad; costos.Costo = Convert.ToDouble(row.Cells["p_u"].Value.ToString()); costos.update_from_compra(); } else { costos.Id_producto = Convert.ToInt32(row.Cells["id_producto"].Value.ToString()); costos.Id_proveedor = Convert.ToInt32(txtNumero.Text); costos.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); costos.Costo = Convert.ToDouble(row.Cells["p_u"].Value.ToString()); costos.create(); } } detalles.createPurchases(); if (row.Cells["lote"].Value.ToString() != "") { Caducida.Id_producto = prod[0].Id; Caducida.Caducidad = row.Cells["caducidad"].Value.ToString(); Caducida.Lote = row.Cells["lote"].Value.ToString(); Caducida.Cantidad = nuevo; using (caducidad) { Caducida.createCaducidad(); } } kardex.Fecha = Convert.ToDateTime(dtFecha.Text).ToString(); kardex.Id_producto = prod[0].Id; kardex.Tipo = "C"; kardex.Cantidad = nuevo; kardex.Antes = prod[0].Existencia; kardex.Id = 0; kardex.Id_documento = Convert.ToInt16(resultado[0].Id); using (kardex) { kardex.CreateKardex(); List <Models.Kardex> numeracion = kardex.getidKardex(prod[0].Id, Convert.ToInt16(resultado[0].Id), "C"); using (afecta) { afecta.Agrega(numeracion[0].Id); } } } } } } foreach (DataGridViewRow row in dtDocumentos.Rows) { Models.Ordenes_compra ordenes = new Models.Ordenes_compra(); using (ordenes) { ordenes.Id = Convert.ToInt32(row.Cells["documento"].Value.ToString()); ordenes.Terminado = true; ordenes.termina_orden(); } } this.Close(); } }
private void btnGuardar_Click(object sender, EventArgs e) { Models.Ajuste ajutes = new Models.Ajuste( 0, dtFecha.Text + " 00:00:00", Convert.ToDouble(txtTotal.Text), "", "A" ); using (ajutes) { ajutes.createAjuste(); List <Models.Ajuste> general = ajutes.getlastAjustes(dtFecha.Text + " 00:00:00", Convert.ToDouble(txtTotal.Text)); Models.det_ajustes detalle = new Models.det_ajustes(); detalle.Id = 0; detalle.Id_ajuste = general[0].Id; Models.Kardex kardex = new Models.Kardex(); Models.Product producto = new Models.Product(); Models.Afecta_inv afecta = new Models.Afecta_inv(); double nuevo = 0; folio = general[0].Id.ToString(); foreach (DataGridViewRow row in dtProductos.Rows) { detalle.Id_producto = Convert.ToInt16(row.Cells["id_producto"].Value.ToString()); detalle.P_u = Convert.ToDouble(row.Cells["costo"].Value.ToString()); detalle.Cantidad = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); detalle.Total = Convert.ToDouble(row.Cells["total"].Value.ToString()); using (detalle) { detalle.craeteDet_ajuste(); using (producto) { Models.Log historia = new Models.Log(); using (historia) { historia.Id_usuario = Convert.ToInt32(Inicial.id_usario); historia.Descripcion = "se ajusto el inventario del producto " + row.Cells["descripcion"].Value.ToString(); historia.createLog(); } List <Models.Product> prod = producto.getProductById(Convert.ToInt16(row.Cells["id_producto"].Value.ToString())); nuevo = Convert.ToDouble(row.Cells["cantidad"].Value.ToString()); while (prod[0].Parent != "0") { nuevo = nuevo * Convert.ToDouble(prod[0].C_unidad); prod = producto.getProductById(Convert.ToInt16(prod[0].Parent)); } kardex.Fecha = Convert.ToDateTime(dtFecha.Text).ToString(); kardex.Id_producto = prod[0].Id; kardex.Tipo = "A"; kardex.Cantidad = nuevo; kardex.Antes = prod[0].Existencia; kardex.Id = 0; kardex.Id_documento = Convert.ToInt16(folio); using (kardex) { kardex.CreateKardex(); List <Models.Kardex> numeracion = kardex.getidKardex(prod[0].Id, Convert.ToInt16(folio), "A"); using (afecta) { afecta.Ajusta(numeracion[0].Id); } } } } } } this.Close(); }
private void button2_Click(object sender, EventArgs e) { Models.Inv_in entrada = new Models.Inv_in( Convert.ToInt16(folio), dtFecha.Text + " 00:00:00", "", Convert.ToDouble(txtTotal.Text), "A" ); Models.Det_entradas det = new Models.Det_entradas(); Models.Kardex kardex = new Models.Kardex(); Models.Product producto = new Models.Product(); Models.Afecta_inv afecta = new Models.Afecta_inv(); int nuevo = 0; det.Id = 0; if (folio == "0") { using (entrada) { entrada.createInv_in(); List <Models.Inv_in> result = entrada.getListabyAll(dtFecha.Text + " 00:00:00", Convert.ToDouble(txtTotal.Text)); folio = result[0].Id.ToString(); det.Id_entrada = Convert.ToInt16(folio); foreach (DataGridViewRow row in dtProductos.Rows) { det.Cantidad = Convert.ToInt16(row.Cells["cantidad"].Value.ToString()); det.Id_producto = Convert.ToInt16(row.Cells["id_producto"].Value.ToString()); det.P_u = Convert.ToDouble(row.Cells["p_u"].Value.ToString()); det.Total = Convert.ToDouble(row.Cells["total"].Value.ToString()); using (det) { det.craeteDet_entrada(); using (producto) { List <Models.Product> prod = producto.getProductById(Convert.ToInt16(row.Cells["id_producto"].Value.ToString())); nuevo = Convert.ToInt16(row.Cells["cantidad"].Value.ToString()); while (prod[0].Parent != "0") { nuevo = nuevo * Convert.ToInt16(prod[0].C_unidad); prod = producto.getProductById(Convert.ToInt16(prod[0].Parent)); } kardex.Fecha = Convert.ToDateTime(dtFecha.Text).ToString(); kardex.Id_producto = prod[0].Id; kardex.Tipo = "E"; kardex.Cantidad = nuevo; kardex.Antes = prod[0].Existencia; kardex.Id = 0; kardex.Id_documento = Convert.ToInt16(folio); using (kardex) { kardex.CreateKardex(); List <Models.Kardex> numeracion = kardex.getidKardex(prod[0].Id, Convert.ToInt16(folio), "E"); using (afecta) { afecta.Agrega(numeracion[0].Id); } } } } } } } if (Entrada == "") { Entradas formInterface = this.Owner as Entradas; formInterface.carga(); } this.Close(); }