コード例 #1
0
        private void btnGetJVData_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text == "")
            {
                System.Media.SystemSounds.Asterisk.Play();
                int num2 = (int)MessageBox.Show("保存するフォルダを選択してください。");
                cOperateForm.enableButton();
                return;
            }

            clsTrain cTrain = new clsTrain(this);

            // 出馬表の読み込み
            if (checkBox2.Checked)
            {
                if (cTrain.GetRaceCardFile(this.textBox1.Text) == "")
                {
                    cOperateForm.enableButton();
                    return;
                }
            }

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            DateTime dt = DateTime.Now;
            string   strlogS;

            strlogS = dt.ToString("HH:mm:ss") +
                      " 調教データ取得開始しました。";
            this.rtbData.Text = strlogS;
            cOperateForm.disableButton();

            bool          isReal       = false;
            int           index1       = 0;
            int           index2       = 0;
            string        str1         = System.Windows.Forms.Application.StartupPath + "\\";
            string        str2         = "Template.xlsx";
            string        str3         = "Template";
            DateTime      datetimeTarg = this.dateTimePicker1.Value;
            string        str4         = datetimeTarg.ToString("yyyyMMdd");
            List <string> stringList1  = new List <string>();
            List <List <List <string> > > stringListListList = new List <List <List <string> > >();
            List <string>           stringList2      = new List <string>();
            List <List <string> >   stringListList1  = new List <List <string> >();
            List <List <cRaceUma> > cRaceUmaListList = new List <List <cRaceUma> >();
            List <cRaceUma>         cRaceUmaList     = new List <cRaceUma>();
            int        num1       = 0;
            int        rowWrite   = 1;
            OperateCSV operateCsv = new OperateCSV();

            Microsoft.Office.Interop.Excel.Application appExl = null;
            Workbook  wbCSV      = null;
            Workbook  wbTemplate = null;
            Worksheet wsCSV      = null;
            Worksheet wsTemplate = null;

            string text = this.textBox1.Text;

            this.prgDownload.Maximum = 100;
            this.prgDownload.Value   = 0;
            //if (this.isRunRaceReal(datetimeTarg))
            //{
            //    isReal = true;
            //}
            // リアルタイムデータか判別する VBAと挙動が異なる
            TimeSpan timeSpan = new TimeSpan(7, 0, 0, 0);

            if (datetimeTarg > DateTime.Now - timeSpan)
            {
                isReal = true;
            }

            if (!this.isRunRace(datetimeTarg))
            {
                System.Media.SystemSounds.Asterisk.Play();
                int num3 = (int)MessageBox.Show("エラー");
                cOperateForm.enableButton();
                return;
            }

            List <string> placeInfoX;

            if (isReal)
            {
                placeInfoX = this.GetPlaceInfoReal(datetimeTarg);
            }
            else
            {
                placeInfoX = this.GetPlaceInfoX(datetimeTarg);
            }
            if (placeInfoX.Count == 0)
            {
                System.Media.SystemSounds.Asterisk.Play();
                int num4 = (int)MessageBox.Show("エラー:会場が取得できません。");
                cOperateForm.enableButton();
                return;
            }

            foreach (string collplace in placeInfoX)
            {
                List <List <string> > raceNumInfoX = this.GetRaceNumInfoX(datetimeTarg, collplace);
                stringListListList.Add(raceNumInfoX);
                foreach (List <string> stringList3 in raceNumInfoX)
                {
                    this.rtbData.Text = "出走馬取得中... " +
                                        collplace.Replace("競馬場", "") +
                                        Strings.StrConv(stringList3[0], VbStrConv.Wide, 0);
                    List <cRaceUma> raceUmaX = this.GetRaceUmaX(datetimeTarg, collplace, stringList3[0]);
                    cRaceUmaListList.Add(raceUmaX);
                    ++num1;
                    this.prgDownload.Value = 33 * num1 / (12 * placeInfoX.Count);
                }
            }

            this.prgDownload.Value = 33;
            this.rtbData.Text      = "調教データ取得中";
            List <string> tyoukyouDataAllX = this.GetTyoukyouDataAllX(datetimeTarg);

            appExl         = new Microsoft.Office.Interop.Excel.Application();
            appExl.Visible = false;
            wbCSV          = appExl.Workbooks.Add(System.Type.Missing);
            wsCSV          = wbCSV.ActiveSheet;
            wbTemplate     = appExl.Workbooks.Open(Path.GetFullPath(str1 + str2));
            wsTemplate     = wbTemplate.Sheets[str3];

            this.prgDownload.Value = 66;
            foreach (List <List <string> > stringListList2 in stringListListList)
            {
                foreach (List <string> stringList3 in stringListList2)
                {
                    this.rtbData.Text = placeInfoX[index2].Replace("競馬場", "") +
                                        Strings.StrConv(stringList3[0], VbStrConv.Wide, 0) +
                                        ".csv\n" + (object)(index1 + 1) + " / " + (object)num1;

                    // テンプレートシートの値の削除
                    wsTemplate.Cells[1, 1].ClearContents();
                    wsTemplate.Cells[1, 2].ClearContents();
                    Range  usedRangeTemp = wsTemplate.UsedRange;
                    object cell1         = wsTemplate.Cells[3, 1];
                    object cell2         = wsTemplate.Cells[usedRangeTemp.Rows.Count, 12];
                    Range  rangeTemp     = wsTemplate.Range[cell1, cell2];
                    rangeTemp.ClearContents();

                    // 調教データを反映
                    string[,] arrDataTyokyou;
                    double[,] arrdblDataTyokyou;
                    long cntRow = this.PutTyoukyouDataAllX(datetimeTarg, tyoukyouDataAllX,
                                                           cRaceUmaListList[index1], out arrDataTyokyou, out arrdblDataTyokyou);

                    cell1           = wsTemplate.Cells[3, 1];
                    cell2           = wsTemplate.Cells[3 + cntRow - 1, 3];
                    rangeTemp       = wsTemplate.Range[cell1, cell2];
                    rangeTemp.Value = arrDataTyokyou;
                    cell1           = wsTemplate.Cells[3, 4];
                    cell2           = wsTemplate.Cells[3 + cntRow - 1, 12];
                    rangeTemp       = wsTemplate.Range[cell1, cell2];
                    rangeTemp.Value = arrdblDataTyokyou;

                    // ファイル名の入力
                    wsTemplate.Cells[1, 1] = "TrainData_" +
                                             datetimeTarg.ToString("yyyyMMdd") + "_" +
                                             placeInfoX[index2].Replace("競馬場", "") + "_" +
                                             stringList3[0];
                    wsTemplate.Cells[1, 2] = stringList3[1];
                    string str5 = placeInfoX[index2].Replace("競馬場", "") +
                                  Strings.StrConv(stringList3[0], VbStrConv.Wide, 0) + ".csv";

                    // 小数点の表示
                    usedRangeTemp = wsTemplate.UsedRange;
                    cell1         = wsTemplate.Cells[3, 5];
                    cell2         = wsTemplate.Cells[3 + cntRow - 1, 12];
                    rangeTemp     = wsTemplate.Range[cell1, cell2];
                    rangeTemp.NumberFormatLocal = "0.0";

                    // 昇順ソート
                    cell1     = wsTemplate.Cells[3, 1];
                    cell2     = wsTemplate.Cells[3 + cntRow - 1, 12];
                    rangeTemp = wsTemplate.Range[cell1, cell2];
                    rangeTemp.Sort(wsTemplate.Cells[3, 12], XlSortOrder.xlAscending);

                    // 結果の反映
                    cell1     = wsTemplate.Cells[2, 152];
                    cell2     = wsTemplate.Cells[22, 158];
                    rangeTemp = wsTemplate.Range[cell1, cell2];
                    rangeTemp.Copy();
                    wsCSV.Cells[rowWrite, 1].PasteSpecial(XlPasteType.xlPasteValues);
                    rowWrite += 22;

                    // 個別ファイル出力
                    if (checkBox1.Checked)
                    {
                        cell1            = wsTemplate.Cells[3, 1];
                        cell2            = wsTemplate.Cells[3 + cntRow - 1, 12];
                        rangeTemp        = wsTemplate.Range[cell1, cell2];
                        object[,] arrTmp = rangeTemp.Value;
                        operateCsv.ConvertObjectToCsv(arrTmp, text + str5);
                    }


                    //appExl.DisplayAlerts = false;
                    //wbTemplate.Save();
                    //appExl.DisplayAlerts = true;
                    ++index1;
                    this.prgDownload.Value = 66 + 34 * index1 / num1;

                    //break;
                }
                ++index2;
                //break;
            }

            string str6 = "c" + str4 + ".csv";

            appExl.DisplayAlerts = false;
            wbCSV.SaveAs(text + str6, 6);
            wbCSV.Close(System.Type.Missing, System.Type.Missing, System.Type.Missing);
            wbTemplate.Save();
            wbTemplate.Close(System.Type.Missing, System.Type.Missing, System.Type.Missing);
            appExl.DisplayAlerts = true;

            appExl.Quit();
            Marshal.ReleaseComObject(wsTemplate);
            Marshal.ReleaseComObject(wbTemplate);
            Marshal.ReleaseComObject(wsCSV);
            Marshal.ReleaseComObject(wbCSV);
            Marshal.ReleaseComObject(appExl);

            dt = DateTime.Now;
            this.rtbData.Text  = strlogS;
            this.rtbData.Text += "\n";
            this.rtbData.Text += dt.ToString("HH:mm:ss") + " " +
                                 str4 + "調教データ取得完了しました。";
            this.AxJVLink1.JVClose();
            System.Media.SystemSounds.Asterisk.Play();
            this.prgDownload.Value = 100;
            System.Threading.Thread.Sleep(500);

            // 調教データ反映
            if (checkBox2.Checked)
            {
                cTrain.ReflectTrainMain();
                dt = DateTime.Now;
                this.rtbData.Text += "\n";
                this.rtbData.Text += dt.ToString("HH:mm:ss") + " " +
                                     str4 + "調教データ反映完了しました。";
                this.AxJVLink1.JVClose();
                System.Media.SystemSounds.Asterisk.Play();
            }

            cOperateForm.enableButton();

            sw.Stop();
            TimeSpan ts = sw.Elapsed;

            this.rtbData.Text += $"\n処理時間:{(ts.Minutes*60) + ts.Seconds}秒";
        }
コード例 #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            clsTrain cTrain = new clsTrain(this);

            cTrain.ReflectTrainMain();
        }