Esempio n. 1
0
        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 = "";
            }
        }
Esempio n. 2
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();
                }
            }
        }