private void btnToevoegen_Click(object sender, EventArgs e)
        {
            string     s   = "";
            Levrancier lev = new Levrancier();
            Adress     ad  = new Adress();

            if (txtNaam.Text != "")
            {
                lev.Naam = txtNaam.Text;
            }
            else
            {
                s += "Naam? ";
            }
            lev.Omschrijving = rtbOmschrijving.Text;
            if (txtTel1.Text != "" && txtTel1.Text.ToCharArray().All(c => char.IsDigit(c)))
            {
                lev.Telefoon1 = txtTel1.Text;
            }
            else
            {
                s += "Telefoon1? ";
            }
            if (txtTel2.Text != "" && txtTel2.Text.ToCharArray().All(c => char.IsDigit(c)))
            {
                lev.Telefoon2 = txtTel2.Text;
            }
            if (re.IsMatch(txtEmail.Text))
            {
                lev.Email = txtEmail.Text;
            }
            else
            {
                s += "Email? ";
            }
            if (newAd)
            {
                if (txtStraat.Text != "" && txtStraat.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Straat = txtStraat.Text;
                }
                else
                {
                    s += "Adress: Straat ? ";
                }
                if (txtHuisNr.Text != "" && txtHuisNr.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Huisnummer = Convert.ToInt32(txtHuisNr.Text);
                }
                else
                {
                    s += "Adress: Huisnummer ? ";
                }
                if (txttGem.Text != "" && txttGem.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Gemeente = txttGem.Text;
                }
                else
                {
                    s += "Adress: Gemeente ? ";
                }
                if (txtPC.Text != "" && txtPC.Text.ToCharArray().All(c => char.IsDigit(c)))
                {
                    ad.Postcode = txtPC.Text;
                }
                else
                {
                    s += "Adress: Postcode ? ";
                }
                if (txtLand.Text != "" && txtLand.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Land = txtLand.Text;
                }
                else
                {
                    s += "Adress: Land ? ";
                }
            }
            if (s == "")
            {
                using (var ctx = new ProjectContext())
                {
                    if (newAd && (ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) == null))
                    {
                        lev.adress = ad;
                    }
                    else if (newAd && ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) != null)
                    {
                        lev.adress = ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land);
                    }
                    else if (!newAd)
                    {
                        lev.adress = ctx.Adressen.FirstOrDefault(a => a.AdressId == ((Adress)cmbAdress.SelectedItem).AdressId);
                    }
                    ctx.Levranciers.Add(lev);
                    ctx.SaveChanges();
                    EditProduct.Leveranciers = ctx.Levranciers.ToList();
                    AddProduct.Leveranciers  = ctx.Levranciers.ToList();
                }
                EditProduct.cmb_Leveranciere.DataSource   = null;
                EditProduct.cmb_Leveranciere.DataSource   = EditProduct.Leveranciers;
                EditProduct.cmb_Leveranciere.SelectedItem = lev;
                AddProduct.cmb_Leveranciere.DataSource    = null;
                AddProduct.cmb_Leveranciere.DataSource    = AddProduct.Leveranciers;
                AddProduct.cmb_Leveranciere.SelectedItem  = lev;
                btnToevoegen.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(s);
                s = "";
            }
        }
