//HentAlle og HentFraID (DRY)
        private Opgave ReadOpgave(SqlDataReader reader)
        {
            int    id          = reader.GetInt32(0);
            String beskrivelse = reader.GetString(1);

            StatusType status = StatusType.IkkeLøst;

            try
            {
                String statusStr = reader.GetString(2);
                status = (StatusType)Enum.Parse(typeof(StatusType), statusStr);
                CheckEnumParseO(status, id);
            }
            catch (ParseToEnumException)
            {
                ParseToEnumException parseFailEx = new ParseToEnumException(id);
                string log = parseFailEx.ToString(); //string til log for exceptions på REST Siden. ikke lagret endnu. mangler liste til at blive lagret i.
            }

            int ventetid = reader.GetInt32(3);
            int udstyrId = reader.GetInt32(4);

            Udstyr udstyr = HentUdstyrFraId(udstyrId);

            return(new Opgave(id, beskrivelse, status, udstyrId, udstyr)); //hvad der der galt med opgave konstructor?
        }
예제 #2
0
        //HentAlle og HentFraID (DRY)
        /// <summary>
        /// Metode til at indlæse et komplet Opgave-objekt fra Databasen
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        private Opgave ReadOpgave(SqlDataReader reader)
        {
            int    id          = reader.GetInt32(0);
            String beskrivelse = reader.GetString(1);

            StatusType status = StatusType.IkkeLøst;

            try
            {
                String statusStr = reader.GetString(2);
                status = (StatusType)Enum.Parse(typeof(StatusType), statusStr);
                CheckEnumParseO(status, id);
            }
            catch (ParseToEnumException)
            {
                ParseToEnumException parseFailEx = new ParseToEnumException(id);
                string log = parseFailEx.ToString();
            }

            int ventetid = reader.GetInt32(3);
            int udstyrId = reader.GetInt32(4);

            //Skal kalde ManageUdstyr hvis vi vil have et komplet Udstyr objekt til Opgave objektet. Ikke nødvendigt i 3. iteration.
            Udstyr udstyr = new Udstyr(udstyrId);

            return(new Opgave(id, beskrivelse, status, ventetid, udstyr));
        }
예제 #3
0
        public void IndsætUdstyr()
        {
            Udstyr udstyr    = UdstyrViewModel.NytUdstyr;
            int    stationID = UdstyrViewModel.AdminStation.StationsId;

            //int udstyrID = UdstyrViewModel.AdminStation.StationsId;

            udstyr.Station.StationsId = stationID;

            //Hvis man ikke skal indtaste dato
            udstyr.Installationsdato = DateTime.Now;

            UdstyrViewModel.Logbog.UFacade.IndsætUdstyr(udstyr);

            //ListView opdatering
            UdstyrViewModel.Logbog.UdstyrsListe.Clear();

            var udstyrliste = UdstyrViewModel.Logbog.UFacade.HentUdstyrForStationID(stationID);

            foreach (var u in udstyrliste)
            {
                UdstyrViewModel.Logbog.AddU(u);
            }

            UdstyrViewModel.UdstyrErValgt = false;
        }
예제 #4
0
        public Udstyr SletUdstyr(int id)
        {
            Udstyr udstyr = HentUdstyrFraId(id);

            if (udstyr == null)
            {
                return(null);
            }

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(deleteSql, connection);
                command.Parameters.AddWithValue("@UdstyrID", id);

                command.Connection.Open();

                int noOfRows = command.ExecuteNonQuery();

                if (noOfRows == 1)
                {
                    return(udstyr);
                }
                return(null);
            }
        }
