Files
BeWoPlaner/ReportImp/KomMitBewo/ServicesOverviewReport.cs

141 lines
3.8 KiB
C#

using System;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using BeWo.Report.ReportObjects;
using BeWo.Report;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Drawing;
using BS.Shared.Core;
using System.IO;
namespace KommMit
{
public partial class Stundenzettel : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
{
public Stundenzettel()
{
InitializeComponent();
}
public void SetReportDataSource(ServicesOverviewRO pRO)
{
DateTime dt;
TimeSpan tspan;
double d;
pRO.Costbearer = String.Format("({0} - {1}) {2}", pRO.ApprovedStartDate, pRO.ApprovedEndDate, pRO.Costbearer);
if (pRO.Services != null)
{
List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();
double echtMinutenGesamt = 0;
foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
{
if (s.IsBillable)
{
ServicesOverviewRO.CreateSignatureString(s);
double echteMinuten = 0;
if (s.ServiceDescription.ToLower().Contains("fehlkontakt"))
{
echteMinuten = s.EndDateNotRounded.Subtract(s.StartDate).TotalMinutes;
s.ServiceCategoryAbbr = "Fehlkontakt";
}
else if (s.IsGroup)
{
echteMinuten = Math.Round(s.EndDateNotRounded.Subtract(s.StartDate).TotalMinutes / s.CustomerCount, 0, MidpointRounding.AwayFromZero);
s.ServiceCategoryAbbr = String.Format("G ({0})", s.CustomerCount);
}
else
{
echteMinuten = s.EndDateNotRounded.Subtract(s.StartDate).TotalMinutes;
s.ServiceCategoryAbbr = "D";
}
echtMinutenGesamt += echteMinuten;
var gerundeteMinuten = s.Minutes;
dt = DateTime.Now.Date.AddMinutes(echteMinuten);
tspan = dt.Subtract(DateTime.Now.Date);
d = tspan.TotalHours;
d = Math.Floor(d);
s.MinutesDateTime = DateTime.Now.Date.AddMinutes(echteMinuten);
s.Minutes = echteMinuten;
dt = DateTime.Now.Date.AddMinutes(gerundeteMinuten);
tspan = dt.Subtract(DateTime.Now.Date);
d = tspan.TotalHours;
d = Math.Floor(d);
s.FLSQualifiedString = String.Format("{0}:{1:00}", d, tspan.Minutes);
servicesBillable.Add(s);
}
else
{
s.FLSQualifiedString = "";
}
}
pRO.TotalFLM = echtMinutenGesamt;
dt = DateTime.Now.Date.AddMinutes(echtMinutenGesamt);
tspan = dt.Subtract(DateTime.Now.Date);
d = tspan.TotalHours;
d = Math.Floor(d);
pRO.TotalFLHoursMinutesString = String.Format("{0}:{1:00}", d, tspan.Minutes);
pRO.Services = servicesBillable;
}
dt = DateTime.Now.Date.AddMinutes(pRO.TotalFLMBillable);
tspan = dt.Subtract(DateTime.Now.Date);
d = tspan.TotalHours;
d = Math.Floor(d);
pRO.TotalFLSQualifiedString = String.Format("{0}:{1:00}", d, tspan.Minutes);
this.bindingSource1.DataSource = pRO;
}
private void picSignature_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
XRPictureBox xrBox = sender as XRPictureBox;
string base64String = xrBox.Tag as string;
if (!String.IsNullOrWhiteSpace(base64String))
{
var base64Data = Regex.Match(base64String, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;
var binData = Convert.FromBase64String(base64Data);
Image img = ByteArrayToImage(binData);
xrBox.Image = Utils.CropImage(img);
}
else
{
xrBox.Image = null;
}
}
public Image ByteArrayToImage(byte[] byteArrayIn)
{
using (var memoryStream = new MemoryStream(byteArrayIn))
{
return Image.FromStream(memoryStream);
}
}
}
}