Beispiel #2
0
        private void btnToevoegen_Click(object sender, EventArgs e)
        {
            Klant  klt = new Klant();
            Adress ad  = new Adress();
            string s   = "";
            Regex  re  = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");

            if (txtVnaam.Text != "" && txtVnaam.Text.ToCharArray().All(c => char.IsLetter(c)))
            {
                klt.Voornaam = txtVnaam.Text;
            }
            else
            {
                s += "Voornaam ? ";
            }
            if (txtAnaam.Text != "" && txtAnaam.Text.ToCharArray().All(c => char.IsLetter(c)))
            {
                klt.achternaam = txtAnaam.Text;
            }
            else
            {
                s += "Achternaam ? ";
            }
            if (dtpGD.Value != null && dtpGD.Value < DateTime.Now)
            {
                klt.Geboortdatum = dtpGD.Value;
            }
            else
            {
                s += "Geboortdatum ? ";
            }
            if (txtTel1.Text != "" && txtTel1.Text.ToCharArray().All(c => char.IsDigit(c)))
            {
                klt.Telefoon1 = txtTel1.Text;
                if (txtTel2.Text != "")
                {
                    klt.Telefoon2 = txtTel2.Text;
                }
            }
            else
            {
                s += "Telefoon ? ";
            }
            if (re.IsMatch(txtEmail.Text))
            {
                klt.Email = txtEmail.Text;
            }
            else
            {
                s += "Email ? ";
            }
            if (newAd)
            {
                if (txtStraat.Text != "" && txtStraat.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Straat = txtStraat.Text;
                }
                else
                {
                    s += "Adress: Straat ? ";
                }
                if (txtHuisNr.Text != "" && txtHuisNr.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Huisnummer = Convert.ToInt32(txtHuisNr.Text);
                }
                else
                {
                    s += "Adress: Huisnummer ? ";
                }
                if (txttGem.Text != "" && txttGem.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Gemeente = txttGem.Text;
                }
                else
                {
                    s += "Adress: Gemeente ? ";
                }
                if (txtPC.Text != "" && txtPC.Text.ToCharArray().All(c => char.IsDigit(c)))
                {
                    ad.Postcode = txtPC.Text;
                }
                else
                {
                    s += "Adress: Postcode ? ";
                }
                if (txtLand.Text != "" && txtLand.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Land = txtLand.Text;
                }
                else
                {
                    s += "Adress: Land ? ";
                }
            }
            klt.IsBedrijf = cbBedrijf.Checked;
            if (txtBTW.Text != "")
            {
                klt.BTWNummer = txtBTW.Text;
            }
            else
            {
                s += "BTW nummer ? ";
            }
            klt.IngevoegdDatum = DateTime.UtcNow;
            if (rtbComentaar.Text != "")
            {
                klt.Commentaar = rtbComentaar.Text;
            }
            if (s == "")
            {
                using (var ctx = new ProjectContext())
                {
                    if (newAd && (ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) == null))
                    {
                        klt.adress = ad;
                        ctx.SaveChanges();
                        Adresses             = ctx.Adressen.ToList();
                        cmbAdress.DataSource = Adresses;
                    }
                    else if (newAd && ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) != null)
                    {
                        klt.adress = ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land);
                    }
                    else if (!newAd)
                    {
                        klt.adress = ctx.Adressen.FirstOrDefault(a => a.AdressId == ((Adress)cmbAdress.SelectedItem).AdressId);
                    }
                    klt.IngevoegdDoor = ctx.Users.FirstOrDefault(u => u.UserId == Login.user.UserId);
                    ctx.Klanten.Add(klt);
                    ctx.SaveChanges();
                    Databeheer.Klanten = ctx.Klanten.Include("Adress").Include("IngevoegdDoor").ToList();
                    AddOrder.Klanten   = ctx.Klanten.Include("Adress").Include("IngevoegdDoor").ToList();
                    EditOrder.Klanten  = ctx.Klanten.Include("Adress").Include("IngevoegdDoor").ToList();
                }
                if (AddOrder.cmb_Klanten != null)
                {
                    AddOrder.cmb_Klanten.DataSource = null;
                    AddOrder.cmb_Klanten.DataSource = AddOrder.Klanten;
                }
                if (EditOrder.cmb_Klanten != null)
                {
                    EditOrder.cmb_Klanten.DataSource = EditOrder.Klanten;
                    EditOrder.cmb_Klanten.Text       = klt.ToString();
                }
                if (Databeheer.dgv_klanten != null)
                {
                    Databeheer.loaddgvklants();
                }

                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(s);
                s = "";
            }
        }
