public bool Post(DaaseVaegt daaseVeVaegt)
        {
            bool retValue = false;

            SqlConnection conn = new SqlConnection(ConnString);

            try
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(INSERT, conn);
                cmd.Parameters.AddWithValue("@PONR", daaseVeVaegt.ProcessOrderNr);
                cmd.Parameters.AddWithValue("@KNR", daaseVeVaegt.KontrolOrderNr);
                cmd.Parameters.AddWithValue("@DNR", daaseVeVaegt.DaaseNr);
                cmd.Parameters.AddWithValue("@Vaegt", daaseVeVaegt.DasseVaegt);

                int rowsAffected = cmd.ExecuteNonQuery();
                retValue = rowsAffected == 1 ? true : false;
            }
            catch (Exception e)
            {
                Console.WriteLine(
                    $"{daaseVeVaegt.ProcessOrderNr}/n{daaseVeVaegt.KontrolOrderNr}/n{daaseVeVaegt.DaaseNr}/n{daaseVeVaegt.DasseVaegt}");
            }

            finally
            {
                conn.Close();
            }

            return(retValue);
        }
Exemple #2
0
 public void add()
 {
     if (_viewModel.SelectedVaegt >= 100)
     {
         DaaseVaegt daase = new DaaseVaegt
         {
             ProcessOrderNr = _viewModel.NewSelectedVaegtKontrol.VaegtKontrol.ProcessOrdreNr,
             KontrolOrderNr = _viewModel.NewSelectedVaegtKontrol.VaegtKontrol.KontrolNr,
             DaaseNr        = _viewModel.SelectedNr,
             DasseVaegt     = _viewModel.SelectedVaegt
         };
         if (PersistenceDaaseVaegt.Post(daase))
         {
             _viewModel.Vaegts.Add(new Record(daase.DaaseNr, daase.DasseVaegt));
             _viewModel.SelectedVaegt = 0;
             _viewModel.SelectedNr    = _viewModel.SelectedNr + 1;
             ClearImage();
             _viewModel.NewSelectedVaegtKontrol.Update();
             GetEstement();
         }
     }
     else
     {
         MessageDialogHelper.Show("Vægten skal være over 100 g", "Ugyldig værdi");
     }
 }
        private DaaseVaegt ReadDaaseVaegt(SqlDataReader reader)
        {
            DaaseVaegt daase = new DaaseVaegt
            {
                DaaseNr        = reader.GetInt32(0),
                DasseVaegt     = reader.GetDouble(1),
                KontrolOrderNr = reader.GetInt32(2),
                ProcessOrderNr = reader.GetInt32(3)
            };


            return(daase);
        }
        public static bool Post(DaaseVaegt NewDaaseVaegt)
        {
            bool ok = true;

            using (HttpClient client = new HttpClient())
            {
                string        serializeObject        = JsonConvert.SerializeObject(NewDaaseVaegt);
                StringContent content                = new StringContent(serializeObject, Encoding.UTF8, "application/json");
                Task <HttpResponseMessage> postAsync = client.PostAsync($"{URI}/DaaseVaegts", content);
                HttpResponseMessage        resps     = postAsync.Result;
                if (resps.IsSuccessStatusCode)
                {
                    string jsonStr = resps.Content.ReadAsStringAsync().Result;
                    ok = JsonConvert.DeserializeObject <bool>(jsonStr);
                }
                else
                {
                    ok = false;
                }
            }

            return(ok);
        }
        public IEnumerable <DaaseVaegt> Get(int ProcessOrderNr, int KontrolNr)
        {
            List <DaaseVaegt> daaser = new List <DaaseVaegt>();

            SqlConnection conn = new SqlConnection(ConnString);

            conn.Open();

            SqlCommand cmd = new SqlCommand(GET, conn);

            cmd.Parameters.AddWithValue("@PONR", ProcessOrderNr);
            cmd.Parameters.AddWithValue("@KNR", KontrolNr);

            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                DaaseVaegt daaseVaegt = ReadDaaseVaegt(reader);
                daaser.Add(daaseVaegt);
            }
            conn.Close();

            return(daaser);
        }
 // POST: api/DaaseVaegts
 public bool Post([FromBody] DaaseVaegt value)
 {
     return(manger.Post(value));
 }