Exemple #1
0
        public static void AddPM(PM AddMe)
        {          
            PMTempDB.Add(AddMe);

            string PM_Path = System.IO.Path.Combine(Base_Path, "PMData.xml");
            System.Xml.Serialization.XmlSerializer Saver = new System.Xml.Serialization.XmlSerializer(typeof(List<PM>));
            System.IO.FileStream file = System.IO.File.Create(PM_Path);
            Saver.Serialize(file, PMTempDB);
            file.Close();
            Load_PMs(PM_Path);
        }
Exemple #2
0
        private void Done_ClickPM(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;
            if (System.Windows.MessageBox.Show("Sure you're done making this PM?", "Confirm Navigation", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
            {
                this.IsEnabled = true;
                return;
            }

            TimeSpan givenInterval = new TimeSpan();
            int parsedValue;
            int.TryParse(intervalNumber.Text, out parsedValue);
            string name = textBox.Text;
              
                       
            if (name == defaultPMName || string.IsNullOrWhiteSpace(name) || name == defaultPMName + " You must enter a name before you click 'Done'")
            {
                System.Windows.MessageBox.Show("Enter a name for the PM");
                this.IsEnabled = true;
                return;
            }
            if(intervalNumber.Text == defaultintervalnumber || DateType.SelectedItem == null)
            {
                System.Windows.MessageBox.Show("Enter the interva of time between when you would have to carry out this PM, if the PM is a one-off task that you shouldn't hav eto do again, raise a work order instead.");
                this.IsEnabled = true;
                return;
            }

            if (DateType.SelectedItem.ToString() == "Days")
            {
                givenInterval = TimeSpan.FromDays(parsedValue);
            }
            if(DateType.SelectedItem.ToString() == "Weeks")
            {
                givenInterval = TimeSpan.FromDays(parsedValue * 7);
            }
            if (DateType.SelectedItem.ToString() == "Months")
            {
                givenInterval = TimeSpan.FromDays(parsedValue * 30);
            }
            if (DateType.SelectedItem.ToString() == "Years")
            {
                givenInterval = TimeSpan.FromDays(parsedValue * 365);
            }

            TimeSpan addTime = new TimeSpan();

            for (int a = 0; a <= (Temp.Count-1); a++)
            {                
                addTime += Temp[a].Tasktime;
            }

            PM StoredPMData = new PM();
            StoredPMData.Created = DateTime.Now;
            StoredPMData.StartFrom = DateTime.Now;
            StoredPMData.Equipment = "Dummy";
            StoredPMData.Interval = givenInterval;
            StoredPMData.PMName = name;
            StoredPMData.Tasks = Temp;
            StoredPMData.Totaltime = addTime;

            PMDatabaseHelpers.AddPM(StoredPMData);
            this.Close();
        }