Пример #1
0
        private void ButtonAddClient_Click(object sender, EventArgs e)
        {
            BloodBankEntities context = new BloodBankEntities();
            int    id     = context.Clients.Count() + 1;
            Client client = new Client()
            {
                // ClientId = ParseInt(textBoxAddClientID.Text),
                ClientId        = id,
                ClientFirstName = textBoxAddClientFirstName.Text,
                ClientLastName  = textBoxAddClientLastName.Text
            };

            //check if user fills name
            if (client.ClientFirstName.Trim().Length == 0 || client.ClientLastName.Trim().Length == 0)
            {
                MessageBox.Show("Please enter all fields");
                return;
            }
            if (Controller <BloodBankEntities, Client> .AddEntity(client) == null)
            {
                MessageBox.Show("Cannot add client to database");
                return;
            }
            // dispose the context and close the form.
            this.DialogResult = DialogResult.OK;
            context.Dispose();
            Close();
        }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         db.Dispose();
     }
     base.Dispose(disposing);
 }
Пример #3
0
        private void ButtonWithdraw_Click(object sender, EventArgs e)
        {
            BloodBankEntities context = new BloodBankEntities();
            //create a BloodWithdrawal object
            BloodWithdrawal bw = new BloodWithdrawal()
            {
                BloodWithdrawalId   = context.BloodWithdrawals.Count() + 1,
                BloodWithdrawalDate = DateTime.Now.Date,
                TransactionValue    = float.Parse(textBoxTotal.Text),
                UnitQuantity        = 1,
                ClientId            = Int32.Parse(dataGridViewClient.SelectedRows[0].Cells[0].Value.ToString())
            };

            //validate
            if (dataGridViewStock.SelectedRows.Count < 1)
            {
                MessageBox.Show("Please select an item to withdraw");
                return;
            }
            if (dataGridViewClient.SelectedRows.Count < 1)
            {
                MessageBox.Show("Please select a client for withdrawal");
                return;
            }
            //add to db
            if (Controller <BloodBankEntities, BloodWithdrawal> .AddEntity(bw) == null)
            {
                MessageBox.Show("Cannot add withdrawal to database");
                return;
            }
            //creates a new BloodWithdrawalUnit object
            BloodWithdrawalUnit bwu = new BloodWithdrawalUnit()
            {
                BloodWithdrawalUnitsId = context.BloodWithdrawalUnits.Count() + 1,
                UnitId            = Int32.Parse(dataGridViewStock.SelectedRows[0].Cells[0].Value.ToString()),
                BloodWithdrawalId = context.BloodWithdrawals.Count(),
            };

            context.Dispose();
            //add to d b
            if (Controller <BloodBankEntities, BloodWithdrawalUnit> .AddEntity(bwu) == null)
            {
                MessageBox.Show("Cannot add withdrawal to database");
                return;
            }

            // adds to the current balance after a withdrawal
            //this.DialogResult = DialogResult.OK;
            initializeDepositDGV();

            BloodBankAppMainForm.SetFundsBalance += Double.Parse(textBoxTotal.Text);
            ReadCurrentFunds(); // re-reads the current balance
        }
Пример #4
0
        private void ButtonSubmit_Click(object sender, EventArgs e)
        {
            BloodBankEntities context = new BloodBankEntities();
            //get id for new donor
            int id = context.Donors.Count() + 1;
            //create new donor object
            Donor donor = new Donor()
            {
                DonorId        = id,
                DonorFirstName = textBoxFirstName.Text,
                DonorLastName  = textBoxLastName.Text,
                DonorBirthday  = dateTimePickerBirthday.Value,
                DonorAddress   = textBoxAddress.Text,
                DonorPhone     = numericUpDown1.Value.ToString(),
                BloodTypeId    = listBoxBloodType.SelectedIndex + 1,
            };

            //validation
            if (!(listBoxBloodType.SelectedItem is BloodType type))
            {
                MessageBox.Show("Must select a blood type!");
                return;
            }
            if (donor.DonorFirstName.Trim().Length == 0 || donor.DonorFirstName.Trim().Length == 0 || donor.DonorBirthday == new DateTime(1900, 01, 01) || donor.DonorAddress.Trim().Length == 0 || donor.DonorPhone == "0" || donor.DonorPhone == null)
            {
                MessageBox.Show("Must fill all fields");
                return;
            }
            if (!donor.DonorAddress.Contains("@") || !donor.DonorAddress.Contains("."))
            {
                MessageBox.Show("Email is not valid");
                return;
            }
            //add to db
            if (Controller <BloodBankEntities, Donor> .AddEntity(donor) == null)
            {
                MessageBox.Show("Cannot add course to database");
                return;
            }
            // dispose the context and close the form.
            this.DialogResult = DialogResult.OK;
            context.Dispose();
            Close();
        }