public void Load(mcweb_MetaViewPreferenceRow preferenceRow, List <string> availableFieldNames) { _columns.Clear(); if (preferenceRow != null) { Dictionary <string, ColumnInfo> columnsByName = new Dictionary <string, ColumnInfo>(); McMetaViewPreference preference = UserMetaViewPreference.GetPreferenceFromString(preferenceRow.XSMetaViewPreference); AttributeCollection attributes = preference.Attributes; for (int i = 0; i < attributes.Count; i++) { string key = attributes.Keys[i]; string[] parts = key.Split(':'); if (parts.Length == 2) { string fieldName = parts[0]; if (availableFieldNames.Contains(fieldName)) { ColumnInfo column; if (columnsByName.ContainsKey(fieldName)) { column = columnsByName[fieldName]; } else { column = new ColumnInfo(fieldName); columnsByName.Add(fieldName, column); } string attributeName = parts[1]; object value = attributes[key]; switch (attributeName) { case "Index": column.Index = (int)value; break; case "Width": column.Width = (int)value; break; } } } } _columns.AddRange(columnsByName.Values); // Sort columns by index. _columns.Sort(); } else { foreach (string name in availableFieldNames) { _columns.Add(new ColumnInfo(name)); } } }
/// <summary> /// Internals the bind header. /// </summary> private void internalBindHeader() { McMetaViewPreference mvPref = GetMetaViewPreference(); int counter = 0; int notMetaFields = 0; for (int i = 0; i < this.CustomColumns.Count; i++) { MainGrid.Columns[i].HeaderText = CHelper.GetResFileString(this.CustomColumns[i].Title); MainGrid.Columns[i].ItemStyle.Width = this.CustomColumns[i].Width; MainGrid.Columns[i].HeaderStyle.Width = this.CustomColumns[i].Width; notMetaFields++; } counter += this.CustomColumns.Count; foreach (MetaField field in this.VisibleMetaFields) { int _width = GetMetaViewPreference().GetMetaFieldWidth(counter - notMetaFields, 100); if (_width == 0) { _width = 100; } MainGrid.Columns[counter].ItemStyle.Width = _width; MainGrid.Columns[counter].HeaderStyle.Width = _width; //add sorting only for metaFileds that supports sorting at MetaData level if (MetaDataWrapper.IsSortable(field)) { MainGrid.Columns[counter].SortExpression = field.Name; } DataControlField controlField = MainGrid.Columns[counter]; controlField.HeaderText = CHelper.GetResFileString(field.FriendlyName); // Raising event ChangingMetaGridColumnHeaderEventArgs e = new ChangingMetaGridColumnHeaderEventArgs(controlField, field); OnChangingMetaGridColumnHeader(e); #region Sorting header text (arrows up/down) if (mvPref.Sorting != null && mvPref.Sorting.Count > 0 && mvPref.Sorting[0].Source == field.Name) { if (mvPref.Sorting[0].Type == SortingElementType.Asc) { MainGrid.Columns[counter].HeaderText += String.Format(" <img alt='' border='0' src='{0}' />", this.ResolveUrl("~/images/IbnFramework/sort_asc.gif")); } else { MainGrid.Columns[counter].HeaderText += String.Format(" <img alt='' border='0' src='{0}' />", this.ResolveUrl("~/images/IbnFramework/sort_desc.gif")); } } #endregion counter++; } }
public McMetaViewPreference GetMetaViewPreference() { McMetaViewPreference pref = Mediachase.Ibn.Core.UserMetaViewPreference.Load(CurrentView, Mediachase.IBN.Business.Security.CurrentUser.UserID); if (pref == null || pref.Attributes.Count == 0) { McMetaViewPreference.CreateDefaultUserPreference(CurrentView); pref = Mediachase.Ibn.Core.UserMetaViewPreference.Load(CurrentView, Mediachase.IBN.Business.Security.CurrentUser.UserID); } return(pref); }
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); }
/// <summary> /// Gets the meta view preference. /// </summary> /// <returns></returns> public McMetaViewPreference GetMetaViewPreference() { McMetaViewPreference pref = UserMetaViewPreference.Load(CurrentView, (int)DataContext.Current.CurrentUserId); if (pref == null || pref.Attributes.Count == 0) { McMetaViewPreference.CreateDefaultUserPreference(CurrentView); pref = UserMetaViewPreference.Load(CurrentView, (int)DataContext.Current.CurrentUserId); } return(pref); }
/// <summary> /// Handles the Sorting event of the MainGrid control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewSortEventArgs"/> instance containing the event data.</param> void MainGrid_Sorting(object sender, GridViewSortEventArgs e) { #region Check for field being meta field bool _flag = false; foreach (MetaField field in CurrentView.AvailableFields) { if (field.Name == e.SortExpression) { _flag = true; break; } } if (!_flag) { return; } #endregion McMetaViewPreference mvPref = GetMetaViewPreference(); //fix bug when user try to sort column which doesn't support sorting at MetaData level if (!MetaDataWrapper.IsSortable(e.SortExpression, mvPref)) { return; } //fix issue with ajaxcontroltoolkit 3.5 Thread.Sleep(750); if (mvPref.Sorting == null || mvPref.Sorting.Count == 0) { SortingElement new_sort = new SortingElement(); mvPref.Sorting.Add(new_sort); } SortingElement sort = mvPref.Sorting[0]; if (sort.Source.Equals(e.SortExpression)) { if (sort.Type == SortingElementType.Asc) { sort.Type = SortingElementType.Desc; } else { sort.Type = SortingElementType.Asc; } } else { sort.Source = e.SortExpression; sort.Type = SortingElementType.Asc; } }
/// <summary> /// Creates the default preference. /// </summary> /// <param name="View">The view.</param> public static void CreateDefaultPreference(MetaView View) { McMetaViewPreference pref = new McMetaViewPreference(); pref.MetaView = View; foreach (MetaField field in View.MetaClass.Fields) { pref.SetAttribute(field.Name, McMetaViewPreference.AttrWidth, 150); } pref.Attributes.Set("MarginTop", 10); pref.Attributes.Set("MarginLeft", 10); pref.Attributes.Set("MarginRight", 10); pref.Attributes.Set("MarginBottom", 10); Mediachase.Ibn.Core.UserMetaViewPreference.SaveDefault(pref); }
private McMetaViewPreference CreateDefaultReportPreferenceTimeTracking(MetaView View) { McMetaViewPreference pref = new McMetaViewPreference(); pref.MetaView = View; pref.ShowAllMetaField(); foreach (MetaField field in pref.GetVisibleMetaField()) { if (field.Name != "Title" && field.Name != "TotalApproved" && field.Name != "Rate" && field.Name != "Cost" && field.Name != "DayT") { pref.HideMetaField(field.Name); } else { if (field.Name == "Title") { pref.SetAttribute <int>(field.Name, McMetaViewPreference.AttrIndex, 0); } else if (field.Name == "DayT") { pref.SetAttribute <int>(field.Name, McMetaViewPreference.AttrIndex, 1); } else if (field.Name == "TotalApproved") { pref.SetAttribute <int>(field.Name, McMetaViewPreference.AttrIndex, 2); } else if (field.Name == "Rate") { pref.SetAttribute <int>(field.Name, McMetaViewPreference.AttrIndex, 3); } else { pref.SetAttribute <int>(field.Name, McMetaViewPreference.AttrIndex, 4); } } } pref.Attributes.Set("PageSize", -1); MetaViewGroupUtil.CollapseAll(MetaViewGroupByType.Secondary, pref); return(pref); }
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); }
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); }
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); } }
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); }
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); }
/// <summary> /// Handles the SelectedIndexChanged event of the ddPaging control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> public void ddPaging_SelectedIndexChanged(object sender, EventArgs e) { McMetaViewPreference mvPref = GetMetaViewPreference(); DropDownList ddPaging = (DropDownList)sender; if (Convert.ToInt32(ddPaging.SelectedValue) != -1) { //MainGrid.AllowPaging = true; MainGrid.PageSize = Convert.ToInt32(ddPaging.SelectedValue); } else { MainGrid.PageSize = 10000; //MainGrid.AllowPaging = false; } mvPref.Attributes.Set("PageSize", Convert.ToInt32(ddPaging.SelectedValue)); Mediachase.Ibn.Core.UserMetaViewPreference.Save(Mediachase.Ibn.Data.Services.Security.CurrentUserId, mvPref); //this.ForceUpdate = true; this.internalBind(); }
public void Invoke(object Sender, object Element) { if (Element is CommandParameters) { CommandParameters cp = (CommandParameters)Element; if (cp.CommandArguments["groupType"] == null || cp.CommandArguments["primaryKeyId"] == null) { throw new ArgumentException("Some expected parameters are null for CollapseExpandBlockTimesheetHandler"); } string ViewName = CHelper.GetFromContext("MetaViewName").ToString(); if (ViewName != null && ViewName != string.Empty) { MetaView CurrentView = Mediachase.Ibn.Data.DataContext.Current.MetaModel.MetaViews[ViewName]; if (CurrentView == null) { throw new ArgumentException(String.Format("Cant find MetaView: {0}", ViewName)); } McMetaViewPreference mvPref = Mediachase.Ibn.Core.UserMetaViewPreference.Load(CurrentView, Mediachase.IBN.Business.Security.CurrentUser.UserID); if (cp.CommandArguments["groupType"] == MetaViewGroupByType.Primary.ToString()) { MetaViewGroupUtil.CollapseOrExpand(MetaViewGroupByType.Primary, mvPref, cp.CommandArguments["primaryKeyId"]); } else { MetaViewGroupUtil.CollapseOrExpand(MetaViewGroupByType.Secondary, mvPref, cp.CommandArguments["primaryKeyId"]); } CHelper.RequireBindGrid(); CHelper.AddToContext("DontShowEditPopup", 1); UserMetaViewPreference.Save(Mediachase.IBN.Business.Security.CurrentUser.UserID, mvPref); } } }
private void BindFilters() { if (!this.Visible) { return; } McMetaViewPreference mvPref = GetMetaViewPreference(); // O.R.: It's expected that the TTFilterPopupEdit is the only filter control on the page, which uses MetaViewPrefrences filters mvPref.Filters.Clear(); FilterElement filter = null; if (tdPeriod.Visible) { switch (ddPeriod.SelectedValue) { case "[DateTimeThisWeek]": filter = new FilterElement("StartDate", FilterElementType.Equal, CHelper.GetWeekStartByDate(DateTime.Today)); break; case "[DateTimeLastWeek]": filter = new FilterElement("StartDate", FilterElementType.Equal, CHelper.GetWeekStartByDate(DateTime.Today.AddDays(-7))); break; case "[DateTimeThisMonth]": filter = new IntervalFilterElement("StartDate", CHelper.GetWeekStartByDate(DateTime.Today.AddDays(1 - DateTime.Now.Day)), CHelper.GetWeekStartByDate(DateTime.Today)); break; case "[DateTimeLastMonth]": filter = new IntervalFilterElement("StartDate", CHelper.GetWeekStartByDate(DateTime.Today.AddDays(1 - DateTime.Now.Day).AddMonths(-1)), CHelper.GetWeekStartByDate(DateTime.Today.AddDays(-DateTime.Now.Day))); break; case "[DateTimeThisYear]": filter = new IntervalFilterElement("StartDate", CHelper.GetWeekStartByDate(DateTime.Today.AddDays(1 - DateTime.Now.DayOfYear)), CHelper.GetWeekStartByDate(DateTime.Today)); break; case "[DateTimeLastYear]": filter = new IntervalFilterElement("StartDate", CHelper.GetWeekStartByDate(DateTime.Today.AddDays(1 - DateTime.Now.DayOfYear).AddYears(-1)), CHelper.GetWeekStartByDate(DateTime.Today.AddDays(-DateTime.Now.DayOfYear))); break; case "0": DateTime dt = DTCBeg.SelectedDate; filter = new FilterElement("StartDate", FilterElementType.Equal, CHelper.GetWeekStartByDate(dt)); break; case "-1": DateTime dt1 = DTCBeg.SelectedDate; DateTime dt2 = DTCEnd.SelectedDate; filter = new IntervalFilterElement("StartDate", CHelper.GetWeekStartByDate(dt1), CHelper.GetWeekStartByDate(dt2)); break; default: break; } } else if (tdWeek.Visible) { DateTime dt = DTCWeek.SelectedDate; filter = new FilterElement("StartDate", FilterElementType.Equal, CHelper.GetWeekStartByDate(dt)); } else if (WeekerDiv.Visible) { DateTime dt = DTCWeeker.SelectedDate; filter = new FilterElement("StartDate", FilterElementType.Equal, CHelper.GetWeekStartByDate(dt)); } if (filter != null) { mvPref.Filters.Add(filter); } if (tdUser.Visible && ddUser.SelectedItem != null && ddUser.SelectedValue != "0") { filter = new FilterElement("OwnerId", FilterElementType.Equal, int.Parse(ddUser.SelectedValue)); mvPref.Filters.Add(filter); } if (ttBlock.Visible && ttBlock.SelectedItem != null && ttBlock.SelectedValue != "0") { filter = new FilterElement("BlockTypeInstanceId", FilterElementType.Equal, int.Parse(ttBlock.SelectedValue)); mvPref.Filters.Add(filter); } if (tdState.Visible && ddState.SelectedValue != "0") { filter = new FilterElement("StateFriendlyName", FilterElementType.Equal, ddState.SelectedValue); mvPref.Filters.Add(filter); } //Mediachase.Ibn.Core.UserMetaViewPreference.Save(Mediachase.IBN.Business.Security.CurrentUser.UserID, mvPref); }
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")); } }
/// <summary> /// Internals the bind. /// </summary> private void internalBind() { MainGrid.Columns.Clear(); McMetaViewPreference mvPref = GetMetaViewPreference(); MainGrid.AllowPaging = true; if (mvPref.Attributes["PageSize"] != null) { int pageSize = Convert.ToInt32(mvPref.Attributes.GetValue("PageSize").ToString()); if (pageSize != -1) { MainGrid.PageSize = pageSize; } else { MainGrid.PageSize = 10000; //MainGrid.AllowPaging = false; } //CHelper.SafeSelect(ddPaging, mvPref.Attributes.Get("PageSize").ToString()); } else { MainGrid.PageSize = 10; mvPref.Attributes.Set("PageSize", 10); Mediachase.Ibn.Core.UserMetaViewPreference.Save((int)DataContext.Current.CurrentUserId, mvPref); } int width = 0; if (this.ShowCheckboxes) { width += 22 + 7; } #region Check Additional columns from xml foreach (MetaGridCustomColumnInfo customColumn in this.CustomColumns) { MainGrid.Columns.Add(customColumn.Column); width += customColumn.Width + 7; } #endregion int counter = 0; foreach (MetaField field in this.VisibleMetaFields) { int cellWidth = 0; if (PlaceName == String.Empty) { MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetColumn(this.Page, field)); } else { MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetColumn(this.Page, field, PlaceName)); } cellWidth = mvPref.GetMetaFieldWidth(counter, 100); if (cellWidth == 0) { cellWidth = 100; } width += cellWidth; counter++; } width += this.VisibleMetaFields.Length * 7; MainGrid.Width = width; #region Adding PrimaryKeyColumn MainGrid.Columns.Add((new ListColumnFactory(this.ViewName)).GetCssColumn(this.Page, CurrentView.MetaClass.Name)); #endregion internalBindHeader(); FilterElement fe = null; if (this.SearchKeyword != string.Empty) { fe = ListManager.CreateFilterByKeyword(mvPref.MetaView.MetaClass, this.SearchKeyword); mvPref.Filters.Add(fe); } MetaObject[] list = CurrentView.List(mvPref); if (fe != null) { mvPref.Filters.Remove(fe); } if (CurrentView.PrimaryGroupBy == null && CurrentView.SecondaryGroupBy == null) { MainGridExt.IsEmpty = (list.Length == 0); if (list.Length == 0) { list = new MetaObject[] { new MetaObject(CurrentView.MetaClass) }; } MainGrid.DataSource = list; } else { if (CurrentView.SecondaryGroupBy != null) { list = MetaViewGroupUtil.ExcludeCollapsed(MetaViewGroupByType.Secondary, CurrentView.SecondaryGroupBy, CurrentView.PrimaryGroupBy, mvPref, list); } list = MetaViewGroupUtil.ExcludeCollapsed(MetaViewGroupByType.Primary, CurrentView.PrimaryGroupBy, null, mvPref, list); MainGridExt.IsEmpty = (list.Length == 0); if (list.Length == 0) { list = new MetaObject[] { new MetaObject(CurrentView.MetaClass) }; } MainGrid.DataSource = list; } this.Count = list.Length; if (MainGridExt.IsEmpty) { this.Count = 0; } MainGrid.DataBind(); internalBindPaging(); if (list.Length == 0) { MainGrid.CssClass = "serverGridBodyEmpty"; } }
private void BindGrid() { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Title", typeof(string))); dt.Columns.Add(new DataColumn("Day1", typeof(string))); dt.Columns.Add(new DataColumn("Day2", typeof(string))); dt.Columns.Add(new DataColumn("Day3", typeof(string))); dt.Columns.Add(new DataColumn("Day4", typeof(string))); dt.Columns.Add(new DataColumn("Day5", typeof(string))); dt.Columns.Add(new DataColumn("Day6", typeof(string))); dt.Columns.Add(new DataColumn("Day7", typeof(string))); dt.Columns.Add(new DataColumn("DayT", typeof(string))); dt.Columns.Add(new DataColumn("StateFriendlyName", typeof(string))); MetaView currentView = GetMetaView(); currentView.Filters = GetFilters(); McMetaViewPreference currentPreferences = Mediachase.UI.Web.Util.CommonHelper.CreateDefaultReportPreferenceTimeTracking(currentView); MetaObject[] list = null; if (String.Compare(Mediachase.IBN.Business.Configuration.Domain, "ibn47.mediachase.net", true) == 0) { list = currentView.List(currentPreferences, McRoundValues); // For Excel for (int i = 1; i <= 8; i++) { MainGrid.Columns[i].ItemStyle.CssClass = "TdTextClass"; } } else { list = currentView.List(currentPreferences); } foreach (MetaObject mo in list) { DataRow row = dt.NewRow(); string additionalTitle = string.Empty; string prefix = ""; string postfix = ""; if (cbShowWeekNumber.Checked && mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() != MetaViewGroupByType.Total.ToString()) { DateTime dtNew = DateTime.MinValue; try { dtNew = (DateTime)mo.Properties["Title"].Value; } catch { } if (dtNew != DateTime.MinValue) { additionalTitle = string.Format("(#{0})", Iso8601WeekNumber.GetWeekNumber((DateTime)mo.Properties["Title"].Value)); } } if (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Primary.ToString()) { prefix = "<b>"; postfix = "</b>"; if (GroupingList.SelectedValue == GroupingWeekUser) { row["Title"] = String.Format("{0}{1} - {2}{3} {4}", prefix, ((DateTime)mo.Properties["Title"].Value).ToString("d MMM yyyy"), ((DateTime)mo.Properties["Title"].Value).AddDays(6).ToString("d MMM yyyy"), prefix, additionalTitle); } else { row["Title"] = String.Format("{0}{1}{2} {3}", prefix, mo.Properties["Title"].Value.ToString(), postfix, additionalTitle); } } else if (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Secondary.ToString()) { prefix = "<b>"; postfix = "</b>"; if (GroupingList.SelectedValue == GroupingUserWeek) { row["Title"] = String.Format("<div style='padding-left: 25px;'>{0}{1} - {2}{3} {4}</div>", prefix, ((DateTime)mo.Properties["Title"].Value).ToString("d MMM yyyy"), ((DateTime)mo.Properties["Title"].Value).AddDays(6).ToString("d MMM yyyy"), prefix, additionalTitle); } else { row["Title"] = String.Format("<div style='padding-left: 25px;'>{0}{1}{2} {3}</div>", prefix, mo.Properties["Title"].Value.ToString(), postfix, additionalTitle); } } else if (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Total.ToString()) { prefix = "<b>"; postfix = "</b>"; row["Title"] = String.Format("{0}{1}{2} {3}", prefix, mo.Properties["Title"].Value.ToString(), postfix, additionalTitle); } else { row["Title"] = String.Format("<div style='padding-left: 50px;'>{0} {1}</div>", mo.Properties["Title"].Value.ToString(), additionalTitle); } if (String.Compare(Mediachase.IBN.Business.Configuration.Domain, "ibn47.mediachase.net", true) == 0) { if (mo.Properties["MetaViewGroupByType"] == null || (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Total.ToString()) || (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Secondary.ToString())) { row["Day1"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["Day1"].Value) / 60.0, postfix); row["Day2"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["Day2"].Value) / 60.0, postfix); row["Day3"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["Day3"].Value) / 60.0, postfix); row["Day4"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["Day4"].Value) / 60.0, postfix); row["Day5"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["Day5"].Value) / 60.0, postfix); row["Day6"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["Day6"].Value) / 60.0, postfix); row["Day7"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["Day7"].Value) / 60.0, postfix); row["DayT"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToInt32(mo.Properties["DayT"].Value) / 60.0, postfix); } } else { row["Day1"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["Day1"].Value) / 60, Convert.ToInt32(mo.Properties["Day1"].Value) % 60, postfix); row["Day2"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["Day2"].Value) / 60, Convert.ToInt32(mo.Properties["Day2"].Value) % 60, postfix); row["Day3"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["Day3"].Value) / 60, Convert.ToInt32(mo.Properties["Day3"].Value) % 60, postfix); row["Day4"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["Day4"].Value) / 60, Convert.ToInt32(mo.Properties["Day4"].Value) % 60, postfix); row["Day5"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["Day5"].Value) / 60, Convert.ToInt32(mo.Properties["Day5"].Value) % 60, postfix); row["Day6"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["Day6"].Value) / 60, Convert.ToInt32(mo.Properties["Day6"].Value) % 60, postfix); row["Day7"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["Day7"].Value) / 60, Convert.ToInt32(mo.Properties["Day7"].Value) % 60, postfix); row["DayT"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["DayT"].Value) / 60, Convert.ToInt32(mo.Properties["DayT"].Value) % 60, postfix); } if (mo.Properties["StateFriendlyName"].Value != null) { row["StateFriendlyName"] = CHelper.GetResFileString(mo.Properties["StateFriendlyName"].Value.ToString()); } else { row["StateFriendlyName"] = ""; } dt.Rows.Add(row); } // Header Text for (int i = 0; i < MainGrid.Columns.Count; i++) { MetaField field = currentPreferences.GetVisibleMetaField()[i]; string fieldName = field.Name; // First day of week can be different, so we should specify it. if (fieldName == "Day1" || fieldName == "Day2" || fieldName == "Day3" || fieldName == "Day4" || fieldName == "Day5" || fieldName == "Day6" || fieldName == "Day7") { DateTime curDate = CHelper.GetRealWeekStartByDate(DateTime.UtcNow); if (fieldName == "Day2") { curDate = curDate.AddDays(1); } else if (fieldName == "Day3") { curDate = curDate.AddDays(2); } else if (fieldName == "Day4") { curDate = curDate.AddDays(3); } else if (fieldName == "Day5") { curDate = curDate.AddDays(4); } else if (fieldName == "Day6") { curDate = curDate.AddDays(5); } else if (fieldName == "Day7") { curDate = curDate.AddDays(6); } MainGrid.Columns[i].HeaderText = GetGlobalResourceObject("IbnFramework.TimeTracking", curDate.DayOfWeek.ToString()).ToString(); } else { MainGrid.Columns[i].HeaderText = CHelper.GetResFileString(field.FriendlyName); } } MainGrid.DataSource = dt; MainGrid.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (Request["ViewName"] != null) { MetaView view = GetViewByName(Request["ViewName"]); string ActionName = Request["Action"]; //TODO: PrincipalId McMetaViewPreference pref = Mediachase.Ibn.Core.UserMetaViewPreference.Load(view, 13 /*Security.CurrentUserId*/); switch (ActionName) { case "ColumnResize": { pref.SetMetaFieldWidth(Convert.ToInt32(Request["columnIndex"]), Convert.ToInt32(Request["newSize"])); break; } case "OrderChange": { pref.ChangeMetaFieldOrder(Convert.ToInt32(Request["oldIndex"]), Convert.ToInt32(Request["newIndex"])); break; } case "HiddenChange": { pref.HideMetaField(Request["columnName"]); break; } case "EditColumns": { pref.ShowAllMetaField(); string hiddenColumns = Request["hiddenColumns"]; if (hiddenColumns.Length > 0) { foreach (string fieldName in hiddenColumns.Split(',')) { pref.HideMetaField(fieldName); } } break; } case "ResizeLayout": { int newSize = Convert.ToInt32(Request["newSize"]); string attrName = string.Empty; #region Convert west -> MarginLeft (etc.) switch (Request["RegionId"]) { case "west": { attrName = "MarginLeft"; break; } case "east": { attrName = "MarginRight"; break; } case "north": { attrName = "MarginTop"; break; } case "south": { attrName = "MarginBottom"; break; } } #endregion pref.Attributes.Set(attrName, newSize); break; } } //TODO: PrincipalId Mediachase.Ibn.Core.UserMetaViewPreference.Save(13 /*Security.CurrentUserId*/, pref); } if (Request["CommandId"] != null) { Response.Write("Test toolbar action: " + Request["CommandId"]); } }
/// <summary> /// Handles the RowDataBound event of the MainGrid control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param> void MainGrid_RowDataBound(object sender, GridViewRowEventArgs e) { McMetaViewPreference mvPref = GetMetaViewPreference(); for (int i = 0; i < e.Row.Cells.Count; i++) { int index = i - this.CustomColumns.Count; if (this.ShowCheckboxes) { index--; } if (this.ShowCheckboxes && i == 0) { continue; } if (e.Row.RowType == DataControlRowType.DataRow) //if (e.Row.Cells[i].Controls[0] is Mediachase.Ibn.Web.UI.Modules.FieldControls.BaseType) { //e.Row.Cells[i].Attributes.Add("unselectable", "on"); if (index <= this.VisibleMetaFields.Length) { ((BaseType)e.Row.Cells[i].Controls[0]).DataItem = (MetaObject)e.Row.DataItem; } if (index < this.VisibleMetaFields.Length && index >= 0) { ((BaseType)e.Row.Cells[i].Controls[0]).FieldName = this.VisibleMetaFields[index].Name; } if (e.Row.Cells[i].Controls[0] is CustomColumnBaseType) { ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ViewName = this.ViewName; ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).Place = this.PlaceName; if (this.ShowCheckboxes) { index++; } //if (index + this.CustomColumns.Count < this.CustomColumns.Count) if (this.ShowCheckboxes) { ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ColumnId = this.CustomColumns[i - 1].Id; } else { ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ColumnId = this.CustomColumns[i].Id; } //else if (index < this.CustomColumns.Count) // ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ColumnId = this.CustomColumns[index].Id; } if (i + 1 != e.Row.Cells.Count) { e.Row.Cells[i].CssClass = this.GridInnerCssClass; } } } GridViewRow row = e.Row; if (row.RowType == DataControlRowType.Header || row.RowType == DataControlRowType.DataRow) { internalBindRowWidth(ref row); } row.DataBind(); if (row.RowType == DataControlRowType.DataRow) { //if (e.Row.DataItem != null && ((MetaObject)e.Row.DataItem).PrimaryKeyId.HasValue) //{ // if (this.ShowCheckboxes) // { // CheckBox cb = (CheckBox)row.Cells[0].Controls[0]; // cb.Attributes.Add(IbnGridView.primaryKeyIdAttr, ((MetaObject)e.Row.DataItem).PrimaryKeyId.Value.ToString()); // } //} if (e.Row.DataItem != null) { e.Row.Attributes.Add(IbnGridView.primaryKeyIdAttr, String.Format("{0}", MetaViewGroupUtil.CreateUniqueKey(CurrentView, (MetaObject)e.Row.DataItem, this.PrimaryGroupType, this.SecondaryGroupType))); if (this.ShowCheckboxes) { CheckBox cb = (CheckBox)row.Cells[0].Controls[0]; cb.Attributes.Add(IbnGridView.primaryKeyIdAttr, String.Format("{0}", MetaViewGroupUtil.CreateUniqueKey(CurrentView, (MetaObject)e.Row.DataItem, this.PrimaryGroupType, this.SecondaryGroupType))); } } } }
/// <summary> /// Handles the ServerClick event of the SaveButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void SaveButton_ServerClick(object sender, EventArgs e) { if (FormatList.Items.Count < 0) { throw new Exception("Format is not specified"); } Page.Validate(); if (!Page.IsValid) { return; } Mediachase.Ibn.Data.Meta.Management.AttributeCollection attr = new Mediachase.Ibn.Data.Meta.Management.AttributeCollection(); string sDefaultValue = String.Empty; IManageControl control = MainPlaceHolder.Controls[0] as IManageControl; if (control != null) { sDefaultValue = control.GetDefaultValue(AllowNullsCheckBox.Checked); attr = control.FieldAttributes; } if (!AllowNullsCheckBox.Checked && sDefaultValue == String.Empty) { ErrorMessage.Text = GetGlobalResourceObject("GlobalMetaInfo", "ErrorMessage_AllowNulls").ToString(); return; } if (sDefaultValue == null) { sDefaultValue = String.Empty; } string sFriendlyName = FriendlyNameTextBox.Text.Trim(); if (mf == null) { string sName; if (!AutogenerateSystemNames) { sName = NameTextBox.Text.Trim(); } else { // Generate the field name as the number of seconds elapsed since 2000-01-01 sName = String.Format(CultureInfo.InvariantCulture, "Field{0}", CHelper.GetDateDiffInSeconds(DateTime.UtcNow, new DateTime(2000, 1, 1))); } try { string typeName = FormatList.SelectedValue; //NewEnum if (attr.ContainsKey("NewEnum")) { string name = attr["EnumName"].ToString(); string friendlyname = attr["EnumFriendlyName"].ToString(); bool isPrivate = (bool)attr["EnumPrivate"]; DataTable dt = (DataTable)attr["EnumDataSource"]; attr.Remove("NewEnum"); attr.Remove("EnumName"); attr.Remove("EnumFriendlyName"); attr.Remove("EnumPrivate"); attr.Remove("EnumDataSource"); MetaFieldType type = MetaEnum.Create(name, friendlyname, false); if (isPrivate) { type.Attributes.Add(McDataTypeAttribute.EnumPrivate, mc.Name); } SortedList sl = new SortedList(); foreach (DataRow dr in dt.Rows) { sl.Add((int)dr["OrderId"], dr["Name"].ToString().Trim()); } foreach (int i in sl.Keys) { MetaEnum.AddItem(type, sl[i].ToString(), i); } typeName = type.Name; } //NewMultiEnum if (attr.ContainsKey("NewMultiEnum")) { string name = attr["EnumName"].ToString(); string friendlyname = attr["EnumFriendlyName"].ToString(); bool isPrivate = (bool)attr["EnumPrivate"]; DataTable dt = (DataTable)attr["EnumDataSource"]; attr.Remove("NewMultiEnum"); attr.Remove("EnumName"); attr.Remove("EnumFriendlyName"); attr.Remove("EnumPrivate"); attr.Remove("EnumDataSource"); MetaFieldType type = MetaEnum.Create(name, friendlyname, true); if (isPrivate) { type.Attributes.Add(McDataTypeAttribute.EnumPrivate, mc.Name); } SortedList sl = new SortedList(); foreach (DataRow dr in dt.Rows) { sl.Add((int)dr["OrderId"], dr["Name"].ToString().Trim()); } foreach (int i in sl.Keys) { MetaEnum.AddItem(type, sl[i].ToString(), i); } typeName = type.Name; } MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[FormatList.SelectedValue]; if (mft != null && mft.McDataType == McDataType.Enum && attr.ContainsKey("EnumFriendlyName")) { mft.FriendlyName = attr["EnumFriendlyName"].ToString(); attr.Remove("EnumFriendlyName"); } MetaField newField = null; if (FieldTypeList.SelectedValue == McDataType.Reference.ToString()) { newField = MetaDataWrapper.CreateReference(mc, attr, sName, sFriendlyName, AllowNullsCheckBox.Checked); if (attr.ContainsKey(McDataTypeAttribute.ReferenceUseSecurity)) { Mediachase.Ibn.Data.Services.Security.AddObjectRolesFromReference(newField); } } else if (FieldTypeList.SelectedValue == McDataType.ReferencedField.ToString()) { newField = MetaDataWrapper.CreateReferencedField(mc, attr, sName, sFriendlyName); } else if (FieldTypeList.SelectedValue == McDataType.BackReference.ToString()) { newField = MetaDataWrapper.CreateBackReference(mc, attr, sName, sFriendlyName); } else { newField = MetaDataWrapper.CreateMetaField(mc, attr, sName, sFriendlyName, typeName, AllowNullsCheckBox.Checked, sDefaultValue); } //add to the forms if (newField != null) { List <FormDocument> metaForms = mfs.MetaForms; foreach (FormDocument fd in metaForms) { if (HistoryManager.MetaClassIsHistory(fd.MetaClassName) && !HistoryManager.IsSupportedField(fd.MetaClassName, newField.Name)) { continue; } FormController.AddMetaPrimitive(fd.MetaClassName, fd.Name, newField.Name); } using (MetaClassManagerEditScope editScope = DataContext.Current.MetaModel.BeginEdit()) { List <string> metaViews = mfs.MetaViews; foreach (string viewName in metaViews) { MetaView metaView = DataContext.Current.MetaModel.MetaViews[viewName]; if (HistoryManager.MetaClassIsHistory(metaView.MetaClassName) && !HistoryManager.IsSupportedField(metaView.MetaClassName, newField.Name)) { continue; } McMetaViewPreference pref = UserMetaViewPreference.Load(metaView, (int)DataContext.Current.CurrentUserId); if (pref == null || pref.Attributes.Count == 0) { McMetaViewPreference.CreateDefaultUserPreference(metaView); pref = UserMetaViewPreference.Load(metaView, (int)DataContext.Current.CurrentUserId); } int counter = metaView.AvailableFields.Count; metaView.AvailableFields.Add(metaView.MetaClass.Fields[newField.Name]); pref.SetAttribute <int>(newField.Name, McMetaViewPreference.AttrIndex, counter); pref.SetAttribute <int>(newField.Name, McMetaViewPreference.AttrWidth, 100); } editScope.SaveChanges(); } } Response.Redirect(String.Format("{0}?class={1}", ReturnUrl, mc.Name), true); } catch (MetaFieldAlreadyExistsException) { ErrorLabel.Text = String.Format(GetGlobalResourceObject("GlobalMetaInfo", "FieldExistsErrorMessage").ToString(), "'" + sName + "'"); ErrorLabel.Visible = true; } /* catch (SqlException sqlException) * { * if (sqlException.Number == 1505) // Duplication key * ErrorLabel.Text = ex.Message; * else * ErrorLabel.Text = ex.Message; * ErrorLabel.Visible = true; * } */ } else // Update { MetaFieldType mft = DataContext.Current.MetaModel.RegisteredTypes[FormatList.SelectedValue]; if (mft.McDataType == McDataType.Enum && attr.ContainsKey("EnumFriendlyName")) { mft.FriendlyName = attr["EnumFriendlyName"].ToString(); attr.Remove("EnumFriendlyName"); } if (FieldTypeList.SelectedValue == McDataType.Reference.ToString() || FieldTypeList.SelectedValue == McDataType.BackReference.ToString() || FieldTypeList.SelectedValue == McDataType.ReferencedField.ToString()) { MetaDataWrapper.UpdateMetaFieldFriendlyName(mf, sFriendlyName); } else { MetaDataWrapper.UpdateMetaField(mf, attr, sFriendlyName, sDefaultValue); } Response.Redirect(String.Format("{0}?class={1}", ReturnUrl, mc.Name), true); } }
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(); }
private void BindGrid() { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Title", typeof(string))); dt.Columns.Add(new DataColumn("Total", typeof(string))); dt.Columns.Add(new DataColumn("TotalApproved", typeof(string))); dt.Columns.Add(new DataColumn("Rate", typeof(string))); dt.Columns.Add(new DataColumn("Cost", typeof(string))); MetaView currentView = GetMetaView(); currentView.Filters = GetFilters(); McMetaViewPreference currentPreferences = CreateDefaultReportPreferenceTimeTracking(currentView); MetaObject[] list = currentView.List(currentPreferences); foreach (MetaObject mo in list) { DataRow row = dt.NewRow(); string additionalTitle = string.Empty; string prefix = ""; string postfix = ""; if (cbShowWeekNumber.Checked && mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() != MetaViewGroupByType.Total.ToString()) { DateTime dtNew = DateTime.MinValue; try { dtNew = (DateTime)mo.Properties["Title"].Value; } catch { } if (dtNew != DateTime.MinValue) { additionalTitle = string.Format("(#{0})", Iso8601WeekNumber.GetWeekNumber((DateTime)mo.Properties["Title"].Value)); } } // Primary Grouping if (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Primary.ToString()) { prefix = "<b>"; postfix = "</b>"; if (GroupingList.SelectedValue == GroupingWeekUser) { row["Title"] = String.Format("{0}{1} - {2}{3} {4}", prefix, ((DateTime)mo.Properties["Title"].Value).ToString("d MMM yyyy"), ((DateTime)mo.Properties["Title"].Value).AddDays(6).ToString("d MMM yyyy"), prefix, additionalTitle); } else { row["Title"] = String.Format("{0}{1}{2} {3}", prefix, mo.Properties["Title"].Value.ToString(), postfix, additionalTitle); } } // Secondary Grouping else if (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Secondary.ToString()) { prefix = "<b>"; postfix = "</b>"; if (GroupingList.SelectedValue == GroupingUserWeek) { row["Title"] = String.Format("<div style='padding-left: 25px;'>{0}{1} - {2}{3} {4}</div>", prefix, ((DateTime)mo.Properties["Title"].Value).ToString("d MMM yyyy"), ((DateTime)mo.Properties["Title"].Value).AddDays(6).ToString("d MMM yyyy"), prefix, additionalTitle); } else { row["Title"] = String.Format("<div style='padding-left: 25px;'>{0}{1}{2} {3}</div>", prefix, mo.Properties["Title"].Value.ToString(), postfix, additionalTitle); } } // Total else if (mo.Properties["MetaViewGroupByType"] != null && mo.Properties["MetaViewGroupByType"].OriginalValue.ToString() == MetaViewGroupByType.Total.ToString()) { prefix = "<b>"; postfix = "</b>"; row["Title"] = String.Format("{0}{1}{2} {3}", prefix, mo.Properties["Title"].Value.ToString(), postfix, additionalTitle); } // Other else { row["Title"] = String.Format("<div style='padding-left: 50px;'>{0} {1}</div>", mo.Properties["Title"].Value.ToString(), additionalTitle); row["Rate"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToDecimal(mo.Properties["Rate"].Value), postfix); } row["Total"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["DayT"].Value) / 60, Convert.ToInt32(mo.Properties["DayT"].Value) % 60, postfix); row["TotalApproved"] = String.Format("{0}{1:D2}:{2:D2}{3}", prefix, Convert.ToInt32(mo.Properties["TotalApproved"].Value) / 60, Convert.ToInt32(mo.Properties["TotalApproved"].Value) % 60, postfix); row["Cost"] = String.Format("{0}{1:F2}{2}", prefix, Convert.ToDecimal(mo.Properties["Cost"].Value), postfix); dt.Rows.Add(row); } // Header Text for (int i = 0; i < MainGrid.Columns.Count; i++) { MetaField field = currentPreferences.GetVisibleMetaField()[i]; MainGrid.Columns[i].HeaderText = CHelper.GetResFileString(field.FriendlyName); } MainGrid.DataSource = dt; MainGrid.DataBind(); }
private void SaveValues() { bool bSavePref = false; McMetaViewPreference pref = GetMetaViewPreference(); if (tdProject.Visible) { bSavePref = pref.SetAttribute <string>(FilterBlockAttr, FilterBlockAttr, ttBlock.SelectedValue); } else { bSavePref = pref.SetAttribute <string>(FilterBlockAttr, FilterBlockAttr, null); } if (tdUser.Visible) { if (pref.SetAttribute <string>(FilterUserAttr, FilterUserAttr, ddUser.SelectedValue)) { bSavePref = true; } } else { if (pref.SetAttribute <string>(FilterUserAttr, FilterUserAttr, null)) { bSavePref = true; } } if (tdPeriod.Visible) { if (pref.SetAttribute <string>("TTFilter_Period", "TTFilter_Period", ddPeriod.SelectedValue)) { bSavePref = true; } if (ddPeriod.SelectedValue == "0") { if (pref.SetAttribute <DateTime>("TTFilter_DTCBeg", "TTFilter_DTCBeg", DTCBeg.SelectedDate)) { bSavePref = true; } } else if (ddPeriod.SelectedValue == "-1") { if (pref.SetAttribute <DateTime>("TTFilter_DTCBeg", "TTFilter_DTCBeg", DTCBeg.SelectedDate)) { bSavePref = true; } if (pref.SetAttribute <DateTime>("TTFilter_DTCEnd", "TTFilter_DTCEnd", DTCEnd.SelectedDate)) { bSavePref = true; } } } else if (tdWeek.Visible) { if (pref.SetAttribute <DateTime>(FilterWeekAttr, FilterWeekAttr, DTCWeek.SelectedDate)) { bSavePref = true; } } else if (WeekerDiv.Visible) { if (pref.SetAttribute <DateTime>(FilterWeekAttr, FilterWeekAttr, DTCWeeker.SelectedDate)) { bSavePref = true; } } if (tdState.Visible) { if (pref.SetAttribute <string>(FilterStateAttr, FilterStateAttr, ddState.SelectedValue)) { bSavePref = true; } } else { if (pref.SetAttribute <string>(FilterStateAttr, FilterStateAttr, null)) { bSavePref = true; } } if (bSavePref) { Mediachase.Ibn.Core.UserMetaViewPreference.Save(Mediachase.IBN.Business.Security.CurrentUser.UserID, pref); } }
private void LoadMetaViewPreference(string ContextKey) { MetaView view = GetViewByName(ContextKey); mvPref = Mediachase.Ibn.Core.UserMetaViewPreference.Load(view, Mediachase.Ibn.Data.Services.Security.CurrentUserId); }
private void LoadMetaViewPreference(string ContextKey) { MetaView view = GetViewByName(ContextKey); mvPref = Mediachase.Ibn.Core.UserMetaViewPreference.Load(view, Mediachase.Ibn.Data.Services.Security.CurrentUserId); }
private McMetaViewPreference CreateDefaultReportPreferenceTimeTracking(MetaView View) { McMetaViewPreference pref = new McMetaViewPreference(); pref.MetaView = View; pref.ShowAllMetaField(); foreach (MetaField field in pref.GetVisibleMetaField()) { if (field.Name != "Title" && field.Name != "TotalApproved" && field.Name != "Rate" && field.Name != "Cost" && field.Name != "DayT") { pref.HideMetaField(field.Name); } else { if (field.Name == "Title") { pref.SetAttribute<int>(field.Name, McMetaViewPreference.AttrIndex, 0); } else if (field.Name == "DayT") { pref.SetAttribute<int>(field.Name, McMetaViewPreference.AttrIndex, 1); } else if (field.Name == "TotalApproved") { pref.SetAttribute<int>(field.Name, McMetaViewPreference.AttrIndex, 2); } else if (field.Name == "Rate") { pref.SetAttribute<int>(field.Name, McMetaViewPreference.AttrIndex, 3); } else { pref.SetAttribute<int>(field.Name, McMetaViewPreference.AttrIndex, 4); } } } pref.Attributes.Set("PageSize", -1); MetaViewGroupUtil.CollapseAll(MetaViewGroupByType.Secondary, pref); return pref; }