コード例 #1
0
        private void InitForm()
        {
            LoadAppConfigItems();

            InitSaveFileDialog();

            foreach (Control ctl in this.Controls)
            {
                if (ctl is CheckBox)
                {
                    CheckBox            chk     = (CheckBox)ctl;
                    SavedBooleanControl saveChk = new SavedBooleanControl();
                    saveChk.Name    = chk.Name;
                    saveChk.Checked = chk.Checked;
                    _saveFormCheckBoxes.Add(saveChk);
                }
                if (ctl is RadioButton)
                {
                    RadioButton         rdo     = (RadioButton)ctl;
                    SavedBooleanControl saveRdo = new SavedBooleanControl();

                    saveRdo.Name    = rdo.Name;
                    saveRdo.Checked = rdo.Checked;
                    _saveFormRadioButtons.Add(saveRdo);
                }
            } //end foreach
        }     //end method
コード例 #2
0
        private bool ProcessOptions()
        {
            bool err            = false;
            bool ret            = true;
            bool formHasChanged = false;
            int  inx            = 0;
            int  maxInx         = -1;

            System.Configuration.Configuration config =
                System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            try
            {
                foreach (Control ctl in this.Controls)
                {
                    if (ctl is CheckBox)
                    {
                        CheckBox            chk = (CheckBox)ctl;
                        SavedBooleanControl saveChk;
                        maxInx = _saveFormCheckBoxes.Count - 1;
                        for (inx = 0; inx <= maxInx; inx++)
                        {
                            saveChk = _saveFormCheckBoxes[inx];
                            if (chk.Name == saveChk.Name)
                            {
                                if (chk.Checked != saveChk.Checked)
                                {
                                    formHasChanged = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (ctl is RadioButton)
                    {
                        RadioButton         rdo = (RadioButton)ctl;
                        SavedBooleanControl saveRdo;
                        maxInx = _saveFormRadioButtons.Count - 1;
                        for (inx = 0; inx <= maxInx; inx++)
                        {
                            saveRdo = _saveFormRadioButtons[inx];
                            if (rdo.Name == saveRdo.Name)
                            {
                                if (rdo.Checked != saveRdo.Checked)
                                {
                                    formHasChanged = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (ctl is TextBox)
                    {
                        TextBox txt = (TextBox)ctl;
                        if (txt.Modified)
                        {
                            formHasChanged = true;
                        }
                    }
                    if (formHasChanged)
                    {
                        break;
                    }
                }//end foreach

                if (formHasChanged)
                {
                    //update all configuration file item values
                    ResetAllConfigurationFileItemValues(config);
                }
            }
            catch (System.Exception ex)
            {
                err         = true;
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
            }



            if (err)
            {
                if (this.chkSaveErrorMessagesToErrorLog.Checked)
                {
                    AppGlobals.AppMessages.DisplayErrorMessage(_msg.ToString(), true);
                }
                else
                {
                    AppGlobals.AppMessages.DisplayErrorMessage(_msg.ToString(), false);
                }
                ret = false;
            }
            else
            {
                if (formHasChanged)
                {
                    config.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection("appSettings");
                    _msg.Length = 0;
                    _msg.Append("Application options have been updated.");
                    if (this.chkSaveErrorMessagesToErrorLog.Checked)
                    {
                        AppGlobals.AppMessages.DisplayInfoMessage(_msg.ToString(), true);
                    }
                    else
                    {
                        AppGlobals.AppMessages.DisplayInfoMessage(_msg.ToString(), false);
                    }
                    this.Refresh();

                    //re-save all input values for future checks
                    _saveFormCheckBoxes.Clear();
                    _saveFormRadioButtons.Clear();
                    foreach (Control ctl in this.Controls)
                    {
                        if (ctl is CheckBox)
                        {
                            CheckBox            chk     = (CheckBox)ctl;
                            SavedBooleanControl saveChk = new SavedBooleanControl();
                            saveChk.Name    = chk.Name;
                            saveChk.Checked = chk.Checked;
                            _saveFormCheckBoxes.Add(saveChk);
                        }
                        if (ctl is RadioButton)
                        {
                            RadioButton         rdo     = (RadioButton)ctl;
                            SavedBooleanControl saveRdo = new SavedBooleanControl();
                            saveRdo.Name    = rdo.Name;
                            saveRdo.Checked = rdo.Checked;
                            _saveFormRadioButtons.Add(saveRdo);
                        }
                        if (ctl is TextBox)
                        {
                            TextBox txt = (TextBox)ctl;
                            txt.Modified = false;
                        }
                    }//end foreach
                }
                ret = true;
            }
            return(ret);
        }