Beispiel #1
0
        public ViewLicenses()
        {
            InitializeComponent();
            LicenserContext db = new LicenserContext();

            dataGrid.ItemsSource = db.Licenses.ToList();
        }
Beispiel #2
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();
        }
Beispiel #3
0
        private void ExportLicenseMenuItem_Click(object sender, RoutedEventArgs e)
        {
            LicenserContext db             = new LicenserContext();
            SaveFileDialog  saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "Excel Files (*.xlsx)|*.xlsx";
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            if (saveFileDialog.ShowDialog() == true)
            {
                var newFile = new FileInfo(saveFileDialog.FileName);
                using (ExcelPackage package = new ExcelPackage(newFile))
                {
                    ExcelWorksheet ws = package.Workbook.Worksheets.Add("Licenses");
                    ws.Cells["A1"].LoadFromCollection <License>(db.Licenses.AsEnumerable <License>(), true, OfficeOpenXml.Table.TableStyles.Light8);
                    package.Save();
                }
            }
        }