//Fill textboxes with info from selected debiteur
        private void FillTextBoxes(string id)
        {
            int                  ID     = int.Parse(id);
            facturen             fact   = db.facturen.Find(ID);
            List <factuur_items> fiList = db.factuur_items.Where(f => f.FactuurID == ID).ToList();

            List <producten> productList = new List <producten>();
            List <int>       pidList     = new List <int>();

            for (int i = 0; i < fiList.Count; i++)
            {
                int pid = fiList[i].ProductID;

                pidList.Add(pid);
            }

            for (int i = 0; i < pidList.Count; i++)
            {
                int       pid = pidList[i];
                producten p   = db.producten.Find(pid);

                productList.Add(p);
            }

            datumBox.Text  = String.Format("{0:dd-MM-yyyy}", fact.Factuurdatum);
            totaalBox.Text = String.Format("{0:C}", fact.Totaalbedrag);
        }
        private void CreateProduct()
        {
            producten product = new producten();

            product.Naam    = naamBox.Text;
            product.Prijs   = decimal.Parse(prijsBox.Text);
            product.BTW     = int.Parse(btwBox.Text);
            product.Korting = int.Parse(kortingBox.Text);

            try
            {
                db.producten.Add(product);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            string debiteur = DebDDL.SelectedValue;

            if (DebDDL.SelectedValue != "")
            {
                string[] name  = debiteur.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   fname = name[0];
                string   lname = "";

                for (int i = 1; i < name.Length; i++)
                {
                    lname += name[i] + " ";
                }

                debiteuren deb = db.debiteuren.Where(d => d.Voornaam == fname && d.Achternaam == lname).SingleOrDefault();

                toewijzen toewijzing = new toewijzen();
                producten prod       = db.producten.Where(p => p.Naam == naamBox.Text).SingleOrDefault();
                toewijzing.ProductID  = prod.ID;
                toewijzing.DebiteurID = deb.ID;

                try
                {
                    db.toewijzen.Add(toewijzing);
                    db.SaveChanges();

                    Message m = new Message();
                    m.Show("Product is aangemaakt!");
                }
                catch (Exception ex)
                {
                    Message m = new Message();
                    m.Show("Product kon niet worden aangemaakt!");
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }
            else
            {
                Message m = new Message();
                m.Show("Product is aangemaakt!");
            }
        }
Exemple #3
0
        private void TxtBox_TextChanged1(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("TextChanged fired up!");

            decimal       total  = 0;
            List <string> values = new List <string>();

            foreach (var tr in SelectTable.Controls.OfType <TableRow>())
            {
                foreach (var td in tr.Controls.OfType <TableCell>())
                {
                    foreach (var chk in td.Controls.OfType <CheckBox>())
                    {
                        if (chk.Checked)
                        {
                            values.Add(chk.Text);
                        }
                    }
                }
            }


            for (int i = 0; i < values.Count; i++)
            {
                string    j = values[i];
                producten p = db.producten.Where(pr => pr.Naam == j).SingleOrDefault();

                string[] split  = values[i].Split('_');
                TextBox  txtBox = null;


                foreach (var tr in SelectTable.Controls.OfType <TableRow>())
                {
                    foreach (var td in tr.Controls.OfType <TableCell>())
                    {
                        foreach (var txt in td.Controls.OfType <TextBox>())
                        {
                            if (txt.ID.Contains(split[0]))
                            {
                                txtBox = txt;
                            }
                        }
                    }
                }

                if (txtBox != null)
                {
                    decimal num   = decimal.Parse(txtBox.Text);
                    decimal price = (decimal)p.Prijs;
                    total += (price * num);
                }
                else
                {
                    total += 0;
                }
            }

            totaalBox.Text = String.Format("{0:C}", total);
        }
Exemple #4
0
 public ActionResult Add(producten model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     d.AddNewProduct(model);
     return(RedirectToAction("Index"));
 }
Exemple #5
0
 public ActionResult Update(producten Pmodel)
 {
     if (!ModelState.IsValid)
     {
         return(View(Pmodel));
     }
     d.UpdateProduct(Pmodel);
     return(RedirectToAction("Producten"));
 }
Exemple #6
0
        //Fill textboxes with info from selected debiteur
        private void FillTextBoxes(string id)
        {
            int       ID      = int.Parse(id);
            producten product = db.producten.Find(ID);

            naamBox.Text    = product.Naam;
            prijsBox.Text   = String.Format("{0:N2}", product.Prijs);
            btwBox.Text     = product.BTW.ToString();
            kortingBox.Text = product.Korting.ToString();
        }
Exemple #7
0
        private void FillTotal(List <producten> products, facturen factuur)
        {
            for (int i = 0; i < products.Count; i++)
            {
                producten pr = products[i];

                decimal?subtotal = (decimal?)(factuur.Totaalbedrag * 100) / (100 + pr.BTW);
                SubtotaalLabel.Text = String.Format("{0:C}", subtotal);
                BTWLabel.Text       = pr.BTW + "%";
                TotaalLabel.Text    = String.Format("{0:C}", factuur.Totaalbedrag);
            }
        }
Exemple #8
0
 //adds new product
 public void AddNewProduct(producten product_add)
 {
     entities.distributie_product.Add(new distributie_product
     {
         naam        = product_add.naam,
         merk        = product_add.merk,
         type        = product_add.type,
         aftmetingen = product_add.afmetingen,
         gewicht     = Convert.ToDecimal(product_add.gewicht),
         voorraad    = product_add.voorraad
     });
     entities.SaveChanges();
 }
        private void Del_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            string id  = btn.ID;

            string[] split = id.Split('_');
            int      ID    = int.Parse(split[1]);

            string confirmValue = Request.Form["confirm_value"];

            if (confirmValue == "Ja")
            {
                try
                {
                    producten            prod        = db.producten.Where(d => d.ID == ID).SingleOrDefault();
                    List <factuur_items> fiList      = db.factuur_items.Where(f => f.ProductID == prod.ID).ToList();
                    List <facturen>      factuurList = new List <facturen>();
                    List <toewijzen>     toewijsList = db.toewijzen.Where(t => t.ProductID == ID).ToList();

                    for (int i = 0; i < fiList.Count; i++)
                    {
                        int fid = fiList[i].FactuurID;

                        facturen fact = db.facturen.Find(fid);
                        factuurList.Add(fact);
                    }

                    db.factuur_items.RemoveRange(fiList);
                    db.facturen.RemoveRange(factuurList);
                    db.toewijzen.RemoveRange(toewijsList);
                    db.producten.Remove(prod);
                    db.SaveChanges();

                    Message m = new Message();
                    m.Show("Product is verwijderd!");

                    Response.Redirect(Request.RawUrl);
                }
                catch (Exception ex)
                {
                    Message m = new Message();
                    m.Show("Product kon niet worden verwijderd!");
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                }
            }
            else
            {
                Response.Redirect(Request.RawUrl);
            }
        }
Exemple #10
0
        //updates product
        public void UpdateProduct(producten model)
        {
            var entity = entities.distributie_product.Single(p => p.product_id == model.productID);

            entity.naam        = model.naam;
            entity.merk        = model.merk;
            entity.type        = model.type;
            entity.aftmetingen = model.afmetingen;
            entity.gewicht     = Convert.ToDecimal(model.gewicht);
            entity.voorraad    = model.voorraad;
            entity.afbeelding  = model.afbeeldingLink;
            entity.Show        = model.Show;

            entities.SaveChanges();
        }
Exemple #11
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            string id = Session["EditID2"].ToString();
            int    ID = int.Parse(id);

            producten product    = db.producten.Find(ID);
            producten newProduct = new producten();

            if (product != null)
            {
                newProduct.ID      = ID;
                newProduct.Naam    = naamBox.Text;
                newProduct.Prijs   = decimal.Parse(prijsBox.Text);
                newProduct.BTW     = int.Parse(btwBox.Text);
                newProduct.Korting = int.Parse(kortingBox.Text);
            }

            db.Entry(product).CurrentValues.SetValues(newProduct);
            db.SaveChanges();

            Response.Redirect("Product.aspx");
        }
        //Save button to update factuur
        private void SaveButton_Click(object sender, EventArgs e)
        {
            string id = Session["EditID3"].ToString();
            int    ID = int.Parse(id);

            facturen fact    = db.facturen.Find(ID);
            facturen newFact = new facturen();

            if (fact != null)
            {
                //Factuur

                newFact.Factuurnummer = ID;
                newFact.Factuurdatum  = DateTime.Parse(datumBox.Text);
                newFact.Totaalbedrag  = decimal.Parse(totaalBox.Text);

                //----------------------------------------------------
                //Debiteur

                string   debiteur = debDDL.SelectedValue;
                string[] name     = debiteur.Split(' ');
                string   fname    = name[0];
                string   lname    = name[1];

                debiteuren deb = db.debiteuren.Where(d => d.Voornaam == fname && d.Achternaam == lname).SingleOrDefault();

                fact.DebiteurID = deb.ID;

                //----------------------------------------------------
                //Product

                List <producten> proList = new List <producten>();
                List <string>    values  = new List <string>();

                foreach (ListItem Item in productCheckBoxList.Items)
                {
                    if (Item.Selected)
                    {
                        values.Add(Item.Value);
                    }
                }

                for (int i = 0; i < values.Count; i++)
                {
                    string    j = values[i];
                    producten p = db.producten.Where(pr => pr.Naam == j).SingleOrDefault();
                    proList.Add(p);
                }

                string products = "";

                for (int i = 0; i < proList.Count; i++)
                {
                    string pname = proList[i].Naam;

                    products += pname + "\n";
                }

                //--------------------------------------
                //Save factuur to database

                try
                {
                    db.facturen.Add(fact);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }

                //--------------------------------------
            }

            db.Entry(fact).CurrentValues.SetValues(newFact);
            db.SaveChanges();

            Response.Redirect("Factuur.aspx");
        }
