예제 #1
0
        private void buttonAddDvd_Click(object sender, EventArgs e)
        {
            if (this.dvdValFlags.Title && this.dvdValFlags.DvdNumber && this.dvdValFlags.Price)
            {

                var dvd = new Dvd
                {
                    Title = textBoxTitel.Text,
                    DvdNumber = Int32.Parse(textBoxNumber.Text),
                    Available = checkBoxAvailable.Checked,
                    Price = decimal.Parse(textBoxPrice.Text),
                    Genre = (Genres)Enum.Parse(typeof(Genres), comboBoxGenre.Text)
                };

                db.Dvds.Add(dvd);
                db.SaveChanges();

                textBoxTitel.Text = "";
                textBoxNumber.Text = "";
                checkBoxAvailable.Checked = false;
                textBoxPrice.Text = "";

                MessageBox.Show("Dvd added!");

            }
            else
            {
                MessageBox.Show("Some fields are incorrect!");
            }
        }
예제 #2
0
        private void buttonDelRental_Click(object sender, EventArgs e)
        {
            if (this.rentalValFlags.DvdNumber)
            {
                var currentDvdNumber = int.Parse(textBoxDelNumber.Text);
                Dvd qDvd             = db.Dvds.Where(d => d.DvdNumber == currentDvdNumber).FirstOrDefault();

                qDvd.Available = true;
                int?currentRent = qDvd.RentId;

                Rent qRent = db.Rents.Where(r => r.RentId == currentRent).FirstOrDefault();
                if (qRent == null)
                {
                    MessageBox.Show("Dvd " + currentDvdNumber.ToString() + " doesn't have charge!");
                    return;
                }

                DateTime returned = DateTime.Now;

                qRent.ReturnDate = returned;  //new DateTime(2016, 1, 15); test date for charges

                db.SaveChanges();

                DateTime?due = qRent.DueDate;
                DateTime?ret = qRent.ReturnDate;
                int?     day = SqlMethods.DateDiffDay(due, ret);

                if (day > 1)
                {
                    qRent.Charge       = day * qDvd.Price;
                    qRent.OverduedDays = day;

                    db.SaveChanges();

                    string msg = qRent.Charge.ToString() + " leva";

                    if (MessageBox.Show(msg, "Pay Charge", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        qDvd.RentId = null;
                        var user = db.Users.Where(row => row.UserId == qRent.UserId).FirstOrDefault();

                        user.NumberOfCharges++;
                        db.Rents.Remove(qRent);
                        db.SaveChanges();
                    }
                    ;

                    textBoxDelNumber.Text = "";

                    return;
                }

                qDvd.RentId = null;
                db.Rents.Remove(qRent);
                db.SaveChanges();

                textBoxDelNumber.Text = "";

                MessageBox.Show("Dvd deleted!");
            }
            else
            {
                MessageBox.Show("Some fields are incorrect!");
            }
        }