/// {"primaryKeyId":6, "column":1, "value":"11:21"} public void UpdateGrid(string ContextKey, object[] ChangesArray) { //List<string> fieldName = new List<string>(); MetaGridContextKey gridContextKey = UtilHelper.JsonDeserialize <MetaGridContextKey>(ContextKey); List <MetaObject> changed = new List <MetaObject>(); CHelper.AddToContext("GridUpdated", 1); LoadMetaViewPreference(gridContextKey.ViewName); MetaView CurrentView = GetViewByName(gridContextKey.ViewName); MetaObject[] list = CurrentView.List(mvPref); if (CurrentView.PrimaryGroupBy != null || CurrentView.SecondaryGroupBy == null) { 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); } foreach (Dictionary <string, object> obj in ChangesArray) { int primaryKeyId = Convert.ToInt32(obj["primaryKeyId"]); int columnId = Convert.ToInt32(obj["column"]); string value = Convert.ToString(obj["value"]); MetaObject tmp = GetMetaObjectById(list, primaryKeyId); MetaObject curObject = null; if (tmp != null) { curObject = MetaObjectActivator.CreateInstance(tmp.GetMetaType(), primaryKeyId); } else { continue; } curObject.Properties[GetFieldNameByIndex(columnId)].Value = GetMinutesFromString(value); changed.Add(curObject); } using (TransactionScope tran = DataContext.Current.BeginTransaction()) { foreach (MetaObject changeObj in changed) { changeObj.Save(); } tran.Commit(); } }
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 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(); }