Beispiel #3
0
        private void btnOpslaan_Click(object sender, EventArgs e)
        {
            string   s   = "";
            Bezorger lev = new Bezorger();
            Adress   ad  = new Adress();

            if (txtNaam.Text != "")
            {
                lev.Naam = txtNaam.Text;
            }
            else
            {
                s += "Naam? ";
            }
            lev.Omschrijving = rtbOmschrijving.Text;
            if (txtTel1.Text != "" && txtTel1.Text.ToCharArray().All(c => char.IsDigit(c)))
            {
                lev.Telefoon1 = txtTel1.Text;
            }
            else
            {
                s += "Telefoon1? ";
            }
            if (txtTel2.Text != "" && txtTel2.Text.ToCharArray().All(c => char.IsDigit(c)))
            {
                lev.Telefoon2 = txtTel2.Text;
            }
            if (re.IsMatch(txtEmail.Text))
            {
                lev.Email = txtEmail.Text;
            }
            else
            {
                s += "Email? ";
            }
            if (newAd)
            {
                if (txtStraat.Text != "" && txtStraat.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Straat = txtStraat.Text;
                }
                else
                {
                    s += "Adress: Straat ? ";
                }
                if (txtHuisNr.Text != "" && txtHuisNr.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Huisnummer = Convert.ToInt32(txtHuisNr.Text);
                }
                else
                {
                    s += "Adress: Huisnummer ? ";
                }
                if (txttGem.Text != "" && txttGem.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Gemeente = txttGem.Text;
                }
                else
                {
                    s += "Adress: Gemeente ? ";
                }
                if (txtPC.Text != "" && txtPC.Text.ToCharArray().All(c => char.IsDigit(c)))
                {
                    ad.Postcode = txtPC.Text;
                }
                else
                {
                    s += "Adress: Postcode ? ";
                }
                if (txtLand.Text != "" && txtLand.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Land = txtLand.Text;
                }
                else
                {
                    s += "Adress: Land ? ";
                }
            }
            if (s == "")
            {
                using (var ctx = new ProjectContext())
                {
                    if (newAd && (ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) == null))
                    {
                        lev.adress = ad;
                    }
                    else if (newAd && ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) != null)
                    {
                        lev.adress = ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land);
                    }
                    else if (!newAd)
                    {
                        lev.adress = ctx.Adressen.FirstOrDefault(a => a.AdressId == ((Adress)cmbAdress.SelectedItem).AdressId);
                    }
                    ctx.Bezorgers.FirstOrDefault(b => b.BezorgerId == Databeheer.bezorger.BezorgerId).Naam      = lev.Naam;
                    ctx.Bezorgers.FirstOrDefault(b => b.BezorgerId == Databeheer.bezorger.BezorgerId).Naam      = lev.Omschrijving;
                    ctx.Bezorgers.FirstOrDefault(b => b.BezorgerId == Databeheer.bezorger.BezorgerId).Telefoon1 = lev.Telefoon1;
                    ctx.Bezorgers.FirstOrDefault(b => b.BezorgerId == Databeheer.bezorger.BezorgerId).Telefoon2 = lev.Telefoon2;
                    ctx.Bezorgers.FirstOrDefault(b => b.BezorgerId == Databeheer.bezorger.BezorgerId).Email     = lev.Email;
                    ctx.Bezorgers.FirstOrDefault(b => b.BezorgerId == Databeheer.bezorger.BezorgerId).adress    = lev.adress;
                    ctx.SaveChanges();
                    Databeheer.Deliverers = ctx.Bezorgers.Include("adress").ToList();
                }
                Databeheer.dgv_Deliverer.DataSource = null;
                Databeheer.dgv_Deliverer.DataSource = Databeheer.Deliverers;
                btnOpslaan.DialogResult             = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(s);
                s = "";
            }
        }