예제 #5
0
 private void TilføjVærdiUdstyr(Udstyr udstyr, SqlCommand command)
 {
     command.Parameters.AddWithValue("@UdstyrID", udstyr.UdstyrId);
     command.Parameters.AddWithValue("@StationNr", udstyr.Station.StationsId);
     command.Parameters.AddWithValue("@Type", udstyr.Type.ToString());
     command.Parameters.AddWithValue("@Installationsdato", udstyr.Installationsdato);
     command.Parameters.AddWithValue("@Beskrivelse", udstyr.Beskrivelse);
 }
        public Udstyr SletUdstyr(int nr)
        {
            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage resultMessage = client.DeleteAsync(Uri + nr).Result;

                if (resultMessage.IsSuccessStatusCode)
                {
                    string resultStr = resultMessage.Content.ReadAsStringAsync().Result;
                    Udstyr udstyr    = JsonConvert.DeserializeObject <Udstyr>(resultStr);
                    return(udstyr);
                }
            }

            return(null);
        }
 public Udstyr HentEtUdstyr(int nr)
 {
     using (HttpClient client = new HttpClient())
     {
         string jsonStr = client.GetStringAsync(Uri + nr).Result; // info fra body
         Udstyr udstyr  = new Udstyr();
         try
         {
             udstyr = JsonConvert.DeserializeObject <Udstyr>(jsonStr);
         }
         catch (Exception ex)
         {
             MessageDialogHandler.Show("Fejl i hetning", "Der er sket en fejl under kontakt med Databasen.");
         }
         return(udstyr);
     }
 }
        public void InputTest()
        {
            //arrange
            StatusType st  = StatusType.Fejlet;
            int        id  = 1;
            string     ts  = "Beskrivelse";
            Udstyr     uds = new Udstyr();


            //act
            Opgave TestOpgave = new Opgave(id, ts, st, id, uds);

            //assert
            Assert.AreEqual(id, TestOpgave.ID);
            Assert.AreEqual(ts, TestOpgave.Beskrivelse);
            Assert.AreEqual(st, TestOpgave.Status);
            Assert.AreEqual(uds, TestOpgave.Udstyr);
        }
예제 #9
0
        public bool IndsætUdstyr(Udstyr udstyr)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(insertSql, connection);

                TilføjVærdiUdstyr(udstyr, command);

                command.Connection.Open();

                int noOfRows = command.ExecuteNonQuery();

                if (noOfRows == 1)
                {
                    return(true);
                }
                return(false);
            }
        }
        public bool IndsætUdstyr(Udstyr udstyr)
        {
            String        json    = JsonConvert.SerializeObject(udstyr);
            StringContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            using (HttpClient client = new HttpClient())
            {
                HttpResponseMessage resultMessage = client.PostAsync(Uri, content).Result;

                if (resultMessage.IsSuccessStatusCode)
                {
                    string resultStr = resultMessage.Content.ReadAsStringAsync().Result;
                    bool   res       = JsonConvert.DeserializeObject <bool>(resultStr);
                    return(res);
                }
            }
            return(false);
        }
예제 #11
0
        public bool OpdaterUdstyr(Udstyr udstyr, int udstyrID)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(updateSql, connection);

                TilføjVærdiUdstyr(udstyr, command);
                command.Parameters.AddWithValue("@ID", udstyrID);

                command.Connection.Open();

                int noOfRows = command.ExecuteNonQuery();

                if (noOfRows == 1)
                {
                    return(true);
                }
                return(false);
            }
        }
예제 #12
0
        /// <summary>
        /// Constructor
        /// </summary>
        public UdstyrViewModel()
        {
            UdstyrHandler = new UdstyrHandler(this);
            Logbog        = LogbogSingleton.Instance;

            StationsListe = new ObservableCollection <Station>(Logbog.SFacade.HentAlleStationer());

            AddCommand    = new RelayCommand(UdstyrHandler.IndsætUdstyr);
            UpdateCommand = new RelayCommand(UdstyrHandler.OpdaterUdstyr);
            RemoveCommand = new RelayCommand(UdstyrHandler.SletUdstyr);

            NytUdstyr = new Udstyr();

            HentCommand = new RelayCommand(UdstyrHandler.HentUdstyr);

            TypeListe = new List <uType>()
            {
                uType.Filter, uType.Termometer, uType.Lufttrykmåler, uType.Computer
            };
        }
