// valueConverter: should return a value not passed by validPredicate on failure, or alternatively throw an exception
        public static PromptResult <T> ShowPrompt <T>(Window owner, string title, string initialInput, Func <string, T> valueConverter, Func <T, bool> validPredicate = null)
        {
            T    inputResult;
            bool potentialSuccess = false;

            do
            {
                var prompt = new PromptWindow(title);
                prompt.Owner      = owner;
                prompt.PromptText = initialInput;

                if (prompt.ShowDialog() != true)
                {
                    return(ResultFailed <T>());
                }

                try
                {
                    inputResult      = valueConverter(prompt.PromptText);
                    potentialSuccess = true;
                }
                catch (Exception)
                {
                    inputResult      = default(T);
                    potentialSuccess = false;
                }
            } while (!potentialSuccess || (validPredicate != null && !validPredicate(inputResult)));

            return(ResultFromValue(inputResult));
        }
Exemplo n.º 2
0
        private void button_StartRemoteDesktop_Click(object sender, RoutedEventArgs e)
        {
            List <Computer> computersToRemoteDesktop = computers.FindAll(c => c.isAlive);

            PromptWindow promptWindow = new PromptWindow();

            promptWindow.Left = mainWindow.Left + 250;
            promptWindow.Top  = mainWindow.Top + 250;
            promptWindow.ShowDialog();

            if (promptWindow.getChoice() == PromptWindowChoice.CANCEL)
            {
                return;
            }

            if (promptWindow.getChoice() == PromptWindowChoice.CONNECT &&
                promptWindow.getLogin().Length > 0 && promptWindow.getPassword().Length > 0)
            {
                foreach (Computer c in computersToRemoteDesktop)
                {
                    c.startRemoteDesktop(promptWindow.getLogin(), promptWindow.getPassword());
                }
            }
            else
            {
                foreach (Computer c in computersToRemoteDesktop)
                {
                    c.startRemoteDesktop();
                }
            }
        }
Exemplo n.º 3
0
        private static void RequestFirstProfileNameFromUser(IProfileManager profileManager)
        {
            IProfileNameValidator validator = DependencyInjection.Container.Instance.Resolve <IProfileNameValidator>();
            Func <string, Tuple <bool, string> > ValidateProfileName = (name) =>
            {
                if (validator.Validate(name))
                {
                    return(Tuple.Create(true, (string)null));
                }
                else
                {
                    return(Tuple.Create(false, "Invalid profile name"));
                }
            };
            PromptWindow prompt = new PromptWindow("Profile name", "Please provide the name of your first profile", ValidateProfileName);

            // Keep the user here until they fill it out
            while (prompt.DialogResult != true)
            {
                prompt.ShowDialog();
            }

            profileManager.Create(prompt.Input);
            profileManager.OpenProfile(prompt.Input, emitMessage: false);
        }
Exemplo n.º 4
0
        private void SubscriptionsPopupNewCategory(object sender, RoutedEventArgs e)
        {
            var treeComponent = (e.OriginalSource as MenuItem)?.DataContext as TreeComponent;

            if (treeComponent == null)
            {
                return;
            }

            var promptDialog = new PromptWindow("Create new category", "Category name");

            if (promptDialog.ShowDialog() == true)
            {
                var category = new Category()
                {
                    Title            = promptDialog.Result,
                    ParentCategoryId = (treeComponent.Item as Category)?.CategoryId
                };
                var newCategoryData = new NewCategoryData()
                {
                    Category            = category,
                    ParentTreeComponent = treeComponent
                };

                CreateCategory?.Invoke(newCategoryData);
            }
        }
