コード例 #1
0
ファイル: BadgeViewModel.cs プロジェクト: rymbln/WPFDB
 public BadgeViewModel(BadgeType obj)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("BadgeType");
     }
     this.Model = obj;
 }
コード例 #2
0
ファイル: DocumentManager.cs プロジェクト: rymbln/WPFDB
        public static string Generate(DocumentType mode, BadgeType obj, ListBoxPrintBadge person)
        {
            switch (mode)
            {
                case DocumentType.BADGE:
                    return DrawBadgeToPicture(obj, person);

                case DocumentType.ORDER:
                    return "";
                default:
                    return "";
            }
        }
コード例 #3
0
ファイル: DocumentManager.cs プロジェクト: rymbln/WPFDB
        private static string DrawBadgeToPicture(BadgeType obj, ListBoxPrintBadge person)
        {
            String filename;
            // Create a temporary file
            var bmp = new Bitmap(obj.Width, obj.Height);
            var gfx = Graphics.FromImage(bmp);
            gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
            if (person != null)
            {
                filename = String.Format("{0}_{1}_{2}.png", person.Id, person.F+person.IO, DefaultManager.Instance.CurrentDateTimeShortString);
            }
            else
            {
                filename = String.Format("{0}.png", DefaultManager.Instance.CurrentDateTimeShortString);
            }
            filename = DefaultManager.Instance.AbstractFilePath + @"\" + filename;

            foreach (var badge in obj.Badges.ToList())
            {
                if (person != null)
                {
                    badge.Value = badge.Value.Replace("$F$", person.F);
                    badge.Value = badge.Value.Replace("$IO$", person.IO);
                    badge.Value = badge.Value.Replace("$COMPANY$", person.Company);
                    badge.Value = badge.Value.Replace("$CITY$", person.City);
                    badge.Value = badge.Value.Replace("$COUNTRY$", person.Country);
                }
                else
                {
                    badge.Value = badge.Value.Replace("$F$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                    badge.Value = badge.Value.Replace("$IO$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                    badge.Value = badge.Value.Replace("$COMPANY$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                    badge.Value = badge.Value.Replace("$CITY$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                    badge.Value = badge.Value.Replace("$COUNTRY$", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
                }
                var color = ConverterManager.HexToColorConverter(badge.ForegroundColor);
                var borderColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B);
                color = ConverterManager.HexToColorConverter(badge.BackgroundColor);
                var backColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B);
                color = ConverterManager.HexToColorConverter(badge.FontColor);
                var fontColor = System.Drawing.Color.FromArgb(color.R, color.G, color.B);

                var brush = new SolidBrush(backColor);
                var pen = new System.Drawing.Pen(borderColor, float.Parse(badge.BorderWidth.ToString()));
                var rectangle = new Rectangle(badge.PositionX1, badge.PositionY1, badge.Width, badge.Height);

                gfx.FillRectangle(brush, rectangle);
                gfx.DrawRectangle(pen, rectangle);

                System.Drawing.Font font = null;
                switch (badge.FontStyle)
                {
                    case "Bold":
                        font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Bold);
                        break;
                    case "Italic":
                        font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Italic);
                        break;
                    case "Regular":
                        font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Regular);
                        break;
                    case "Underline":
                        font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Underline);
                        break;
                    case "Strikeout":
                        font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Strikeout);
                        break;
                    case "BoldItalic":
                        font = new System.Drawing.Font(badge.Font, (float)badge.FontSize, FontStyle.Bold | FontStyle.Italic);
                        break;
                    default:
                        break;
                }
                var rect = new RectangleF(badge.PositionX1, badge.PositionY1, badge.Width, badge.Height);
                brush = new SolidBrush(fontColor);
                var sf = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                sf.Trimming = StringTrimming.Word;
                gfx.DrawString(badge.Value, font, brush, rect, sf);

            }

            gfx.Flush();

            bmp.Save(filename, ImageFormat.Png);
            return filename;
        }
コード例 #4
0
ファイル: DocumentManager.cs プロジェクト: rymbln/WPFDB
        private static string DrawBadge(BadgeType obj, Person person)
        {
            String filename;
            // Create a temporary file

            var s_document = new PdfDocument();
            if (person != null)
            {
                 filename = String.Format("{0}_{1}_{2}.pdf", person.Id, person.FullName, DefaultManager.Instance.CurrentDateTimeShortString);
                 s_document.Info.Title = person.FullName;
            } else
            {
                 filename = String.Format("{0}.pdf",  DefaultManager.Instance.CurrentDateTimeShortString);
                 s_document.Info.Title = "IACMAC";
            }
            filename = DefaultManager.Instance.AbstractFilePath + @"\" + filename;
            s_document.Info.Author = "IACMAC";
            s_document.Info.Subject = "IACMAC Conference Badge";

            // Create  pages
            var page = s_document.AddPage();

            PageSize[] pageSizes = (PageSize[])Enum.GetValues(typeof(PageSize));
            foreach (PageSize pageSize in pageSizes)
            {
                if (pageSize == PageSize.Undefined)
                    continue;
                page.Width = obj.Width;
                page.Height = obj.Height;
                page.Orientation = PageOrientation.Portrait;
            }

            XGraphics gfx = XGraphics.FromPdfPage(page);

            foreach (var badge in obj.Badges.ToList())
            {
                if (person != null)
                {
                       badge.Value = badge.Value.Replace("$F$", person.FirstName);
                       badge.Value = badge.Value.Replace("$FI$", person.FirstName + " " + person.SecondName);
                       badge.Value = badge.Value.Replace("$FIO$", person.FirstName + " " + person.SecondName + " " + person.ThirdName);
                       badge.Value = badge.Value.Replace("$POST$", person.Post);
                       badge.Value = badge.Value.Replace("$CITY$", person.Addresses.Select(o => o.CityName).FirstOrDefault());
                       badge.Value = badge.Value.Replace("$COUNTRY$", person.Addresses.Select(o => o.CountryName).FirstOrDefault());
                    //badge.Value.Replace("$COMPANY$", person);
                }
                DrawBadgeElement(badge, gfx);
            }

            //   DrawRoundedRectangle(gfx, 2);
            //  DrawEllipse(gfx, 3);

            // Save the s_document...
            s_document.Save(filename);
            // ...and start a viewer
            return filename;
        }
コード例 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the BadgeTypes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToBadgeTypes(BadgeType badgeType)
 {
     base.AddObject("BadgeTypes", badgeType);
 }
コード例 #6
0
 /// <summary>
 /// Create a new BadgeType object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="code">Initial value of the Code property.</param>
 /// <param name="width">Initial value of the Width property.</param>
 /// <param name="height">Initial value of the Height property.</param>
 /// <param name="sourceId">Initial value of the SourceId property.</param>
 public static BadgeType CreateBadgeType(global::System.Guid id, global::System.String name, global::System.String code, global::System.Int32 width, global::System.Int32 height, global::System.Int32 sourceId)
 {
     BadgeType badgeType = new BadgeType();
     badgeType.Id = id;
     badgeType.Name = name;
     badgeType.Code = code;
     badgeType.Width = width;
     badgeType.Height = height;
     badgeType.SourceId = sourceId;
     return badgeType;
 }