Beispiel #1
0
        /// <summary>
        /// Instance of the current user of the application to house settings and preferences
        /// </summary>
        /// <param name="domainName"></param>
        public User(string domainName)
        {
            try
            {
                DomainName = domainName.ToLower();
            }
            catch (Exception ex)
            {
                IMethods.WriteToErrorLog("User.cs -> Setting domain name.", ex.Message, null);
            }
            using var _nat02context = new NAT02Context();
            EoiSettings settings = _nat02context.EoiSettings.SingleOrDefault(row => row.DomainName.Trim().ToLower() == domainName.Trim().ToLower());

            try
            {
                System.IO.StreamReader streamReader = new System.IO.StreamReader(@"\\nshare\VB_Apps\NatoliOrderInterface\version.json");
                string version = "";
                while (!streamReader.ReadLine().Contains(':'))
                {
                    version = streamReader.ReadLine().Split(':')[1].Trim('"');
                    break;
                }
                PackageVersion          = version;
                settings.PackageVersion = PackageVersion;
                _nat02context.SaveChanges();
            }
            catch (Exception ex)
            {
                IMethods.WriteToErrorLog("User.cs -> Export applications version.", ex.Message, null);
            }
            _nat02context.Dispose();
            string deptCode = DomainName.Length == 0 ? "GUEST" : SetUserName();

            EmployeeCode = settings.EmployeeId;
            userName     = settings.FullName;
            using var _driveworksContext = new DriveWorksContext();
            dwDisplayName = userName == "Gregory Lyle" ? "Greg Lyle" : userName == "Nicholas Tarte" ? "Nick Tarte" : userName == "Floyd Smith" ? "Joe Smith" : userName == "Ronald Faltus" ? "Ron Faltus" : userName;
            if (_driveworksContext.SecurityUsers.Any(su => su.DisplayName == dwDisplayName))
            {
                dwPrincipalId = _driveworksContext.SecurityUsers.First(su => su.DisplayName == dwDisplayName).PrincipalId;
            }
            else
            {
                dwDisplayName = "";
                dwPrincipalId = "";
            }
            _driveworksContext.Dispose();
            Subscribed           = settings.Subscribed.Split().ToList();
            Width                = settings.Width;
            Height               = settings.Height;
            Top                  = settings.Top;
            Left                 = settings.Left;
            Maximized            = settings.Maximized;
            QuoteDays            = settings.QuoteDays;
            Zoom                 = settings.Zoom;
            ModuleRows           = (short)settings.ModuleRows;
            FilterActiveProjects = settings.FilterActiveProjects;
            DepartmentCode       = deptCode;
            if (deptCode == "D1153" || DomainName == "pturner" || DomainName == "rmouser")
            {
                Department = "Engineering";
            }
            else if (deptCode == "D1102")
            {
                Department = "Hob Programming";
            }
            else if (deptCode == "D1151")
            {
                Department = "Order Entry";
            }
            else if (deptCode == "D1133")
            {
                Department = "Barb";
            }
            else
            {
                Department = "Customer Service";
            }
            VisiblePanels = settings.Panels.Split(',').ToList();
            foreach (string panel in VisiblePanels)
            {
                if (panel == "TabletProjectsNotStarted" || panel == "TabletProjectsStarted" || panel == "TabletProjectsDrawn" || panel == "TabletProjectsSubmitted" ||
                    panel == "TabletProjectsOnHold" || panel == "ToolProjectsNotStarted" || panel == "ToolProjectsStarted" || panel == "ToolProjectsDrawn" || panel == "ToolProjectsOnHold")
                {
                    VisiblePanels.Remove(panel);
                }
            }
            if (DomainName == "dkruggel")
            {
                SignatureLeft = 955; SignatureBottom = 20;
            }
            else if (DomainName == "twilliams")
            {
                SignatureLeft = 958; SignatureBottom = 20;
            }
            else if (DomainName == "dsachuk")
            {
                SignatureLeft = 958; SignatureBottom = 20;
            }
            else
            {
                SignatureLeft = 0; SignatureBottom = 0;
            }
            if (userName.ContainsAny("David Kruggel", "Tyler Williams", "Mustafa Mulaosmanovic"))
            {
                ViewReports = true;
            }
            //if (DomainName == "dkruggel" || DomainName == "twilliams")
            //{
            //    InputBox inputBox = new InputBox("Enter password", "Password");
            //    inputBox.ShowDialog();
            //    Password = inputBox.ReturnString;
            //}
        }
Beispiel #2
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);
            }
        }