Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private DateTime GetStartDateFromFilter()
        {
            DateTime             retval = DateTime.MinValue;
            McMetaViewPreference prefs  = CHelper.GetMetaViewPreference(CurrentView);

            if (prefs != null && prefs.Filters != null)
            {
                foreach (FilterElement filter in prefs.Filters.GetListBySource("startdate"))
                {
                    if (filter.Value != null)
                    {
                        retval = (DateTime)filter.Value;
                        break;
                    }
                }
            }
            return(retval);
        }
Ejemplo n.º 3
0
        private int GetUserFromFilter()
        {
            int retval = -1;
            McMetaViewPreference prefs = CHelper.GetMetaViewPreference(CurrentView);

            if (prefs != null && prefs.Filters != null)
            {
                foreach (FilterElement filter in prefs.Filters.GetListBySource("ownerid"))
                {
                    if (filter.Value != null)
                    {
                        retval = (int)filter.Value;
                        break;
                    }
                }
            }
            return(retval);
        }
Ejemplo n.º 4
0
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters cp = (CommandParameters)Element;
                if (cp.CommandArguments == null)
                {
                    return;
                }
                DateTime dtStart = DateTime.Parse(cp.CommandArguments["primaryKeyId"], CultureInfo.InvariantCulture);

                MetaView             currentView = DataContext.Current.MetaModel.MetaViews["TT_MyGroupByWeekProject"];
                McMetaViewPreference pref        = CHelper.GetMetaViewPreference(currentView);
                pref.SetAttribute <DateTime>("TTFilter_DTCWeek", "TTFilter_DTCWeek", dtStart);
                Mediachase.Ibn.Core.UserMetaViewPreference.Save(Mediachase.IBN.Business.Security.CurrentUser.UserID, pref);

                ((System.Web.UI.Control)(Sender)).Page.Response.Redirect("~/Apps/TimeTracking/Pages/Public/ListTimeTrackingNew.aspx?ViewName=TT_MyGroupByWeekProject", true);
            }
        }
Ejemplo n.º 5
0
        private bool Process()
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return(false);
            }

            if (startDate == DateTime.MinValue)
            {
                throw new NotSupportedException("Start date is not specified");
            }

            int blockTypeInstanceId = int.Parse(ProjectList.SelectedValue);

            if (blockTypeInstanceId < 0)
            {
                lblError2.Style.Add("display", "");
                return(false);
            }

            McMetaViewPreference pref = CHelper.GetMetaViewPreference(CurrentView);
            int ownerId = int.Parse(UserList.SelectedValue, CultureInfo.InvariantCulture);

            double maxMinutes = (double)(24 * 60);

            TimeTrackingManager.AddEntryWithData(blockTypeInstanceId,
                                                 startDate,
                                                 ownerId,
                                                 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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
 private McMetaViewPreference GetMetaViewPreference()
 {
     return(CHelper.GetMetaViewPreference(CurrentView));
 }
Ejemplo n.º 8
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();
        }