Exemplo n.º 5
0
    /// <summary>
    /// 実行
    /// </summary>
    /// <param name="message">メッセージ</param>
    protected override void InvokeAction(InteractionMessage message)
    {
        if (message is not PromptMessage prompt)
        {
            return;
        }

        var viewModel = new PromptViewModel
        {
            Title        = prompt.Title,
            Description  = prompt.Description,
            Text         = prompt.Text,
            IsAllowEmpty = prompt.IsAllowEmpty,
            Validation   = prompt.Validation,
        };

        prompt.Response = null;

        var window = new PromptWindow
        {
            DataContext = viewModel,
            Owner       = Window.GetWindow(this.AssociatedObject),
        };

        if (window.ShowDialog() ?? false)
        {
            prompt.Response = viewModel.Text;
        }
    }
        private void ConfirmPurchaseOrderCollectionExecute(object parameter)
        {
            string       message       = "是否确认订单";
            string       detailMessage = "请检查进货订单中的每一个条目是否正确,确认订单后将无法修改";
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                DateTime CurrentTime = DateTime.Now;
                PurchaseOrderCollectionViewModel.PurchaseOrderCollection.PurchaseTime = CurrentTime;
                foreach (var purchaseorderviewmodel in PurchaseOrderCollectionViewModel.PurchaseOrderViewModels)
                {
                    purchaseorderviewmodel.PurchaseOrder.PurchaseTime = CurrentTime;
                    CMContext.PurchaseOrder.Add(purchaseorderviewmodel.PurchaseOrder);
                    BlockViewModel blockViewModel             = purchaseorderviewmodel.BlockViewModel;
                    IEnumerable <CargoCollectionViewModel> cc = blockViewModel.CargoCollectionViewModels.Where <CargoCollectionViewModel>(item => item.CargoCollection.PreciseCargoName == purchaseorderviewmodel.PurchaseOrder.PreciseCargoName);
                    if (cc.Count() == 0)
                    {
                        CargoCollectionViewModel c = new CargoCollectionViewModel(CMContext, purchaseorderviewmodel)
                        {
                            BlockViewModel = blockViewModel, CargoCollectionViewModels = CargoCollectionViewModels
                        };
                        CargoCollectionViewModels.Add(c);
                        blockViewModel.CargoCollectionViewModels.Add(c);
                        CMContext.CargoCollection.Add(c.CargoCollection);
                        PurchasePrizeDic p1 = new PurchasePrizeDic(purchaseorderviewmodel.PurchaseOrder)
                        {
                            UnitPurchasePrize = -1
                        };
                        PurchasePrizeDic p2 = new PurchasePrizeDic(purchaseorderviewmodel.PurchaseOrder);
                        CMContext.PurchasePrizeDic.Add(p1);
                        CMContext.PurchasePrizeDic.Add(p2);
                        c.SelectedPurchasePrizeDic = p1;
                    }
                    else
                    {
                        CargoCollectionViewModel c = cc.First();
                        c.CargoCollection.Amount += purchaseorderviewmodel.PurchaseOrder.Amount;
                        c.CargoCollection.PurchasePrizeDics[0].Amount = c.CargoCollection.Amount;
                        IEnumerable <PurchasePrizeDic> pp = c.CargoCollection.PurchasePrizeDics.Where <PurchasePrizeDic>(item => item.UnitPurchasePrize == purchaseorderviewmodel.PurchaseOrder.UnitPurchasePrize);
                        if (pp.Count() == 0)
                        {
                            PurchasePrizeDic p = new PurchasePrizeDic(purchaseorderviewmodel.PurchaseOrder);
                            CMContext.PurchasePrizeDic.Add(p);
                        }
                        else
                        {
                            pp.First().Amount += purchaseorderviewmodel.PurchaseOrder.Amount;
                        }
                    }
                }
                CMContext.PurchaseOrderCollection.Add(PurchaseOrderCollectionViewModel.PurchaseOrderCollection);
                PurchaseOrderCollectionViewModels.Add(PurchaseOrderCollectionViewModel);
                CMContext.SaveChanges();
                PurchaseOrderCollectionViewModel = null;
                OutPurchaseOrderButtonIsEnabled  = false;
            }
        }
        public bool?Prompt(string message)
        {
            var promptWindow = new PromptWindow {
                Owner = Window.GetWindow(View), Text = message
            };

            return(promptWindow.ShowDialog());
        }
        private void DeletePurchaseOrderCollectionExecute(object parameter)
        {
            string       message       = "是否删除订单";
            string       detailMessage = "删除进货订单将删除订单中的每一个条目,请确定后删除";
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                PurchaseOrderCollectionViewModel = null;
                OutPurchaseOrderButtonIsEnabled  = false;
            }
        }
        private void DeleteExecute(object parameter)
        {
            string       message       = "是否删除卖货订单";
            string       detailMessage = "删除的卖货订单记录将无法恢复,请确认是否是删除该订单\n删除之前备份订单的信息以便错误删除后进行恢复";
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                SellOrderCollectionViewModels.Remove(this);
                CMContext.SellOrderCollection.Remove(SellOrderCollection);
                CMContext.SaveChanges();
            }
        }
