コード例 #1
0
        public void DriversCarsReportExport(DriversCarsReportPackage driversCarsReportPackage, DateTime startTime, DateTime endTime, string path)
        {
            // Getting the complete workbook...
              HSSFWorkbook templateWorkbook = CreateEmptyWorkbook("Samochody\\Kierowcy raport zbiorczy",
            string.Format("FROM_{0}_TO_{1}", startTime.ToString("yyyy_mm_dd"), endTime.ToString("yyyy_mm_dd")));

              // Getting the worksheet by its name...
              var  sheet = templateWorkbook.GetSheetAt(0);

              // Getting the row... 0 is the first row.
              var dataRow = sheet.CreateRow(0);

              // Setting the value 77 at row 5 column 1
              dataRow.CreateCell(0).SetCellValue(77);

              // Forcing formula recalculation...
              sheet.ForceFormulaRecalculation = true;

              WriteWorkbook(templateWorkbook, path);
        }
コード例 #2
0
        public DriversCarsReportPackage GetDriversCarsDataReport(DateTime startTime, DateTime endTime)
        {
            try
              {
            using (var ctx = new SmartWorkingEntities())
            {
              DriversCarsReportPackage result = new DriversCarsReportPackage();
              List<DeliveryNote> allDeliveryNotes =
            ctx.DeliveryNotes.Include("Car").Include("Driver").Where(x => !x.Deactivated.HasValue && x.DateDrawing >= startTime && x.DateDrawing <= endTime).ToList();
              foreach (DeliveryNote deliveryNote in allDeliveryNotes)
              {
            if (deliveryNote.Car != null)
            {
              if (result.ColumntElements.Where(x => x.Id == deliveryNote.Car.Id).FirstOrDefault() == null)
              {
                result.ColumntElements.Add(deliveryNote.Car.GetPrimitive());
              }
            }
            if (deliveryNote.Driver != null)
            {
              if (result.RowElements.Where(x => x.Id == deliveryNote.Driver.Id).FirstOrDefault() == null)
              {
                result.RowElements.Add(deliveryNote.Driver.GetPrimitive());
              }
            }

            ReportRow row = result.RowValues.Where(x => x.Id == deliveryNote.Driver_Id).FirstOrDefault();
            if (row == null)
            {
              row = new ReportRow();
              row.Id = deliveryNote.Driver_Id.Value;
              row.ReportValues.Add(new ReportValue()
                               {Id = deliveryNote.Car_Id.Value, Amount = deliveryNote.Amount, NoOfTransports = 1});
              result.RowValues.Add(row);
            }
            else
            {
              ReportValue reportValue = row.ReportValues.Where(x => x.Id == deliveryNote.Car_Id.Value).FirstOrDefault();
              if (reportValue == null)
              {
                reportValue = new ReportValue();
                reportValue.Id = deliveryNote.Car_Id.Value;
                reportValue.Amount = deliveryNote.Amount;
                reportValue.NoOfTransports = 1;
                row.ReportValues.Add(reportValue);
              }
              else
              {
                reportValue.Amount += deliveryNote.Amount;
                reportValue.NoOfTransports += 1;
              }
            }

              }
              return result;
            }
              }
              catch(Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }