/* void procesandoProgresabar() { progressBar1.RunWorkerAsync(); }*/ private void button3_Click(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); PedidoBL pbl = new PedidoBL(); FacturaBL facBl = new FacturaBL(); FacturaBE factbe = new FacturaBE(); PedidoBE pedbe = new PedidoBE(); DataTable dtdetallepedidos = new DataTable(); if (dtpedidos.Rows.Count >=1) { Boolean procesados = false; DataGridViewCheckBoxCell oCell; foreach(DataGridViewRow row in dataGridView1.Rows) { dtdetallepedidos.Clear(); dtdetallefactura.Clear(); //Boolean data = Convert.ToBoolean(int.Parse(row.Cells[0].ToString())); oCell = row.Cells["item"] as DataGridViewCheckBoxCell; bool bChecked = (null != oCell && null != oCell.Value && true == (bool)oCell.Value); int codigo = int.Parse(row.Cells["Numero_Pedido"].Value.ToString()); int codigotipocp = int.Parse(row.Cells["codtipodocumento"].Value.ToString()); if (bChecked) { procesados = true; pedbe = pbl.getpedido(codigo); dtdetallepedidos = pbl.obtenerDetalledPedidos_completo(codigo); factbe = rellenarfactura(pedbe); factbe.TipoCP = codigotipocp; //construirDetallefactura(dtdetallefactura); dtdetallefactura = rellenardetfactura(dtdetallepedidos); if (facBl.insertFacturaDetalleXLote(factbe, dtdetallefactura)) { pbl.updateestadopedido(codigo, "FACTURADO"); MessageBox.Show("Pedido Proceso :" + codigo); } } } if (!procesados) { progressBar1.Value = 100; MessageBox.Show("Seleccionar un pedido para su procesamiento"); backgroundWorker1.CancelAsync(); progressBar1.Value = 0; } else { MessageBox.Show("Proceso Finalizado"); backgroundWorker1.CancelAsync(); progressBar1.Value = 0; ACTUALIZARREGISTROS(); } } }
public FacturaBE rellenarfactura(PedidoBE pebe) { FacturaBE fctbe = new FacturaBE(); fctbe.FacturaId = 0; fctbe.ClienteId = pebe.IDCliente; fctbe.FechaEmision = pebe.FechaEmision; fctbe.FechaEntrega = pebe.FechaEntrega; fctbe.ModalidadCreditoId = pebe.IDModalidadCredito; fctbe.FechaPago = pebe.FechaPago; fctbe.Credito = pebe.Credito; fctbe.Direccion = pebe.Direccion; fctbe.IdVendedor = pebe.IDVendedor; fctbe.Observacion = pebe.Observacion; fctbe.ValorVenta = 0; fctbe.PrecioIncluyeImpuesto = pebe.PrecioIncluyeImpuesto; fctbe.DireccionEntrega = pebe.DireccionEntrega; fctbe.EstadoFacturacion = "FACTURADO POR LOTE"; fctbe.Subtotal = 0; fctbe.Total = 0; fctbe.MontoIGV = 0; fctbe.Observaciones = "GENERADO DESDE PEDIDO/"+pebe.PKID; fctbe.CodigoReq = 1; fctbe.CodigoSolAtencion = 1; fctbe.CodigoFormato = 0; return fctbe; }
public Boolean insertFacturaDetalleXLote(FacturaBE be, DataTable dt) { String con = appventa.Default.Setting; using (SqlConnection connection = new SqlConnection(con)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction("SampleTransaction"); // Must assign both transaction object and connection // to Command object for a pending local transaction command.Connection = connection; command.Transaction = transaction; try { command.CommandText = "sp_vt_insertcomprobaventa_porlote"; command.CommandType = CommandType.StoredProcedure; SqlParameter OutputParam = new SqlParameter("@CodCodigo", SqlDbType.Int); OutputParam.Direction = ParameterDirection.Output; command.Parameters.Add(OutputParam); command.Parameters.Add( new SqlParameter("@IDcliente", be.ClienteId)); command.Parameters.Add( new SqlParameter("@fechaemision", be.FechaEmision)); command.Parameters.Add( new SqlParameter("@fechaentrega", DateTime.Now)); command.Parameters.Add( new SqlParameter("@fecregistro", DateTime.Now)); command.Parameters.Add( new SqlParameter("@fecvencimiento", be.FechaEmision)); command.Parameters.Add( new SqlParameter("@idmoddalidadcredito", be.ModalidadCreditoId)); command.Parameters.Add( new SqlParameter("@fechapago", be.FechaPago)); command.Parameters.Add( new SqlParameter("@credito", be.Credito)); command.Parameters.Add( new SqlParameter("@direccion", be.Direccion)); command.Parameters.Add( new SqlParameter("@idvendedor", be.IdVendedor)); command.Parameters.Add( new SqlParameter("@observacion", be.Observacion)); command.Parameters.Add( new SqlParameter("@observaciones", be.Observaciones)); command.Parameters.Add( new SqlParameter("@precioincluyeim", be.PrecioIncluyeImpuesto)); command.Parameters.Add( new SqlParameter("@direccionentrega", be.DireccionEntrega)); command.Parameters.Add( new SqlParameter("@valorventa", decimal.Parse("0.0") )); command.Parameters.Add( new SqlParameter("@subtotal", decimal.Parse("0.0"))); command.Parameters.Add( new SqlParameter("@montoigv", decimal.Parse("0.0"))); command.Parameters.Add( new SqlParameter("@total", decimal.Parse("0.0"))); command.Parameters.Add( new SqlParameter("@tipocp", be.TipoCP) ); command.Parameters.Add( new SqlParameter("@estadoFacturacion", be.EstadoFacturacion)); command.Parameters.Add( new SqlParameter("@codsolatencion", 1)); command.Parameters.Add( new SqlParameter("@codreq", 1)); command.Parameters.Add( new SqlParameter("@codformato", 1)); // command.Parameters.Add( //new SqlParameter("@codmoneda", be.CodMoneda)); // command.Parameters.Add( //new SqlParameter("@codalmacen", be.CodAlmacen)); command.ExecuteNonQuery(); int codigo = int.Parse(command.Parameters["@CodCodigo"].Value.ToString()); if (codigo == 0) { codigo = 1; } /*EL DETALLE*/ foreach (DataRow row in dt.Rows) { command.CommandText = "sp_vt_insertdetfactu"; command.CommandType = CommandType.StoredProcedure; int stridproducto = int.Parse(row[0].ToString()); // int codigoperu = prodao.ObtenerCodigoIDProducto(stridproducto); decimal cantidad = Convert.ToDecimal((row[1].ToString())); decimal precio = Convert.ToDecimal(row[2].ToString()); String obs = row[3].ToString(); command.Parameters.Clear(); command.Parameters.Add( new SqlParameter("@idproducto", stridproducto)); command.Parameters.Add( new SqlParameter("@cantidad", cantidad )); command.Parameters.Add( new SqlParameter("@valortotal", precio)); command.Parameters.Add( new SqlParameter("@observacion", obs)); command.Parameters.Add( new SqlParameter("@IdFactura", codigo)); command.Parameters.Add( new SqlParameter("@Codreq", 1)); command.ExecuteNonQuery(); } // Attempt to commit the transaction. transaction.Commit(); Console.WriteLine("Both records are written to database."); return true; } catch (Exception ex) { try { transaction.Rollback(); return false; } catch (Exception ex2) { return false; // This catch block will handle any errors that may have occurred // on the server that would cause the rollback to fail, such as // a closed connection. Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType()); Console.WriteLine(" Message: {0}", ex2.Message); } } } }
public FacturaBE getFactura(int id) { FacturaBE be = new FacturaBE(); SqlConnection con = DConexion.obtenerBD(); string textoCmd = "sp_vt_getfactura"; SqlCommand cmd = new SqlCommand(textoCmd, con); cmd.CommandType = CommandType.StoredProcedure; // 3. add parameter to command, which // will be passed to the stored procedure cmd.Parameters.Add( new SqlParameter("@codfactu", id)); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { if (object.ReferenceEquals(dr["FacturaId"], DBNull.Value)) { be.FacturaId = 0; } else { be.FacturaId = int.Parse( dr["FacturaId"].ToString()); } if (object.ReferenceEquals(dr["NumeroFact"], DBNull.Value)) { be.NumeroFact = 0; } else { be.NumeroFact = int.Parse( dr["NumeroFact"].ToString()); } if (object.ReferenceEquals(dr["ClienteId"], DBNull.Value)) { be.ClienteId = 0; } else { be.ClienteId = int.Parse( dr["ClienteId"].ToString()); } if (object.ReferenceEquals(dr["FechaEmision"], DBNull.Value)) { //be.FechaEmision = null; } else { be.FechaEmision = DateTime.Parse( dr["FechaEmision"].ToString() ); } if (object.ReferenceEquals(dr["FechaEntrega"], DBNull.Value)) { // be.FechaEntrega = null; } else { be.FechaEntrega = DateTime.Parse( dr["FechaEntrega"] .ToString()); } if (object.ReferenceEquals(dr["ModalidadCreditoId"], DBNull.Value)) { be.ModalidadCreditoId = 0; } else { be.ModalidadCreditoId = int.Parse( dr["ModalidadCreditoId"].ToString()); } if (object.ReferenceEquals(dr["FechaPago"], DBNull.Value)) { //be.FechaPago = null; } else { be.FechaPago = DateTime.Parse( dr["FechaPago"].ToString()); } if (object.ReferenceEquals(dr["Credito"], DBNull.Value)) { //be.Credito = null; } else { be.Credito = Boolean.Parse( dr["Credito"].ToString()); } if (object.ReferenceEquals(dr["Direccion"], DBNull.Value)) { be.Direccion = null; } else { be.Direccion = dr["Direccion"].ToString(); } if (object.ReferenceEquals(dr["IdVendedor"], DBNull.Value)) { be.IdVendedor = 0; } else { be.IdVendedor = int.Parse( dr["IdVendedor"].ToString()); } if (object.ReferenceEquals(dr["Observacion"], DBNull.Value)) { be.Observacion = null; } else { be.Observacion = dr["Observacion"].ToString(); } if (object.ReferenceEquals(dr["ValorVenta"], DBNull.Value)) { be.ValorVenta = 0; } else { be.ValorVenta = double.Parse( dr["ValorVenta"].ToString()); } if (object.ReferenceEquals(dr["PrecioIncluyeImpuesto"], DBNull.Value)) { //be.PrecioIncluyeImpuesto = 0; } else { be.PrecioIncluyeImpuesto = Boolean.Parse( dr["PrecioIncluyeImpuesto"].ToString()); } if (object.ReferenceEquals(dr["EstadoFacturacion"], DBNull.Value)) { be.EstadoFacturacion = null; } else { be.EstadoFacturacion = dr["EstadoFacturacion"].ToString(); } if (object.ReferenceEquals(dr["DireccionEntrega"], DBNull.Value)) { be.DireccionEntrega = null; } else { be.DireccionEntrega = dr["DireccionEntrega"].ToString(); } if (object.ReferenceEquals(dr["Subtotal"], DBNull.Value)) { be.Subtotal = 0; } else { be.Subtotal = Decimal.Parse( dr["Subtotal"].ToString()); } if (object.ReferenceEquals(dr["MontoIGV"], DBNull.Value)) { //be.MontoIGV = null; } else { be.MontoIGV = decimal.Parse( dr["MontoIGV"].ToString()); } if (object.ReferenceEquals(dr["Total"], DBNull.Value)) { //be.Total = null; } else { be.Total = Decimal.Parse( dr["Total"].ToString()); } if (object.ReferenceEquals(dr["Observaciones"], DBNull.Value)) { be.Observaciones = null; } else { be.Observaciones = dr["Observaciones"].ToString(); } if (object.ReferenceEquals(dr["FechaRegistro"], DBNull.Value)) { //be.FechaRegistro = null; } else { be.FechaRegistro = DateTime.Parse( dr["FechaRegistro"].ToString()); } if (object.ReferenceEquals(dr["FechaVencimiento"], DBNull.Value)) { //be.FechaVencimiento = null; } else { be.FechaVencimiento = DateTime.Parse( dr["FechaVencimiento"].ToString()); } if (object.ReferenceEquals(dr["CodigoSolAtencion"], DBNull.Value)) { //be.CodigoSolAtencion = null; } else { be.CodigoSolAtencion = int.Parse( dr["CodigoSolAtencion"].ToString()); } if (object.ReferenceEquals(dr["CodigoReq"], DBNull.Value)) { //be.CodigoReq = null; } else { be.CodigoReq = int.Parse( dr["CodigoReq"].ToString()); } if (object.ReferenceEquals(dr["CodigoFormato"], DBNull.Value)) { //be.CodigoFormato = null; } else { be.CodigoFormato = int.Parse( dr["CodigoFormato"].ToString()); } } } return be; }
public Boolean insertFacturaDetalleXLote(FacturaBE be, DataTable dt) { return pd.insertFacturaDetalleXLote(be, dt); }
private void Button8_Click(object sender, EventArgs e) { if (txtCodCliente.Text == "") { MessageBox.Show("Debe seleccionar un Cliente", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCodCliente.Focus(); this.Cursor = Cursors.Default; return; } if (txtCodVendedor.Text == "") { MessageBox.Show("Debe seleccionar un Vendedor", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); txtCodVendedor.Focus(); this.Cursor = Cursors.Default; return; } if (txtDireccionEntrega.Text == "") { MessageBox.Show("Debe Ingresar una Dirección de entrega", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); this.SelectTabWithoutFocus(this.TabControl1.TabPages[1]); ; this.Cursor = Cursors.Default; return; } if (dtgDetalleProd.Rows.Count == 0) { MessageBox.Show("Debe Ingresar Items", "Ventas", MessageBoxButtons.OK, MessageBoxIcon.Error); btnNuevo2.Focus(); this.Cursor = Cursors.Default; return; } else ped = new FacturaBE(); ped.ClienteId = cli.IdCliente; ped.FechaEmision = DateTimePicker1.Value; ped.FechaEntrega = DateTimePicker2.Value; ped.FechaPago = DateTimePicker1.Value; if (cli.IDTipoDocIdentidad ==1) { ped.TipoCP = 1; }else if (cli.IDTipoDocIdentidad == 2) { ped.TipoCP = 2; } ped.ModalidadCreditoId = cli.IDModalidadCredito; ped.Credito = true; ped.Direccion = txtDireccion.Text; ped.IdVendedor = int.Parse(txtCodVendedor.Text); ped.Observacion = "kjhjkh"; ped.PrecioIncluyeImpuesto = true; ped.EstadoFacturacion = "FACTURADO"; ped.DireccionEntrega = txtDireccionEntrega.Text; ped.FacturaId = 0; ped.ValorVenta = double.Parse(txtTotal.Text); ped.Subtotal = decimal.Parse(txtSubTotal.Text); ped.Total = decimal.Parse(txtTotal.Text); ped.MontoIGV = decimal.Parse(txtimpuesto.Text); ped.Observaciones = "GENERADO DESDE COMPROBANTE DE VENTA"; ped.CodigoReq = 1; ped.CodigoSolAtencion = 1; ped.CodigoFormato = 0; //string codigo = cbMonedas.SelectedValue.ToString(); // ped. = int.Parse(codigo); FacturaBL pbl = new FacturaBL(); Boolean valor = pbl.insertFactura(ped, dtdetalle); if (valor == true) { MessageBox.Show("Comprobante de Venta guardado satisfactoriamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); } else { MessageBox.Show("Problema con el registro de Comprobante de Venta , Comunciarse con [email protected]", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }