private void ExecuteSPData()
        {
            //dsGLTrialC ds = new dsGLTrialC();
            SqlConnection Con = new SqlConnection(clsGVar.ConString1);
            SqlCommand    cmd = new SqlCommand();
            //DataSet ds = null;
            SqlDataAdapter adapter;

            //Table Getting
            //SqlConnection ConLogo = new SqlConnection(clsGVar.ConString1);
            //SqlCommand cmdLogo = new SqlCommand("Select ID, Name, Photo From Photos where id=16", ConLogo);
            //SqlCommand com = new SqlCommand(flstField, con);
            //DataSet ds = null;
            //SqlDataAdapter adapterLogo;

            try
            {
                Con.Open();

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = fStoreProcName;

                string[] aryField = flstField.Split(',');
                string[] aryType  = flstType.Split(',');
                string[] aryValue = flstValue.Split(',');

                for (int i = 0; i < aryField.Length; i++)
                {
                    switch (int.Parse(aryType[i]))
                    {
                    //sqlDBType.Int
                    case 8:
                    {
                        cmd.Parameters.Add(aryField[i], SqlDbType.Int).Value = int.Parse(aryValue[i]);
                        break;
                    }

                    //sqlDBType.DateTime
                    case 4:
                    {
                        cmd.Parameters.Add(aryField[i], SqlDbType.DateTime).Value = DateTime.Parse(aryValue[i]);
                        break;
                    }

                    //sqlDBType.Text
                    case 18:
                    {
                        cmd.Parameters.Add(aryField[i], SqlDbType.Text).Value = aryValue[i];
                        break;
                    }

                    default:
                        break;
                    }
                }


                //DateTime = 4,
                //Decimal = 5,
                //Float = 6,
                //Image = 7,
                //Int = 8,
                //Money = 9,
                //NChar = 10,
                //NText = 11,
                //NVarChar = 12,
                //Real = 13,
                //UniqueIdentifier = 14,
                //SmallDateTime = 15,
                //SmallInt = 16,
                //SmallMoney = 17,
                //Text = 18,

                //cmd.Parameters.Add("@Co_ID", SqlDbType.Int).Value = 1;
                //cmd.Parameters.Add("@ToDate", SqlDbType.Text).Value = fToDate; //"2013-01-01";
                cmd.Connection = Con;

                adapter = new SqlDataAdapter(cmd);
                //adapter.TableMappings.Add("Table", "Table");

                adapter.Fill(fDs);
                //
                int cCount = fDs.Tables[1].Rows.Count;
                // Table 1 is used as table 0 is already present at the time of design of DataSet.
                //CrGLTrial rpt1 = new CrGLTrial();                 // Instiantiate a report
                //CrBira01 rpt1 = new CrBira01();                 // Instiantiate a report
                //rpt1.SetDataSource(ds.Tables[1]);

                frpt1.DataDefinition.FormulaFields["CoName"].Text      = "'" + clsGVar.CoTitle1 + "'";
                frpt1.DataDefinition.FormulaFields["RptTitle"].Text    = "'" + fRptTitle + "'";
                frpt1.DataDefinition.FormulaFields["AppUserName"].Text = "'" + clsGVar.AppUserTitle + "'";
                frpt1.DataDefinition.FormulaFields["fromdate"].Text    = "'" + fp + "'";
                frpt1.DataDefinition.FormulaFields["ToDate"].Text      = "'" + fp_2 + "'";

                //frpt1.SetDataSource(fDs.Tables[1]);
                //frpt1.OpenSubreport("CrImage").SetDataSource(fDs.Tables[2]);
                //
                crystalReportViewer1.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None;
                crystalReportViewer1.Width         = 900;
                crystalReportViewer1.Height        = 300;
                //
                //---------------------***********
                //dsPhoto ds = new dsPhoto();
                //cmdLogo.Connection = ConLogo;
                //adapterLogo = new SqlDataAdapter(cmdLogo);
                //ConLogo.Open();
                //SqlDataAdapter adapterLogo = new SqlDataAdapter();
                //adapterLogo.SelectCommand = cmdLogo;
                //adapter.TableMappings.Add("table", fTableName);
                //adapterLogo.TableMappings.Add("table", "abctablename"); // Actual table has nothing to do with DataSet.
                //
                //adapterLogo.Fill(ds);
                //
                //---------------****************
                //CrLogo rptLogo = new CrLogo();
                //rptLogo.SetDataSource(ds.Tables["Photos"]);

                //frpt1.OpenSubreport("CrImages.rpt").SetDataSource(ds.Tables["Photos"]);
                //frpt1.OpenSubreport("CrBira01.rpt").SetDataSource(dsPhoto.Tables["Photos"]);
                //customerReport.OpenSubreport("MainSubReport.rpt").SetDataSource(dsSubReportResult.Tables["MainTableSubReportRecord"]); ;

                //frpt1.SetDataSource(fDs.Tables[1]);
                //frpt1.OpenSubreport("CrLogo.rpt").SetDataSource(fDs.Tables[2]);
                //frpt1.OpenSubreport("CrReceiptSub.rpt").SetDataSource(fDs.Tables[1]);
                //frpt1.OpenSubreport("CrPaymentSub.rpt").SetDataSource(fDs.Tables[2]);

                frpt1.OpenSubreport("CrMfgClose.rpt").SetDataSource(fDs.Tables[1]);
                frpt1.OpenSubreport("CrMfgCloseHeader.rpt").SetDataSource(fDs.Tables[1]);
                frpt1.OpenSubreport("CrLogo.rpt").SetDataSource(fDs.Tables[2]);

                frpt1.OpenSubreport("CrMfgSumSubWOOpn.rpt").SetDataSource(fDs.Tables[3]);
                frpt1.OpenSubreport("CrStockSumSub.rpt").SetDataSource(fDs.Tables[4]);

                crystalReportViewer1.ReportSource = frpt1;
                //crystalReportViewer1.ReportSource = rptLogo;
                crystalReportViewer1.Refresh();
                //adapterLogo.Dispose();
                //cmdLogo.Dispose();
                //ConLogo.Close();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Beispiel #2
0
        public ActionResult GenerateReport(string empresa,string entidade)
        {
            ClientesDataSet dt = imprimirPdf(empresa,entidade);
            
            ReportClass objReport = new ReportClass();
            objReport.FileName = Server.MapPath("/Content/Reports/ExtratoPendentes.rpt");
            objReport.Load();

            //objReport.SetDataSource(dt);
            
            objReport.SetDataSource(dt.Tables["Pendentes"]);
            objReport.Database.Tables["Pendentes"].SetDataSource(dt.Tables["Pendentes"]);
            objReport.Database.Tables["Clientes"].SetDataSource(dt.Tables["Clientes"]);

            objReport.Subreports["ContasBancarias"].SetDataSource(dt.Tables["Banco"]);

            objReport.OpenSubreport("Pendentes").SetDataSource(dt.Tables["Pendentes"]);
            objReport.DataDefinition.FormulaFields["NomeEmpresa"].Text = "'" + "Accsys" + "'";
            objReport.DataDefinition.FormulaFields["MoradaEmpresa"].Text = "'" + "Maputo" + "'";
            objReport.DataDefinition.FormulaFields["LocalidadeEmpresa"].Text = "'" + "Maputo" + "'";
            objReport.DataDefinition.FormulaFields["TelefoneEmpresa"].Text = "'+ " + "+258" + "'";
            objReport.DataDefinition.FormulaFields["NuitEmpresa"].Text = "' Nuit : " + "123456" + "'";
            objReport.DataDefinition.FormulaFields["EmailEmpresa"].Text = "'" + "*****@*****.**" + "'";
            //objReport.DataDefinition.FormulaFields["Ao_Cuidado_de"].Text = "' " + objectoContacto.Titulo + " " + objectoContacto.PrimeiroNome + " " + objectoContacto.UltimoNome + "'";
                
            
            Stream stream = objReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            return File(stream, "application/pdf");
        }