private ReportesVentaXSucursal ObtenerDatosReporte()
 {
     try
     {
         ReportesVentaXSucursal DatosAux = new ReportesVentaXSucursal();
         Int32 RowData = this.dgvReporteVentasXSucursal.Rows.GetFirstRow(DataGridViewElementStates.Selected);
         if (RowData > -1)
         {
             int             ID        = 0;
             DataGridViewRow FilaDatos = this.dgvReporteVentasXSucursal.Rows[RowData];
             int.TryParse(FilaDatos.Cells["IDReporte"].Value.ToString(), out ID);
             DatosAux.IDReporte = ID;
             DateTime FechaInicio = DateTime.MinValue;
             DateTime FechaFin    = DateTime.MinValue;
             string   IDSucursal  = (FilaDatos.Cells["IDSucursal"].Value.ToString());
             DateTime.TryParse(FilaDatos.Cells["FechaInicio"].Value.ToString(), out FechaInicio);
             DateTime.TryParse(FilaDatos.Cells["FechaFin"].Value.ToString(), out FechaFin);
         }
         return(DatosAux);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// obtener reporte Ventas Por sucursal con detalle de ventas por caja
        /// </summary>
        /// <param name="Conexion"></param>
        /// <param name="IDReporte"></param>
        /// <returns></returns>
        public ReportesVentaXSucursal ObtenerDetalleReportesVentasXSucursal(string Conexion, int IDReporte)
        {
            try
            {
                ReportesVentaXSucursal Resultado = new ReportesVentaXSucursal();
                DataSet Ds = SqlHelper.ExecuteDataset(Conexion, "Reportes.spCSLDB_get_ReporteVentasXSucursalXID", IDReporte);
                if (Ds != null)
                {
                    if (Ds.Tables.Count == 3)
                    {
                        DataTableReader Dr = Ds.Tables[0].CreateDataReader();
                        while (Dr.Read())
                        {
                            Resultado.FechaInicio    = !Dr.IsDBNull(Dr.GetOrdinal("FechaInicio")) ? Dr.GetDateTime(Dr.GetOrdinal("FechaInicio")) : DateTime.MinValue;
                            Resultado.FechaFin       = !Dr.IsDBNull(Dr.GetOrdinal("FechaFin")) ? Dr.GetDateTime(Dr.GetOrdinal("FechaFin")) : DateTime.MinValue;
                            Resultado.NombreSucursal = !Dr.IsDBNull(Dr.GetOrdinal("NombreSucursal")) ? Dr.GetString(Dr.GetOrdinal("NombreSucursal")) : string.Empty;
                            break;
                        }
                        Dr.Close();

                        List <ReporteVentasXSucursalDetalleVentasXCaja> Lista1 = new List <ReporteVentasXSucursalDetalleVentasXCaja>();
                        ReporteVentasXSucursalDetalleVentasXCaja        Item;
                        DataTableReader Dr2 = Ds.Tables[1].CreateDataReader();
                        while (Dr2.Read())
                        {
                            Item                = new ReporteVentasXSucursalDetalleVentasXCaja();
                            Item.FechaInicio    = !Dr2.IsDBNull(Dr2.GetOrdinal("FechaInicio")) ? Dr2.GetDateTime(Dr2.GetOrdinal("FechaInicio")) : DateTime.MinValue;
                            Item.NombreCompleto = !Dr2.IsDBNull(Dr2.GetOrdinal("NombreCompleto")) ? Dr2.GetString(Dr2.GetOrdinal("NombreCompleto")) : string.Empty;
                            Item.TotalCobros    = !Dr2.IsDBNull(Dr2.GetOrdinal("TotalCobros")) ? Dr2.GetDecimal(Dr2.GetOrdinal("TotalCobros")) :0;


                            Lista1.Add(Item);
                        }
                        Dr2.Close();

                        List <ReporteVentasXSucursalDetalleXFormasPago> Lista2 = new List <ReporteVentasXSucursalDetalleXFormasPago>();
                        ReporteVentasXSucursalDetalleXFormasPago        Item2;
                        DataTableReader Dr3 = Ds.Tables[2].CreateDataReader();
                        while (Dr3.Read())
                        {
                            Item2             = new ReporteVentasXSucursalDetalleXFormasPago();
                            Item2.Descripcion = !Dr3.IsDBNull(Dr3.GetOrdinal("Descripcion")) ? Dr3.GetString(Dr3.GetOrdinal("Descripcion")) : string.Empty;
                            Item2.Monto       = !Dr3.IsDBNull(Dr3.GetOrdinal("Monto")) ? Dr3.GetDecimal(Dr3.GetOrdinal("Monto")) : 0;
                            Lista2.Add(Item2);
                        }
                        Dr2.Close();

                        Resultado.Detalle1 = Lista1;
                        Resultado.Detalle2 = Lista2;
                        Resultado.Completo = true;
                    }
                }
                return(Resultado);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 //Camiar hdtptm
 private ReportesVentaXSucursal ObtenerDatos()
 {
     try
     {
         Sucursal DtsCliente = this.ObtenerElementoComboSuc();
         this.IDCliente = DtsCliente.IDSucursal;
         ReportesVentaXSucursal DatosAux = new ReportesVentaXSucursal();
         DatosAux.FechaInicio = dtpFechaInicio.Value;
         DatosAux.FechaFin    = dtpFechaFin.Value;
         DatosAux.IDSucursal  = this.IDCliente;
         return(DatosAux);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private void GenerarReporteVentasXSucursal()
 {
     try
     {
         reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
         reportViewer1.ZoomMode    = ZoomMode.Percent;
         reportViewer1.ZoomPercent = 100;
         reportViewer1.LocalReport.DataSources.Clear();
         ReporteVentasXSucursal_Negocio Neg1         = new ReporteVentasXSucursal_Negocio();
         ReportesVentaXSucursal         DatosReporte = Neg1.ObtenerDetalleReporteVentasXSucursal(Comun.Conexion, IDReporte);
         reportViewer1.LocalReport.EnableExternalImages = true;
         ReportParameter[] Parametros = new ReportParameter[8];
         Parametros[0] = new ReportParameter("Empresa", Comun.NombreComercial);
         Parametros[1] = new ReportParameter("Eslogan", Comun.Eslogan);
         Parametros[2] = new ReportParameter("Direccion", Comun.Direccion);
         Parametros[3] = new ReportParameter("TituloReporte", "REPORTE DE VENTAS POR SUCURSAL");
         if (File.Exists(@"Resources\Documents\" + Comun.UrlLogo.ToLower()))
         {
             string Aux = new Uri(Path.Combine(System.Windows.Forms.Application.StartupPath, @"Resources\Documents\" + Comun.UrlLogo.ToLower())).AbsoluteUri;
             Parametros[4] = new ReportParameter("UrlLogo", new Uri(Path.Combine(System.Windows.Forms.Application.StartupPath, @"Resources\Documents\" + Comun.UrlLogo.ToLower())).AbsoluteUri);
         }
         else
         {
             Parametros[4] = new ReportParameter("UrlLogo", new Uri(Path.Combine(System.Windows.Forms.Application.StartupPath, @"Resources\Documents\Default.jpg")).AbsoluteUri);
         }
         Parametros[5] = new ReportParameter("FechaInicio", DatosReporte.FechaInicio.ToShortDateString());
         Parametros[6] = new ReportParameter("FechaFin", DatosReporte.FechaFin.ToShortDateString());
         Parametros[7] = new ReportParameter("Sucursal", DatosReporte.NombreSucursal);
         this.reportViewer1.LocalReport.ReportEmbeddedResource = "StephManager.Informes.Reportes.VentasXSucursal.rdlc";
         reportViewer1.LocalReport.SetParameters(Parametros);
         reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", DatosReporte.Detalle2));
         reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", DatosReporte.Detalle1));
         this.reportViewer1.RefreshReport();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 private void btnImpresion_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.dgvReporteVentasXSucursal.SelectedRows.Count == 1)
         {
             ReportesVentaXSucursal       Datos      = this.ObtenerDatosReporte();
             frmVerReporteVentasXSucursal VerReporte = new frmVerReporteVentasXSucursal(Datos.IDReporte);
             VerReporte.ShowDialog();
             VerReporte.Dispose();
         }
         else
         {
             MessageBox.Show("Seleccione una fila.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         LogError.AddExcFileTxt(ex, "frmReporteVentasXSucursal ~ btnImpresion_Click");
         MessageBox.Show(Comun.MensajeError, Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                this.txtMensajeError.Visible = false;
                List <Error> Errores = this.ValidarDatos();

                if (Errores.Count == 0)
                {
                    ReportesVentaXSucursal         Datos = this.ObtenerDatos();
                    ReporteVentasXSucursal_Negocio Neg   = new ReporteVentasXSucursal_Negocio();

                    int IDReporte = Neg.GenerarReporteVentasXSucursal(Comun.Conexion, Datos.FechaInicio, Datos.FechaFin, Comun.IDUsuario, Datos.IDSucursal);
                    //IDReporte = Neg.GenerarReporteVentasXSucursalXFormasPago (Comun.Conexion, Datos.FechaInicio, Datos.FechaFin, IDReporte , Datos.IDSucursal);

                    if (IDReporte > 0)
                    {
                        frmVerReporteVentasXSucursal VerReporte = new frmVerReporteVentasXSucursal(IDReporte);
                        VerReporte.ShowDialog();
                        VerReporte.Dispose();
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("Ocurrió un error al generar el reporte.", Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    this.MostrarMensajeError(Errores);
                }
            }
            catch (Exception ex)
            {
                LogError.AddExcFileTxt(ex, "frmNuevoReporteVentasXSucursal ~ btnGuardar_Click");
                MessageBox.Show(Comun.MensajeError, Comun.Sistema, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 /// <summary>
 /// Otener el reporte de Ventas por Sucursal
 /// </summary>
 /// <param name="Conexion"></param>
 /// <param name="Fecha"></param>
 /// <returns></returns>
 public List <ReportesVentaXSucursal> ObtenerReporteVentasXSucursal(string Conexion, DateTime Fecha)
 {
     try
     {
         List <ReportesVentaXSucursal> Lista = new List <ReportesVentaXSucursal>();
         ReportesVentaXSucursal        Item;
         SqlDataReader Dr = SqlHelper.ExecuteReader(Conexion, "Reportes.spCSLDB_get_ReporteVentasXSucursal", Fecha);
         while (Dr.Read())
         {
             Item                = new ReportesVentaXSucursal();
             Item.IDReporte      = !Dr.IsDBNull(Dr.GetOrdinal("IDReporte")) ? Dr.GetInt32(Dr.GetOrdinal("IDReporte")) : 0;
             Item.FechaInicio    = !Dr.IsDBNull(Dr.GetOrdinal("FechaInicio")) ? Dr.GetDateTime(Dr.GetOrdinal("FechaInicio")) : DateTime.MinValue;
             Item.FechaFin       = !Dr.IsDBNull(Dr.GetOrdinal("FechaFin")) ? Dr.GetDateTime(Dr.GetOrdinal("FechaFin")) : DateTime.MinValue;
             Item.NombreSucursal = !Dr.IsDBNull(Dr.GetOrdinal("NombreSucursal")) ? Dr.GetString(Dr.GetOrdinal("NombreSucursal")) : string.Empty;
             Lista.Add(Item);
         }
         Dr.Close();
         return(Lista);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }