コード例 #1
0
ファイル: ProjectsController.cs プロジェクト: aminp/Mentoring
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
コード例 #2
0
        private async Task <SeriesCollection> BuildOrdersChart(DateTime?beginningDateTime, DateTime?endDateTime)
        {
            SeriesCollection sc = new SeriesCollection();
            string           orderReportQuery = "EXECUTE NAT02.dbo.sp_EOI_EngineeringProduction_Orders @StartDate = {0}, @EndDate = {1}";

            string[] dates = new string[] { beginningDateTime.Value.ToShortDateString(), endDateTime.Value.ToShortDateString() };

            List <OrdersReport> ordersReport = new List <OrdersReport>();

            using var _ = new ProjectsContext();
            await Task.Run((Action)(() =>
            {
                ordersReport = _.OrdersReport.FromSqlRaw(orderReportQuery, dates).ToList();
            }));

            _.Dispose();


            sc.Add(new RowSeries
            {
                Title  = "Orders Scanned In",
                Values = new ChartValues <int>(ordersReport.Select(or => or.OrdersIn))
            });

            sc.Add(new RowSeries
            {
                Title  = "Orders Scanned Out",
                Values = new ChartValues <int>(ordersReport.Select(or => or.OrdersOut))
            });

            sc.Add(new RowSeries
            {
                Title  = "Orders To Office",
                Values = new ChartValues <int>(ordersReport.Select(or => or.OrdersToOffice))
            });
            YAxis.Labels     = ordersReport.Select(or => or.Employee).ToList();
            YAxis.FontSize   = 25;
            YAxis.Foreground = new SolidColorBrush(Colors.Black);
            return(sc);
        }
        private void FillNotifications()
        {
            NM_DockPanel.Children.Clear();

            using var _ = new NAT02Context();
            List <EoiNotificationsActive> active = _.EoiNotificationsActive.Where(n => n.User == user.DomainName).OrderBy(a => a.Timestamp).ToList();
            List <EoiNotificationsViewed> viewed = _.EoiNotificationsViewed.Where(n => n.User == user.DomainName).OrderBy(a => a.Timestamp).ToList();

            List <(int Id, string Number, string CustomerName, string Message, bool Bl, string Type)> notifications = new List <(int, string, string, string, bool, string)>();

            foreach (EoiNotificationsActive a in active)
            {
                using var __  = new NAT01Context();
                using var ___ = new NECContext();
                using var _projectsContext = new ProjectsContext();
                string acctNo   = "";
                string custName = "";
                if (a.Type == "Project")
                {
                    if (_projectsContext.EngineeringProjects.Any(ep => ep.ProjectNumber == a.Number))
                    {
                        string endUserName  = _projectsContext.EngineeringProjects.First(ep => ep.ProjectNumber == a.Number).EndUserName;
                        string customerName = _projectsContext.EngineeringProjects.First(ep => ep.ProjectNumber == a.Number).CustomerName;
                        string shipToName   = _projectsContext.EngineeringProjects.First(ep => ep.ProjectNumber == a.Number).ShipToName;
                        custName =
                            !string.IsNullOrEmpty(endUserName) && !string.IsNullOrWhiteSpace(endUserName) ? endUserName :
                            !string.IsNullOrEmpty(customerName) && !string.IsNullOrWhiteSpace(customerName) ? customerName :
                            !string.IsNullOrEmpty(shipToName) && !string.IsNullOrWhiteSpace(shipToName) ? shipToName : "";
                    }
                    else if (_projectsContext.EngineeringArchivedProjects.Any(eap => eap.ProjectNumber == a.Number))
                    {
                        string rev = _projectsContext.EngineeringArchivedProjects.Where(eap => eap.ProjectNumber == a.Number).Max(p => p.RevNumber);

                        string endUserName  = _projectsContext.EngineeringArchivedProjects.First(eap => eap.ProjectNumber == a.Number && eap.RevNumber == rev).EndUserName;
                        string customerName = _projectsContext.EngineeringArchivedProjects.First(eap => eap.ProjectNumber == a.Number && eap.RevNumber == rev).CustomerName;
                        string shipToName   = _projectsContext.EngineeringArchivedProjects.First(eap => eap.ProjectNumber == a.Number && eap.RevNumber == rev).ShipToName;
                        custName =
                            !string.IsNullOrEmpty(endUserName) && !string.IsNullOrWhiteSpace(endUserName) ? endUserName :
                            !string.IsNullOrEmpty(customerName) && !string.IsNullOrWhiteSpace(customerName) ? customerName :
                            !string.IsNullOrEmpty(shipToName) && !string.IsNullOrWhiteSpace(shipToName) ? shipToName : "";
                    }
                }
                else
                {
                    acctNo   = __.OrderHeader.Single(o => o.OrderNo / 100 == double.Parse(a.Number)).UserAcctNo;
                    custName = ___.Rm00101.Single(r => r.Custnmbr.Trim() == acctNo.Trim()).Custname;
                }

                notifications.Add((a.Id, a.Number, custName, a.Message, true, a.Type));
                __.Dispose();
                ___.Dispose();
                _projectsContext.Dispose();
            }
            foreach (EoiNotificationsViewed v in viewed)
            {
                using var __  = new NAT01Context();
                using var ___ = new NECContext();
                using var _projectsContext = new ProjectsContext();
                string acctNo   = "";
                string custName = "";
                if (v.Type == "Project")
                {
                    if (_projectsContext.EngineeringProjects.Any(ep => ep.ProjectNumber == v.Number))
                    {
                        string endUserName  = _projectsContext.EngineeringProjects.First(ep => ep.ProjectNumber == v.Number).EndUserName;
                        string customerName = _projectsContext.EngineeringProjects.First(ep => ep.ProjectNumber == v.Number).CustomerName;
                        string shipToName   = _projectsContext.EngineeringProjects.First(ep => ep.ProjectNumber == v.Number).ShipToName;
                        custName =
                            !string.IsNullOrEmpty(endUserName) && !string.IsNullOrWhiteSpace(endUserName) ? endUserName :
                            !string.IsNullOrEmpty(customerName) && !string.IsNullOrWhiteSpace(customerName) ? customerName :
                            !string.IsNullOrEmpty(shipToName) && !string.IsNullOrWhiteSpace(shipToName) ? shipToName : "";
                    }
                    else if (_projectsContext.EngineeringArchivedProjects.Any(eap => eap.ProjectNumber == v.Number))
                    {
                        string rev = _projectsContext.EngineeringArchivedProjects.Where(eap => eap.ProjectNumber == v.Number).Max(p => p.RevNumber);

                        string endUserName  = _projectsContext.EngineeringArchivedProjects.First(eap => eap.ProjectNumber == v.Number && eap.RevNumber == rev).EndUserName;
                        string customerName = _projectsContext.EngineeringArchivedProjects.First(eap => eap.ProjectNumber == v.Number && eap.RevNumber == rev).CustomerName;
                        string shipToName   = _projectsContext.EngineeringArchivedProjects.First(eap => eap.ProjectNumber == v.Number && eap.RevNumber == rev).ShipToName;
                        custName =
                            !string.IsNullOrEmpty(endUserName) && !string.IsNullOrWhiteSpace(endUserName) ? endUserName :
                            !string.IsNullOrEmpty(customerName) && !string.IsNullOrWhiteSpace(customerName) ? customerName :
                            !string.IsNullOrEmpty(shipToName) && !string.IsNullOrWhiteSpace(shipToName) ? shipToName : "";
                    }
                }
                else
                {
                    acctNo   = __.OrderHeader.Single(o => o.OrderNo / 100 == double.Parse(v.Number)).UserAcctNo;
                    custName = ___.Rm00101.Single(r => r.Custnmbr.Trim() == acctNo.Trim()).Custname;
                }
                notifications.Add((v.NotificationId, v.Number, custName, v.Message, false, v.Type));
                __.Dispose();
                ___.Dispose();
                _projectsContext.Dispose();
            }

            if (notifications.Count > 0)
            {
                notifications.OrderBy(n => n.Item1);

                foreach ((int Id, string Number, string CustomerName, string Message, bool Bl, string Type)notification in notifications)
                {
                    ContentControl contentControl = new ContentControl()
                    {
                        Style = notification.Bl ? FindResource("ActiveNotificationGrid") as Style :
                                FindResource("InactiveNotificationGrid") as Style
                    };

                    contentControl.ApplyTemplate();
                    (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType <Grid>().First().Children.OfType <TextBlock>().Single(tb => tb.Name == "OrderNumberTextBlock").Text         = notification.Number;
                    (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType <Grid>().First().Children.OfType <TextBlock>().Single(tb => tb.Name == "CustomerNameTextBlock").Text        = notification.CustomerName;
                    (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType <Grid>().First().Children.OfType <TextBlock>().Single(tb => tb.Name == "NotificationMessageTextBlock").Text =
                        notification.Message.Replace("Document", notification.Type);

                    NM_DockPanel.Children.Add(contentControl);
                }
            }
            else
            {
                TextBlock textBlock = new TextBlock
                {
                    Text                = "No new notifications." + Environment.NewLine + "Check back later.",
                    Style               = Application.Current.Resources["BoldTextBlock"] as Style,
                    FontSize            = 20,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    TextAlignment       = TextAlignment.Center,
                    Opacity             = .5,
                    Cursor              = Cursors.Arrow
                };
                NotificationWindowGrid.Children.Add(textBlock);
            }

            //List<EoiAllOrdersView> orders = _.EoiAllOrdersView.OrderBy(o => o.OrderNumber).ToList();

            //foreach (EoiAllOrdersView order in orders)
            //{
            //    ContentControl contentControl = new ContentControl()
            //    {
            //        Style = FindResource("OrderGrid") as Style
            //    };

            //    contentControl.ApplyTemplate();
            //    Grid grid = (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType<Grid>().First();

            //    string location = "";
            //    string state = "";

            //    if (order.BeingEntered == 1)
            //    {
            //        location = "Order Entry";
            //        state = "Being Converted to Order";
            //    }
            //    else if (order.EnteredUnscanned == 1)
            //    {
            //        location = "Order Entry/Eng.";
            //        state = "Ready for Engineering";
            //    }
            //    else if (order.InEngineering == 1)
            //    {
            //        location = "Engineering";
            //        if (order.BeingChecked == 1)
            //        {
            //            state = "Being Checked";
            //        }
            //        else if (order.MarkedForChecking == 1)
            //        {
            //            state = "Ready to be Checked";
            //        }
            //        else
            //        {
            //            state = "Being Drawn";
            //        }
            //    }
            //    else if (order.ReadyToPrint == 1)
            //    {
            //        location = "Engineering";
            //        state = "Ready to Print";
            //    }
            //    else if (order.Printed == 1)
            //    {
            //        location = "Engineering";
            //        state = "Printed/Ready for Production";
            //    }
            //    else if (order.InTheOffice == 1)
            //    {
            //        location = "Office";
            //        state = "Sent to Office";
            //    }

            //    if (order.DoNotProcess == 1)
            //    {
            //        grid.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#55FFC0CB"));
            //    }
            //    else if (order.DoNotProcess == 1)
            //    {
            //        grid.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#55FFC0CB"));
            //    }

            //    if (order.RushYorN == "Y" || order.PaidRushFee == "Y")
            //    {
            //        foreach (TextBlock textBlock in grid.Children.OfType<TextBlock>()) { textBlock.Foreground = FindResource("Tertiary.Dark") as SolidColorBrush; }
            //    }

            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "OrderNumberTextBlock").Text = order.OrderNumber.ToString();
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "QuoteNumberTextBlock").Text = order.QuoteNumber.ToString();
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "QuoteRevNumberTextBlock").Text = order.QuoteRev.ToString();
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "CustomerNameTextBlock").Text = order.CustomerName.Trim();
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "NumDaysToShipTextBlock").Text = order.NumDaysToShip.ToString();
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "NumDaysInDeptTextBlock").Text = order.DaysInDept.ToString();
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "EmployeeTextBlock").Text = order.EmployeeName;
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "LocationTextBlock").Text = location;
            //    grid.Children.OfType<TextBlock>().Single(tb => tb.Name == "StateTextBlock").Text = state;

            //    NM_DockPanel.Children.Add(contentControl);
            //}

            //for (int i = 0; i < 10; i++)
            //{
            //    ContentControl contentControl = new ContentControl()
            //    {
            //        Style = FindResource("ActiveNotificationGrid") as Style
            //    };
            //    NM_DockPanel.Children.Add(contentControl);
            //}

            _.Dispose();
        }