Exemplo n.º 10
0
        private static IWorkbookSet showPromptWindow(AKProduct product, Project project, string productCutx, SpecificationGroup specificationGroup)
        {
            string globalGvfx    = Path.Combine(project.JobPath, specificationGroup.GlobalFileName);
            string cutPartsCtpx  = Path.Combine(project.JobPath, specificationGroup.CutPartsFileName);
            string edgeEdgx      = Path.Combine(project.JobPath, specificationGroup.EdgeBandFileName);
            string hardwareHwrx  = Path.Combine(project.JobPath, specificationGroup.HardwareFileName);
            string doorstyleDsvx = Path.Combine(project.JobPath, specificationGroup.DoorWizardFileName);

            PromptsViewModel viewmodel = new PromptsViewModel(productCutx, globalGvfx, cutPartsCtpx, edgeEdgx, hardwareHwrx, doorstyleDsvx,
                                                              product.Tab.Name, product.Tab.Photo, product.Tab.VarX, product.Tab.VarZ, product.Tab.VarY);

            PromptWindow prompt = new PromptWindow();

            prompt.ViewModel = viewmodel;
            prompt.ShowDialog();

            return(viewmodel.BookSet);
        }
        public void DeletePlaneExecute(object parameter)
        {
            string       message       = "是否确定删除";
            string       detailMessage = string.Format("本操作将会删除楼层:{0},以及该楼层内全部区域和区域内的货物", Plane.PlaneName);
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                WarehouseManagementUserControl          wmuc   = parameter as WarehouseManagementUserControl;
                WarehouseManagementUserControlViewModel wmucvm = wmuc.DataContext as WarehouseManagementUserControlViewModel;
                wmucvm.CargoCollectionViewModels = null;
                DeleteCargoCollections();
                CMContext.Plane.Remove(Plane);
                WarehouseViewModel.PlaneViewModels.Remove(this);
                CMContext.SaveChanges();
            }
        }
Exemplo n.º 12
0
        // ## Auto Generating Electives

        /// <summary>
        /// The electivesToolStripMenuItem method is used to handle autogening course
        /// elective placeholders. It can generate a list of eaither general or major
        /// electives and add them to the courseList.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void electivesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // open a new form
            AutoGenElectives genElectWindow = new AutoGenElectives(courseList);

            genElectWindow.ShowDialog();

            // override bool
            bool containsDuplicates = false;

            // check if generated electives already exist
            if (genElectWindow.GeneratedElectives is null)
            {
                return;
            }
            foreach (Course elective in genElectWindow.GeneratedElectives)
            {
                if (courseList.Contains(elective))
                {
                    containsDuplicates = true;
                }
            }

            // if gened electives already exist, prompt to override
            if (containsDuplicates)
            {
                // open prompt form
                PromptWindow prompt = new PromptWindow("Generated Electives of this type already exist.\n" +
                                                       "Override existing?");
                prompt.ShowDialog();
                if (!prompt.Result)
                {
                    return;
                }
            }

            // add all generated electives to Course list and reload
            foreach (Course elective in genElectWindow.GeneratedElectives)
            {
                courseList.Add(elective);
            }
            updateCourseViewer();
        }
        public void DeleteBlockExecute(object parameter)
        {
            string       message       = "是否确定删除";
            string       detailMessage = string.Format("本操作将会删除区域:{0},以及该区域内的全部货物", Block.BlockName);
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                WarehouseManagementUserControl          wmuc   = parameter as WarehouseManagementUserControl;
                WarehouseManagementUserControlViewModel wmucvm = wmuc.DataContext as WarehouseManagementUserControlViewModel;
                wmucvm.CargoCollectionViewModels = null;
                AllCargoCollectionViewModels     = wmucvm.AllCargoCollectionViewModels;
                DeleteCargoCollections();
                CMContext.Block.Remove(Block);
                PlaneViewModel.BlockViewModels.Remove(this);
                CMContext.SaveChanges();
            }
        }
        public void DeleteExecute(object parameter)
        {
            string       message       = "是否删除该品类";
            string       detailMessage = "删除该品类将会删除所有库存中该品类的商品";
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                var p = CargoCollectionViewModels.Where <CargoCollectionViewModel>
                            (item => item.CargoCollection.PreciseCargoName == Cargo.PreciseCargoName).ToList();
                foreach (var i in p)
                {
                    i.DeleteCargoCollection();
                }
                CMContext.Cargo.Remove(Cargo);
                CargoViewModels.Remove(this);
                CMContext.SaveChanges();
            }
        }
