Beispiel #1
0
        private void loadDevices(string textToFind = "", bool custom = false)
        {
            listViewDevices.Items.Clear();
            MySqlDataReader reader = DeviceInfo.readAll();

            if (reader == null)
            {
                Console.WriteLine("reader is null.");
                return;
            }
            while (reader.Read())
            {
                Boolean checker = Lendings.isActive(reader.GetInt16(0));
                //Boolean isActive = Lendings.isActive(reader.GetInt16(0));

                //lvi.Tag = Devices;
                string LvStatus = string.Empty;
                if (checker == true)
                {
                    LvStatus = "uitgeleent";
                }
                else
                {
                    LvStatus = "uitleenbaar";
                }
                if (!reader.GetString(1).StartsWith(textToFind) && custom)
                {
                    continue;
                }
                var row = new string[] { reader.GetString(1), reader.GetString(2), LvStatus, reader.GetString(3), reader.GetString(0) }; // adding the item to the list.
                var lvi = new ListViewItem(row);
                listViewDevices.Items.Add(lvi);
            }
        }
Beispiel #2
0
        private void ReturnScreenReturnButton_Click(object sender, EventArgs e)
        {
            // RETURNING A DEVICE
            var item = listViewDevices.SelectedItems[0];

            int    id         = int.Parse(item.SubItems[4].Text);
            string returnDesc = returnBescrijving.Text;

            Lendings.delete(id, returnDesc);
            ReturnScreenPanel.Visible = false;
            loadDevices();
        }
Beispiel #3
0
        private void LendingScreenSaveButton_Click(object sender, EventArgs e)
        {
            // LENDING SAVE BUTTON
            // idk where the button is to go to this screen actually, lol.
            string errMessage    = string.Empty;
            Regex  regFName      = new Regex(@"^[A-Z][a-z]{2,20}$");
            Regex  regLName      = new Regex(@"^[A-Z][a-z]{2,20}$");
            Regex  regStudentNum = new Regex(@"^[0-9]{6,10}$");
            Regex  regClass      = new Regex(@"^[a-zA-Z0-9]{6,10}$");

            if (!regFName.Match(LendingScreenFirstName.Text).Success)
            {
                errMessage += "First name can only contain letters and starts with a captial letter and needs to have 2 - 20 letters.\n\n";
            }
            if (!regLName.Match(LendingScreenLastName.Text).Success)
            {
                errMessage += "Last name can only contain letters and starts with a captial letter and needs to have 2 - 20 letters.\n\n";
            }
            if (!regStudentNum.Match(LendingScreenStudentNum.Text).Success)
            {
                errMessage += "Sudent ID can only contain numbers and can have a length between 6 - 10.\n\n";
            }
            if (LendingScreenClass.Text.Length > 0 && !regClass.Match(LendingScreenClass.Text).Success)
            {
                errMessage += "Class can only contain letters and numbers and can have a length between 6 - 10.";
            }
            if (errMessage.EndsWith("\n\n"))
            {
                errMessage = errMessage.Substring(0, errMessage.Length - 4);
            }
            if (errMessage.Length > 0)
            {
                handleError(errMessage);
                return;
            }
            int userId = User.add(LendingScreenFirstName.Text, LendingScreenLastName.Text, int.Parse(LendingScreenStudentNum.Text), LendingScreenClass.Text);

            if (userId == -1)
            {
                handleError("Something went wrong, try again later!");
                return;
            }
            var item = listViewDevices.SelectedItems[0];

            int id = int.Parse(item.SubItems[4].Text);

            Lendings.add(id, userId);
            LendingScreenPanel.Visible = false;
            ReturnScreenPanel.Visible  = false;
            loadDevices();
        }