protected override void OnRender(DrawingContext dc) { Point textPoint = new Point(0, 32); Point rectPoint = new Point(0, 32); // Create a Pen to add to the GeometryDrawing created above. _Pen = new Pen(); _Pen.Thickness = 1; _Pen.LineJoin = PenLineJoin.Miter; _Pen.EndLineCap = PenLineCap.Square; // Create a gradient to use as a value for the Pen's Brush property. GradientStop firstStop = new GradientStop(); firstStop.Color = Colors.Black; GradientStop secondStop = new GradientStop(); secondStop.Offset = 1.0; secondStop.Color = Colors.Black; LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(); myLinearGradientBrush.GradientStops.Add(firstStop); myLinearGradientBrush.GradientStops.Add(secondStop); _Pen.Brush = myLinearGradientBrush; int Regnskabid = (int)_Bilag.regnskabid; recMemRegnskab rec_regnskab = (from r in Program.memRegnskab where r.Rid == Regnskabid select r).First(); string firma = rec_regnskab.Firmanavn; DateTime startdato = (DateTime)rec_regnskab.Start; DateTime slutdato = (DateTime)rec_regnskab.S**t; DateTime bilagsdato = (DateTime)_Bilag.dato; int startMonth = startdato.Month; int bilagMonth = bilagsdato.Month; int regnskabsaar = slutdato.Year; int pnr; if (bilagMonth < startMonth) { pnr = bilagMonth + 12 - startMonth + 1; } else { pnr = bilagMonth - startMonth + 1; } DateTime PeriodeMonthYear = new DateTime(slutdato.Year, pnr, 1); string Periode = PeriodeMonthYear.ToString("MM-yyyy"); dc.DrawText(MakeHeader0("Bogføringsbilag " + firma, (int)(Width - (2 * PageMargin)), TextAlignment.Left), textPoint); textPoint.Y += 72; textPoint.X = 0; dc.DrawText(MakeHeader1("Dato", 50, TextAlignment.Left), textPoint); textPoint.X += 50; dc.DrawText(MakeHeader1(((DateTime)_Bilag.dato).ToShortDateString(), 80, TextAlignment.Left), textPoint); textPoint.X = ((Width - 2 * PageMargin) / 2) - 60; dc.DrawText(MakeHeader1("Periode", 60, TextAlignment.Left), textPoint); textPoint.X += 60; dc.DrawText(MakeHeader1(Periode, 60, TextAlignment.Right), textPoint); textPoint.X = Width - (2 * PageMargin + 30 + 30); dc.DrawText(MakeHeader1("Bilag", 30, TextAlignment.Left), textPoint); textPoint.X += 30; dc.DrawText(MakeHeader1(((int)_Bilag.bilag).ToString(), 30, TextAlignment.Right), textPoint); textPoint.Y += 72; textPoint.X = 5.5; TextinBox(dc, "Tekst", 248, TextAlignment.Left, textPoint); textPoint.X += 248; TextinBox(dc, "Kontonr", 50, TextAlignment.Right, textPoint); textPoint.X += 50; TextinBox(dc, "Kontonavn", 172, TextAlignment.Left, textPoint); textPoint.X += 172; TextinBox(dc, "Debet", 85, TextAlignment.Right, textPoint); textPoint.X += 85; TextinBox(dc, "Kredit", 85, TextAlignment.Right, textPoint); foreach (var t in _Bilag.tbltrans) { textPoint.Y += LineHeight; textPoint.X = 5.5; TextinBox(dc, t.tekst, 248, TextAlignment.Left, textPoint); textPoint.X += 248; TextinBox(dc, t.kontonr.ToString(), 50, TextAlignment.Right, textPoint); textPoint.X += 50; TextinBox(dc, t.kontonavn, 172, TextAlignment.Left, textPoint); textPoint.X += 172; if (t.debet != null) { TextinBox(dc, ((decimal)(t.debet)).ToString("#,0.00;-#,0.00"), 85, TextAlignment.Right, textPoint); } else { TextinBox(dc, t.debet.ToString(), 85, TextAlignment.Right, textPoint); } textPoint.X += 85; if (t.kredit != null) { TextinBox(dc, ((decimal)(t.kredit)).ToString("#,0.00;-#,0.00"), 85, TextAlignment.Right, textPoint); } else { TextinBox(dc, t.kredit.ToString(), 85, TextAlignment.Right, textPoint); } } textPoint.Y = 956; textPoint.X = 0; dc.DrawText(MakeHeader1(".", 25, TextAlignment.Left), textPoint); }
public bool ReadRegnskaber() { string RegnskabId; string RegnskabMappe; string line; FileStream ts; string Eksportmappe; string Datamappe; try { Eksportmappe = (string)Registry.CurrentUser.OpenSubKey(@"SOFTWARE\STONE'S SOFTWARE\SUMMAPRO\START").GetValue("Eksportmappe"); Datamappe = (string)Registry.CurrentUser.OpenSubKey(@"SOFTWARE\STONE'S SOFTWARE\SUMMAPRO\START").GetValue("Datamappe"); } catch (System.NullReferenceException) { return(false); } DirectoryInfo dir = new DirectoryInfo(Datamappe); foreach (var sub_dir in dir.GetDirectories()) { if (Information.IsNumeric(sub_dir.Name)) { switch (sub_dir.Name.ToUpper()) { case "-2": case "-1": case "0": break; default: //do somthing here RegnskabId = sub_dir.Name; try { m_rec_Regnskab = (from d in Program.memRegnskab where d.Rid.ToString() == RegnskabId select d).First(); } catch (System.InvalidOperationException) { m_rec_Regnskab = new recMemRegnskab() { Rid = int.Parse(RegnskabId) }; Program.memRegnskab.Add(m_rec_Regnskab); } RegnskabMappe = Datamappe + sub_dir.Name + @"\"; m_rec_Regnskab.Placering = RegnskabMappe; m_rec_Regnskab.Eksportmappe = Eksportmappe + @"\"; string[] files = new string[2]; files[0] = RegnskabMappe + "regnskab.dat"; files[1] = RegnskabMappe + "status.dat"; m_rec_Regnskab.Afsluttet = false; foreach (var file in files) { ts = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None); using (StreamReader sr = new StreamReader(ts, Encoding.Default)) { while ((line = sr.ReadLine()) != null) { if (line.Length > 0) { string[] X = line.Split('='); switch (X[0]) { case "Navn": m_rec_Regnskab.Navn = X[1]; break; case "Oprettet": m_rec_Regnskab.Oprettet = clsUtil.MSSerial2DateTime(double.Parse(X[1])); break; case "Start": m_rec_Regnskab.Start = clsUtil.MSSerial2DateTime(double.Parse(X[1])); break; case "S**t": m_rec_Regnskab.S**t = clsUtil.MSSerial2DateTime(double.Parse(X[1])); break; case "DatoLaas": m_rec_Regnskab.DatoLaas = clsUtil.MSSerial2DateTime(double.Parse(X[1])); break; case "Afsluttet": m_rec_Regnskab.Afsluttet = (X[1] == "1") ? true : false; break; case "Firmanavn": m_rec_Regnskab.Firmanavn = X[1]; break; } } } } } break; } } } return(true); }
public static void UdskrivBilag(tblbilag Bilag) { int Regnskabid = (int)Bilag.regnskabid; recMemRegnskab rec_regnskab = (from r in Program.memRegnskab where r.Rid == Regnskabid select r).First(); string firma = rec_regnskab.Firmanavn; string regnskabsnavn = rec_regnskab.Navn; DateTime startdato = (DateTime)rec_regnskab.Start; DateTime slutdato = (DateTime)rec_regnskab.S**t; DateTime bilagsdato = (DateTime)Bilag.dato; int startMonth = startdato.Month; int bilagMonth = bilagsdato.Month; int regnskabsaar = slutdato.Year; int pnr; if (bilagMonth < startMonth) { pnr = bilagMonth + 12 - startMonth + 1; } else { pnr = bilagMonth - startMonth + 1; } DateTime PeriodeMonthYear = new DateTime(slutdato.Year, pnr, 1); string Periode = PeriodeMonthYear.ToString("MM"); //Create a pdf document. PdfDocument doc = new PdfDocument(); doc.DocumentInformation.Author = "Hafsjold Data ApS"; doc.DocumentInformation.Title = String.Format("Bogføringsbilag {0}", regnskabsnavn); doc.DocumentInformation.Creator = "Trans2SummaHDA"; doc.DocumentInformation.Subject = String.Format("Bilag {0}", ((int)Bilag.bilag).ToString()); doc.DocumentInformation.CreationDate = DateTime.Now; //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(2f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; // Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin); float width = page.Canvas.ClientSize.Width; float y = 10; //title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold)); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left); string s = String.Format("Bogføringsbilag {0}", regnskabsnavn); page.Canvas.DrawString(s, font1, brush1, 1, y, format1); y = y + font1.MeasureString(s, format1).Height; y = y + 25; PdfBrush brush2 = PdfBrushes.Black; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold)); PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Left); s = String.Format("Dato: {0}", ((DateTime)Bilag.dato).ToShortDateString()); page.Canvas.DrawString(s, font2, brush2, 1, y, format2); PdfStringFormat format21 = new PdfStringFormat(PdfTextAlignment.Center); s = String.Format("Periode: {0}", Periode); page.Canvas.DrawString(s, font2, brush2, width / 2, y, format21); PdfStringFormat format22 = new PdfStringFormat(PdfTextAlignment.Right); s = String.Format("Bilag: {0}", ((int)Bilag.bilag).ToString()); page.Canvas.DrawString(s, font2, brush2, width, y, format22); y = y + font2.MeasureString(s, format2).Height; y = y + 25; String[][] dataSource = new String[Bilag.tbltrans.Count + 1][]; int i = 0; foreach (tbltran t in Bilag.tbltrans) { if (i == 0) { String[] headings = new String[5]; headings[0] = "Tekst"; headings[1] = "Kontonr"; headings[2] = "Kontonavn"; headings[3] = "Debet"; headings[4] = "Kredit"; dataSource[i++] = headings; } String[] datarow = new String[5]; datarow[0] = t.tekst; datarow[1] = t.kontonr.ToString(); datarow[2] = t.kontonavn; datarow[3] = t.debet != null ? ((decimal)(t.debet)).ToString("#,0.00;-#,0.00") : ""; datarow[4] = t.kredit != null ? ((decimal)(t.kredit)).ToString("#,0.00;-#,0.00") : ""; dataSource[i++] = datarow; } PdfTable table = new PdfTable(); table.Style.CellPadding = 5; //2; table.Style.HeaderSource = PdfHeaderSource.Rows; table.Style.HeaderRowCount = 1; table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold)); table.Style.ShowHeader = true; table.Style.RepeatHeader = true; table.DataSource = dataSource; table.Columns[0].Width = width * 0.30f * width; table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); table.Columns[1].Width = width * 0.10f * width; table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); table.Columns[2].Width = width * 0.30f * width; table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); table.Columns[3].Width = width * 0.15f * width; table.Columns[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); table.Columns[4].Width = width * 0.15f * width; table.Columns[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); PdfLayoutResult result = table.Draw(page, new PointF(0, y)); y = y + result.Bounds.Height + 5; //Save pdf file. string BilagPath = (from r in Program.karTrans2Summa where r.key == "BilagPath" select r.value).First(); string BilagNavn = String.Format(@"Bilag {0}.pdf", ((int)Bilag.bilag).ToString()); string filename = Path.Combine(BilagPath, BilagNavn); doc.SaveToFile(filename); doc.Close(); }