Ejemplo n.º 1
0
        /* REGARDING TAKING OVER DELETE FUNCTIONS ETC ...
         * you would need to create and bind SelectedItem to act on that
         * (then it would reflect in the view/datagrid)
         * but then it also needs handling/converters for when the interface
         * goes to the "new item" line. Trust you - you tried it already,
         * but it was way too much work to start at 03:40 on the ward. ;-)
         */

        /*
         * public MyCommand ValidateDatabaseCommand { get; private set; }
         * private void ExecuteValidateDatabaseCommand(object parameter)
         * {
         *  MessageBox.Show("Not implemented.");
         * }
         *
         * private bool CanExecuteValidateDatabaseCommand(object parameter)
         * {
         *  if (MedcinData.IsEmpty())
         *      return false;
         *  else
         *      return true;
         * }
         *
         * public MyCommand ValidateMedcinUIdCommand { get; private set; }
         * private void ExecuteValidateMedcinUIdCommand(object parameter)
         * {
         *  MessageBox.Show("Not implemented.");
         * }
         *
         * private bool CanExecuteValidateMedcinUIdCommand(object parameter)
         * {
         *  if (MedcinData.IsEmpty()) return false;
         *  else return true;
         * } */

        #endregion


        #region METHODS

        private void ExportXml(string path)
        {
            Busy = true;

            // create a temporary file stream so that if something goes wrong,
            // it doesn't corrupt the existing file
            string tempFile = Path.GetTempFileName();

            using (FileStream stream = File.Create(tempFile))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    writer.WriteStartElement("MedcinTerms");
                    MedcinData.WriteXml(writer);
                    writer.WriteEndElement();
                }
            }

            File.Copy(tempFile, path, true);
            File.Delete(tempFile);

            Dirty = false;
            Busy  = false;
        }
Ejemplo n.º 2
0
        private void SetupMenu()
        {
            // Tier 1: medcin term option
            this.Header = "Choose a Medcin term ...";

            // Tier 2: categories
            List <MenuItem> tier2 = new List <MenuItem>();

            foreach (Common.Category cat in Enum.GetValues(typeof(Common.Category)))
            {
                MenuItem item = new MenuItem();
                item.Header = cat.ToString();
                item.Tag    = cat;
                tier2.Add(item);
            }

            // Tier 3: medcin terms
            foreach (var item in tier2)
            {
                IEnumerable <MedcinTerm> choices = MedcinData.ExtractBy((Category)item.Tag);
                item.ItemsSource = choices;
            }

            // Tie it all together
            this.ItemsSource = tier2;
        }
Ejemplo n.º 3
0
 private bool CanExecuteSaveDatabaseCommand(object parameter)
 {
     if (MedcinData.IsEmpty())
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 4
0
        private void ImportXml(string path)
        {
            Busy = true;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;

            using (XmlReader reader = XmlReader.Create(path, settings))
            {
                MedcinData.ReadXml(reader);
            }

            Dirty = false;
            Busy  = false;
        }
Ejemplo n.º 5
0
        private void ExecuteNewDatabaseCommand(object parameter)
        {
            // prevent user from inadvertently losing work
            if (!MedcinData.IsEmpty() && Dirty)
            {
                MessageBoxResult result = MessageBox.Show("Current database has unsaved changes which will be lost. Proceed?",
                                                          "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }

            MedcinData.Reset();
            curFilePath = "";
            Dirty       = false;
        }
Ejemplo n.º 6
0
        private void ExecuteOpenDatabaseCommand(object parameter)
        {
            // prevent user from inadvertently losing work
            if (!MedcinData.IsEmpty() && Dirty)
            {
                MessageBoxResult result = MessageBox.Show("Current database has unsaved changes which will be lost. Proceed?",
                                                          "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "Xml (*.xml)|*.xml";
            openFileDialog.RestoreDirectory = true;
            if (openFileDialog.ShowDialog() == true)
            {
                CurrentFilePath = openFileDialog.FileName;
                MedcinData.Reset();
                ImportXml(CurrentFilePath);
            }
        }