Exemple #13
0
        //Fill textboxes with info from selected debiteur
        private void ShowInfo(string id)
        {
            int ID = int.Parse(id);

            facturen factuur = db.facturen.Find(ID);

            int        debID = factuur.DebiteurID;
            debiteuren deb   = db.debiteuren.Find(debID);

            List <factuur_items> fiList      = db.factuur_items.Where(f => f.FactuurID == ID).ToList();
            List <producten>     productList = new List <producten>();
            List <int>           pidList     = new List <int>();
            List <int>           aantalList  = new List <int>();

            for (int i = 0; i < fiList.Count; i++)
            {
                int productID = fiList[i].ProductID;
                pidList.Add(productID);
            }

            for (int i = 0; i < fiList.Count; i++)
            {
                int aantal = fiList[i].Aantal;
                aantalList.Add(aantal);
            }

            for (int i = 0; i < pidList.Count; i++)
            {
                int       pid = pidList[i];
                producten p   = db.producten.Find(pid);

                productList.Add(p);
            }

            TableCell cell  = new TableCell();
            TableCell cell1 = new TableCell();
            TableCell cell2 = new TableCell();
            TableCell cell3 = new TableCell();
            TableCell cell4 = new TableCell();
            TableCell cell5 = new TableCell();

            cell.Text  = factuur.Factuurnummer.ToString();
            cell1.Text = String.Format("{0:dd-MM-yyyy}", factuur.Factuurdatum);
            cell2.Text = String.Format("{0:C}", factuur.Totaalbedrag);
            cell3.Text = deb.Voornaam + " " + deb.Achternaam;

            string products = "";

            for (int i = 0; i < productList.Count; i++)
            {
                products += productList[i].Naam + "<br />";
            }

            string aantallen = "";

            for (int i = 0; i < aantalList.Count; i++)
            {
                aantallen += aantalList[i] + "<br />";
            }

            cell4.Text = products;
            cell5.Text = aantallen;

            TableRow row = new TableRow();

            row.Cells.Add(cell);
            row.Cells.Add(cell1);
            row.Cells.Add(cell2);
            row.Cells.Add(cell3);
            row.Cells.Add(cell4);
            row.Cells.Add(cell5);


            factuurTable.Rows.Add(row);
        }
