private void Populate()
        {
            try
            {
                oBackupSetting = oSettingBL.GetBackupSetting();
                if (oBackupSetting != null)
                {
                    if (oBackupSetting.On == "day/week")
                    {
                        dtEveryDayWeekTime.EditValue = oBackupSetting.Time;

                        List <string> _days = oSettingBL.GetBackupDays(oBackupSetting.Day);

                        foreach (var _controls in layoutControl1.Controls)
                        {
                            if (_controls is CheckButton)
                            {
                                var _btn = _controls as CheckButton;
                                foreach (var _d in _days)
                                {
                                    if (_btn.Text == _d)
                                    {
                                        _btn.Checked = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else if (oBackupSetting.On == "every month")
                    {
                        cboEveryMonthDay.EditValue = oBackupSetting.Day;
                        dtEveryMonthTime.EditValue = oBackupSetting.Time;
                    }
                    else if (oBackupSetting.On == "every year")
                    {
                        cboEveryYearMonth.EditValue = oBackupSetting.Month;
                        cboEveryYearDay.EditValue   = oBackupSetting.Day;
                        dtEveryYearTime.EditValue   = oBackupSetting.Time;
                    }

                    txtBackupLocation.Text = oBackupSetting.BackupLocation;
                    List <string> _cboOptions = new List <string>();
                    foreach (var i in cboBackupPeriod.Properties.Items)
                    {
                        _cboOptions.Add(i.ToString().ToLower());
                    }

                    cboBackupPeriod.SelectedIndex = _cboOptions.IndexOf(oBackupSetting.On);
                }
            }
            catch (Exception ex)
            {
                DbUtilityHelper.DisplayMessageBox(ex.Message, "error");
            }
        }
Example #2
0
        public bool Add(BackupSetting setting)
        {
            try
            {
                XmlDocument _doc = new XmlDocument();

                //Create neccessary nodes
                XmlDeclaration _declaration    = _doc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
                XmlElement     _root           = _doc.CreateElement("Settings");
                XmlElement     _backup         = _doc.CreateElement("Backup");
                XmlAttribute   _on             = _doc.CreateAttribute("On");
                XmlElement     _month          = _doc.CreateElement("Month");
                XmlElement     _day            = _doc.CreateElement("Day");
                XmlElement     _time           = _doc.CreateElement("Time");
                XmlElement     _backupLocation = _doc.CreateElement("BackupLocation");

                //Add the values for each nodes
                _on.Value                 = setting.On;
                _month.InnerText          = setting.Month;
                _day.InnerText            = setting.Day;
                _time.InnerText           = setting.Time;
                _backupLocation.InnerText = setting.BackupLocation;

                //Construct the document
                _doc.AppendChild(_declaration);
                //doc.AppendChild(comment);
                _doc.AppendChild(_root);
                _root.AppendChild(_backup);
                _backup.Attributes.Append(_on);
                _backup.AppendChild(_month);
                _backup.AppendChild(_day);
                _backup.AppendChild(_time);
                _backup.AppendChild(_backupLocation);

                if (!Directory.Exists(LOCAL_APP_DATA))
                {
                    Directory.CreateDirectory(LOCAL_APP_DATA);
                }

                _doc.Save(BACKUP_SETTING_PATH);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public frmBackupSetting()
        {
            InitializeComponent();

            oSettingBL     = new SettingBL();
            oBackupSetting = new BackupSetting();

            customDays = new Dictionary <int, string>();

            cboBackupPeriod_SelectedIndexChanged(null, null);

            btnSunday.LookAndFeel.UseDefaultLookAndFeel = false;
            btnSunday.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;

            Populate();
        }
Example #4
0
        public BackupSetting GetBackupSetting()
        {
            try
            {
                if (System.IO.File.Exists(BACKUP_SETTING_PATH))
                {
                    XmlDocument _doc = new XmlDocument();
                    _doc.Load(BACKUP_SETTING_PATH);

                    //Get root element
                    XmlElement _root = _doc.DocumentElement;

                    //Get the record at the current index
                    XmlElement _currentServer = (XmlElement)_root.ChildNodes[0];

                    if (_currentServer.ChildNodes.Count > 0)
                    {
                        //Show the record information
                        BackupSetting _setting = new BackupSetting();
                        _setting.On             = _currentServer.Attributes["On"].Value;
                        _setting.Month          = _currentServer.GetElementsByTagName("Month")[0].InnerText;
                        _setting.Day            = _currentServer.GetElementsByTagName("Day")[0].InnerText;
                        _setting.Time           = _currentServer.GetElementsByTagName("Time")[0].InnerText;
                        _setting.BackupLocation = _currentServer.GetElementsByTagName("BackupLocation")[0].InnerText;

                        return(_setting);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (cboBackupPeriod.SelectedItem != null && !string.IsNullOrEmpty(txtBackupLocation.Text))
                {
                    oBackupSetting = null;

                    #region Backup on day/week
                    if (cboBackupPeriod.SelectedIndex == 0) //day/week selected
                    {
                        if (customDays.Count <= 0 || dtEveryDayWeekTime.EditValue == null)
                        {
                            DbUtilityHelper.DisplayMessageBox("Please specify the day(s) of the week to take backup on", "warning");
                        }
                        else
                        {
                            oBackupSetting = new BackupSetting()
                            {
                                Month = string.Empty,
                                Day   = selectedDays,
                                Time  = dtEveryDayWeekTime.Text
                            };
                        }
                    }
                    #endregion

                    #region Backup on every month
                    else if (cboBackupPeriod.SelectedIndex == 1) //month selected
                    {
                        if (cboEveryMonthDay.SelectedItem == null || dtEveryDayWeekTime.EditValue == null)
                        {
                            DbUtilityHelper.DisplayMessageBox("Please specify the day and time of the month to take backup", "warning");
                        }
                        else
                        {
                            oBackupSetting = new BackupSetting()
                            {
                                Month = string.Empty,
                                Day   = cboEveryMonthDay.EditValue.ToString(),
                                Time  = dtEveryMonthTime.Text
                            };
                        }
                    }
                    #endregion

                    #region Backup on every year
                    else if (cboBackupPeriod.SelectedIndex == 2) //year selected
                    {
                        if (cboEveryYearMonth.SelectedItem == null || cboEveryYearDay.SelectedItem == null || dtEveryYearTime.EditValue == null)
                        {
                            DbUtilityHelper.DisplayMessageBox("Please specify month, day and time of the year to take backup", "warning");
                        }
                        else
                        {
                            oBackupSetting = new BackupSetting()
                            {
                                Month = cboEveryYearMonth.EditValue.ToString(),
                                Day   = cboEveryYearDay.EditValue.ToString(),
                                Time  = dtEveryYearTime.Text
                            };
                        }
                    }
                    #endregion

                    if (oBackupSetting != null)
                    {
                        oBackupSetting.On             = on;
                        oBackupSetting.BackupLocation = txtBackupLocation.Text.Trim();

                        if (oSettingBL.Add(oBackupSetting))
                        {
                            DbUtilityHelper.DisplayMessageBox("Setting successfully saved", "information");
                            this.Close();
                        }
                        else
                        {
                            DbUtilityHelper.DisplayMessageBox("Setting could not be saved. Please try again.", "error");
                        }
                    }
                }
                else
                {
                    DbUtilityHelper.DisplayMessageBox("Please select backup period", "warning");
                }
            }
            catch (Exception ex)
            {
                DbUtilityHelper.DisplayMessageBox(ex.Message, "error");
            }
        }