void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (balTransaction == null)
                {
                    return;
                }
                BmsTransaction transaction = FetchData();
                bool           state       = balTransaction.Add(transaction);

                if (state)
                {
                    // Change Inventory value
                    BmsBloodInventory oldValue = balInventory.GetAll().
                                                 FirstOrDefault(c => c.BloodInventoryID == transaction.BloodInventoryID);

                    // Make transaction
                    oldValue.NumberofBottles += transaction.NumberofBottles;
                    BmsBloodInventory newValue = oldValue;
                    state = balInventory.Modify(oldValue);
                }

                if (state)
                {
                    applicationStatus.Text        = "Blood Transaction Information Added Successfully.";
                    applicationStatusMessage.Text = "Blood Transaction Information Added Successfully.";
                }
                else
                {
                    applicationStatus.Text        = "Failed Adding Blood Transaction Information.";
                    applicationStatusMessage.Text = "Blood Transaction Information Added Successfully.";
                }
                clock.Start();
                EditableFields(false);
                btnAdd.Visibility   = System.Windows.Visibility.Hidden;
                btnReset.Visibility = System.Windows.Visibility.Hidden;
                //ClearFields();
                txtTransactionID.Text = "-1";
            }
            catch (ValidationException ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
            catch (ConnectedDalException ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
            catch (Exception ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
        }
        private void BarDonorWeightDistribution()
        {
            try
            {
                List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >();

                var donorsWeights = balDonation.GetAll().GroupBy(donor => donor.Weight).Select(group => new { Key = group.Key, Count = group.Count() }).OrderBy(x => x.Key);


                foreach (var item in donorsWeights)
                {
                    list.Add(new KeyValuePair <string, int>(item.Key.ToString(), item.Count));
                }
                donorWeightDistribution.DataContext = list;
            }
            catch (Exception ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
        }
        private void PieBloodByGroup()
        {
            try
            {
                List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >();

                var inventories      = balInventory.GetAll().Where(item => item.BloodBankID == MainWindow.CurrentAdminSystem.BloodBankID);
                var inventoryByGroup = inventories.GroupBy(inventory => inventory.BloodGroup).Select(group => new { Key = group.Key, Count = group.Sum(bottles => bottles.NumberofBottles) }).OrderBy(x => x.Key);
                foreach (var item in inventoryByGroup)
                {
                    list.Add(new KeyValuePair <string, int>(item.Key, item.Count));
                }
                List <string> colors = ColorShades.blueRedShades.ToList();
                colors.Reverse();
                Charting.SetPieChart(bloodByGroup, colors, list);
            }
            catch (Exception ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
        }
        private void CalanderTrans()
        {
            try
            {
                List <DateTime> list = null;
                //list = (from e in balTransaction.GetAll() where e.CreationDate < DateTime.Now.AddMonths(MonthRange) && e.CreationDate > DateTime.Now.AddMonths(-MonthRange) select e.CreationDate).ToList();
                list = (from e in balTransaction.GetAll() where e.CreationDate <DateTime.Now.AddMonths(MonthRange) && e.CreationDate> DateTime.Now.AddMonths(-MonthRange) select e.CreationDate).ToList();

                Style s = (Style)Resources["styleCalendarDayButtonStyleTrans"];
                foreach (var holidayDates in list)
                {
                    DataTrigger dataTrigger = new DataTrigger()
                    {
                        Binding = new Binding("Date"), Value = holidayDates
                    };
                    dataTrigger.Setters.Add(new Setter(System.Windows.Controls.Primitives.CalendarDayButton.BackgroundProperty, Brushes.OrangeRed));
                    s.Triggers.Add(dataTrigger);
                }
            }
            catch (Exception ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
        }
        public void Attach(IBAL <BmsTransaction> balTransaction, IBAL <BmsHospital> balHospital,
                           IBAL <BmsBloodInventory> balInventory, TextBlock applicationStatus, ActionMode mode = ActionMode.ADD, object value = null)
        {
            try
            {
                this.balTransaction = balTransaction;
                this.balInventory   = balInventory;
                this.balHospital    = balHospital;

                this.applicationStatus = applicationStatus;

                switch (mode)
                {
                case ActionMode.ADD:
                {
                    txbTransactionID.Visibility = System.Windows.Visibility.Hidden;
                    txtTransactionID.Visibility = System.Windows.Visibility.Hidden;
                    txtTransactionID.Text       = "-1";

                    var hospitalList = balHospital.GetAll().Where(c => c.City == MainWindow.CurrentAdminSystem.City);
                    foreach (var item in hospitalList)
                    {
                        txtHospitalID.Items.Add(item.HospitalID);
                    }

                    var inentoryList = balInventory.GetAll().Where(c => c.BloodBankID == MainWindow.CurrentAdminSystem.BloodBankID);
                    foreach (var item in inentoryList)
                    {
                        txtBloodInventoryID.Items.Add(item.BloodInventoryID);
                    }

                    txtCreationDate.Text = DateTime.Now.ToShortDateString();

                    btnAdd         = new Button();
                    btnAdd.Name    = "btnAdd";
                    btnAdd.Click  += btnAdd_Click;
                    btnAdd.Content = "Transaction";
                    stackButtons.Children.Add(btnAdd);

                    btnReset         = new Button();
                    btnReset.Name    = "btnReset";
                    btnReset.Click  += btnReset_Click;
                    btnReset.Content = "Reset";
                    stackButtons.Children.Add(btnReset);
                }
                break;

                case ActionMode.UPDATE:
                {
                    PopulateFields((BmsTransaction)value);
                    EditableFields();
                    btnUpdate         = new Button();
                    btnUpdate.Name    = "btnUpdate";
                    btnUpdate.Click  += btnUpdate_Click;
                    btnUpdate.Content = "Edit";
                    stackButtons.Children.Add(btnUpdate);
                }
                break;

                case ActionMode.DELETE:
                {
                    EditableFields();
                    PopulateFields((BmsTransaction)value);
                    btnDelete         = new Button();
                    btnDelete.Name    = "btnDelete";
                    btnDelete.Click  += btnDelete_Click;
                    btnDelete.Content = "Delete";
                    stackButtons.Children.Add(btnDelete);
                }
                break;
                }
            }
            catch (Exception ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
        }
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (bal == null)
                {
                    return;
                }

                BmsBloodBank newAdminSystem     = FetchData();
                BmsBloodBank currentAdminSystem = null;
                string       ConfigSecurityMode = ConfigSecurityMode = ConfigurationManager.AppSettings.Get("security");
                ConfigSecurityMode = string.IsNullOrEmpty(ConfigSecurityMode) ? "low" : ConfigSecurityMode;

                if (ConfigSecurityMode.Trim().ToLower() == "high")
                {
                    currentAdminSystem = bal.GetAll().FirstOrDefault(item => item.SysId == HelperMethods.SystemId() && item.UserID == newAdminSystem.UserID);
                }
                else
                {
                    currentAdminSystem = bal.GetAll().FirstOrDefault(item => item.UserID == newAdminSystem.UserID);
                }
                if (currentAdminSystem != null)
                {
                    // this user Id already exists
                    MessageHandler.ShowInfoMessage("User Id [ " + currentAdminSystem.UserID + " ] alrady exists." + Environment.NewLine +
                                                   "Please provide different User Id");
                    return;
                }

                bool state = bal.Add(newAdminSystem);

                if (state)
                {
                    MessageHandler.ShowInfoMessage("Successfully Added to the System");
                }
                else
                {
                    MessageHandler.ShowErrorMessage("Failed to Add you to the System");
                }
            }

            catch (System.Data.SqlClient.SqlException ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }

            catch (ValidationException ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
            catch (ConnectedDalException ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }
            catch (Exception ex)
            {
                MessageHandler.ShowErrorMessage(ex.Message);
            }

            this.DialogResult = true;
        }