Beispiel #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     User us = new User();
     Adress ad = new Adress();
     string s = "";
     Regex re = new Regex(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
     Regex re1 = new Regex("^(?=.*?[A-Za-z])(?=.*?[0-9])(?=.*?[#?!@$%^_&*-]).{8,}$");
     if (txtVnaam.Text != "" && txtVnaam.Text.ToCharArray().All(c => char.IsLetter(c)))
         us.Voornaam = txtVnaam.Text;
     else
         s += "Voornaam ? ";
     if (txtAnaam.Text != "" && txtAnaam.Text.ToCharArray().All(c => char.IsLetter(c)))
         us.Achternaam = txtAnaam.Text;
     else
         s += "Achternaam ? ";
     if (dtpGD.Value != null && dtpGD.Value < DateTime.Now)
         us.Geboortdatum = dtpGD.Value;
     else
         s += "Geboortdatum ? ";
     if (txtTel.Text != "" && txtTel.Text.ToCharArray().All(c => char.IsDigit(c)))
         us.Telefoon = txtTel.Text;
     else
         s += "Telefoon ? ";
     if (re.IsMatch(txtEmail.Text))
         us.Email = txtEmail.Text;
     else
         s += "Email ? ";
     if (newAd)
     {
         if (txtStraat.Text != "" && txtStraat.Text.ToCharArray().All(c => char.IsLetter(c)))
             ad.Straat = txtStraat.Text;
         else
             s += "Adress: Straat ? ";
         if (txtHuisNr.Text != "" && txtHuisNr.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
             ad.Huisnummer = Convert.ToInt32(txtHuisNr.Text);
         else
             s += "Adress: Huisnummer ? ";
         if (txttGem.Text != "" && txttGem.Text.ToCharArray().All(c => char.IsLetter(c)))
             ad.Gemeente = txttGem.Text;
         else
             s += "Adress: Gemeente ? ";
         if (txtPC.Text != "" && txtPC.Text.ToCharArray().All(c => char.IsDigit(c)))
             ad.Postcode = txtPC.Text;
         else
             s += "Adress: Postcode ? ";
         if (txtLand.Text != "" && txtLand.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
             ad.Land = txtLand.Text;
         else
             s += "Adress: Land ? ";
     }
     us.Role = (RoleUser)cmbRoles.SelectedItem;
     if (s == "")
     {
         using (var ctx = new ProjectContext())
         {
             if (newAd && (ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) == null))
                 us.adress = ad;
             else if (newAd && ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) != null)
                 us.adress = ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land);
             else if (!newAd)
                 us.adress = ctx.Adressen.FirstOrDefault(a => a.AdressId == ((Adress)cmbAdress.SelectedItem).AdressId);
             ctx.Users.FirstOrDefault(u => u.UserId == Databeheer.user.UserId).Voornaam = us.Voornaam;
             ctx.Users.FirstOrDefault(u => u.UserId == Databeheer.user.UserId).Achternaam = us.Achternaam;
             ctx.Users.FirstOrDefault(u => u.UserId == Databeheer.user.UserId).Geboortdatum = us.Geboortdatum;
             ctx.Users.FirstOrDefault(u => u.UserId == Databeheer.user.UserId).Telefoon = us.Telefoon;
             ctx.Users.FirstOrDefault(u => u.UserId == Databeheer.user.UserId).Email = us.Email;
             ctx.Users.FirstOrDefault(u => u.UserId == Databeheer.user.UserId).adress = us.adress;
             ctx.Users.FirstOrDefault(u => u.UserId == Databeheer.user.UserId).Role = us.Role;
             ctx.SaveChanges();
             Databeheer.Users = ctx.Users.Include("Adress").ToList();
         }
         Databeheer.loaddgvusers();
         this.DialogResult = DialogResult.OK;
     }
     else
     {
         MessageBox.Show(s);
         s = "";
     }
 }
