public static void ExpireOverlappingInstances(ICategorizedTemporalList <T> list, T newInstance) { DateTime effectiveDate = newInstance.EffectivePeriod.EffectiveDate; TreeListNode newCat = ((ICategorizedTemporal)newInstance).Category; //Validate foreach (T i in list) { if (i.EffectivePeriod.EffectiveDate > effectiveDate && ((ICategorizedTemporal)i).Category == newCat) { throw new iSabayaException("The effective date of the added instance is less than existing effective date"); } } //Expire the current one foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(effectiveDate) && item.Category == newCat) { item.EffectivePeriod.ExpiryDate = effectiveDate; } } }
private long CreatePartyAttribute(long ID) { PartyAttribute attribute = null; if (ID == 0) { attribute = new PartyAttribute(); attribute.ID = 0; } else { attribute = PartyAttribute.Find(iSabayaContext, ID); if (attribute == null) { return(0); } // Set Properties } if (ctrlAttributeKey.SelectedNode == null) { return(0); } attribute.Party = this.GetPartyOwner(); attribute.AttributeKey = ctrlAttributeKey.SelectedNode; attribute.AttributeKeyRootNode = ctrlAttributeKey.SelectedNode.Root; DateTime dateFrom = ctrlEffectiveFrom.Date; dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); attribute.EffectivePeriod = new TimeInterval(dateFrom, ctrlEffectiveTo.Date); attribute.ValueDate = ctrlValueDate.Date; if (!string.IsNullOrEmpty(hddValueImage.Value)) { attribute.ValueImage = ImageUtil.Base64ToImage(hddValueImage.Value); } attribute.ValueMLS = ctrlValueMLS.Value; attribute.ValueNode = null; attribute.ValueNodeRoot = null; attribute.ValueNumber = Convert.ToSingle(spnValueNumber.Value); attribute.ValueText = txtValueText.Text; if (OwnerID != 0) { attribute.Save(iSabayaContext); } else { ICategorizedTemporalList <PartyAttribute> attributes = PartyAttributes; for (int i = 0; i < attributes.Count; i++) { if (attributes[i].AttributeKey.NodeID == attribute.AttributeKey.NodeID) { attributes.Remove(attributes[i]); break; } } PartyAttributes.Add(attribute); } return(attribute.ID); }
public static T GetInstance(ICategorizedTemporalList <T> list, DateTime when, TreeListNode category) { foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(when) && item.Category == category) { return(i); } } return(default(T)); }
public static IList <T> GetInstances(ICategorizedTemporalList <T> list, TreeListNode category) { CategorizedTemporalList <T> matches = new CategorizedTemporalList <T>(); foreach (T i in list) { if (((ICategorizedTemporal)i).Category == category) { matches.Add(i); } } return(matches); }
public static IList <T> GetInstances(ICategorizedTemporalList <T> list, DateTime when) { CategorizedTemporalList <T> matches = new CategorizedTemporalList <T>(); foreach (T i in list) { if (((ICategorizedTemporal)i).EffectivePeriod.IsEffectiveOn(when)) { matches.Add(i); } } return(matches); }
public static IList <T> GetInstances(ICategorizedTemporalList <T> list, DateTime when, TreeListNode parentCategory) { CategorizedTemporalList <T> matches = new CategorizedTemporalList <T>(); foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(when) && item.Category.Parent == parentCategory) { matches.Add(i); } } return(matches); }
public static bool ContainsCategoryParent(ICategorizedTemporalList <T> list, DateTime when, TreeListNode parentCategory) { bool exist = false; foreach (T i in list) { ICategorizedTemporal item = (ICategorizedTemporal)i; if (item.EffectivePeriod.IsEffectiveOn(when) && item.Category.Parent == parentCategory) { exist = true; break; } } return(exist); }
protected void cbpEdit_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { JsonObjectCollection objs = new JsonObjectCollection(); ASPxCallbackPanel cbp = (ASPxCallbackPanel)sender; int attributeID = 0; bool isEffective = false; PartyAttribute partyAttribute = null; string[] parameters = e.Parameter.Split(';'); if (parameters.Length > 1) { int index = int.Parse(parameters[1]); if (index >= 0) { if (OwnerID != 0) { attributeID = (int)gdvPartyAttribute.GetRowValues(index, gdvPartyAttribute.KeyFieldName); partyAttribute = PartyAttribute.Find(iSabayaContext, attributeID); } else { TreeListNode node = (TreeListNode)gdvPartyAttribute.GetRowValues(index, "AttributeKey"); ICategorizedTemporalList <PartyAttribute> attributes = PartyAttributes; for (int i = 0; i < attributes.Count; i++) { if (attributes[i].AttributeKey.NodeID == node.NodeID) { partyAttribute = attributes[i]; break; } } } } } switch (parameters[0]) { case KEY_DISPLAY: tbButtonSaveCancel.Visible = false; uplImage.Visible = false; btnUploadImg.Visible = false; if (partyAttribute != null) { isEffective = partyAttribute.EffectivePeriod.IsEffective(); if (!isEffective) { string color = ColorTranslator.ToHtml(System.Drawing.Color.Red); tdAttributeKey.Style.Add(HtmlTextWriterStyle.Color, color); tdEffectiveTo.Style.Add(HtmlTextWriterStyle.Color, color); tdEffectiveFrom.Style.Add(HtmlTextWriterStyle.Color, color); tdValueDate.Style.Add(HtmlTextWriterStyle.Color, color); tdValueMLS.Style.Add(HtmlTextWriterStyle.Color, color); tdValueNode.Style.Add(HtmlTextWriterStyle.Color, color); tdValueNumber.Style.Add(HtmlTextWriterStyle.Color, color); tdValueText.Style.Add(HtmlTextWriterStyle.Color, color); tdValueImage.Style.Add(HtmlTextWriterStyle.Color, color); } tdAttributeKey.InnerText = partyAttribute.AttributeKey.Title.ToString(LanguageCode); tdEffectiveTo.InnerText = partyAttribute.EffectivePeriod.ExpiryDate.ToString(base.DateOutputFormat); tdEffectiveFrom.InnerText = partyAttribute.EffectivePeriod.EffectiveDate.ToString(base.DateOutputFormat); tdValueDate.InnerText = partyAttribute.ValueDate.ToString(base.DateOutputFormat); tdValueMLS.InnerHtml = " "; if (partyAttribute.ValueMLS != null) { string value = partyAttribute.ValueMLS.ToString(base.LanguageCode); if (!string.IsNullOrEmpty(value)) { tdValueMLS.InnerHtml = partyAttribute.ValueMLS.ToString(base.LanguageCode); } } tdValueNode.InnerHtml = partyAttribute.ValueNode != null?partyAttribute.ValueNode.ToString(base.LanguageCode) : " "; tdValueNumber.InnerHtml = partyAttribute.ValueNumber.ToString(); tdValueText.InnerHtml = !String.IsNullOrEmpty(partyAttribute.ValueText) ? partyAttribute.ValueText : " "; if (partyAttribute.ValueImage != null) { Size aspectSize = ImageUtil.GetAspectSize(partyAttribute.ValueImage.Size, 100); byte[] imageBytes = ImageUtil.ImageToBytes(partyAttribute.ValueImage); ctrlValueImage.ContentBytes = imageBytes; ctrlValueImage.Width = aspectSize.Width; ctrlValueImage.Height = aspectSize.Height; } else { tdValueImage.InnerHtml = " "; } } else { panelEditForm.Controls.Clear(); panelEditForm.Controls.Add(new Label() { Text = "No Party Attribute" }); } break; //=============================================================================== // Edit case is obsoleted //=============================================================================== case KEY_EDIT: tbButtonSaveCancel.Visible = true; TreeListNode rootNode = null; switch (OwnerDiscriminator) { case 10: rootNode = iSabayaContext.Configuration.Organization.AttributeKeyParentNode; break; //Organization; case 15: rootNode = iSabayaContext.Configuration.Organization.AttributeKeyParentNode; break; //OrgUnit case 20: rootNode = iSabayaContext.Configuration.Person.AttributeKeyParentNode; break; //Person //case 30: rootNode = iSabayaContext.iSabayaConfig.MF.AttributeKeyRootNode; break; //MutualFund //case 40: rootNode = iSabayaContext.iSabayaConfig.MF.AttributeKeyRootNode; break; // ProvidentFund //case 50: rootNode = iSabayaContext.iSabayaConfig.MF.AttributeKeyRootNode; break; // MFAccount //case 60: rootNode = iSabayaContext.iSabayaConfig.MF.AttributeKeyRootNode; break; //Employee default: break; } ctrlAttributeKey.ParentNode = rootNode; ctrlAttributeKey.DataBind(); ctrlAttributeKey.SetValidation("attributeEdit"); //ctrlAttributeKey.InitializeTreeListNode("Attribute Key", rootNode, null); uplImage.Visible = true; btnUploadImg.Visible = true; if (gdvPartyAttribute.FocusedRowIndex >= 0) { if (partyAttribute != null) { ctrlAttributeKey.SelectedNode = partyAttribute.AttributeKey; ctrlEffectiveFrom.Date = partyAttribute.EffectivePeriod.EffectiveDate; ctrlEffectiveTo.Date = partyAttribute.EffectivePeriod.ExpiryDate; ctrlValueDate.Value = partyAttribute.ValueDate != null ? (object)partyAttribute.ValueDate : null; ctrlValueMLS.Value = partyAttribute.ValueMLS; spnValueNumber.Value = partyAttribute.ValueNumber; txtValueText.Value = partyAttribute.ValueText; if (partyAttribute.ValueImage != null) { Size aspectSize = ImageUtil.GetAspectSize(partyAttribute.ValueImage.Size, 100); byte[] imageBytes = ImageUtil.ImageToBytes(partyAttribute.ValueImage); ctrlValueImage.ContentBytes = imageBytes; ctrlValueImage.Width = aspectSize.Width; ctrlValueImage.Height = aspectSize.Height; } } } else { ctrlEffectiveTo.Date = TimeInterval.MaxDate; } break; //================================================================================= default: break; } //jsonCollection.Add(new JsonStringValue("CallbackType", e.Parameter)); objs.Add(new JsonBooleanValue("isEffective", isEffective)); objs.Add(new JsonNumericValue("AttributeID", attributeID)); cbp.JSProperties[KEY_CP_RESULT] = objs.ToString(); }
protected void gdvPartyAttribute_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) { ASPxGridView gdv = (ASPxGridView)sender; ITransaction tx = iSabayaContext.PersistenceSession.BeginTransaction(); JsonObjectCollection objs = new JsonObjectCollection(); bool isSetNewFoucused = false; bool isCommit = true; long attributeID = 0; string msg = ""; try { string[] parameters = e.Parameters.Split(';'); switch (parameters[0]) { case KEY_EDIT: attributeID = this.CreatePartyAttribute(long.Parse(parameters[1])); isSetNewFoucused = true; break; case KEY_EXPIRE: int index = Int32.Parse(parameters[1]); if (OwnerID == 0) { gdv.DataBind(); PartyAttribute attribute = (PartyAttribute)gdv.GetRow(index); ICategorizedTemporalList <PartyAttribute> attributes = PartyAttributes; for (int i = 0; i < attributes.Count; i++) { if (attributes[i].AttributeKey == attribute.AttributeKey) { attributes.Remove(attributes[i]); break; } } } else { attributeID = (int)gdv.GetRowValues(index, gdv.KeyFieldName); this.ExpirePartyAttribute(attributeID); } break; // when owner id = 0 only case "clear": if (OwnerID == 0) { PartyAttributes.Clear(); } break; default: isCommit = false; break; } if (isCommit) { tx.Commit(); } gdv.DataBind(); if (attributeID > 0 && isSetNewFoucused) { for (int i = gdv.VisibleRowCount - 1; i >= gdv.VisibleStartIndex; i--) { if ((int)gdv.GetRowValues(i, gdv.KeyFieldName) == attributeID) { gdv.FocusedRowIndex = i; break; } } } else { gdv.FocusedRowIndex = 0; } } catch (Exception ex) { if (isCommit) { tx.Rollback(); } while (ex != null) { msg = ex.Message + "\n" + msg; ex = ex.InnerException; } gdv.DataBind(); } objs.Add(new JsonNumericValue("AttributeID", attributeID)); objs.Add(new JsonStringValue("Message", msg)); gdv.JSProperties[KEY_CP_RESULT] = objs.ToString(); }