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 FormOption : Form
    {
        private static string str = "ICE.TWF.{0}.{1}.{2}.{3}";
        public FormOption()
        {
            InitializeComponent();
            setCategory(false);
            txtAct.Text = iniData.instance.d.account;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OrderData o = new OrderData();
            string symbol;
            symbol = string.Format(str, txtSymbol.Text, txtMonth.Text, cbbCallPut.SelectedItem.ToString().Substring(0, 1), txtStrikePrice.Text);
            o.orderCategory = "O";  //0:委託類別
            o.account = txtAct.Text;//1:帳號
            o.symbolID = symbol;//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.ToDouble(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:倉別 0:新倉,1:平倉
            o.callPut = cbbCallPut.SelectedItem.ToString().Substring(0, 1);//16:CallPut
            o.strikePrice = Convert.ToDouble(txtStrikePrice.Text);
            if (cbbCategory.SelectedItem.ToString().Substring(0, 1) == "2")
            {
                o.orderCategory = "O2";
                o.symbolID2 = string.Format(str, txtSymbol2.Text, txtMonth2.Text, cbbCallPut2.SelectedItem.ToString().Substring(0, 1), txtStrikePrice2.Text);//20商品ID2
                o.buySell2 = cbbBuySell2.SelectedItem.ToString().Substring(0, 1);//21買賣別2
                o.commYM2 = txtMonth2.Text;//22商品年月2
                o.callPut2 = cbbCallPut2.SelectedItem.ToString().Substring(0, 1);//23CallPut
                o.strikePrice2 = Convert.ToDouble(txtStrikePrice2.Text);//24履約價2
            }
            Form1.instance.Order(o);
        }

        private void cbbCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbCategory.SelectedItem.ToString().Substring(0, 1) == "1")
            {
                setCategory(false);
                cbbOrderType.SelectedIndex = 0;
            }
            else
            {
                setCategory(true);
                cbbOrderType.SelectedIndex = 2;
            }
        }
        private void setCategory(bool tag)
        {
            txtMonth2.Visible = tag;
            txtSymbol2.Visible = tag;
            txtStrikePrice2.Visible = tag;
            cbbBuySell2.Visible = tag;
            cbbCallPut2.Visible = tag;
        }
    }
}