Exemplo n.º 15
0
        public GmailDataHelper Create()
        {
            int            n    = 0;
            PromptSettings ps   = _recorder.LoadData("Prompt" + n);
            String         pass = "";

            if (!String.IsNullOrEmpty(ps.Password))
            {
                ps.SecurePassword = ProtectData.DecryptString(ps.Password);
                pass        = "******".Repeat(ps.SecurePassword.Length);
                ps.Password = pass;
            }
            PromptWindow pw = new PromptWindow();

            pw.DataContext = ps;

            if (pw.ShowDialog() == true)
            {
                if (!String.Equals(pass, ps.Password))
                {
                    ps.SecurePassword = new SecureString();
                    foreach (char c in ps.Password)
                    {
                        ps.SecurePassword.AppendChar(c);
                    }
                }
                var credit = new NetworkCredential(ps.Login, ps.SecurePassword);

                ps.Password       = ProtectData.EncryptString(ps.SecurePassword);
                ps.SecurePassword = null;
                _recorder.StoreData("Prompt" + n, ps);

                GmailDataHelper gdhn = new GmailDataHelper(ps.Login, credit);
                new MailTray(gdhn);
                gdhn.AutoRefresh();
                return(gdhn);
            }
            return(null);
        }
Exemplo n.º 16
0
        protected override void addCourseButton_Click(object sender, EventArgs e)
        {
            try
            {
                //Attempt to create course object
                StringCourseBuilder builder = new Course.StringCourseBuilder(courseNameTB.Text, courseDescriptionTB.Text,
                                                                             coursePrefixTB.Text, courseIDTB.Text, courseCreditsTB.Text, courses);
                builder.ValidTerms    = validSemestersTB.Text;
                builder.Dependencies  = courseDependenciesTB.Text;
                builder.Copendencies  = courseCopendenciesTB.Text;
                builder.CourseDetails = detailsEditForm.courseDetails;
                Course editedCourse = builder.build();

                //check to ensure course ref is the same
                if (!editedCourse.Equals(editCourse))
                {
                    //if not, ensure it does not already exist in the course list
                    if (courses.Contains(editedCourse))
                    {
                        throw new Exception("Course already exists!");
                    }
                }

                //find all dependees that will need there dependent ref updated
                List <Course> dependenciesToModify = new List <Course>();
                List <Course> copendenciesToModify = new List <Course>();

                foreach (Course course in courses)
                {
                    if (course.dependencies.Contains(editCourse))
                    {
                        dependenciesToModify.Add(course);
                    }
                    if (course.copendencies.Contains(editCourse))
                    {
                        copendenciesToModify.Add(editCourse);
                    }
                }

                //add edited course to list
                courses.Add(editedCourse);

                if (!(dependenciesToModify.Count == 0 && copendenciesToModify.Count == 0))
                {
                    //prompt the user to ensure continue
                    String message =
                        "Warning: This will overide the course dependent for the following courses from\n"
                        + editCourse.courseReference + " to " + editedCourse.courseReference + ", Continue?\n"
                        + "Course List: ";

                    foreach (Course course in dependenciesToModify)
                    {
                        message += course.courseReference + ", ";
                    }
                    foreach (Course course in copendenciesToModify)
                    {
                        message += course.courseReference + ", ";
                    }
                    message = message.TrimEnd(',');

                    PromptWindow confirm = new PromptWindow(message);
                    this.SuspendLayout();
                    confirm.ShowDialog();

                    // if ok, overrite, else cancel
                    if (confirm.Result)
                    {
                        foreach (Course course in dependenciesToModify)
                        {
                            CourseBuilder newCourse = new Course.CourseBuilder(course, courses);
                            newCourse.removeDependency(editCourse);
                            newCourse.addDependency(editedCourse);

                            courses.Remove(course);
                            courses.Add(newCourse.build());
                        }
                        foreach (Course course in copendenciesToModify)
                        {
                            CourseBuilder newCourse = new Course.CourseBuilder(course, courses);
                            newCourse.removeCopendency(editCourse);
                            newCourse.addCopendency(editedCourse);

                            courses.Remove(course);
                            courses.Add(newCourse.build());
                        }
                    }
                    else
                    {
                        courses.Remove(editedCourse);
                        return;
                    }
                }

                //remove the course from the list
                courses.Remove(editCourse);

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 17
0
        // ## remove

        /// <summary>
        /// the deleteToolStripMenuItem will attempt to delete the selected course
        /// from the viewer and courseList. It will find a list of all courses that
        /// may depend on the selected course and warn the user that they will be
        /// removed as well.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //course
            if (CourseView.SelectedItems.Count == 1)
            {
                //variable
                Course deleteCourse = courseList[CourseView.SelectedItems[0].Index];

                //find all dependees that depend on deleteCourse
                List <Course> toDelete = new List <Course>();
                toDelete.Add(deleteCourse);


                int counter = 0;
                while (counter < toDelete.Count)
                {
                    foreach (Course course in courseList)
                    {
                        if (course.dependencies.Contains(toDelete[counter]) ||
                            course.copendencies.Contains(toDelete[counter]))
                        {
                            toDelete.Add(course);
                        }
                    }
                    counter++;
                }

                //remove seed course
                toDelete.Remove(deleteCourse);


                if (!(toDelete.Count == 0))
                {
                    //prompt the user to ensure continue
                    String message =
                        "Warning: This will also remove the following courses that\n"
                        + "depend on " + deleteCourse.courseReference + ", Continue?\n"
                        + "Course List: ";

                    foreach (Course course in toDelete)
                    {
                        message += course.courseReference + ", ";
                    }
                    message = message.TrimEnd(',');

                    PromptWindow confirm = new PromptWindow(message);
                    this.SuspendLayout();
                    confirm.ShowDialog();

                    // if ok, delete, else cancel
                    if (confirm.Result)
                    {
                        foreach (Course course in toDelete)
                        {
                            courseList.Remove(course);
                            removePrescheduledCourse(course);
                        }
                    }
                    else
                    {
                        return;
                    }
                }

                //remove the course from the list
                courseList.Remove(deleteCourse);
                removePrescheduledCourse(deleteCourse);

                //update course view
                updateCourseViewer();

                //update prefixes
                updatePrefixes();
            }
            //semester
            else if (SemesterViewer.SelectedItems.Count == 1)
            {
                //remove the semester
                semesterList.RemoveAt(SemesterViewer.SelectedItems[0].Index);

                //update semester view
                updateSemesterViewer();
            }
            else
            {
                throw new Exception("Not Allowed!");
            }
        }
        private void ConfirmSellOrderCollectionExecute(object parameter)
        {
            string       message       = "是否确认订单";
            string       detailMessage = "请检查卖货订单中的每一个条目是否正确,确认订单后将无法修改";
            PromptWindow prompt        = new PromptWindow(message, detailMessage);
            bool?        IsConfirmed   = prompt.ShowDialog();

            if (IsConfirmed == true)
            {
                DateTime CurrentTime = DateTime.Now;
                SellOrderCollectionViewModel.SellOrderCollection.SellTime = CurrentTime;
                foreach (var sellorderviewmodel in SellOrderCollectionViewModel.SellOrderViewModels)
                {
                    sellorderviewmodel.SellOrder.SellTime = CurrentTime;
                    CMContext.SellOrder.Add(sellorderviewmodel.SellOrder);
                    CargoCollectionViewModel cargoCollectionViewModel = sellorderviewmodel.CargoCollectionViewModel;
                    if (cargoCollectionViewModel.CargoCollection.Amount == sellorderviewmodel.SellOrder.Amount)
                    {
                        CMContext.CargoCollection.Remove(cargoCollectionViewModel.CargoCollection);
                        cargoCollectionViewModel.BlockViewModel.CargoCollectionViewModels.Remove(cargoCollectionViewModel);
                        cargoCollectionViewModel.CargoCollectionViewModels.Remove(cargoCollectionViewModel);
                    }
                    else
                    {
                        int BufferAmount = sellorderviewmodel.SellOrder.Amount;
                        cargoCollectionViewModel.CargoCollection.PurchasePrizeDics[0].Amount -= sellorderviewmodel.SellOrder.Amount;
                        cargoCollectionViewModel.CargoCollection.Amount -= sellorderviewmodel.SellOrder.Amount;
                        foreach (var dic in cargoCollectionViewModel.CargoCollection.PurchasePrizeDics)
                        {
                            if (dic.UnitPurchasePrize == -1)
                            {
                                continue;
                            }
                            else if (BufferAmount == 0)
                            {
                                break;
                            }
                            else if (dic.Amount == BufferAmount)
                            {
                                dic.Amount   = 0;
                                BufferAmount = 0;
                            }
                            else if (dic.Amount < BufferAmount)
                            {
                                BufferAmount -= dic.Amount;
                                dic.Amount    = 0;
                            }
                            else if (dic.Amount > BufferAmount)
                            {
                                dic.Amount  -= BufferAmount;
                                BufferAmount = 0;
                            }
                        }
                        var bufferresult = cargoCollectionViewModel.CargoCollection.PurchasePrizeDics.Where <PurchasePrizeDic>(item => item.Amount == 0).ToList();

                        for (int i = 0; i < bufferresult.Count(); i++)
                        {
                            cargoCollectionViewModel.CargoCollection.PurchasePrizeDics.Remove(bufferresult[i]);
                        }
                    }
                }
                CMContext.SellOrderCollection.Add(SellOrderCollectionViewModel.SellOrderCollection);
                SellOrderCollectionViewModels.Add(SellOrderCollectionViewModel);
                CMContext.SaveChanges();
                SellOrderCollectionViewModel = null;
                OutSellOrderButtonIsEnabled  = false;
            }
        }