// If Equals() returns true for a pair of objects // then GetHashCode() must return the same value for these objects. public int GetHashCode(ListBoxPrintBadge item) { //Check whether the object is null if (Object.ReferenceEquals(item, null)) { return(0); } //Get hash code for the Name field if it is not null. int hashProductName = item.ToString == null ? 0 : item.ToString.GetHashCode(); //Get hash code for the Code field. int hashProductCode = item.Id.GetHashCode(); //Calculate the hash code for the product. return(hashProductName ^ hashProductCode); }
// Products are equal if their names and product numbers are equal. public bool Equals(ListBoxPrintBadge x, ListBoxPrintBadge y) { //Check whether the compared objects reference the same data. if (Object.ReferenceEquals(x, y)) { return(true); } //Check whether any of the compared objects is null. if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null)) { return(false); } //Check whether the products' properties are equal. return(x.Id == y.Id && x.ToString == y.ToString); }
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 ""; } }
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; }
// Products are equal if their names and product numbers are equal. public bool Equals(ListBoxPrintBadge x, ListBoxPrintBadge y) { //Check whether the compared objects reference the same data. if (Object.ReferenceEquals(x, y)) return true; //Check whether any of the compared objects is null. if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null)) return false; //Check whether the products' properties are equal. return x.Id == y.Id && x.ToString == y.ToString; }
// If Equals() returns true for a pair of objects // then GetHashCode() must return the same value for these objects. public int GetHashCode(ListBoxPrintBadge item) { //Check whether the object is null if (Object.ReferenceEquals(item, null)) return 0; //Get hash code for the Name field if it is not null. int hashProductName = item.ToString == null ? 0 : item.ToString.GetHashCode(); //Get hash code for the Code field. int hashProductCode = item.Id.GetHashCode(); //Calculate the hash code for the product. return hashProductName ^ hashProductCode; }