/// <summary> /// リストの再読み込み /// </summary> public void Reload() { int ctlCount = pnlMain.Controls.Count; pnlMain.Controls.Clear(); using (global.conn = new SQLiteConnection(global.gDataSource)) { try { global.conn.Open(); global.sql = "select * from Settings"; global.command = new SQLiteCommand(global.sql, global.conn); global.rd = global.command.ExecuteReader(); while (global.rd.Read()) { try { Info = new InfoAdd(); //フォームにデータを追加 Info.Name = "InfoAdd" + int.Parse((ctlCount + global.rd.GetValue(global.ID).ToString())).ToString(); Info.lblName.Text = global.rd.GetValue(global.NAME).ToString(); Info.lblUrl.Text = global.rd.GetValue(global.URL).ToString(); Info.lblPath.Text = global.rd.GetValue(global.PATH).ToString(); pnlMain.Controls.Add(Info); } catch (Exception) { } } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); Notify.SendMailError(DateTime.Now, ex.Message, "frmMain - 400~425"); } finally { global.conn.Close(); } } }
/// <summary> /// チェックされたカラムの削除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDel_Click(object sender, EventArgs e) { int count = pnlMain.Controls.Count; int i = 0; int arrayCount = 0; Info = new InfoAdd(); /*------------------------ * 配列の要素計算 * ------------------------*/ for (i = 0; i < 99; i++) { if (global.ChkInfo[i] != null) { arrayCount++; } } /*------------------------ * チェックが入っていない場合はエラー * ------------------------*/ if (arrayCount == 0) { MessageBox.Show(this, "削除する項目が選択されていません", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult result = MessageBox.Show(this, arrayCount + "個のデータを削除しますか?", "お知らせ", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2); /*------------------------ * チェックされた項目を削除 * ------------------------*/ if (result == DialogResult.Yes) { //フォームから削除 for (i = 0; i < count; i++) { if (pnlMain.Controls.IndexOfKey(global.ChkInfo[i]) > -1) { int dataNum = pnlMain.Controls.IndexOfKey(global.ChkInfo[i]); global.sql = "delete from Settings where exam = '" + global.ChkInfo[i] + "'"; using (global.conn = new SQLiteConnection(global.gDataSource)) { try { global.conn.Open(); global.command = new SQLiteCommand(global.sql, global.conn); global.command.ExecuteNonQuery(); pnlMain.Controls.RemoveAt(pnlMain.Controls.IndexOfKey(global.ChkInfo[i])); MessageBox.Show(this, "削除しました", "お知らせ", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { } global.conn.Close(); } } } //配列をnullで初期化 for (i = 0; i < 99; i++) { global.ChkInfo[i] = null; } } }
/// <summary> /// 設定の読み込み /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmMain_Load(object sender, EventArgs e) { int ctlCount = pnlMain.Controls.Count; menuSettings.Enabled = false; /*------------------------ * 起動時に一回だけ実行 * ------------------------*/ if (!global.FirstRun_flg) { ShowInTaskbar = false; Hide(); menuSettings.Enabled = true; notifyIcon1.ShowBalloonTip(5000, "お知らせ", "AutoDownloader へようこそ!\r\n講義の登録はこちらから行えます", ToolTipIcon.Info); Update_Check(0); //アップデート確認 //.oldファイル削除 if (File.Exists("AutoDownloader.old")) { File.Delete("AutoDownloader.old"); } RefreshInterval.Enabled = true; global.FirstRun_flg = true; } /*------------------------ * データベースを元にフォームへ追加 * ------------------------*/ pnlMain.Controls.Clear(); using (global.conn = new SQLiteConnection(global.gDataSource)) { try { global.conn.Open(); global.sql = "select * from Settings"; global.command = new SQLiteCommand(global.sql, global.conn); global.rd = global.command.ExecuteReader(); while (global.rd.Read()) { try { Info = new InfoAdd(); Info.Name = "InfoAdd" + int.Parse((ctlCount + global.rd.GetValue(global.ID).ToString())).ToString(); Info.lblName.Text = global.rd.GetValue(global.NAME).ToString(); Info.lblUrl.Text = global.rd.GetValue(global.URL).ToString(); Info.lblPath.Text = global.rd.GetValue(global.PATH).ToString(); pnlMain.Controls.Add(Info); } catch (Exception) { } } } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); Notify.SendMailError(DateTime.Now, ex.Message, "frmMain - 147~171"); } finally { global.conn.Close(); } } /*------------------------ * タイマセット * ------------------------*/ if (System.IO.File.Exists(@"settings.ini")) //INIファイルが存在する { switch (ini.getValueString("Interval", "time")) { case "5 分": RefreshInterval.Interval = 300000; break; case "10 分": RefreshInterval.Interval = 600000; break; case "30 分": RefreshInterval.Interval = 1800000; break; case "1 時間": RefreshInterval.Interval = 3600000; break; case "6 時間": RefreshInterval.Interval = 21600000; break; case "12 時間": RefreshInterval.Interval = 43200000; break; case "1 日": RefreshInterval.Interval = 86400000; break; default: break; } } else { RefreshInterval.Interval = 3600000; } //RefreshInterval.Interval = 60000; //デバッグ用 RefreshInterval.Enabled = true; ShowInTaskbar = false; Hide(); menuSettings.Enabled = true; }