Пример #1
0
        private ActionResult exportReport <T>(string reportFileName, string modelName, IList <T> dataList, string outputFileName)
        {
            //Prepare report
            ReportDocument rd = new ReportDocument();

            rd.Load(Path.Combine(Server.MapPath("~/Report/Crystal"), reportFileName + ".rpt"));

            //Set datasource
            InBondExBondRawMaterial_01 ibrd = new InBondExBondRawMaterial_01();
            DataTable inbondTb = ibrd.Tables[ibrd.Tables.IndexOf(modelName)];

            DataRow dr;

            foreach (object ib in dataList)
            {
                dr = inbondTb.NewRow();
                DataColumnCollection dcc = inbondTb.Columns;
                foreach (DataColumn dc in dcc)
                {
                    Type         tp    = ib.GetType();
                    PropertyInfo pif   = tp.GetProperty(dc.ColumnName);
                    var          value = pif.GetValue(ib);
                    dr[dc.ColumnName] = ib.GetType().GetProperty(dc.ColumnName).GetValue(ib, null);
                }
                inbondTb.Rows.Add(dr);
            }

            rd.SetDataSource(inbondTb);


            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            try
            {
                Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);
                return(File(stream, "application/pdf", outputFileName + ".pdf"));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("BMSReport: Time-" + DateTime.Now + " Exception = " + e.ToString());
                ViewBag.ErrorMsg = "Report Development is On going";
                throw e;
            }
        }
Пример #2
0
        private void LoadReport()
        {
            Int32 bonderId = (Int32)Session[AppConstants.SearchBonderID];

            System.DateTime searchDateFrom = (System.DateTime)Session[AppConstants.SearchFromDate];
            System.DateTime searchDateTo   = (System.DateTime)Session[AppConstants.SearchToDate];

            List <InBondExBondMaterial> reportData = new List <InBondExBondMaterial>();

            string queryStr1 = "SELECT"
                               + " BONDER.BONDERSLNO AS BonderID,"
                               + " BONDER.BONDERNAME AS BonderName,"
                               + " BONDER.BONDLICENSENO AS BonderLCNo,"
                               + " BONDER.ADDRESS AS BonderAddress,"
                               + " INBOND.BOENUMBER AS BOE,"
                               + " INBOND.LCDATE AS ImportDate,"
                               + " INBOND.LCNUMBER AS LC,"
                               + " INBOND.CREATEDDATE AS InBondDate,"
                               + " INBONDRAWMATERIAL.PRODUCTQUANTITY AS InBondQuantity,"
                               + " INBONDRAWMATERIAL.QUANTITYUNIT AS InBondQuantityUnit,"
                               + " INBONDRAWMATERIAL.PRODUCTCOST AS InBondValue,"
                               + " INBONDRAWMATERIAL.COSTUNIT AS InBondValueUnit,"
                               + " MATERIALS.MHSCODE AS HSCode,"
                               + " MATERIALS.MATERIALNAME AS RawMaterialName,"
                               + " MATERIALS.MSLNO AS RAWMATERIALCODE"
                               + " FROM INBONDRAWMATERIAL"
                               + " INNER JOIN INBOND ON INBOND.ID = INBONDRAWMATERIAL.INBONDID"
                               + " INNER JOIN MATERIALS ON MATERIALS.MSLNO = INBONDRAWMATERIAL.RAWMATERIALCODE"
                               + " INNER JOIN BONDER ON BONDER.BONDERSLNO = INBOND.BONDERID"

                               + " WHERE INBOND.BONDERID = " + bonderId + " and INBOND.CREATEDDATE BETWEEN TO_DATE('" + searchDateFrom + "', '" + AppConstants.DATE_FORMATE + "')"
                               + "     AND TO_DATE('" + searchDateTo + "', '" + AppConstants.DATE_FORMATE + "')"
                               + "     ORDER BY MATERIALS.MATERIALNAME, INBOND.CREATEDDATE";

            reportData = db.Database.SqlQuery <InBondExBondMaterial>(queryStr1).ToList();

            List <InBondExBondMaterial> finalData = new List <InBondExBondMaterial>();

            //Update data based on response
            for (int i = 0; i < reportData.Count(); i++)
            {
                InBondExBondMaterial ibebm = reportData.ElementAt(i);
                //Adding fromdate and todate value to show in report

                ibebm.DateFrom = searchDateFrom;
                ibebm.DateTo   = searchDateTo;
                finalData.Add(ibebm);
                List <InBondExBondMaterial> exbondList = new List <InBondExBondMaterial>();
                if (i == reportData.Count - 1)
                {
                    //Last element. add all exbond from this to SearchToDate
                    exbondList = exbondListByRawMaterialInDate(ibebm, ibebm.DateTo, false);
                }
                else
                {   //Get the next element and check if it is same material
                    InBondExBondMaterial ibNext = reportData.ElementAt(i + 1);
                    if (ibNext.RAWMATERIALCODE.Equals(ibebm.RAWMATERIALCODE))
                    {
                        exbondList = exbondListByRawMaterialInDate(ibebm, ibNext.InBondDate, true);
                    }
                    else
                    {
                        //Last element of this kind. add all exbond from this to SearchToDate
                        exbondList = exbondListByRawMaterialInDate(ibebm, ibebm.DateTo, false);
                    }
                }
                finalData.AddRange(exbondList);
            }

            //return finalData;

            //Clear session data
            //Session[AppConstants.SearchBonderID] = null;
            //Session[AppConstants.SearchFromDate] = null;
            //Session[AppConstants.SearchToDate] = null;

            //Load data in report

            //Prepare report
            ReportDocument rd = new ReportDocument();

            rd.Load(Path.Combine(Server.MapPath("~/Report/Crystal"), "InBondExBondRawMaterialStatus_2.rpt"));

            //Set datasource
            InBondExBondRawMaterial_01 ibrd = new InBondExBondRawMaterial_01();
            DataTable inbondTb = ibrd.Tables[ibrd.Tables.IndexOf("InBondExBondRawMaterial")];

            DataRow dr;

            foreach (object ib in finalData)
            {
                dr = inbondTb.NewRow();
                DataColumnCollection dcc = inbondTb.Columns;
                foreach (DataColumn dc in dcc)
                {
                    Type         tp    = ib.GetType();
                    PropertyInfo pif   = tp.GetProperty(dc.ColumnName);
                    var          value = pif.GetValue(ib);
                    dr[dc.ColumnName] = ib.GetType().GetProperty(dc.ColumnName).GetValue(ib, null);
                }
                inbondTb.Rows.Add(dr);
            }

            rd.SetDataSource(inbondTb);

            InBondExBondRptVwr.ReportSource = rd;
            InBondExBondRptVwr.DataBind();
        }