private void btnDcaSimlulate_Click(object sender, EventArgs e)
 {
     try
     {
         DateTime value = this.dateTimePicker1.Value;
         DateTime value2 = this.dateTimePicker2.Value;
         if (this.cbDcaStock.Text == string.Empty)
         {
             this.ShowMessageBox("Invalid symbol", frmOrderFormConfirm.OpenStyle.Error, this.cbDcaStock);
         }
         else
         {
             StockList.StockInformation stockInformation = ApplicationInfo.StockInfo[this.cbDcaStock.Text];
             if (stockInformation.Number <= 0)
             {
                 this.ShowMessageBox("Invalid symbol", frmOrderFormConfirm.OpenStyle.Error, this.cbDcaStock);
             }
             else
             {
                 long num;
                 long.TryParse(this.tbDcaBudget.Text.Replace(",", ""), out num);
                 if (num <= 0L)
                 {
                     this.ShowMessageBox("Invalid budget!!!", frmOrderFormConfirm.OpenStyle.Error, this.tbDcaBudget);
                 }
                 else if (value.ToShortDateString() == DateTime.Now.ToShortDateString())
                 {
                     this.ShowMessageBox("Start date is tomorrow onwards.", frmOrderFormConfirm.OpenStyle.Error, this.dateTimePicker1);
                 }
                 else if (value < DateTime.Now)
                 {
                     this.ShowMessageBox("Start date is tomorrow onwards.", frmOrderFormConfirm.OpenStyle.Error, this.dateTimePicker1);
                 }
                 else if (value2 <= value)
                 {
                     this.ShowMessageBox("Invalid end date!!!", frmOrderFormConfirm.OpenStyle.Error, this.dateTimePicker2);
                 }
                 else
                 {
                     if (this.cbDcaTiming.Text.ToLower() == "every day")
                     {
                         DateTime dateTime = this.getNextDate(value);
                         List<DateTime> list = new List<DateTime>();
                         while (dateTime <= value2)
                         {
                             list.Add(dateTime);
                             dateTime = dateTime.AddDays(1.0);
                             dateTime = this.getNextDate(dateTime);
                         }
                         if (list.Count <= 0)
                         {
                             this.ShowMessageBox("Can not create command Please check the terms", frmOrderFormConfirm.OpenStyle.Error, null);
                             return;
                         }
                         decimal num2 = (list.Count > 0) ? (num / (long)list.Count) : 0L;
                         this.gridDcaSimm.Rows = list.Count;
                         int i = 0;
                         foreach (DateTime current in list)
                         {
                             RecordItem recordItem = this.gridDcaSimm.Records(i);
                             recordItem.Fields("no").Text = i + 1;
                             recordItem.Fields("date").Text = current.ToString("dd MMM yy");
                             recordItem.Fields("tmp_date").Text = current.ToString("yyyyMMdd");
                             recordItem.Fields("budget").Text = num2.ToString();
                             i++;
                         }
                         list.Clear();
                         this.gridDcaSimm.Redraw();
                     }
                     else if (this.cbDcaTiming.Text.ToLower() == "every week")
                     {
                         DateTime dateTime = value;
                         DayOfWeek dayOfWeek = DayOfWeek.Sunday;
                         string text = this.cbDcaTiming2.Text.ToLower().Trim();
                         if (text != null)
                         {
                             if (!(text == "monday"))
                             {
                                 if (!(text == "tuesday"))
                                 {
                                     if (!(text == "wednesday"))
                                     {
                                         if (!(text == "thursday"))
                                         {
                                             if (text == "friday")
                                             {
                                                 dayOfWeek = DayOfWeek.Friday;
                                             }
                                         }
                                         else
                                         {
                                             dayOfWeek = DayOfWeek.Thursday;
                                         }
                                     }
                                     else
                                     {
                                         dayOfWeek = DayOfWeek.Wednesday;
                                     }
                                 }
                                 else
                                 {
                                     dayOfWeek = DayOfWeek.Tuesday;
                                 }
                             }
                             else
                             {
                                 dayOfWeek = DayOfWeek.Monday;
                             }
                         }
                         dateTime = this.getNextWeek(dateTime, dayOfWeek);
                         List<DateTime> list = new List<DateTime>();
                         while (dateTime <= value2)
                         {
                             list.Add(dateTime);
                             dateTime = dateTime.AddDays(1.0);
                             dateTime = this.getNextWeek(dateTime, dayOfWeek);
                             if (dateTime > value2)
                             {
                                 break;
                             }
                         }
                         if (list.Count <= 0)
                         {
                             this.ShowMessageBox("Can not create command Please check the terms", frmOrderFormConfirm.OpenStyle.Error, null);
                             return;
                         }
                         decimal num2 = (list.Count > 0) ? (num / (long)list.Count) : 0L;
                         this.gridDcaSimm.Rows = list.Count;
                         int i = 0;
                         foreach (DateTime current in list)
                         {
                             RecordItem recordItem = this.gridDcaSimm.Records(i);
                             recordItem.Fields("no").Text = i + 1;
                             recordItem.Fields("date").Text = current.ToString("dd MMM yy");
                             recordItem.Fields("tmp_date").Text = current.ToString("yyyyMMdd");
                             recordItem.Fields("budget").Text = num2.ToString();
                             i++;
                         }
                         list.Clear();
                         this.gridDcaSimm.Redraw();
                     }
                     else if (this.cbDcaTiming.Text.ToLower() == "every month")
                     {
                         DateTime dateTime = value;
                         int dayOfMonth;
                         int.TryParse(this.cbDcaTiming2.Text, out dayOfMonth);
                         int num3 = dateTime.Month;
                         int num4 = dateTime.Year;
                         dateTime = this.getNextMonth(dateTime, num3, num4, dayOfMonth);
                         List<DateTime> list = new List<DateTime>();
                         while (dateTime <= value2)
                         {
                             list.Add(dateTime);
                             num3++;
                             if (num3 > 12)
                             {
                                 num3 = 1;
                                 num4++;
                             }
                             dateTime = dateTime.AddDays(1.0);
                             dateTime = this.getNextMonth(dateTime, num3, num4, dayOfMonth);
                             if (dateTime > value2)
                             {
                                 break;
                             }
                         }
                         if (list.Count <= 0)
                         {
                             this.ShowMessageBox("Can not create command Please check the terms", frmOrderFormConfirm.OpenStyle.Error, null);
                             return;
                         }
                         decimal num2 = (list.Count > 0) ? (num / (long)list.Count) : 0L;
                         this.gridDcaSimm.Rows = list.Count;
                         int i = 0;
                         foreach (DateTime current in list)
                         {
                             RecordItem recordItem = this.gridDcaSimm.Records(i);
                             recordItem.Fields("no").Text = i + 1;
                             recordItem.Fields("date").Text = current.ToString("dd MMM yy");
                             recordItem.Fields("tmp_date").Text = current.ToString("yyyyMMdd");
                             recordItem.Fields("budget").Text = num2.ToString();
                             i++;
                         }
                         list.Clear();
                         this.gridDcaSimm.Redraw();
                     }
                     string text2 = this.cbDcaStock.Text;
                     if (text2 == string.Empty)
                     {
                         this.ShowMessageBox("Invalid order symbol", frmOrderFormConfirm.OpenStyle.Error, this.cbDcaStock);
                     }
                     else
                     {
                         stockInformation = ApplicationInfo.StockInfo[text2];
                         if (stockInformation.Number <= 0)
                         {
                             this.ShowMessageBox("Invalid order symbol", frmOrderFormConfirm.OpenStyle.Error, this.cbDcaStock);
                         }
                         else if (num <= 0L)
                         {
                             this.ShowMessageBox("Invalid budget!", frmOrderFormConfirm.OpenStyle.Error, this.tbDcaBudget);
                         }
                         else if (value == DateTime.MinValue || value2 == DateTime.MinValue)
                         {
                             this.ShowMessageBox("Invalid date!", frmOrderFormConfirm.OpenStyle.Error, this.dateTimePicker1);
                         }
                         else if (this.gridDcaSimm.Rows <= 0)
                         {
                             this.ShowMessageBox("Transaction not found!", frmOrderFormConfirm.OpenStyle.Error, this.dateTimePicker2);
                         }
                         else
                         {
                             this._commandDca = new AutoTradeDCACommand();
                             this._commandDca.UserId = ApplicationInfo.UserLoginID;
                             this._commandDca.Account = ApplicationInfo.AccInfo.CurrentAccount;
                             this._commandDca.CustType = ApplicationInfo.AccInfo.Items[ApplicationInfo.AccInfo.CurrentAccount].PcFlag;
                             this._commandDca.Symbol = text2;
                             this._commandDca.CommandType = "ADD";
                             this._commandDca.Budget = num;
                             CultureInfo cultureInfo = new CultureInfo("en-US");
                             this._commandDca.StartDate = value.ToString("yyyyMMdd");
                             this._commandDca.EndDate = value2.ToString("yyyyMMdd");
                             if (this.cbDcaTiming.Text.ToLower().IndexOf("day") > 0)
                             {
                                 this._commandDca.Period = "D";
                             }
                             else if (this.cbDcaTiming.Text.ToLower().IndexOf("week") > 0)
                             {
                                 this._commandDca.Period = "W";
                             }
                             else if (this.cbDcaTiming.Text.ToLower().IndexOf("month") > 0)
                             {
                                 this._commandDca.Period = "M";
                             }
                             this._commandDca.Items = new List<AutoTradeDCAItem>();
                             for (int i = 0; i < this.gridDcaSimm.Rows; i++)
                             {
                                 RecordItem recordItem = this.gridDcaSimm.Records(i);
                                 long.TryParse(recordItem.Fields("budget").Text.ToString().Replace(",", ""), out num);
                                 if (num <= 0L)
                                 {
                                     this.ShowMessageBox("The budget is not enough!", frmOrderFormConfirm.OpenStyle.Error, this.tbDcaBudget);
                                     break;
                                 }
                                 AutoTradeDCAItem item = new AutoTradeDCAItem(i + 1, recordItem.Fields("tmp_date").Text.ToString(), num, this._commandDca.Account, this._commandDca.CustType);
                                 this._commandDca.Items.Add(item);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         this.ShowError("btn3Simlulate_Click", ex);
     }
 }
 private void btnDcaCancel_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.gridDcaMain.FocusItemIndex > -1 && AutoTradeConstant.GetStatusByName(this.gridDcaMain.Records(this.gridDcaMain.FocusItemIndex).Fields("status").Text.ToString(), this._typeId) == "ST")
         {
             RecordItem recordItem = this.gridDcaMain.Records(this.gridDcaMain.FocusItemIndex);
             long num;
             long.TryParse(recordItem.Fields("refno").Text.ToString(), out num);
             string text = recordItem.Fields("stock").Text.ToString();
             AutoTradeDCACommand autoTradeDCACommand = new AutoTradeDCACommand();
             autoTradeDCACommand.RefNo = num;
             autoTradeDCACommand.Symbol = text;
             autoTradeDCACommand.CommandType = "CANCEL";
             autoTradeDCACommand.Items = new List<AutoTradeDCAItem>();
             this._commandMain = new AutoTradeMain();
             this._commandMain.Pack("DCA", autoTradeDCACommand);
             string orderParam = string.Concat(new object[]
             {
                 "Dolla Cost Average :",
                 "Cancel DCA , Reference no ",
                 num,
                 "\nStock : ‘",
                 text,
                 "’"
             });
             this.ShowOrderFormConfirm("Do you want to cancel?\r\n", orderParam, frmOrderFormConfirm.OpenStyle.ConfirmCancel);
         }
         else
         {
             this.ShowMessageBox("Can not find the item you want to cancel.", frmOrderFormConfirm.OpenStyle.ShowBox, null);
         }
     }
     catch (Exception ex)
     {
         this.ShowError("btn3Cancel_Click", ex);
     }
 }