예제 #13
0
        public void OpdaterUdstyr()
        {
            Udstyr udstyr    = UdstyrViewModel.NytUdstyr;
            int    stationID = UdstyrViewModel.AdminStation.StationsId;

            int udstyrID = UdstyrViewModel.ValgtUdstyr.UdstyrId;

            UdstyrViewModel.Logbog.UFacade.OpdaterEtUdstyr(udstyrID, udstyr);

            //ListView opdatering
            UdstyrViewModel.Logbog.UdstyrsListe.Clear();

            var udstyrliste = UdstyrViewModel.Logbog.UFacade.HentUdstyrForStationID(stationID);

            foreach (var u in udstyrliste)
            {
                UdstyrViewModel.Logbog.AddU(u);
            }

            UdstyrViewModel.UdstyrErValgt = false;
        }
예제 #14
0
 public void AddU(Udstyr udstyr)
 {
     UdstyrsListe.Add(udstyr);
 }
 // POST: api/Udstyr/
 public bool Post([FromBody] Udstyr value)
 {
     return(manager.IndsætUdstyr(value));
 }
예제 #16
0
        private Medarbejder OpretMedarbejder(Medarbejder medarbejder)
        {
            medarbejder.navn                = collection.Get("medarbejderNavn");
            medarbejder.afdelingsnavn       = collection.Get("afdelinger");
            medarbejder.initialer           = collection.Get("initialer");
            medarbejder.stillingsbetegnelse = collection.Get("stillingsbetegnelse");
            medarbejder.område_id           = Convert.ToInt32(collection.Get("område"));
            medarbejder.cpr     = collection.Get("cpr");
            medarbejder.fiks_id = Convert.ToInt32(collection.Get("fiks"));
            medarbejder.telefon = Convert.ToInt32(collection.Get("telefon"));

            medarbejder.start_dato = DateTime.ParseExact(collection.Get("datepicker").ToString(), "d", null);

            List <string>  grupperList = collection.GetValues("a360").ToList();
            List <Grupper> grupper     = new List <Grupper>();

            foreach (string gruppe in grupperList)
            {
                Grupper g = new Grupper();
                g.Medarbejder_id = medarbejder.id;
                g.Gruppe         = gruppe;
                grupper.Add(g);
            }

            medarbejder.Grupper.Clear();
            medarbejder.Grupper = grupper;


            List <string> postkasserList = collection.GetValues("postkasse").ToList();

            Collection <Medarbejder_funktionspostkasse> postkasser = new Collection <Medarbejder_funktionspostkasse>();

            foreach (string postkasse in postkasserList)
            {
                Medarbejder_funktionspostkasse medarbejderPostkasse = new Medarbejder_funktionspostkasse();
                medarbejderPostkasse.funktionspostkasse = postkasse;
                postkasser.Add(medarbejderPostkasse);
            }

            medarbejder.Medarbejder_funktionspostkasse.Clear();
            medarbejder.Medarbejder_funktionspostkasse = postkasser;

            //List<string> specialprogrammer = collection.GetValues("specialeprogrammer").ToList();
            //Collection



            List <string>       udstyrList = collection.GetValues("udstyr").ToList();
            Collection <Udstyr> udstyr     = new Collection <Udstyr>();

            foreach (string item in udstyrList)
            {
                Udstyr medarbejderUdstyr = db.Udstyr.Find(Convert.ToInt32(item));
                udstyr.Add(medarbejderUdstyr);
            }
            medarbejder.Udstyr.Clear();
            medarbejder.Udstyr = udstyr;


            return(medarbejder);
        }
 // PUT: api/Udstyr/5
 public bool Put(int id, [FromBody] Udstyr value)
 {
     return(manager.OpdaterUdstyr(value, id));
 }