Beispiel #1
0
        private void btnCreateEq_Click(object sender, RoutedEventArgs e)
        {
            DateTime date;

            bool missing = false;

            Dictionary <string, string> propList = FillOutProperty();

            if (propList.Count == 0)
            {
                missing = true;
            }

            foreach (KeyValuePair <string, string> item in propList)
            {
                if (string.IsNullOrWhiteSpace(item.Value))
                {
                    missing = true;
                }
            }

            if (CBCategory.SelectedValue == null)
            {
                lbError.Content = "Du skal vælge en kategori";
            }
            else if (dtpService.IsReadOnly == false && !DateTime.TryParse(dtpService.Text, out date))
            {
                lbError.Content = "Du skal udfylde en dato for service";
            }
            else if (dtpService.IsReadOnly == false && Convert.ToDateTime(dtpService.Text).Ticks < DateTime.Now.Ticks)
            {
                lbError.Content = "Sæt en korrekt service";
            }
            else if (missing)
            {
                lbError.Content = "Du mangler at udfylde en værdi";
            }
            else
            {
                Category cat = CatRep.GetByName(CBCategory.SelectedValue.ToString());

                DateTime?dateend;

                if (string.IsNullOrWhiteSpace(dtpService.Text))
                {
                    dateend = null;
                }
                else
                {
                    dateend = Convert.ToDateTime(dtpService.Text);
                }

                Equipment eq = new Equipment(
                    cat._id,
                    dateend,
                    propList
                    );

                DataFac.AddEquipment(eq);

                MessageBox.Show("Udstyret: " + cat._name + " er nu oprettet");

                Edit ed = Edit.Instance;
                ed.runAlarm();

                (Application.Current.MainWindow.FindName("FrameFilter") as Frame).Source  = null;
                (Application.Current.MainWindow.FindName("FrameChart") as Frame).Source   = null;
                (Application.Current.MainWindow.FindName("FrameContent") as Frame).Source = new Uri(@"\Views\FrontPage.xaml", UriKind.RelativeOrAbsolute);
            }
        }