コード例 #4
0
        private void FillProjectList()
        {
            using var _ = new ProjectsContext();
            List <ProjectSpecSheet> projectSpecSheet = _.ProjectSpecSheet.Where(p => (p.InternationalId != "N/A" ? p.InternationalId == CustomerNumber : p.CustomerNumber == CustomerNumber) &&
                                                                                // ((!(bool)p.Tools && string.IsNullOrEmpty(p.TabletCheckedBy)) || ((bool)p.Tools && string.IsNullOrEmpty(p.ToolCheckedBy))) &&
                                                                                p.HoldStatus != "CANCELED" && p.HoldStatus != "CANCELLED" && p.HoldStatus != "ON HOLD")
                                                       .OrderByDescending(p => p.ProjectNumber).ToList();

            _.Dispose();

            foreach (ProjectSpecSheet project in projectSpecSheet)
            {
                ContentControl contentControl = new ContentControl()
                {
                    Style = FindResource("ProjectGrid") as Style
                };

                SolidColorBrush back;
                SolidColorBrush fore;
                FontWeight      fontWeight;
                FontStyle       fontStyle;
                bool            priority = project.MarkedPriority is null ? false : project.MarkedPriority == "PRIORITY";
                using var nat02context = new NAT02Context();
                bool finished = nat02context.EoiProjectsFinished.Where(p => p.ProjectNumber == project.ProjectNumber && p.RevisionNumber == project.RevisionNumber).Any() ||
                                ((bool)project.Tools && project.ToolCheckedBy.Length > 0) ||
                                ((bool)project.Tablet && !(bool)project.Tools && project.TabletCheckedBy.Length > 0);
                nat02context.Dispose();
                bool   onHold = project.HoldStatus == "On Hold";
                string stage  = "";

                // Tablet
                //       Entered:   tablet=true, tabletstartedby=""
                //       Started:   tablet=true, tabletdrawnby=""
                //       Drawn:     tablet=true, tabletsubmittedby=""
                //       Submitted: tablet=true, tabletcheckedby=""
                //       Finished:  tablet=true, tool=false, projectfinished=true
                // Tool
                //       Entered:   tools=true, toolstartedby=""
                //       Started:   tools=true, tooldrawnby=""
                //       Drawn:     tools=true, toolcheckedby=""
                //       Finished:  tools=true, projectfinished=true

                bool tablet          = (bool)project.Tablet;
                bool tool            = (bool)project.Tools;
                bool tabletEntered   = false;
                bool tabletStarted   = false;
                bool tabletDrawn     = false;
                bool tabletSubmitted = false;
                bool tabletFinished  = false;
                bool toolEntered     = false;
                bool toolStarted     = false;
                bool toolDrawn       = false;
                bool toolFinished    = false;

                if (tablet && !tool)
                {
                    tabletFinished = finished;
                    if (tabletFinished)
                    {
                        stage = "Tablet Finished";
                        goto JumpPoint;
                    }
                    tabletSubmitted = project.TabletSubmittedBy is null ? false : project.TabletSubmittedBy.Length > 0;
                    if (tabletSubmitted)
                    {
                        stage = "Tablet Being Checked";
                        goto JumpPoint;
                    }
                    tabletDrawn = project.TabletDrawnBy.Length > 0;
                    if (tabletDrawn)
                    {
                        stage = "Tablet Drawn";
                        goto JumpPoint;
                    }
                    tabletStarted = project.ProjectStartedTablet.Length > 0;
                    if (tabletStarted)
                    {
                        stage = "Tablet Started";
                        goto JumpPoint;
                    }
                    tabletEntered = !tabletSubmitted && !tabletDrawn && !tabletStarted && !tabletFinished;
                    if (tabletEntered)
                    {
                        stage = "Tablet Entered";
                        goto JumpPoint;
                    }
                }
                else if (tablet && tool)
                {
                    toolFinished = finished;
                    if (toolFinished)
                    {
                        stage = "Tool Finished";
                        goto JumpPoint;
                    }
                    toolDrawn = project.ToolDrawnBy.Length > 0;
                    if (toolDrawn)
                    {
                        stage = "Tool Drawn";
                        goto JumpPoint;
                    }
                    toolStarted = project.ProjectStartedTool.Length > 0;
                    if (toolStarted)
                    {
                        stage = "Tool Started";
                        goto JumpPoint;
                    }
                    toolEntered = !toolDrawn && !toolStarted && !toolFinished;
                    if (tabletFinished)
                    {
                        stage = "Tablet Finished";
                        goto JumpPoint;
                    }
                    tabletSubmitted = project.TabletSubmittedBy is null ? false : project.TabletSubmittedBy.Length > 0;
                    if (tabletSubmitted)
                    {
                        stage = "Tablet Being Checked";
                        goto JumpPoint;
                    }
                    tabletDrawn = project.TabletDrawnBy.Length > 0;
                    if (tabletDrawn)
                    {
                        stage = "Tablet Drawn";
                        goto JumpPoint;
                    }
                    tabletStarted = project.ProjectStartedTablet.Length > 0;
                    if (tabletStarted)
                    {
                        stage = "Tablet Started";
                        goto JumpPoint;
                    }
                    tabletEntered = !tabletSubmitted && !tabletDrawn && !tabletStarted && !tabletFinished;
                    if (tabletEntered)
                    {
                        stage = "Tablet Entered";
                        goto JumpPoint;
                    }
                }
                else
                {
                    toolFinished = finished;
                    if (toolFinished)
                    {
                        stage = "Tool Finished";
                        goto JumpPoint;
                    }
                    toolDrawn = project.ToolDrawnBy.Length > 0;
                    if (toolDrawn)
                    {
                        stage = "Tool Drawn";
                        goto JumpPoint;
                    }
                    toolStarted = project.ProjectStartedTool.Length > 0;
                    if (toolStarted)
                    {
                        stage = "Tool Started";
                        goto JumpPoint;
                    }
                    toolEntered = !toolDrawn && !toolStarted && !toolFinished;
                    if (toolEntered)
                    {
                        stage = "Tool Entered";
                        goto JumpPoint;
                    }
                }

JumpPoint:
                if (tool)
                {
                    fontStyle = FontStyles.Oblique;
                }
                else
                {
                    fontStyle = FontStyles.Normal;
                }

                if (priority)
                {
                    fore       = new SolidColorBrush(Colors.DarkRed);
                    fontWeight = FontWeights.Bold;
                }
                else
                {
                    fore       = new SolidColorBrush(Colors.Black);
                    fontWeight = FontWeights.Normal;
                }

                if (onHold)
                {
                    // back = new SolidColorBrush(Colors.MediumPurple);
                }
                else if (finished)
                {
                    // back = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFADFF2F"));
                }
                else if (tabletSubmitted)
                {
                    // back = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF0A7DFF"));
                }
                else if (tabletDrawn || toolDrawn)
                {
                    // back = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF52A3FF"));
                }
                else if (tabletStarted || toolStarted)
                {
                    // back = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFB2D6FF"));
                }
                else
                {
                    // back = (SolidColorBrush)(new BrushConverter().ConvertFrom("#00FFFFFF"));
                }

                back = (SolidColorBrush)(new BrushConverter().ConvertFrom("#00FFFFFF"));

                using var __ = new NECContext();
                string customerName = __.Rm00101.Single(r => r.Custnmbr == (project.InternationalId == "N/A" ? project.CustomerNumber : project.InternationalId)).Custname.Trim();
                __.Dispose();

                contentControl.ApplyTemplate();

                (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType <Grid>().First().Background = back;

                (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType <Grid>().First().Children.OfType <TextBlock>().Single(tb => tb.Name == "ProjectNumberTextBlock").Text = project.ProjectNumber.ToString();
                (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType <Grid>().First().Children.OfType <TextBlock>().Single(tb => tb.Name == "ProjectStageTextBlock").Text  = stage;
                (VisualTreeHelper.GetChild(contentControl as DependencyObject, 0) as Grid).Children.OfType <Grid>().First().Children.OfType <TextBlock>().Single(tb => tb.Name == "CustomerNameTextBlock").Text  = customerName;

                ProjectDockPanel.Children.Add(contentControl);
            }
        }
コード例 #5
0
        private void SetOnHold()
        {
            try
            {
                using var _nat02Context = new NAT02Context();
                if (!engineeringProject)
                {
                    using var _projectsContext   = new ProjectsContext();
                    using var _driveworksContext = new DriveWorksContext();


                    if (_projectsContext.HoldStatus.Any(p => p.ProjectNumber == projectNumber && p.RevisionNumber == revisionNumber))
                    {
                        // Update data in HoldStatus
                        HoldStatus holdStatus = _projectsContext.HoldStatus.Where(p => p.ProjectNumber == projectNumber && p.RevisionNumber == revisionNumber).First();
                        holdStatus.HoldStatus1   = "ON HOLD";
                        holdStatus.TimeSubmitted = DateTime.Now;
                        holdStatus.OnHoldComment = CommentBox.Text;
                        holdStatus.User          = User.GetUserName() ?? Environment.UserName.ToLower();
                        _projectsContext.HoldStatus.Update(holdStatus);
                    }
                    else
                    {
                        // Insert into HoldStatus
                        HoldStatus holdStatus = new HoldStatus();
                        holdStatus.ProjectNumber  = projectNumber;
                        holdStatus.RevisionNumber = revisionNumber;
                        holdStatus.TimeSubmitted  = DateTime.Now;
                        holdStatus.HoldStatus1    = "ON HOLD";
                        holdStatus.OnHoldComment  = CommentBox.Text;
                        holdStatus.User           = User.GetUserName() ?? Environment.UserName.ToLower();
                        _projectsContext.HoldStatus.Add(holdStatus);
                    }

                    // Drive specification transition name to "On Hold - " projectType
                    string         _name = projectNumber + (Convert.ToInt32(revisionNumber) > 0 ? "_" + revisionNumber : "");
                    Specifications spec  = _driveworksContext.Specifications.Where(s => s.Name == _name).First();
                    spec.StateName = "On Hold - " + projectType;
                    _driveworksContext.Specifications.Update(spec);

                    var name = IMethods.GetDisplayNameFromDWPrincipalID(_projectsContext.ProjectSpecSheet.First(p => p.ProjectNumber.ToString() == projectNumber && p.RevisionNumber.ToString() == revisionNumber).Csr).Split(' ');
                    EoiNotificationsActive eoiNotificationsActive = new EoiNotificationsActive()
                    {
                        Type      = "Project",
                        Number    = projectNumber,
                        Message   = "Project has been put on hold.",
                        User      = (name[0].Substring(0, 1) + name[1]).ToLower(),
                        Timestamp = DateTime.Now
                    };
                    _nat02Context.EoiNotificationsActive.Add(eoiNotificationsActive);
                    if (!string.IsNullOrEmpty(_projectsContext.ProjectSpecSheet.First(p => p.ProjectNumber.ToString() == projectNumber && p.RevisionNumber.ToString() == revisionNumber).ReturnToCsr))
                    {
                        name = IMethods.GetDisplayNameFromDWPrincipalID(_projectsContext.ProjectSpecSheet.First(p => p.ProjectNumber.ToString() == projectNumber && p.RevisionNumber.ToString() == revisionNumber).ReturnToCsr).Split(' ');
                        EoiNotificationsActive eoiNotificationsActive1 = new EoiNotificationsActive()
                        {
                            Type      = "Project",
                            Number    = projectNumber,
                            Message   = "Project has been put on hold.",
                            User      = (name[0].Substring(0, 1) + name[1]).ToLower(),
                            Timestamp = DateTime.Now
                        };
                        _nat02Context.EoiNotificationsActive.Add(eoiNotificationsActive1);
                    }


                    _projectsContext.SaveChanges();
                    _driveworksContext.SaveChanges();
                    _nat02Context.SaveChanges();
                    _projectsContext.Dispose();
                    _driveworksContext.Dispose();
                    _nat02Context.Dispose();
                    parent.BoolValue = true;
                }
                else
                {
                    using var _projectsContext = new ProjectsContext();

                    EngineeringProjects eProject = _projectsContext.EngineeringProjects.First(p => p.ProjectNumber == projectNumber.ToString() && p.RevNumber == revisionNumber.ToString());
                    eProject.OnHold         = true;
                    eProject.OnHoldComment  = CommentBox.Text;
                    eProject.OnHoldDateTime = DateTime.UtcNow;
                    eProject.OnHoldUser     = User.GetUserName() ?? Environment.UserName.ToLower();
                    var name = IMethods.GetDisplayNameFromDWPrincipalID(eProject.CSR).Split(' ');
                    EoiNotificationsActive eoiNotificationsActive = new EoiNotificationsActive()
                    {
                        Type      = "Project",
                        Number    = projectNumber,
                        Message   = "Project has been put on hold.",
                        User      = (name[0].Substring(0, 1) + name[1]).ToLower(),
                        Timestamp = DateTime.Now
                    };
                    _nat02Context.EoiNotificationsActive.Add(eoiNotificationsActive);
                    if (!string.IsNullOrEmpty(eProject.ReturnToCSR) && eProject.ReturnToCSR.Length > 0)
                    {
                        name = IMethods.GetDisplayNameFromDWPrincipalID(eProject.ReturnToCSR).Split(' ');
                        EoiNotificationsActive eoiNotificationsActive1 = new EoiNotificationsActive()
                        {
                            Type      = "Project",
                            Number    = projectNumber,
                            Message   = "Project has been put on hold.",
                            User      = (name[0].Substring(0, 1) + name[1]).ToLower(),
                            Timestamp = DateTime.Now
                        };
                        _nat02Context.EoiNotificationsActive.Add(eoiNotificationsActive1);
                    }


                    //string _name = projectNumber + (Convert.ToInt32(revisionNumber) > 0 ? "_" + revisionNumber : "");
                    //Specifications spec = _driveworksContext.Specifications.Where(s => s.Name == _name).First();
                    //spec.StateName = "On Hold - " + projectType;
                    //_driveworksContext.Specifications.Update(spec);

                    _projectsContext.SaveChanges();
                    _nat02Context.SaveChanges();
                    _projectsContext.Dispose();
                    _nat02Context.Dispose();
                    if (projectWindow != null)
                    {
                        projectWindow.PutOnHoldButton.Content = "Take Off Hold";
                    }
                }
                string path = @"R:\TOOLING AUTOMATION\Project Specifications\" + projectNumber + "\\";
                if (File.Exists(path + "On_Hold_Comment.txt"))
                {
                    int i = 1;
                    while (File.Exists(path + "On_Hold_Comment_" + i + ".txt"))
                    {
                        i++;
                    }
                    path = path + "On_Hold_Comment_" + i + ".txt";
                }

                try
                {
                    // Create a file to write to.
                    using (StreamWriter sw = File.CreateText(path))
                    {
                        sw.Write("Comment: " + Environment.NewLine +
                                 CommentBox.Text + Environment.NewLine + Environment.NewLine +
                                 "Time: " + Convert.ToString(DateTime.Now) + Environment.NewLine +
                                 "User: "******"SetOnHold", ex.Message);
            }
        }
コード例 #6
0
        private async Task <SeriesCollection> BuildToolsChart(DateTime?beginningDateTime, DateTime?endDateTime)
        {
            SeriesCollection sc = new SeriesCollection();
            string           toolProjectsReportQuery        = "EXECUTE NAT02.dbo.sp_EOI_EngineeringProduction_ToolProject_Start_End @StartDate = {0}, @EndDate = {1}";
            string           toolProjectsCheckedReportQuery = "EXECUTE NAT02.dbo.sp_EOI_EngineeringProduction_Tools_Checked @StartDate = {0}, @EndDate = {1}";

            string[] dates = new string[] { beginningDateTime.Value.ToShortDateString(), endDateTime.Value.ToShortDateString() };
            List <ToolProjectsReportStartEnd> toolProjectsReport         = new List <ToolProjectsReportStartEnd>();
            List <ToolProjectsCheckedReport>  toolProjectsCheckedReports = new List <ToolProjectsCheckedReport>();

            using var _ = new ProjectsContext();
            await Task.Run((Action)(() =>
            {
                toolProjectsReport = _.ToolProjectsReportStartEnd.FromSqlRaw(toolProjectsReportQuery, dates).ToList();
                toolProjectsCheckedReports = _.ToolProjectsCheckedReport.FromSqlRaw(toolProjectsCheckedReportQuery, dates).ToList();
            }));

            _.Dispose();
            List <(string Drafter, decimal Hours, int Projects)> drafters = new List <(string Drafter, decimal Hours, int Projects)>();

            foreach (string drafter in toolProjectsReport.Select(o => o.Drafter).Distinct())
            {
                if (drafter == "Tyler")
                {
                }
                List <ToolProjectsReportStartEnd> draftersProjects = toolProjectsReport.Where(o => o.Drafter == drafter).ToList();
                List <Interval> intervals = new List <Interval>();
                foreach (ToolProjectsReportStartEnd project in draftersProjects.Where(p => p.Minutes > 1))
                {
                    intervals.Add(Interval.CreateInterval(project.ToolStartedDateTime, project.ToolDrawnDateTime));
                }
                intervals = Interval.MergeOverlappingIntervals(intervals.AsEnumerable()).ToList();
                TimeSpan totalTime     = Interval.GetTimeSpanOfIntervals(intervals.AsEnumerable());
                int      totalProjects = draftersProjects.Count;
                decimal  hours         = intervals.Count > 0 ? Convert.ToDecimal(totalTime.TotalSeconds / 3600) / Convert.ToDecimal(draftersProjects.Count(p => p.Minutes > 1)) : -1;
                drafters.Add((drafter, hours, totalProjects));
            }
            List <(string Drafter, decimal Hours, int ProjectsDrawn, int ProjectsChecked)> draftersFinal = new List <(string Drafter, decimal Hours, int ProjectsDrawn, int ProjectsChecked)>();
            List <string> ds = new List <string>();

            ds.AddRange(drafters.Select(d => d.Drafter));
            ds.AddRange(toolProjectsCheckedReports.Select(d => d.ToolCheckedBy));
            ds = ds.Distinct().ToList();
            foreach (string d in ds)
            {
                (string Drafter, decimal Hours, int Projects)_drafter = (d, -1, 0);
                ToolProjectsCheckedReport _toolProjectsCheckedReport = new ToolProjectsCheckedReport {
                    Projects = 0, ToolCheckedBy = d
                };
                if (drafters.Any(drafter => drafter.Drafter == d))
                {
                    _drafter = drafters.First(drafter => drafter.Drafter == d);
                }
                if (toolProjectsCheckedReports.Any(drafter => drafter.ToolCheckedBy == d))
                {
                    _toolProjectsCheckedReport = toolProjectsCheckedReports.First(drafter => drafter.ToolCheckedBy == d);
                }
                draftersFinal.Add((d, _drafter.Hours, _drafter.Projects, _toolProjectsCheckedReport.Projects));
            }
            draftersFinal = draftersFinal.OrderBy(d => d.ProjectsDrawn).ToList();
            sc.Add(new RowSeries
            {
                Title  = "Tool Projects Drawn",
                Values = new ChartValues <int>(draftersFinal.Select(or => or.ProjectsDrawn))
            });
            sc.Add(new RowSeries
            {
                Title  = "Tool Projects Checked",
                Values = new ChartValues <int>(draftersFinal.Select(or => or.ProjectsChecked))
            });
            YAxis.Labels     = draftersFinal.Select(or => or.Drafter + ": " + Math.Round(or.Hours, 2)).ToList();
            YAxis.FontSize   = 25;
            YAxis.Foreground = new SolidColorBrush(Colors.Black);
            return(sc);
        }