private void UpdateProcess() { frmProg.Show(); try { int pid = System.Diagnostics.Process.GetCurrentProcess().Id; /*------------------------ * 旧ファイルを.oldへ * ------------------------*/ File.Delete("AutoDownloader.old"); File.Move("AutoDownloader.exe", "AutoDownloader.old"); /*------------------------ * 新ファイルダウンロード * ------------------------*/ foreach (string fileName in _addfiletxt) { try { /*if (download_state == false) * { * download_state = true; */ //ダウンロード元URL Uri u = new Uri("http://www.nxtg-t.net/downloads/AutoDownloader/" + _NewVersion + "/" + fileName); versionUpdate = new System.Net.WebClient(); versionUpdate.DownloadProgressChanged += versionUpdate_DownloadProgressChanged; versionUpdate.DownloadFileCompleted += versionUpdate_DownloadFileCompleted; versionUpdate.DownloadFileAsync(u, fileName); /*} * else * { * await Task.Delay(1000); * }*/ } catch (Exception) { break; } } } catch (Exception ex) { MessageBox.Show(this, "バージョンアップに失敗しました\r\n\r\nエラー:" + ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); frmProg.Close(); File.Move("AutoDownloader.old", "AutoDownloader.exe"); Notify.SendMailError(DateTime.Now, ex.Message, "frmMain - 697~722"); return; } }
/// <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 btnAdd_Click(object sender, EventArgs e) { int ctlCount = frm.pnlMain.Controls.Count; if (txtName.Text == "" || txtURL.Text == "" || txtPath.Text == "") { MessageBox.Show(this, "入力に誤りがあります", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /*------------------------ 登録 ------------------------*/ using (global.conn = new SQLiteConnection(global.gDataSource)) { try { global.conn.Open(); global.sql = "insert into Settings (name, url, path) values ( " + "'" + txtName.Text + "'," + "'" + txtURL.Text + "'," + "'" + txtPath.Text + "'" + ")"; global.command = new SQLiteCommand(global.sql, global.conn); global.command.ExecuteNonQuery(); /*------------------------ データベースのexamを更新 ------------------------*/ frm.pnlMain.Controls.Clear(); try { global.sql = "select * from Settings"; global.command = new SQLiteCommand(global.sql, global.conn); global.rd = global.command.ExecuteReader(); while (global.rd.Read()) { try { global.sql = "update Settings set exam = 'InfoAdd" + int.Parse((ctlCount + global.rd.GetValue(global.ID).ToString())).ToString() + "' where no = " + global.rd.GetValue(global.ID).ToString(); global.command = new SQLiteCommand(global.sql, global.conn); global.command.ExecuteNonQuery(); } catch (Exception) { } } } catch (Exception){ } } catch (Exception ex) { MessageBox.Show(this, "Error : " + ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); Notify.SendMailError(DateTime.Now, ex.Message, "frmAdd - 64~101"); } finally { global.conn.Close(); frm.Dispose(); this.Close(); } MessageBox.Show(this, "登録が完了しました", "お知らせ", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <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; }