public static ReporteRendicion Instance() { if (frm == null) { frm = new ReporteRendicion(); } return(frm); }
private void kryptonButton1_Click(object sender, EventArgs e) { try { string valor = txtTotalValor.Text; string totalmonto = txtTotalMonto.Text; string turno = cbTurno.SelectedItem.ToString(); string emitidas = txtTotalCantidad.Text; string totalemitidas = txtTotalEmitidas.Text; string fecha = dtpFecha.Value.ToShortDateString(); int folio = 0; if (txtNombreCajero.Text == string.Empty) { MessageBox.Show("Debe ingresar su nombre"); txtNombreCajero.Focus(); } else if (txtDesde.Value == 0 || txtHasta.Value == 0 || txtMonto.Value == 0) { MessageBox.Show("Uno de los campos contiene valor 0, verifique"); } else if (!valor.Equals(totalmonto)) { MessageBox.Show("Montos ingresados no coinciden, verifique"); } else if (!emitidas.Equals(totalemitidas)) { MessageBox.Show("Cantidad de boletas emitidas no coinciden, verifique"); } else { string con = ConfigurationManager.ConnectionStrings["PP"].ConnectionString; using (SqlConnection connection = new SqlConnection(con)) { using (SqlCommand cmd = new SqlCommand("SELECT COUNT(id_registro)" + "FROM registro_rendicion", connection)) { connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { folio = reader.GetInt32(0); if (folio == 0) { folio++; MessageBox.Show($"Se ha generado rendición con n° de folio {folio}"); } else { folio++; MessageBox.Show($"Se ha generado rendición con n° de folio {folio}"); } } } connection.Close(); using (SqlCommand cmd = new SqlCommand("sp_RegistroDocumentosRendicion", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@cod_usuario", SqlDbType.Int).Value = Convert.ToInt32(lblCodUsuario.Text); cmd.Parameters.Add("@fecharegistro", SqlDbType.Date).Value = Convert.ToDateTime(DateTime.Now.ToShortDateString()); cmd.Parameters.Add("@cod_turno", SqlDbType.Int).Value = Convert.ToInt32(cbTurno.SelectedIndex) + 1; cmd.Parameters.Add("@idregistro", SqlDbType.Int).Value = Convert.ToInt32(folio); cmd.Parameters.Add("@desde", SqlDbType.Int).Value = Convert.ToInt32(txtDesde.Value); cmd.Parameters.Add("@hasta", SqlDbType.Int).Value = Convert.ToInt32(txtHasta.Value); cmd.Parameters.Add("@cantidadnulas", SqlDbType.Int).Value = Convert.ToInt32(txtCantidadNulas.Value); cmd.Parameters.Add("@monto", SqlDbType.Int).Value = Convert.ToInt32(txtMonto.Value); cmd.Parameters.Add("@fecharendicion", SqlDbType.Date).Value = Convert.ToDateTime(fecha); connection.Open(); cmd.ExecuteNonQuery(); } connection.Close(); foreach (DataGridViewRow dr in dgvVehiculo.Rows) { string cod = dr.Cells[0].Value.ToString().Substring(0, 3).Trim(); int cantidad = Convert.ToInt32(dr.Cells[1].Value.ToString()); using (SqlCommand cmd = new SqlCommand("sp_VehiculoRendicion", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@id_registro", SqlDbType.Int).Value = Convert.ToInt32(folio); cmd.Parameters.Add("@cod_vehiculos", SqlDbType.Int).Value = cod; cmd.Parameters.Add("@cantidad", SqlDbType.Int).Value = cantidad; connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); } } } ReporteRendicion rep = ReporteRendicion.Instance(); List <Datos> lst = new List <Datos>(); lst.Clear(); foreach (DataGridViewRow dr in dgvVehiculo.Rows) { Datos d = new Datos { Descripcion = dr.Cells[0].Value.ToString(), Cantidad = Convert.ToInt32(dr.Cells[1].Value.ToString()), Valor = Convert.ToInt32(dr.Cells[2].Value.ToString()), Total = Convert.ToInt32(dr.Cells[3].Value.ToString()), }; lst.Add(d); } ReportDataSource rs = new ReportDataSource(); rs.Name = "DataSet1"; rs.Value = lst; rep.reportViewer1.LocalReport.DataSources.Add(rs); rep.reportViewer1.LocalReport.ReportEmbeddedResource = "RendicionCaja.Report1.rdlc"; ReportParameter[] rparams = new ReportParameter[] { new ReportParameter("NombreCajero", txtNombreCajero.Text), new ReportParameter("Desde", txtDesde.Value.ToString()), new ReportParameter("Hasta", txtHasta.Value.ToString()), new ReportParameter("Monto", txtMonto.Value.ToString("C")), new ReportParameter("Cantidad", txtCantidadNulas.Text), new ReportParameter("Emitidas", txtTotalEmitidas.Text), new ReportParameter("TotalMonto", txtTotalMonto.Text), new ReportParameter("Turno", turno), new ReportParameter("Folio", folio.ToString()), new ReportParameter("FechaRendicion", fecha) }; rep.reportViewer1.LocalReport.SetParameters(rparams); //var bindinglist = new BindingList<Datos>(lst); //BindingSource bs = new BindingSource(bindinglist, null); //dgvVehiculo.DataSource = source; //BindingSource bs = source; //DataTable dt = (DataTable)bs.DataSource; rep.reportViewer1.RefreshReport(); rep.StartPosition = FormStartPosition.CenterScreen; rep.WindowState = FormWindowState.Normal; rep.Show(); rep.Activate(); } } catch (Exception ex) { KryptonMessageBox.Show(ex.Message); } }