/// <summary> /// "Type" the contents of this record into a NovaCode Cell. /// </summary> /// <param name="c"></param> /// <param name="rec"></param> protected override void TypeOneRecord(Cell c, object rec) { string family_last_name; string gen; c.MarginTop = (int)(0.1 * (int)DocPartUnits.Margins); GiftLabelInfo gli = (GiftLabelInfo)rec; // Xceed.Words.NET should initialize Cells with one // paragraph. But, in the unlikeley case // that that paragraph isn't there, add one. Paragraph p = c.Paragraphs.First(); if (p == null) { p = c.InsertParagraph(); } gen = gli.child_gender == "NotSpecified" ? "" : ", " + gli.child_gender; if (this.RequestType == "Other") { family_last_name = $" ({gli.family_last_name}) "; } else { family_last_name = ""; } string top_line = $"{Dnr.code} {gli.family_id}{family_last_name} {gli.child_name} {gli.child_age} Yr{gen}"; p.Append(top_line).Bold() .AppendLine(gli.request_detail); if (this.RequestType == "Clothing") { p.AppendLine(Properties.Resources.GiftReceiptRequest); } }
// GiftLabelInfo methods /// <summary> /// //////////////////// public GiftLabelInfo MatchingGiftLabelInfo(GiftLabelInfo other) { return this._glicoll.Find(g => g.year == other.year && g.family_id == other.family_id && g.child_name == other.child_name && g.request_type == other.request_type ).FirstOrDefault(); }
/// <summary> /// Add passed-in object to database collection, if /// it's not already present. If it is already there, /// update the database element with the properties /// of the passed-inobject. /// </summary> /// <param name="bli"></param> /// <returns></returns> public GiftLabelInfo AddOrUpdateGLI(GiftLabelInfo gli) { GiftLabelInfo dbo = this.MatchingGiftLabelInfo(gli); if (dbo == null) { // not found -- insert the one passed // to us. As a side effect, the Insert() // method updates the Id property of the // inserted object. this._glicoll.Insert(gli); } else { // found -- set the id of the passed-in object to // that of the found object. gli.Id = dbo.Id; // Now replace the object in the database with // the one passed in. this._glicoll.Update(gli); } return gli; }