Esempio n. 1
0
        private void DriveSettings_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (DialogResult == DialogResult.OK)
                {
                    string drive = txtDrive.Text.Trim();

                    if (string.IsNullOrEmpty(drive))
                    {
                        throw new Exception("You must select drive.");
                    }

                    if (!Directory.Exists(drive))
                    {
                        throw new Exception("The path does not exist.");
                    }

                    string volumeName   = (new System.IO.DriveInfo(Path.GetPathRoot(drive))).VolumeLabel;
                    string operation    = ComboBoxTools.GetSelectedValue(cboOperation);
                    int    timeInterval = (int)numTimeInterval.Value;
                    string timeUnit     = ComboBoxTools.GetSelectedValue(cboTimeUnit);
                    int    status       = chkEnabled.Checked ? 1 : 0;

                    if (Database.DatabaseManager.Exist(_id, drive))
                    {
                        var driveInfo = Database.DatabaseManager.GetByDrive(drive);

                        if (driveInfo.VolumeNames.Contains(volumeName))
                        {
                            throw new Exception("You have already specified drive with the same volume name.");
                        }

                        _id = driveInfo.ID;
                    }

                    if (timeInterval < 1)
                    {
                        throw new Exception("Cannot have time interval less than one minute.");
                    }

                    if (_id == 0)
                    {
                        Database.DatabaseManager.Insert(id: out _id, drive: drive, volumeName: volumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status);
                    }
                    else
                    {
                        Database.DatabaseManager.Update(id: _id, drive: drive, volumeName: volumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status);
                    }
                }
            }
            catch (Exception exc)
            {
                e.Cancel = true;
                LogManager.Write(exc.Message);
                MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
Esempio n. 2
0
        private void DriveSettingsMulti_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (DialogResult == DialogResult.OK)
                {
                    int    timeInterval = (int)numTimeInterval.Value;
                    string operation    = ComboBoxTools.GetSelectedValue(cboOperation);
                    string timeUnit     = ComboBoxTools.GetSelectedValue(cboTimeUnit);
                    int    status       = chkEnabled.Checked ? 1 : 0;

                    if (timeInterval < 1)
                    {
                        throw new Exception("Cannot have time interval less than one minute.");
                    }

                    foreach (string drive in _drives)
                    {
                        if (!Database.DatabaseManager.Exist(-1, drive))
                        {
                            string sVolumeName = (new System.IO.DriveInfo(Path.GetPathRoot(drive))).VolumeLabel;

                            Database.DatabaseManager.Insert(out _id, drive: drive, volumeName: sVolumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status);
                        }
                        else
                        {
                            string sVolumeName = (new System.IO.DriveInfo(Path.GetPathRoot(drive))).VolumeLabel;

                            var driveInfo = Database.DatabaseManager.GetByDrive(drive);

                            if (driveInfo != null)
                            {
                                _id = driveInfo.ID;
                                Database.DatabaseManager.Update(id: _id, drive: drive, volumeName: sVolumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status);
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                e.Cancel = true;
                LogManager.Write(exc.Message);
                MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }
Esempio n. 3
0
        private void cboOperation_SelectedIndexChanged(object sender, EventArgs e)
        {
            string operation = ComboBoxTools.GetSelectedValue(cboOperation);

            lblOperationInfo.Text = operation == "r" ? "disk every" : "file every";
        }