Beispiel #5
0
        private void btnAddOrder_Click(object sender, EventArgs e)
        {
            bool   overstock = false;
            Adress ad        = new Adress();
            string s         = "";

            Order       ord   = new Order();
            OrderDetail orddt = new OrderDetail();

            ord.OrderDatum = DateTime.UtcNow;
            ord.status     = (OrderStatus)cmbStatus.SelectedItem;
            if (ord.status > OrderStatus.Geanuleerd && ord.BezorgdDoor == null)
            {
                s += "Bestellingen met staus 'Klaar' of 'Verzondzn' moet ueen bezorger hebben ? ";
            }
            if (newAd)
            {
                if (txtStraat.Text != "" && txtStraat.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Straat = txtStraat.Text;
                }
                else
                {
                    s += "Adress: Straat ? ";
                }
                if (txtHuisNr.Text != "" && txtHuisNr.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Huisnummer = Convert.ToInt32(txtHuisNr.Text);
                }
                else
                {
                    s += "Adress: Huisnummer ? ";
                }
                if (txttGem.Text != "" && txttGem.Text.ToCharArray().All(c => char.IsLetter(c)))
                {
                    ad.Gemeente = txttGem.Text;
                }
                else
                {
                    s += "Adress: Gemeente ? ";
                }
                if (txtPC.Text != "" && txtPC.Text.ToCharArray().All(c => char.IsDigit(c)))
                {
                    ad.Postcode = txtPC.Text;
                }
                else
                {
                    s += "Adress: Postcode ? ";
                }
                if (txtLand.Text != "" && txtLand.Text.ToCharArray().All(c => char.IsLetterOrDigit(c)))
                {
                    ad.Land = txtLand.Text;
                }
                else
                {
                    s += "Adress: Land ? ";
                }
            }
            using (var ctx = new ProjectContext())
            {
                foreach (ProductOrdered item in ProductsOrdered)
                {
                    if (ctx.Products.FirstOrDefault(p => p.ProductId == item.ProductId).UnitsOnStock < item.aantal)
                    {
                        overstock = true;
                        s        += $"Slechts {ctx.Products.FirstOrDefault(p => p.ProductId == item.ProductId).UnitsOnStock} stuks zijn beschikbaar voor artikel: {ctx.Products.FirstOrDefault(p => p.ProductId == item.ProductId)} ";
                    }
                }
            }

            if (s == "")
            {
                using (var ctx = new ProjectContext())
                {
                    this.DialogResult = DialogResult.OK;
                    if (newAd && (ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) == null))
                    {
                        ord.BezorgdAdress = ad;
                    }
                    else if (newAd && ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) != null)
                    {
                        ord.BezorgdAdress = ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land);
                    }
                    else if (!newAd)
                    {
                        ord.BezorgdAdress = ctx.Adressen.FirstOrDefault(a => a.AdressId == ((Klant)cmbKlanten.SelectedItem).adress.AdressId);
                    }
                    ord.klant = ctx.Klanten.FirstOrDefault(k => k.KlantId == ((Klant)cmbKlanten.SelectedItem).KlantId);
                    ord.user  = ctx.Users.FirstOrDefault(a => a.UserId == ((User)Login.user).UserId);
                    if (cmbBezorgers.SelectedIndex > -1)
                    {
                        ord.BezorgdDoor = ctx.Bezorgers.FirstOrDefault(b => b.BezorgerId == ((Bezorger)cmbBezorgers.SelectedItem).BezorgerId);
                    }
                    ctx.Orders.Add(ord);
                    ctx.SaveChanges();
                    foreach (ProductOrdered item in ProductsOrdered)
                    {
                        orddt.order   = ctx.Orders.FirstOrDefault(o => o.OrderId == ord.OrderId);
                        orddt.product = ctx.Products.FirstOrDefault(p => p.ProductId == item.ProductId);
                        orddt.Aantal  = item.aantal;
                        ctx.Products.FirstOrDefault(p => p.ProductId == item.ProductId).UnitsOnStock -= item.aantal;
                        ctx.OrderDetails.Add(orddt);
                        ctx.SaveChanges();
                    }
                    Bestellingen.OrderLines = ctx.Orders.Join(ctx.OrderDetails, o => o.OrderId, od => od.order.OrderId, (o, od) => new OrderLine()
                    {
                        orderid = o.OrderId, klant = o.klant, user = o.user, orderdate = o.OrderDatum, status = o.status, bezorgddoor = o.BezorgdDoor, adress = o.BezorgdAdress, orderdetailid = od.ID, product = od.product, aantal = od.Aantal
                    }).OrderByDescending(o => o.orderdate).ToList();
                    Bestellingen.loaddgvOrders();
                    DialogResult dr = MessageBox.Show("FActuur afdrukken?", "", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Yes)
                    {
                        printDocument1.Print();
                    }
                }
            }
            else
            {
                MessageBox.Show(s);
                s = "";
            }
        }
