Example #1
0
        /// <summary>
        ///     Method in which we check whether or not person can be found in database
        /// </summary>
        /// <param name="strInput"></param>
        private void ProcessPerson(string strInput)
        {
            // By Default, the CAC stores the DoDID as a base 32, that by itself is a unique
            // identifier and as such there's no need to convert it back into its base 10 equivalent
            DataRow Person = datPeople.NewRow();

            Person["DoDID32"] = CalcProcess.GetRawDoDID(strInput);

            // Try to find a person on the list with that DoDID number
            DataRow PersonMatch = datPeople.Rows.Find(Person["DoDID32"]);

            // Person match returns null if it doesn't find a person
            if (PersonMatch != null)
            {
                bool blnBelowLimit = (int)PersonMatch["Count"] < LimitDrinks;

                btnAdd.IsEnabled = blnBelowLimit;

                txtDrinksInput.IsEnabled = blnBelowLimit;

                ToggleIcon(blnBelowLimit);

                PersonOfInterest = PersonMatch;

                DrinksLeft = LimitDrinks - (int)PersonOfInterest["Count"];

                if (blnBelowLimit)
                {
                    txtDrinksInput.Focus();
                    txtDrinksInput.SelectAll();

                    ToggleIncrementButtons();
                }
                else
                {
                    btnCancel.Focus();
                }
            }
            else
            {
                // Add the new LEGAL person to the list;
                Person["Count"] = 0;
                datPeople.Rows.Add(Person);
                PersonOfInterest = Person;

                DataParse.SaveData(DateOfProgram, LimitDrinks, HoursBeforeReset, AgeReq, datPeople);

                ToggleIcon(true);

                txtDrinksInput.Focus();
                txtDrinksInput.SelectAll();

                DrinksLeft = LimitDrinks - (int)PersonOfInterest["Count"];

                grpStatus.Header = string.Format(ProjStrings.DrinksRemaining, NameOfPerson, DrinksLeft);

                ToggleIncrementButtons();
            }
        }
Example #2
0
        public MainWindow()
        {
            InitializeComponent();

            // Formats the data table.
            datPeople.Columns.Add("DoDID32", typeof(string));
            datPeople.Columns.Add("Count", typeof(int));
            datPeople.PrimaryKey = new[] { datPeople.Columns["DoDID32"] };

            // Loads user configuration + datafile
            DataParse.LoadFile(ref LimitDrinks, ref HoursBeforeReset, ref AgeReq, ref DateOfProgram, ref datPeople);

            txtInput.Focus();
        }
Example #3
0
        /// <summary>
        ///     Add Number of drinks into database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            // Validate
            bool blnInputGood = ValidateDrinks(out int intInputDrink);

            if (blnInputGood)
            {
                PersonOfInterest["Count"] = (int)PersonOfInterest["Count"] + intInputDrink;

                grpStatus.Header = string.Format(ProjStrings.DrinksRemaining, NameOfPerson, DrinksLeft);

                ToggleIcon((int)PersonOfInterest["Count"] < LimitDrinks);

                ResetFields();

                DataParse.SaveData(DateOfProgram, LimitDrinks, HoursBeforeReset, AgeReq, datPeople);

                txtInput.Focus();
            }
        }
Example #4
0
        /// <summary>
        ///     Occurs when a CAC is scanned. The btnSubmit by default is the form's "Accept Button".
        ///     After a successful scan, it will set focus,
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            // We use the groupbox header as the status message, this resets it.
            grpStatus.Header = string.Empty;

            // Get the input and then clear the input text box
            string strInput = txtInput.Password;

            txtInput.Clear();

            // Clear any fields that are native to that user.
            ResetFields();

            // If the program is left running randomly overnight w/o closing the program then we
            // need to do some work and reset fields
            if ((DateTime.Now - DateOfProgram).TotalHours > HoursBeforeReset)
            {
                DateOfProgram = DateTime.Now;

                datPeople.Rows.Clear();
                DataParse.SaveData(DateOfProgram, LimitDrinks, HoursBeforeReset, AgeReq, datPeople);
            }

            txtInput.IsEnabled  = false;
            btnSubmit.IsEnabled = false;
            btnCancel.IsEnabled = true;

            // This is in a try/catch block in case the user tries to scan in something other than
            // the Front side of the CAC...
            try
            {
                NameOfPerson = string.Format(ProjStrings.Name,
                                             strInput.Substring(15, 1),                                                            // First Initial
                                             strInput.Substring(35, 26).Trim());                                                   // Entire Last Name

                // Name
                grpStatus.Header = NameOfPerson;

                DateTime DateOfBirth = DateTime.FromOADate(CalcProcess.ConvertToBase10(strInput.Substring(61, 4), 32) - DblWeirdDOBOffset);

                // There's no .TotalYears function, so we have to use .TotalDays.
                int intAge = (int)((DateTime.Today - DateOfBirth).TotalDays / 365);
                txtAge.Text = string.Format(ProjStrings.Age, intAge);

                // If the Age is >= the AgeReq, then enable the add button.
                bool personIsLegal = intAge >= AgeReq;

                grpStatus.Header = personIsLegal ? "" : string.Format(ProjStrings.Underaged, NameOfPerson);

                ToggleIcon(personIsLegal);

                btnAdd.IsEnabled         = personIsLegal;
                txtDrinksInput.IsEnabled = personIsLegal;

                // If they are legal, then we proceed to do other checks
                if (personIsLegal)
                {
                    ProcessPerson(strInput);

                    grpStatus.Header = string.Format(ProjStrings.DrinksRemaining, NameOfPerson, DrinksLeft);
                }
                else
                {
                    btnCancel.Focus();
                }
            }
            catch
            {
                ResetFields();

                grpStatus.Header = ProjStrings.ReadyToScan;

                MessageBox.Show(ProjStrings.ErrorReading);

                txtInput.Focus();
            }
        }