private void RunButton_Click(object sender, EventArgs e) { try { if (JanCodeFileTextBox.Text == "") { throw new ApplicationException("JANコードファイルパスを入力してください。"); } SaveFileDialog dlg = new SaveFileDialog(); dlg.Title = "結果ファイルの出力先を指定して下さい。"; dlg.Filter = "csvファイル (*.csv)|*.csv|すべてのファイル (*.*)|*.*"; dlg.FileName = $"{System.IO.Path.GetFileNameWithoutExtension(JanCodeFileTextBox.Text)}_result{DateTime.Now.ToString("yyyyMMddHHmmss")}.csv"; if (dlg.ShowDialog() == DialogResult.Cancel) { return; } dataGridView1.Rows.Clear(); var task = new ToysrusBot(); task.ExecutingStateChanged += Task_ExecutingStateChanged; task.Start(JanCodeFileTextBox.Text, dlg.FileName, (int)DelayNumericUpDown.Value, IncludeUnPostedCheckBox.Checked); } catch (ApplicationException ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { if (args.Length == 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new ExecForm()); } else { string resultFileName = $"{System.IO.Path.GetFileNameWithoutExtension(Properties.Settings.Default.JanCodeFileName)}_result{DateTime.Now.ToString("yyyyMMddHHmmss")}.csv"; var task = new ToysrusBot(); task.Start(Properties.Settings.Default.JanCodeFileName, resultFileName, Properties.Settings.Default.Delay, Properties.Settings.Default.IncludeUnPosted); } }