using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MasterLinkFutures.Data;
using MasterLinkFutures.utils;
namespace MasterLinkFutures
{
    public partial class FormFutures : Form
    {
        private static string str = "ICE.TWF.{0}.{1}";
        public FormFutures()
        {
            InitializeComponent();
            txtMonth2.Visible = false;
            txtSymbol2.Visible = false;
            cbbBuySell2.Visible = false;
            txtAct.Text = iniData.instance.d.account;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OrderData o = new OrderData();
            o.orderCategory = "F";  //0:委託類別
            o.account = txtAct.Text;//1:帳號
            o.symbolID = string.Format(str,txtSymbol.Text,txtMonth.Text);//2:商品ID
            o.orderType = cbbOrderType.SelectedItem.ToString().Substring(0, 1);//3:委託別
            o.buySell = cbbBuySell.SelectedItem.ToString().Substring(0, 1);//4:買賣
            o.priceFlag = cbbPriceFlag.SelectedItem.ToString().Substring(0, 1);//5:價格別
            o.price = Convert.ToInt32(txtPrice.Text);//6:委託價格
            o.qty = Convert.ToInt32(txtQty.Text);//7:委託數量
            o.marketType = "";//8:市場別(證券)
            o.marketAP = "";//9:盤別(證券)
            o.dayTrade = cbbDayTrade.SelectedItem.ToString().Substring(0, 1);//10:當沖 Y/N
            o.userKey = genUserKey.instance.getKey();//11 UserKey
            o.marketNo = "";//12交易所代碼
            o.commYM = txtMonth.Text;//13商品年月
            o.stopPrice = 0;//14:停損價格
            o.openClose = cbbOpenClose.SelectedItem.ToString().Substring(0, 1);//15:倉別
            if (cbbCategory.SelectedItem.ToString().Substring(0, 1) == "2")
            {
                o.orderCategory = "F2";
                o.symbolID2 = string.Format(str, txtSymbol2.Text, txtMonth2.Text);//20商品ID2
                o.buySell2 = cbbBuySell2.SelectedItem.ToString().Substring(0, 1);//21買賣別2
                o.commYM2 = txtMonth2.Text;//22商品年月2
            }
            //int cnt = Convert.ToInt16(textBox1.Text);
            //for (int i = 0; i < cnt; i++)
            //{
            //    Form1.instance.Order(o);
            //    o.userKey = genUserKey.instance.getKey();//11 UserKey
            //}
            Form1.instance.Order(o);
        }

        private void cbbCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbCategory.SelectedItem.ToString().Substring(0, 1) == "1")
            {
                txtMonth2.Visible = false;
                txtSymbol2.Visible = false;
                cbbBuySell2.Visible = false;
            }
            else
            {
                txtMonth2.Visible = true;
                txtSymbol2.Visible = true;
                cbbBuySell2.Visible = true;
            }
        }

        private void cbbBuySell_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbBuySell.SelectedItem.ToString().Substring(0, 1) == "B")
            {
                cbbBuySell2.SelectedIndex = 1;
            }
            else
            {
                cbbBuySell2.SelectedIndex = 0;
            }
        }
    }
}
