Example #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (txtCompanyName.Text.Length <= 0)
            {
                var result = System.Windows.MessageBox.Show("Please enter a company name.", "Company Name Required", MessageBoxButton.OK);
                return;
            }
            if (txtTotalLicenseCount.Text.Length <= 0 || txtTotalLicenseCount.Value <= 0)
            {
                var result = System.Windows.MessageBox.Show("Please enter a license count greater than zero.", "License Count Required", MessageBoxButton.OK);
                return;
            }
            if (cbTypeOfLicense.SelectedIndex < 0)
            {
                var result = System.Windows.MessageBox.Show("Please select a license type.", "License Type Required", MessageBoxButton.OK);
                return;
            }
            if (dateLicenseIssueDate.SelectedDate == null)
            {
                var result = System.Windows.MessageBox.Show("Please select a valid issue date.", "License Issue Date Required", MessageBoxButton.OK);
                return;
            }
            if (dateLicenseExpirationDate.SelectedDate == null)
            {
                var result = System.Windows.MessageBox.Show("Please selected a valid expiration date.", "License Expiration Date Required", MessageBoxButton.OK);
                return;
            }
            if (dateLicenseIssueDate.SelectedDate >= dateLicenseExpirationDate.SelectedDate)
            {
                var result = System.Windows.MessageBox.Show("Expiration date must occur after issue date.", "Invalid Date Selections", MessageBoxButton.OK);
                return;
            }

            //prep our encrtyped string
            SimpleAES encryptText = new SimpleAES("V&WWJ3d39brdR5yUh5(JQGHbi:FB@$^@", "W4aRWS!D$kgD8Xz@");

            LicenserContext db         = new LicenserContext();
            License         newLicense = new License
            {
                CompanyName           = txtCompanyName.Text,
                TotalLicenseCount     = Convert.ToInt32(txtTotalLicenseCount.Text),
                TypeOfLicense         = ((ComboBoxItem)cbTypeOfLicense.SelectedItem).Content.ToString(),
                LicenseIssueDate      = (DateTime)dateLicenseIssueDate.SelectedDate,
                LicenseExpirationDate = (DateTime)dateLicenseExpirationDate.SelectedDate,
                LicenseEncodedString  = encryptText.EncryptToString(txtCompanyName.Text + ";" + txtTotalLicenseCount.Text + ";" +
                                                                    ((ComboBoxItem)cbTypeOfLicense.SelectedItem).Content.ToString() + ";" + dateLicenseIssueDate.SelectedDate.ToString() + ";" +
                                                                    dateLicenseExpirationDate.SelectedDate.ToString())
            };

            db.Licenses.Add(newLicense);
            db.SaveChanges();

            ContentControl contentArea = (ContentControl)this.Parent;

            contentArea.Content = new ViewLicenses();
        }
Example #2
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            var result = System.Windows.MessageBox.Show("Are you sure you want to delete this license?  Unless you have backed it up via an Excel export, it will be gone forever.", "Confirm Deletion", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.No)
            {
                return;
            }
            int LicenseID = (int)((Button)sender).CommandParameter;
            var item      = db.Licenses.Where(x => x.LicenseID == LicenseID).FirstOrDefault <License>();

            db.Licenses.Remove(item);
            db.SaveChanges();
            dataGrid.ItemsSource = db.Licenses.ToList();
        }