// // CUSTOM FUNCTIONS // public DTO.ReportFormData GetReportData(int userId, int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; DTO.ReportFormData data = new DTO.ReportFormData(); data.Data = new DTO.WorkOrder(); data.OPSequenceDetails = new List <DTO.OPSequenceDetail>(); data.ProductionTeams = new List <DTO.ProductionTeam>(); data.FactoryWarehouses = new List <DTO.FactoryWarehouse>(); data.Details = new List <DTO.Detail>(); data.Receipts = new List <DTO.Receipt>(); data.ReceiptOverviews = new List <DTO.ReceiptOverview>(); data.ReceiptOverviewDetails = new List <DTO.ReceiptOverviewDetail>(); //try to get data try { using (WorkOrderRptEntities context = CreateContext()) { int companyId = fwFactory.GetCompanyID(userId).Value; data.Data = converter.DB2DTO_WorkOrder(context.WorkOrderRpt_WorkOrder_View.SingleOrDefault(o => o.WorkOrderID == id && o.CompanyID == companyId)); data.OPSequenceDetails = converter.DB2DTO_OPSequenceDetail(context.WorkOrderRpt_OPSequenceDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.ProductionTeams = converter.DB2DTO_ProductionTeam(context.WorkOrderRpt_ProductionTeamBySequenceDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.FactoryWarehouses = converter.DB2DTO_FactoryWarehouse(context.WorkOrderRpt_FactoryWarehouseBySequenceDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.Details = converter.DB2DTO_Detail(context.WorkOrderRpt_InOutDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.Receipts = converter.DB2DTO_Receipt(context.WorkOrderRpt_InOutReceipt_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); data.ReceiptOverviews = converter.DB2DTO_ReceiptOverview(context.WorkOrderRpt_ReceiptOverview_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).OrderBy(o => o.ReceiptDate).ToList()); data.ReceiptOverviewDetails = converter.DB2DTO_ReceiptOverviewDetail(context.WorkOrderRpt_ReceiptOverviewDetail_View.Where(o => o.WorkOrderID == id && o.CompanyID == companyId).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
// // CUSTOM FUNCTION // public DTO.ReportFormData GetOverview(int year, out Library.DTO.Notification notification) { DTO.ReportFormData data = new DTO.ReportFormData(); data.Overviews = new List <DTO.Overview>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success, Message = string.Empty }; try { using (DevRequestOverviewRptEntities context = CreateContext()) { data.Overviews = converter.DB2DTO_Overview(context.DevRequestOverviewRpt_function_getOverview(year).ToList()); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }
public DTO.ReportFormData GetHTMLReport(int userId, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification { Type = Library.DTO.NotificationType.Success }; string season = "2018/2019"; DateTime tetDate = new DateTime(2019, 2, 5); DateTime fromDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); while ((int)fromDate.DayOfWeek != 1) { fromDate = fromDate.AddDays(-1); } DateTime toDate = new DateTime(2019, 5, 20); List <int> wIDs = new List <int>(); DTO.ReportFormData data = new DTO.ReportFormData(); data.WeekInfoDTOs = new List <DTO.WeekInfoDTO>(); data.ReportDetailDTOs = new List <DTO.ReportDetailDTO>(); data.SumDataRow = new DTO.ReportDetailDTO { CapacityB = 0, CapacityA = 0, OrderB = 0, OrderA = 0, PreOrderB = 0, PreOrderA = 0, PreProducedB = 0, PreProducedA = 0 }; try { using (PreOrderPlanningOverviewRptEntities context = CreateContext()) { //context.Database.CommandTimeout = 3 * 60; data.WeekInfoDTOs = converter.DB2DTO_WeeklyInfo(context.WeekInfo.Where(o => o.WeekStart <= toDate && o.WeekStart >= fromDate).OrderBy(o => o.WeekStart).ToList()); data.TetWeekInfoID = context.WeekInfo.FirstOrDefault(o => o.WeekStart <= tetDate && o.WeekEnd >= tetDate).WeekInfoID; var dbItems = context.PreOrderPlanningOverviewRpt_function_GetWeeklyOverview(fromDate, toDate).ToList(); data.TotalPreOrder = context.FactoryPlanningSetting.FirstOrDefault(o => o.Season == season).TotalPreOrder.Value; // // processing manually - bad practice // foreach (var wInfo in data.WeekInfoDTOs) { decimal capacity, order, preorder, preproduced; capacity = order = preorder = preproduced = 0; foreach (var detail in dbItems.Where(o => o.WeekInfoID == wInfo.WeekInfoID)) { if (detail.WeekStart >= tetDate) { data.SumDataRow.CapacityA += detail.Capacity.Value; data.SumDataRow.OrderA += detail.TotalOrderQnt.Value; data.SumDataRow.PreOrderA += detail.PreOrderQnt.Value; data.SumDataRow.PreProducedA += detail.PreProducedQnt.Value; } else { data.SumDataRow.CapacityB += detail.Capacity.Value; data.SumDataRow.OrderB += detail.TotalOrderQnt.Value; data.SumDataRow.PreOrderB += detail.PreOrderQnt.Value; data.SumDataRow.PreProducedB += detail.PreProducedQnt.Value; } capacity += detail.Capacity.Value; order += detail.TotalOrderQnt.Value; preorder += detail.PreOrderQnt.Value; preproduced += detail.PreProducedQnt.Value; } data.SumDataRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = wInfo.WeekInfoID, Color = "#000", Value = capacity }); data.SumDataRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = wInfo.WeekInfoID, Color = "#000", Value = order }); data.SumDataRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = wInfo.WeekInfoID, Color = "#000", Value = preorder }); data.SumDataRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = wInfo.WeekInfoID, Color = "#000", Value = preproduced }); data.SumDataRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = wInfo.WeekInfoID, Color = (capacity + preproduced - (order + preorder) >= 0) ? "#000" : "#ff0000", Value = capacity + preproduced - (order + preorder) }); } foreach (var factory in dbItems.Select(o => new { FactoryUD = o.FactoryUD, FactoryNM = o.FactoryName }).Distinct()) { DTO.ReportDetailDTO detailRow = new DTO.ReportDetailDTO { FactoryUD = factory.FactoryUD, FactoryNM = factory.FactoryNM, CapacityB = 0, CapacityA = 0, OrderB = 0, OrderA = 0, PreOrderB = 0, PreOrderA = 0, PreProducedB = 0, PreProducedA = 0 }; foreach (var detail in dbItems.Where(o => o.FactoryUD == factory.FactoryUD).OrderBy(o => o.WeekStart)) { if (detail.WeekStart >= tetDate) { detailRow.CapacityA += detail.Capacity.Value; detailRow.OrderA += detail.TotalOrderQnt.Value; detailRow.PreOrderA += detail.PreOrderQnt.Value; detailRow.PreProducedA += detail.PreProducedQnt.Value; data.SumDataRow.CapacityA += detail.Capacity.Value; data.SumDataRow.OrderA += detail.TotalOrderQnt.Value; data.SumDataRow.PreOrderA += detail.PreOrderQnt.Value; data.SumDataRow.PreProducedA += detail.PreProducedQnt.Value; } else { detailRow.CapacityB += detail.Capacity.Value; detailRow.OrderB += detail.TotalOrderQnt.Value; detailRow.PreOrderB += detail.PreOrderQnt.Value; detailRow.PreProducedB += detail.PreProducedQnt.Value; data.SumDataRow.CapacityB += detail.Capacity.Value; data.SumDataRow.OrderB += detail.TotalOrderQnt.Value; data.SumDataRow.PreOrderB += detail.PreOrderQnt.Value; data.SumDataRow.PreProducedB += detail.PreProducedQnt.Value; } detailRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = detail.WeekInfoID, Color = "#000", Value = detail.Capacity.Value }); detailRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = detail.WeekInfoID, Color = "#000", Value = detail.TotalOrderQnt.Value }); detailRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = detail.WeekInfoID, Color = "#000", Value = detail.PreOrderQnt.Value }); detailRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = detail.WeekInfoID, Color = "#000", Value = detail.PreProducedQnt.Value }); detailRow.ReportWeekDetailDTOs.Add(new DTO.ReportWeekDetailDTO { WeekInfoID = detail.WeekInfoID, Color = (detail.Capacity.Value + detail.PreProducedQnt.Value - (detail.TotalOrderQnt.Value + detail.PreOrderQnt.Value) >= 0) ? "#000" : "#ff0000", Value = detail.Capacity.Value + detail.PreProducedQnt.Value - (detail.TotalOrderQnt.Value + detail.PreOrderQnt.Value) }); } data.ReportDetailDTOs.Add(detailRow); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; } //data.ReportDetailDTOs = data.ReportDetailDTOs.OrderByDescending(o => o.OrderB).ToList(); data.ReportDetailDTOs = data.ReportDetailDTOs.OrderBy(o => o.FactoryUD).ToList(); return(data); }
// // CUSTOM FUNCTION // public DTO.ReportFormData GetConclusion(string fromDate, string toDate, string employee, string company, string module, string location, out Library.DTO.Notification notification) { if (!string.IsNullOrEmpty(fromDate)) { if (DateTime.TryParse(fromDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { fromDate = tmpDate.ToString("yyyy-MM-dd"); } } else { fromDate = null; } if (!string.IsNullOrEmpty(toDate)) { if (DateTime.TryParse(toDate, nl, System.Globalization.DateTimeStyles.None, out tmpDate)) { toDate = tmpDate.ToString("yyyy-MM-dd"); } } else { toDate = null; } DTO.ReportFormData data = new DTO.ReportFormData(); data.ActiveBrowsers = new List <DTO.ActiveBrowser>(); data.ActiveCompanies = new List <DTO.ActiveCompany>(); data.ActiveCompanyWeeklyHits = new List <DTO.ActiveCompanyWeeklyHit>(); data.ActiveIPs = new List <DTO.ActiveIP>(); data.ActiveModules = new List <DTO.ActiveModule>(); data.ActiveUsers = new List <DTO.ActiveUser>(); notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success, Message = string.Empty }; try { Task task1 = Task.Factory.StartNew(() => { using (UsageTrackingRptEntities context = CreateContext()) { data.ActiveCompanies = converter.DB2DTO_ActiveCompanyList(context.UsageTrackingRpt_function_getTop5ActiveCompany(fromDate, toDate, DefaultNumberOfItem, employee, location, company, module).ToList()); data.ActiveCompanyWeeklyHits = converter.DB2DTO_ActiveCompanyWeeklyHitList(context.UsageTrackingRpt_function_getActiveCompanyWeeklyHit(fromDate, toDate, DefaultNumberOfItem, employee, location, company, module).ToList()); } }); Task task2 = Task.Factory.StartNew(() => { using (UsageTrackingRptEntities context = CreateContext()) { data.ActiveModules = converter.DB2DTO_ActiveModuleList(context.UsageTrackingRpt_function_getTop5ActiveModule(fromDate, toDate, DefaultNumberOfItem, employee, location, company, module).ToList()); } }); Task task3 = Task.Factory.StartNew(() => { using (UsageTrackingRptEntities context = CreateContext()) { data.ActiveUsers = converter.DB2DTO_ActiveUserList(context.UsageTrackingRpt_function_getTop5ActiveUser(fromDate, toDate, DefaultNumberOfItem, employee, location, company, module).ToList()); } }); Task task4 = Task.Factory.StartNew(() => { using (UsageTrackingRptEntities context = CreateContext()) { data.HitCounts = converter.DB2DTO_HitCountList(context.UsageTrackingRpt_HitCountByWeek_View.Where(o => o.WeekStart.Value.Year == DateTime.Now.Year).ToList()); } }); Task task5 = Task.Factory.StartNew(() => { using (UsageTrackingRptEntities context = CreateContext()) { data.UserMutations = converter.DB2DTO_UserMutationList(context.UsageTrackingRpt_UserIncreasingByWeek_View.Where(o => o.WeekStart.Value.Year == DateTime.Now.Year).ToList()); // create cumulative int totalUserCum = 0; int?preTotalUser = context.UsageTrackingRpt_UserIncreasingByWeek_View.Where(o => o.WeekStart.Value.Year < DateTime.Now.Year).Sum(o => o.TotalUser); if (preTotalUser.HasValue) { totalUserCum = preTotalUser.Value; } foreach (DTO.UserMutation dtoUserMutation in data.UserMutations) { dtoUserMutation.TotalUser += totalUserCum; totalUserCum = dtoUserMutation.TotalUser; } } }); //Task task1 = Task.Factory.StartNew(() => //{ // using (UsageTrackingRptEntities context = CreateContext()) // { // data.ActiveBrowsers = converter.DB2DTO_ActiveBrowserList(context.UsageTrackingRpt_function_getTop5ActiveBrowser(fromDate, toDate, DefaultNumberOfItem, employee, company, module).ToList()); // } //}); //Task task3 = Task.Factory.StartNew(() => //{ // using (UsageTrackingRptEntities context = CreateContext()) // { // data.ActiveIPs = converter.DB2DTO_ActiveIPList(context.UsageTrackingRpt_function_getTop5ActiveIPAddress(fromDate, toDate, DefaultNumberOfItem, employee, company, module).ToList()); // } //}); Task.WaitAll(task1, task2, task3, task4, task5); } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; } return(data); }