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 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 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 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(); }
/// <summary> /// Gets the index of the field name by. /// </summary> /// <param name="ColumnIndex">Index of the column.</param> /// <returns></returns> private string GetFieldNameByIndex(int ColumnIndex) { return(mvPref.GetVisibleMetaField()[ColumnIndex].Name); }