Beispiel #6
0
        private void btnupload_Click(object sender, EventArgs e)
        {
            Product        pr     = new Product();
            OpenFileDialog dialog = new OpenFileDialog();

            //dialog.Filter = "Text files | *.txt";
            dialog.Multiselect = false;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string FileLocation = dialog.FileName;
                Microsoft.Office.Interop.Word.Application App  = new Microsoft.Office.Interop.Word.Application();
                Microsoft.Office.Interop.Word.Document    Doc  = App.Documents.Open(FileLocation);
                Microsoft.Office.Interop.Word.Table       tab1 = Doc.Content.Tables[1];
                Microsoft.Office.Interop.Word.Table       tab2 = Doc.Content.Tables[2];
                Microsoft.Office.Interop.Word.Table       tab3 = Doc.Content.Tables[3];
                Levrancier lev = new Levrancier();
                Adress     ad  = new Adress();
                lev.Naam         = tab1.Cell(2, 1).Range.Text.Substring(0, tab1.Cell(2, 1).Range.Text.Length - 2);
                lev.Omschrijving = tab1.Cell(2, 2).Range.Text.Substring(0, tab1.Cell(2, 2).Range.Text.Length - 2);
                lev.Telefoon1    = tab1.Cell(2, 3).Range.Text.Substring(0, tab1.Cell(2, 3).Range.Text.Length - 2);
                lev.Telefoon2    = tab1.Cell(2, 4).Range.Text.Substring(0, tab1.Cell(2, 4).Range.Text.Length - 2);
                lev.Email        = tab1.Cell(2, 5).Range.Text.Substring(0, tab1.Cell(2, 5).Range.Text.Length - 2);
                ad.Straat        = tab2.Cell(2, 1).Range.Text.Substring(0, tab2.Cell(2, 1).Range.Text.Length - 2);
                ad.Huisnummer    = Convert.ToInt32(tab2.Cell(2, 2).Range.Text.Substring(0, tab2.Cell(2, 2).Range.Text.Length - 2));
                ad.Gemeente      = tab2.Cell(2, 3).Range.Text.Substring(0, tab2.Cell(2, 3).Range.Text.Length - 2);
                ad.Postcode      = tab2.Cell(2, 4).Range.Text.Substring(0, tab2.Cell(2, 4).Range.Text.Length - 2);
                ad.Land          = tab2.Cell(2, 5).Range.Text.Substring(0, tab2.Cell(2, 5).Range.Text.Length - 2);

                for (int i = 2; i <= tab3.Rows.Count; i++)
                {
                    pr.ProductNaam   = tab3.Cell(i, 1).Range.Text.Substring(0, tab3.Cell(i, 1).Range.Text.Length - 2);
                    pr.UnitPrice     = Convert.ToDouble(tab3.Cell(i, 3).Range.Text.Substring(0, tab3.Cell(i, 3).Range.Text.Length - 2));
                    pr.UnitsOnStock  = Convert.ToInt32(tab3.Cell(i, 2).Range.Text.Substring(0, tab3.Cell(i, 2).Range.Text.Length - 2));
                    pr.ProductNummer = tab3.Cell(i, 4).Range.Text.Substring(0, tab3.Cell(i, 4).Range.Text.Length - 2);
                    pr.BarCode       = tab3.Cell(i, 5).Range.Text.Substring(0, tab3.Cell(i, 5).Range.Text.Length - 2);
                    pr.Gewicht       = Convert.ToDouble(tab3.Cell(i, 6).Range.Text.Substring(0, tab3.Cell(i, 6).Range.Text.Length - 2));
                    pr.Breedte       = Convert.ToDouble(tab3.Cell(i, 7).Range.Text.Substring(0, tab3.Cell(i, 7).Range.Text.Length - 2));
                    pr.Lengte        = Convert.ToDouble(tab3.Cell(i, 8).Range.Text.Substring(0, tab3.Cell(i, 8).Range.Text.Length - 2));
                    pr.Hoogte        = Convert.ToDouble(tab3.Cell(i, 9).Range.Text.Substring(0, tab3.Cell(i, 9).Range.Text.Length - 2));
                    pr.Omschrijving  = tab3.Cell(i, 10).Range.Text.Substring(0, tab3.Cell(i, 10).Range.Text.Length - 2);
                    using (var ctx = new ProjectContext())
                    {
                        Product P = ctx.Products.FirstOrDefault(p => p.ProductNummer == pr.ProductNummer);
                        if (P == null)
                        {
                            if (ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land) == null)
                            {
                                lev.adress = ad;
                            }
                            else
                            {
                                lev.adress = ctx.Adressen.FirstOrDefault(a => a.Straat + " " + a.Huisnummer + " " + a.Gemeente + " " + a.Postcode + " " + a.Land == ad.Straat + " " + ad.Huisnummer + " " + ad.Gemeente + " " + ad.Postcode + " " + ad.Land);
                            }
                            ctx.SaveChanges();
                            if (ctx.Levranciers.FirstOrDefault(l => l.Naam == lev.Naam) == null)
                            {
                                pr.levrancier = lev;
                            }
                            else
                            {
                                pr.levrancier = ctx.Levranciers.FirstOrDefault(l => l.Naam == lev.Naam);
                            }
                            ctx.Products.Add(pr);
                            ctx.SaveChanges();
                        }
                        else
                        {
                            ctx.Products.FirstOrDefault(p => p.ProductNummer == pr.ProductNummer).UnitsOnStock = P.UnitsOnStock + pr.UnitsOnStock;
                        }
                        ctx.SaveChanges();
                        Producten = ctx.Products.Include("levrancier").ToList();
                    }
                    loaddgvprodut();
                }
            }
        }