/// <summary> /// app.configに設定値保存 /// </summary> private void appConfigSave() { app = ToolSettingModel.Load(); app.ExcelFullPath = this.textBox_excelFullPath.Text; app.SqlString = this.textBox_sql.Text; app.DbType = (this.comboBox_dbType.SelectedIndex == -1 ? Define.DatabaseType.SqlServer : (Define.DatabaseType)this.comboBox_dbType.SelectedIndex); app.SqlType = (this.radioButton_sql_input.Checked ? Define.ExecuteSqlType.Input : Define.ExecuteSqlType.OutFile); app.ConnectionType = (this.radioButton_connStr_input.Checked ? Define.ExecuteConnType.Input : Define.ExecuteConnType.OutFile); app.IsOpenExcel = this.checkBox_isOpenExcel.Checked; #region 接続文字列履歴 if (!string.IsNullOrEmpty(this.comboBox_connectStr.Text)) { // 履歴内に同じものが含んでいれば、削除する(先頭に持ってくるため) if (app.ConnectionStringHistory.Contains(this.comboBox_connectStr.Text)) { app.ConnectionStringHistory.Remove(this.comboBox_connectStr.Text); } // 接続文字列履歴が10件あれば、最後のものを削除する else if (app.ConnectionStringHistory.Count >= HISTORY_MAX) { app.ConnectionStringHistory.RemoveRange(HISTORY_MAX - 1, (app.ConnectionStringHistory.Count - HISTORY_MAX + 1)); } // 接続文字列を一番上にする app.ConnectionStringHistory.Insert(0, this.comboBox_connectStr.Text); } #endregion app.Save(); }
/// <summary> /// ほぞん /// </summary> /// <param name="_model"></param> /// <returns></returns> public static bool Save(ToolSettingModel _toolModel) { try { if (!Directory.Exists(Path.GetDirectoryName(Define.AppSettingDataFullPath))) { Directory.CreateDirectory(Path.GetDirectoryName(Define.AppSettingDataFullPath)); } //XmlSerializerオブジェクトを作成 //オブジェクトの型を指定する XmlSerializer serializer = new XmlSerializer(typeof(ToolSettingModel)); //書き込むファイルを開く(UTF-8 BOM無し) using (StreamWriter sw = new StreamWriter(Define.AppSettingDataFullPath, false, new System.Text.UTF8Encoding(false))) { //シリアル化し、XMLファイルに保存する serializer.Serialize(sw, _toolModel); } return true; } catch { throw; } }
/// <summary> /// 初期化 /// </summary> private void Initialize() { app = ToolSettingModel.Load(); // 初期化 this.comboBox_dbType.Items.Clear(); this.comboBox_connectStr.Items.Clear(); this.comboBox_connectStr.Text = string.Empty; this.textBox_excelFullPath.Text = app.ExcelFullPath; this.textBox_sql.Text = app.SqlString.Replace("\n", "\r\n").Replace("\r\r", "\r"); this.checkBox_isOpenExcel.Checked = app.IsOpenExcel; if (app.SqlType == Define.ExecuteSqlType.Input) { this.radioButton_sql_input.Checked = true; } else { this.radioButton_sql_out.Checked = true; } if (app.ConnectionType == Define.ExecuteConnType.Input) { this.radioButton_connStr_input.Checked = true; } else { this.radioButton_connStr_output.Checked = true; } this.comboBox_connectStr.Items.AddRange(app.ConnectionStringHistory.ToArray()); if (this.comboBox_connectStr.Items.Count > 0) { this.comboBox_connectStr.SelectedIndex = 0; } foreach (Define.DatabaseType item in Enum.GetValues(typeof(Define.DatabaseType))) { this.comboBox_dbType.Items.Add(Define.GetDbTypeString(item)); if (item == app.DbType) { this.comboBox_dbType.SelectedIndex = (int)item; } } // 外部SQL 無ければフォルダ作成 if (!Directory.Exists(Define.UserOutSqlDirFullPath)) { Directory.CreateDirectory(Define.UserOutSqlDirFullPath); } // 外部CDBS 無ければフォルダ作成 if (!Directory.Exists(Define.UserOutCdbsDirFullPath)) { Directory.CreateDirectory(Define.UserOutCdbsDirFullPath); } // 外部SQLファイル読み込み foreach (var item in Bis.GetFileList(Define.UserOutSqlDirFullPath, "*.sql")) { this.comboBox_sqlFileList.Items.Add(Path.GetFileName(item)); if (app.SelectSqlString == item) { this.comboBox_sqlFileList.SelectedItem = item; } } // 外部cdbsファイル読み込み foreach (var item in Bis.GetFileList(Define.UserOutCdbsDirFullPath, "*.cdbs")) { this.comboBox_cdbsFileList.Items.Add(Path.GetFileName(item)); if (app.SelectCdbsString == item) { this.comboBox_cdbsFileList.SelectedItem = item; } } }