Exemple #14
0
        private void CreateFactuur()
        {
            List <int> aantalList = new List <int>();
            facturen   factuur    = new facturen();

            factuur.Factuurdatum = DateTime.Parse(datumBox.Text);

            //---------------------------------
            //Debiteur
            string debiteur = debDDL.SelectedValue;

            string[] name = debiteur.Split(' ');
            System.Diagnostics.Debug.WriteLine("fname: " + name[0]);
            System.Diagnostics.Debug.WriteLine("lname: " + name[1]);

            string fname = name[0];
            string lname = name[1];

            /*
             * for (int i = 1; i < name.Length; i++)
             * {
             *  lname += name[i] + " ";
             * }
             */

            debiteuren deb = db.debiteuren.Where(d => d.Voornaam == fname && d.Achternaam == lname).SingleOrDefault();

            factuur.DebiteurID = deb.ID;

            //---------------------------------
            //Product
            List <producten> proList = new List <producten>();
            List <string>    values  = new List <string>();

            foreach (var tr in SelectTable.Controls.OfType <TableRow>())
            {
                foreach (var td in tr.Controls.OfType <TableCell>())
                {
                    foreach (var chk in td.Controls.OfType <CheckBox>())
                    {
                        if (chk.Checked)
                        {
                            values.Add(chk.Text);
                        }
                    }
                }
            }

            string product = "";

            for (int i = 0; i < values.Count; i++)
            {
                string j = values[i];
                product = j;


                producten p = db.producten.Where(pr => pr.Naam == j).SingleOrDefault();
                proList.Add(p);
            }

            System.Diagnostics.Debug.WriteLine("size proList: " + proList.Count);


            //Totaalbedrag factuur
            string totalString = totaalBox.Text;
            string str         = totalString.Replace("€", string.Empty);

            decimal total = decimal.Parse(str);

            factuur.Totaalbedrag = total;


            //--------------------------------------
            //Save factuur to database

            try
            {
                db.facturen.Add(factuur);
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            //--------------------------------------

            List <factuur_items> fiList = new List <factuur_items>();

            TextBox txtBox = null;

            foreach (var tr in SelectTable.Controls.OfType <TableRow>())
            {
                foreach (var td in tr.Controls.OfType <TableCell>())
                {
                    foreach (var txt in td.Controls.OfType <TextBox>())
                    {
                        if (txt.ID.Contains(product))
                        {
                            txtBox = txt;
                        }
                    }
                }
            }



            if (proList.Count == 1)
            {
                System.Diagnostics.Debug.WriteLine("Only one item in list");

                factuur_items fi = new factuur_items();
                fi.FactuurID = factuur.Factuurnummer;
                fi.Aantal    = int.Parse(txtBox.Text);
                fi.ProductID = proList[0].ID;

                try
                {
                    db.factuur_items.Add(fi);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }
            else if (proList.Count > 1)
            {
                System.Diagnostics.Debug.WriteLine("More than one item in list");

                for (int i = 0; i < proList.Count; i++)
                {
                    factuur_items sfi = new factuur_items();
                    sfi.FactuurID = factuur.Factuurnummer;
                    sfi.Aantal    = int.Parse(txtBox.Text);

                    sfi.ProductID = proList[i].ID;
                    fiList.Add(sfi);
                }

                try
                {
                    db.factuur_items.AddRange(fiList);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }
        }
Exemple #15
0
        //Fill textboxes with info from selected debiteur
        private void ShowInfo(string id)
        {
            int ID = int.Parse(id);

            facturen factuur = db.facturen.Find(ID);

            int        debID = factuur.DebiteurID;
            debiteuren deb   = db.debiteuren.Find(debID);

            List <factuur_items> fiList      = db.factuur_items.Where(f => f.FactuurID == ID).ToList();
            List <producten>     productList = new List <producten>();
            List <int>           pidList     = new List <int>();
            List <int>           aantalList  = new List <int>();

            for (int i = 0; i < fiList.Count; i++)
            {
                int productID = fiList[i].ProductID;
                pidList.Add(productID);
            }

            for (int i = 0; i < fiList.Count; i++)
            {
                int aantal = fiList[i].Aantal;
                aantalList.Add(aantal);
            }

            for (int i = 0; i < pidList.Count; i++)
            {
                int       pid = pidList[i];
                producten p   = db.producten.Find(pid);

                productList.Add(p);
            }

            //Table cells
            TableCell cell  = new TableCell();
            TableCell cell1 = new TableCell();
            TableCell cell2 = new TableCell();
            TableCell cell3 = new TableCell();
            TableCell cell4 = new TableCell();
            TableCell cell5 = new TableCell();

            //Set debiteur naam and address label
            DebiteurNaamLabel.Text  = deb.Voornaam + " " + deb.Achternaam;
            DebiteurAdresLabel.Text = deb.Adres;

            if (deb.Land == "Nederland")
            {
                DebiteurPostcodeLabel.Text = deb.Postcode + " " + deb.Plaats;
            }
            else
            {
                DebiteurPostcodeLabel.Text = deb.Postcode + " " + deb.Plaats + " " + deb.Land;
            }

            //Set factuurnummer and date label
            FactuurNummerLabel.Text = factuur.Factuurnummer.ToString();
            FactuurDatumLabel.Text  = String.Format("{0:dd-MM-yyyy}", factuur.Factuurdatum);

            //Set cell text
            for (int i = 0; i < productList.Count; i++)
            {
                producten pr = productList[i];

                string aantallen = "";

                for (int j = 0; j < aantalList.Count; j++)
                {
                    aantallen += aantalList[j] + "<br />";
                }

                cell.Text  = pr.Naam;
                cell1.Text = String.Format("{0:C}", pr.Prijs);
                cell2.Text = pr.BTW + "%";
                cell3.Text = pr.Korting + "%";
                cell4.Text = aantallen;
                cell5.Text = String.Format("{0:C}", factuur.Totaalbedrag);

                TableRow row = new TableRow();

                row.Cells.Add(cell);
                row.Cells.Add(cell1);
                row.Cells.Add(cell2);
                row.Cells.Add(cell3);
                row.Cells.Add(cell4);
                row.Cells.Add(cell5);

                FactuurTable.Rows.Add(row);
            }

            FillTotal(productList, factuur);
        }