private int GetProjectFromFilter() { int retval = -1; McMetaViewPreference prefs = CHelper.GetMetaViewPreference(CurrentView); string blockId = prefs.GetAttribute <string>(TTFilterPopupEdit.FilterBlockAttr, TTFilterPopupEdit.FilterBlockAttr, "0"); if (blockId != string.Empty) { retval = Convert.ToInt32(blockId, CultureInfo.InvariantCulture); } return(retval); }
private bool Process() { Page.Validate(); if (!Page.IsValid) { return(false); } int blockTypeInstanceId = int.Parse(ProjectList.SelectedValue); if (blockTypeInstanceId < 0) { lblError2.Style.Add("display", ""); return(false); } McMetaViewPreference pref = CHelper.GetMetaViewPreference(CurrentView); DateTime startDate = CHelper.GetRealWeekStartByDate(pref.GetAttribute <DateTime>(TTFilterPopupEdit.FilterWeekAttr, TTFilterPopupEdit.FilterWeekAttr, DateTime.Today)); if (startDate == DateTime.MinValue) { startDate = CHelper.GetRealWeekStartByDate(DateTime.Today); } double maxMinutes = (double)(24 * 60); TimeTrackingManager.AddEntryWithData(blockTypeInstanceId, startDate, Mediachase.IBN.Business.Security.CurrentUser.UserID, txtEntry.Text, Math.Min((new TimeSpan(Day1Time.Value.Ticks)).TotalMinutes, maxMinutes), Math.Min((new TimeSpan(Day2Time.Value.Ticks)).TotalMinutes, maxMinutes), Math.Min((new TimeSpan(Day3Time.Value.Ticks)).TotalMinutes, maxMinutes), Math.Min((new TimeSpan(Day4Time.Value.Ticks)).TotalMinutes, maxMinutes), Math.Min((new TimeSpan(Day5Time.Value.Ticks)).TotalMinutes, maxMinutes), Math.Min((new TimeSpan(Day6Time.Value.Ticks)).TotalMinutes, maxMinutes), Math.Min((new TimeSpan(Day7Time.Value.Ticks)).TotalMinutes, maxMinutes)); BindNullValues(); return(true); }
private void BindSavedValues() { McMetaViewPreference pref = GetMetaViewPreference(); if (tdProject.Visible) { CHelper.SafeSelect(ttBlock, pref.GetAttribute <string>(FilterBlockAttr, FilterBlockAttr, "0")); } if (tdUser.Visible) { CHelper.SafeSelect(ddUser, pref.GetAttribute <string>(FilterUserAttr, FilterUserAttr, Mediachase.IBN.Business.Security.CurrentUser.UserID.ToString())); } if (tdPeriod.Visible) { CHelper.SafeSelect(ddPeriod, pref.GetAttribute <string>("TTFilter_Period", "TTFilter_Period", "[DateTimeThisWeek]")); if (ddPeriod.SelectedValue == "0") //week { DateTime dt = CHelper.GetWeekStartByDate(pref.GetAttribute <DateTime>("TTFilter_DTCBeg", "TTFilter_DTCBeg", DateTime.Now)); DTCBeg.SelectedDate = dt; } else if (ddPeriod.SelectedValue == "-1") //period { DateTime dt = CHelper.GetWeekStartByDate(pref.GetAttribute <DateTime>("TTFilter_DTCBeg", "TTFilter_DTCBeg", DateTime.Now)); DTCBeg.SelectedDate = dt; dt = CHelper.GetWeekStartByDate(pref.GetAttribute <DateTime>("TTFilter_DTCEnd", "TTFilter_DTCEnd", DateTime.Now)); DTCEnd.SelectedDate = dt; } } else if (tdWeek.Visible) { DateTime dt = CHelper.GetWeekStartByDate(pref.GetAttribute <DateTime>(FilterWeekAttr, FilterWeekAttr, DateTime.Now)); if (dt == DateTime.MinValue) { dt = CHelper.GetWeekStartByDate(DateTime.Now); } DTCWeek.SelectedDate = dt; if (this.Visible) { CHelper.AddToContext("SelectedWeek", dt); } } else if (WeekerDiv.Visible) { DateTime dt = CHelper.GetWeekStartByDate(pref.GetAttribute <DateTime>(FilterWeekAttr, FilterWeekAttr, DateTime.Now)); if (dt == DateTime.MinValue) { dt = CHelper.GetWeekStartByDate(DateTime.Now); } DTCWeeker.SelectedDate = dt; if (this.Visible) { CHelper.AddToContext("SelectedWeek", dt); } } if (tdState.Visible) { CHelper.SafeSelect(ddState, pref.GetAttribute <string>(FilterStateAttr, FilterStateAttr, "0")); } }
private void BindBlocks() { ProjectList.Items.Clear(); string titledFieldName = TimeTrackingManager.GetBlockTypeInstanceMetaClass().TitleFieldName; McMetaViewPreference pref = CHelper.GetMetaViewPreference(CurrentView); DateTime startDate = CHelper.GetRealWeekStartByDate(pref.GetAttribute <DateTime>(TTFilterPopupEdit.FilterWeekAttr, TTFilterPopupEdit.FilterWeekAttr, DateTime.MinValue)); if (startDate == DateTime.MinValue) { startDate = CHelper.GetRealWeekStartByDate(DateTime.Now); } int ownerId = Mediachase.IBN.Business.Security.CurrentUser.UserID; BindDayHeaders(startDate); // Non-project #region 1. Make the list of all BlockTypeInstances List <int> idList = new List <int>(); Dictionary <int, string> allList = new Dictionary <int, string>(); foreach (TimeTrackingBlockTypeInstance item in TimeTrackingManager.GetNonProjectBlockTypeInstances()) { idList.Add(item.PrimaryKeyId.Value); allList.Add(item.PrimaryKeyId.Value, item.Title); } #endregion #region 2. Check the rights AddMyTTBlock and AddAnyTTBlock and remove from the allList the forbidden items SerializableDictionary <int, Collection <string> > objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), idList.ToArray()); foreach (KeyValuePair <int, Collection <string> > item in objectRights) { int id = item.Key; Collection <string> allowedRights = item.Value; if (!((allowedRights.Contains(TimeTrackingManager.Right_AddMyTTBlock) && ownerId == Mediachase.Ibn.Data.Services.Security.CurrentUserId) || allowedRights.Contains(TimeTrackingManager.Right_AddAnyTTBlock))) { allList.Remove(id); } } #endregion #region 3. Make the list of the TimeTrackingBlocks by OwnerId, StartDate and BlockTypeInstanceId[] List <string> blockTypeInstanceIdList = new List <string>(); foreach (int id in allList.Keys) { blockTypeInstanceIdList.Add(id.ToString(CultureInfo.InvariantCulture)); } List <int> blockIdList = new List <int>(); Dictionary <int, int> blockInstanceList = new Dictionary <int, int>(); TimeTrackingBlock[] blocks = TimeTrackingBlock.List( FilterElement.EqualElement("OwnerId", ownerId), FilterElement.EqualElement("StartDate", startDate), new FilterElement("BlockTypeInstanceId", FilterElementType.In, blockTypeInstanceIdList.ToArray()) ); foreach (TimeTrackingBlock block in blocks) { blockIdList.Add(block.PrimaryKeyId.Value); blockInstanceList.Add(block.PrimaryKeyId.Value, block.BlockTypeInstanceId); } #endregion #region 4. Check the right Write and remove from the allList the forbidden items objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlock.GetAssignedMetaClass(), blockIdList.ToArray()); foreach (KeyValuePair <int, Collection <string> > item in objectRights) { int id = item.Key; Collection <string> allowedRights = item.Value; if (!allowedRights.Contains(Mediachase.Ibn.Data.Services.Security.RightWrite)) { allList.Remove(blockInstanceList[id]); } } #endregion #region 5. Fill in the dropdown if (allList.Count > 0) { ProjectList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByActivity").ToString(), "-1")); foreach (KeyValuePair <int, string> item in allList) { ListItem li = new ListItem(" " + item.Value, item.Key.ToString()); ProjectList.Items.Add(li); } } #endregion // Projects #region 1. Make the list of all BlockTypeInstances idList = new List <int>(); allList = new Dictionary <int, string>(); foreach (TimeTrackingBlockTypeInstance item in TimeTrackingManager.GetProjectBlockTypeInstances()) { idList.Add(item.PrimaryKeyId.Value); allList.Add(item.PrimaryKeyId.Value, item.Title); } #endregion #region 2. Check the rights AddMyTTBlock and AddAnyTTBlock and remove from the allList the forbidden items objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), idList.ToArray()); foreach (KeyValuePair <int, Collection <string> > item in objectRights) { int id = item.Key; Collection <string> allowedRights = item.Value; if (!((allowedRights.Contains(TimeTrackingManager.Right_AddMyTTBlock) && ownerId == Mediachase.Ibn.Data.Services.Security.CurrentUserId) || allowedRights.Contains(TimeTrackingManager.Right_AddAnyTTBlock))) { allList.Remove(id); } } #endregion #region 3. Make the list of the TimeTrackingBlocks by OwnerId, StartDate and BlockTypeInstanceId[] blockTypeInstanceIdList = new List <string>(); foreach (int id in allList.Keys) { blockTypeInstanceIdList.Add(id.ToString(CultureInfo.InvariantCulture)); } blockIdList = new List <int>(); blockInstanceList = new Dictionary <int, int>(); blocks = TimeTrackingBlock.List( FilterElement.EqualElement("OwnerId", ownerId), FilterElement.EqualElement("StartDate", startDate), new FilterElement("BlockTypeInstanceId", FilterElementType.In, blockTypeInstanceIdList.ToArray()) ); foreach (TimeTrackingBlock block in blocks) { blockIdList.Add(block.PrimaryKeyId.Value); blockInstanceList.Add(block.PrimaryKeyId.Value, block.BlockTypeInstanceId); } #endregion #region 4. Check the right Write and remove from the allList the forbidden items objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlock.GetAssignedMetaClass(), blockIdList.ToArray()); foreach (KeyValuePair <int, Collection <string> > item in objectRights) { int id = item.Key; Collection <string> allowedRights = item.Value; if (!allowedRights.Contains(Mediachase.Ibn.Data.Services.Security.RightWrite)) { allList.Remove(blockInstanceList[id]); } } #endregion #region 5. Fill in the dropdown if (allList.Count > 0) { ProjectList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByProject").ToString(), "-2")); foreach (KeyValuePair <int, string> item in allList) { ListItem li = new ListItem(" " + item.Value, item.Key.ToString()); ProjectList.Items.Add(li); } } #endregion if (blockInstanceId > 0) { CHelper.SafeSelect(ProjectList, blockInstanceId.ToString()); } EnsureSelectInstance(); }