Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the database has already been configured by Q-Drive
        /// </summary>
        /// <returns>True if the DB is already configured</returns>
        public static bool IsQDConfigured()
        {
            if (File.Exists(QDInfo.ConfigFile))
            {
                try
                {
                    using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
                    {
                        object result = sqlite.ExecuteScalarACon("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.SetupSuccess);

                        if (result != null && Convert.ToBoolean(Convert.ToInt16(result)))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        private void AddEditGroup_Load(object sender, EventArgs e)
        {
            if (IsEditMode)
            {
                this.Text         = "Edit Group";
                btnSubmit.Text    = "Update Group";
                txbGroupName.Text = sql.ExecuteScalarACon <string>($"SELECT Name FROM Groups WHERE ID = '{GroupID}'");
            }
            else
            {
                this.Text = "Add New Group";
            }


            // Load all devices and add then to the view
            sql.Open();
            using (SQLiteDataReader reader = sql.ExecuteQuery("SELECT * FROM Devices LEFT JOIN GroupAssigns ON Devices.MACAddress = GroupAssigns.MACAddress WHERE GroupAssigns.GroupID IS NULL ORDER BY Devices.Name ASC"))
            {
                while (reader.Read())
                {
                    // Add device to view
                    GroupViewItem gvi = new GroupViewItem(
                        Convert.ToString(reader["Name"]),
                        grvDevices.SmallImageList.Images.IndexOfKey(
                            Convert.ToString(reader["DeviceType"]) + "_RAW")
                        );
                    gvi.Tag = Convert.ToString(reader["MACAddress"]);

                    grvDevices.GroupViewItems.Add(gvi);
                }
            }


            if (!IsEditMode)
            {
                // Create new group
                sql.ExecuteNonQuery($"INSERT INTO Groups (Name, Description, DeviceType) VALUES ('{newGroupGuid}', '', '{DeviceType.UnknownDevice}')");
                GroupID = sql.ExecuteScalar <int>($"SELECT ID FROM Groups WHERE Name = '{newGroupGuid}'");
            }

            sql.Close();

            UpdateGroupDeviceList();
        }
Ejemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txbDeviceName.Text))
            {
                DeviceName = txbDeviceName.Text;
            }
            else
            {
                MessageBox.Show("Please enter a Device-Name.", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txbDeviceName.Focus();
                return;
            }

            DeviceDescription = txbDeviceDescription.Text;
            DeviceHostname    = txbDeviceHostname.Text;

            if (string.IsNullOrEmpty(txbDeviceIPv4.Text) || (IPAddress.TryParse(txbDeviceIPv4.Text, out IPAddress ipv4Check) && ipv4Check.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork))
            {
                DeviceIPv4 = txbDeviceIPv4.Text;
            }
            else
            {
                MessageBox.Show("The entered IPv4-Address is not valid. Please enter a valid IPv4-Address.\r\n\r\nFormat: XXX.XXX.XXX.XXX", "Faulty Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txbDeviceIPv4.Focus();
                return;
            }

            if (string.IsNullOrEmpty(txbDeviceIPv6.Text) || (IPAddress.TryParse(txbDeviceIPv6.Text, out IPAddress ipv6Check) && ipv6Check.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6))
            {
                DeviceIPv6 = txbDeviceIPv6.Text;
            }
            else
            {
                MessageBox.Show("The entered IPv6-Address is not valid. Please enter a valid IPv6-Address.", "Faulty Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txbDeviceIPv6.Focus();
                return;
            }

            if (!string.IsNullOrEmpty(txbDeviceMac.Text))
            {
                if (Regex.IsMatch(txbDeviceMac.Text, "^[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}-[A-Fa-f0-9]{2}") && txbDeviceMac.Text.Length == 17)
                {
                    if (sql.ExecuteScalarACon <int>($"SELECT COUNT(*) FROM Devices WHERE MACAddress = '{txbDeviceMac.Text}' AND MACAddress != '{OriginalDeviceMac}'") == 0)
                    {
                        DeviceMac = txbDeviceMac.Text;
                    }
                    else
                    {
                        MessageBox.Show("The entered MAC-Address already exists. Please enter a new MAC-Address.\r\n\r\nFormat: XX-XX-XX-XX-XX-XX", "Duplicate MAC-Address", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txbDeviceMac.Focus();
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("The entered MAC-Address is not valid. Please enter a valid MAC-Address.\r\n\r\nFormat: XX-XX-XX-XX-XX-XX", "Faulty Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txbDeviceMac.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please enter a MAC-Address.", "Missing Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txbDeviceMac.Focus();
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();
        }