예제 #1
0
        public static void unarchiveCompetition(Panel parent)
        {
            string archiveDirectory = DataManager.getAbsolutePath(DataManager.Settings.ArchiveDirectory);

            if (!Directory.Exists(archiveDirectory))
            {
                Directory.CreateDirectory(archiveDirectory);
            }

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.InitialDirectory = archiveDirectory;
            dlg.DefaultExt       = ".comp";
            dlg.Filter           = "Competition File (*.comp)|*.comp";
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                DialogBox.showOptionBox(parent, "Do you want to archive the current competition? If you do not archive the current competition and all of its data/images it will be deleted.", "Archive The Current Competition?", "Delete", "Archive", delegate(DialogBox.DialogResult res)
                {
                    bool done = false;
                    if (res == DialogBox.DialogResult.MainOption)
                    {
                        if (!archiveCompetition())
                        {
                            done = true;
                        }
                    }

                    if (!done)
                    {
                        FileInfo saveFile = new FileInfo(dlg.FileName);
                        string fileName   = saveFile.Name.Substring(0, saveFile.Name.IndexOf(saveFile.Extension));

                        string tempFolder = saveFile.Directory + @"\" + saveFile.Name.Substring(0, saveFile.Name.IndexOf(saveFile.Extension));
                        if (Directory.Exists(tempFolder))
                        {
                            Directory.Delete(tempFolder, true);
                        }
                        Directory.CreateDirectory(tempFolder);

                        ZipFile.ExtractToDirectory(saveFile.FullName, tempFolder);

                        string imagesDirectory = DataManager.getAbsolutePath(DataManager.Settings.ImageDirectory);


                        if (Directory.Exists(imagesDirectory))
                        {
                            Directory.Delete(imagesDirectory, true);
                        }
                        if (File.Exists(getAbsolutePath(Competition.DefaltFileName)))
                        {
                            File.Delete(getAbsolutePath(Competition.DefaltFileName));
                        }

                        Directory.Move(tempFolder + @"\" + DataManager.Settings.ImageDirectory, imagesDirectory);               //move images folder to normal folder

                        File.Move(tempFolder + @"\" + Competition.DefaltFileName, getAbsolutePath(Competition.DefaltFileName)); //move images folder to normal folder

                        Directory.Delete(tempFolder, true);
                        File.Delete(saveFile.FullName);

                        _competition      = Competition.Load();
                        _competition.Name = fileName;
                        triggerCompetitionChanged();
                    }
                });
            }
        }
예제 #2
0
        private static void MakeDialog(Panel parent, RacerDetails content, WindowType type)
        {
            content._dialogHost = new Dialog(parent, content, false, false, true, delegate()
            {
                if (content._type == WindowType.Display)    //only allow saving after clicking of dialog, if not creating a new car
                {
                    if (content.createSaveRacer())
                    {
                        return(DialogButton.ReturnEvent.Close);
                    }
                    else
                    {
                        return(DialogButton.ReturnEvent.DoNothing);
                    }
                }
                else
                {
                    return(DialogButton.ReturnEvent.DoNothing);
                }
            }, (type == WindowType.Display ? new DialogButton("Delete", DialogButton.Alignment.Left, DialogButton.Style.Flat, delegate() {
                DialogBox.showOptionBox(parent, "This will completly remove \"" + content.tbCarName.Text + "\" from the competition. All of its history will be deleted. The current race will also be reset.", "Delete \"" + content.tbCarName.Text + "\"?", "Keep", "Delete", delegate(DialogBox.DialogResult result)
                {
                    if (result == DialogBox.DialogResult.MainOption)
                    {
                        DataManager.Competition.Racers.Remove(content._racer);
                        content.triggerUpdatedRacer();
                        content.triggerDeletedRacer();
                        content._dialogHost.Close();    //close this host dialog
                    }
                });

                return(DialogButton.ReturnEvent.DoNothing);
            }) : null), new DialogButton((type == WindowType.Display ? "Revert" : "Forget"), DialogButton.Alignment.Right, DialogButton.Style.Flat, delegate() {
                if (type == WindowType.Display)
                {
                    string changes = "";

                    if (content._racer.Car.Name != content.tbCarName.Text)
                    {
                        changes += Environment.NewLine + "Car's Name: " + content._racer.Car.Name + " -> " + content.tbCarName.Text;
                    }
                    if (content._racer.Car.ImageUri != DataManager.getRelativePath(content.imgCarPicture.Source.ToString()))
                    {
                        changes += Environment.NewLine + "Car's Image";
                    }
                    if (content._racer.Maker.Name != content.tbCreatorName.Text)
                    {
                        changes += Environment.NewLine + "Creator's Name: " + content._racer.Maker.Name + " -> " + content.tbCreatorName.Text;
                    }
                    if (content._racer.Maker.ImageUri != DataManager.getRelativePath(content.imgCreatorPicture.Source.ToString()))
                    {
                        changes += Environment.NewLine + "Creator's Name";
                    }
                    if (content._racer.Barcode != content.tbBarcode.Text)
                    {
                        changes += Environment.NewLine + "Barcode: " + content._racer.Barcode + " -> " + content.tbBarcode.Text;
                    }
                    if (content._racer.Class != content.cboClass.Text)
                    {
                        changes += Environment.NewLine + "Class: " + content._racer.Class + " -> " + content.cboClass.Text;
                    }
                    if (content._racer.PassedInspection != (content.passedInspect.IsChecked == true))
                    {
                        changes += Environment.NewLine + "Passed Inspection: " + (content._racer.PassedInspection ? "Yes" : "No") + " -> " + ((content.passedInspect.IsChecked == true)?"Yes":"No");
                    }

                    //no nothing, this will act like a revert
                    if (changes.Length > 0)
                    {
                        DialogBox.showOptionBox(parent, "This will revert the following changes" + changes, "Revert Changes Made To \"" + content.tbCarName.Text + "\"?", "Keep", "Revert", delegate(DialogBox.DialogResult result)
                        {
                            if (result == DialogBox.DialogResult.MainOption)
                            {
                                content._dialogHost.Close();    //close this host dialog
                            }
                        });
                    }
                    else
                    {
                        return(DialogButton.ReturnEvent.Close);
                    }
                }
                else
                {
                    bool changed = false;
                    if ("" != content.tbCarName.Text)
                    {
                        changed = true;
                    }
                    if (DataManager.Settings.DefaltCarImageUri != DataManager.getRelativePath(content.imgCarPicture.Source.ToString()))
                    {
                        changed = true;
                    }
                    if ("" != content.tbCreatorName.Text)
                    {
                        changed = true;
                    }
                    if (DataManager.Settings.DefaltMakerImageUri != DataManager.getRelativePath(content.imgCreatorPicture.Source.ToString()))
                    {
                        changed = true;
                    }
                    if ("" != content.tbBarcode.Text)
                    {
                        changed = true;
                    }
                    if ("" != content.cboClass.Text)
                    {
                        changed = true;
                    }
                    if (false != (content.passedInspect.IsChecked == true))
                    {
                        changed = true;
                    }

                    if (changed)
                    {
                        DialogBox.showOptionBox(parent, "This will erase all data entered for " + content.tbCarName.Text + ".", "Forget \"" + content.tbCarName.Text + "\"?", "Keep", "Forget", delegate(DialogBox.DialogResult result)
                        {
                            if (result == DialogBox.DialogResult.MainOption)
                            {
                                content._dialogHost.Close();    //close this host dialog
                            }
                        });
                    }
                    else
                    {
                        return(DialogButton.ReturnEvent.Close);
                    }
                }

                return(DialogButton.ReturnEvent.DoNothing);
            }), new DialogButton("Save", DialogButton.Alignment.Right, DialogButton.Style.Normal, delegate() {
                if (content.createSaveRacer())    //save racer on save button click
                {
                    return(DialogButton.ReturnEvent.Close);
                }
                else
                {
                    return(DialogButton.ReturnEvent.DoNothing);
                }
            }));
        }