Beispiel #1
0
 public static bool Rent(Item i, bool beschikbaarMateriaalWeergeven)
 {
     if (!started)
         Start();
     if (!string.IsNullOrEmpty(tag))
     {
         RFIDPerson rp = new RFIDPerson
     {
             RFID = tag
         };
         try
         {
             if (DatabaseManager.ContainsItem(rp, new[] {"RFID"}).RFID.Equals(rp.RFID))
             {
                 //Niet geheel veilig maar oke
                 if (!beschikbaarMateriaalWeergeven)
                 {
                     ReservationMaterial rm = new ReservationMaterial()
                     {
                         RFID = rp.RFID,
                         Item = i.ID
                     };
                     DatabaseManager.DeleteItem(rm);
                 }
                 LeaseMaterial lm = new LeaseMaterial()
                 {
                     RFID = rp.RFID,
                     Item = i.ID
                 };
                 if (lm.EqualsPrimairy(DatabaseManager.ContainsItem(lm, new[] {"RFID", "Item"})))
                 {
                     DatabaseManager.UpdateItem(lm);
                     ReturnMaterial rm = new ReturnMaterial()
                     {
                         RFID = lm.RFID,
                         Item = i.ID
                     };
                     DatabaseManager.DeleteItem(rm);
                     return true;
                 }
                 DatabaseManager.InsertItem(lm);
                 return true;
             }
         }
         catch
         {
             MessageBox.Show("Incorrect RFID.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     return false;
 }
Beispiel #2
0
        private void btInnemen_Click(object sender, EventArgs e)
        {
            frmEnterProdCode ProdCode = new frmEnterProdCode() { Location = Location, StartPosition = FormStartPosition.CenterParent };

            if (ProdCode.ShowDialog(this) == DialogResult.OK)
            {
                string productcode = ProdCode.productcode;
                if (!System.Text.RegularExpressions.Regex.IsMatch(productcode, @"^\d+$"))
                {
                    MessageBox.Show("Productcode is geen integer, probeer opnieuw.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                Item i = new Item()
                {
                    Productcode = int.Parse(productcode)
                };
                Item item = DatabaseManager.ContainsItem(i, new [] {"Productcode"});
                if (item == default(Item))
                {
                    MessageBox.Show("Productcode bestaat niet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                LeaseMaterial lm = new LeaseMaterial()
                {
                    Item = item.ID
                };
                LeaseMaterial lease = DatabaseManager.ContainsLease(lm, "Item");
                if (lease == default(LeaseMaterial))
                {
                    MessageBox.Show("Item is niet verhuurd.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                ReturnMaterial rm = new ReturnMaterial()
                {
                    RFID = lease.RFID,
                    Item = lease.Item
                };
                int renttime = (rm.ReturnDate - lease.LeaseDate).Days;
                Material m = new Material()
                {
                    ID = item.Material
                };
                Material mat = DatabaseManager.ContainsItem(m, new[] {"ID"});
                int price = 0;
                if(mat.PricePW > 0)
                {
                    price += (renttime / 7) * mat.PricePW + (renttime % 7) * mat.PricePD;
                }
                else
                {
                    price += renttime * mat.PricePD;
                }
                frmPayscreen payscreen = new frmPayscreen(renttime, price, rm.RFID, mat.Product) { Location = Location, StartPosition = FormStartPosition.CenterParent };
                if(payscreen.ShowDialog(this) == DialogResult.OK)
                {
                    bool gelukt = false;
                    if (rm.EqualsPrimairy(DatabaseManager.ContainsItem(rm, new[] { "RFID", "Item" })))
                    {
                        DatabaseManager.UpdateItem(rm);
                        gelukt = true;
                    }
                    else
                    {
                        DatabaseManager.InsertItem(rm);
                        gelukt = true;
                    }
                    if (gelukt)
                    {
                        MessageBox.Show("Gelukt!");
                        AvailableItems();
                        return;
                    }
                }
                else if(payscreen.ShowDialog(this) == DialogResult.Cancel)
                    return;
                MessageBox.Show("Het is helaas niet gelukt. Probeer opnieuw.");
                return;
            }
            else if(ProdCode.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }
            MessageBox.Show("Geen geldige productcode, probeer opnieuw.");
        }