Created
October 1, 2012 11:47
-
-
Save anonymous/3811148 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace BetRates_NS | |
{ | |
public partial class Rates : Form | |
{ | |
public Rates() | |
{ | |
InitializeComponent(); | |
} | |
BackgroundWorker bw = new BackgroundWorker(); | |
private BFGlobalService bfg1 = new BFGlobalService(); | |
private BFExchangeService.BFExchangeService bfg2 = new BetRates_NS.BFExchangeService.BFExchangeService(); | |
public void ClearTextBoxes(Control control) | |
{ | |
foreach (Control c in control.Controls) | |
{ | |
if (c is TextBox) | |
{ | |
((TextBox)c).Clear(); | |
} | |
if (c.HasChildren) | |
{ | |
ClearTextBoxes(c); | |
} | |
} | |
} | |
public delegate void RefreshRates1(object mark); | |
private void RefreshRates(object marketid_t) | |
{ | |
try | |
{ | |
int marketid_temp = Convert.ToInt32(marketid_t); | |
//ClearTextBoxes(this); | |
BFExchangeService.APIRequestHeader header2 = new BetRates_NS.BFExchangeService.APIRequestHeader(); | |
header2.clientStamp = 0; | |
header2.sessionToken = sessionToken; | |
//**************************** GET PRICES FROM WEB SERVICE **************************** | |
GetMarketPricesCompressedReq price_req1 = new GetMarketPricesCompressedReq(); | |
price_req1.header = header2; | |
price_req1.marketId = marketId1; | |
price_req1.currencyCode = "GBP"; | |
GetMarketPricesCompressedResp price_resp = new GetMarketPricesCompressedResp(); | |
price_resp = bfg2.getMarketPricesCompressed(price_req1); | |
string prices = price_resp.marketPrices; | |
string[] Parts = prices.Split(':'); | |
BeginInvoke(new Is_InPlay1(is_InPlay), new object[] { Parts[0] }); | |
BeginInvoke(new FillData1(fillData), new object[] { Parts.Length - 1, Parts }); | |
} | |
catch (Exception ep) | |
{ | |
} | |
} | |
public delegate void Is_InPlay1(string temp1); | |
private void is_InPlay(string temp) | |
{ | |
string[] check = temp.Split('~'); | |
if (Convert.ToInt32(check[3]) != 0) | |
{ | |
inPlay = true; | |
pictureBox2.Visible = true; | |
ToolTip t1 = new ToolTip(); | |
t1.SetToolTip(this.pictureBox2, "InPlay"); | |
} | |
else | |
{ | |
inPlay = false; | |
pictureBox2.Visible = false; | |
} | |
} | |
//******************* FORM LOAD ********************************* | |
private void Rates_Load(object sender, EventArgs e) | |
{ | |
this.Text = match_name; | |
//lbl_match.Text = match_name; | |
BFExchangeService.APIRequestHeader header2 = new BetRates_NS.BFExchangeService.APIRequestHeader(); | |
header2.clientStamp = 0; | |
header2.sessionToken = sessionToken; | |
GetMarketReq market_req1 = new GetMarketReq(); | |
market_req1.header = header2; | |
market_req1.marketId = Convert.ToInt32(marketId1); | |
GetMarketResp market_resp1= bfg2.getMarket(market_req1); | |
Market market1 = market_resp1.market; | |
Runner[] runners_list = market1.runners; | |
makeMyRows(runners_list.Length); | |
this.Height=60+(36*runners_list.Length); | |
int max_length = 0; | |
for (int i = 0; i < runners_list.Length; i++) | |
{ | |
if (max_length < runners_list[i].name.Length) | |
{ | |
max_length = runners_list[i].name.Length; | |
} | |
int label_counter = i + 1; | |
string ctrl_name = "lbl" + label_counter.ToString(); | |
Label temp = null; | |
foreach (Control ctl in this.Controls) | |
{ | |
if ((ctl is Label) && (ctl.Name == ctrl_name)) | |
{ temp = (Label)ctl; } | |
} | |
if (temp != null) | |
{ temp.Text = runners_list[i].name; } | |
} | |
bw.DoWork += new DoWorkEventHandler(bw_DoWork); | |
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer(); | |
myTimer.Interval = 200; | |
myTimer.Tick += new EventHandler(myTimer_Tick); | |
myTimer.Enabled = true; | |
//-------------------------------------------------------------------------- | |
this.Focus(); | |
if (this.VerticalScroll.Visible == true) | |
{ | |
this.Width = this.Width + 24; | |
} | |
} | |
private void OnTimedEvent(object source, ElapsedEventArgs e) | |
{ | |
RefreshRates(marketId1); | |
} | |
void bw_DoWork(object sender, DoWorkEventArgs e) | |
{ | |
RefreshRates(marketId1); | |
} | |
private void button1_Click_1(object sender, EventArgs e) | |
{ | |
this.Refresh(); | |
this.RefreshRates(marketId1); | |
} | |
private void groupBox1_Enter(object sender, EventArgs e) | |
{ | |
} | |
public delegate void FillData1(int count1, string[] parts1); | |
private void fillData(int count,string[] Parts) | |
{ | |
for (int i = 1; i <= count; i++) | |
{ | |
string[] subParts = Parts[i].Split('|'); | |
for (int j = 1; j <= subParts.Length-1; j++) | |
{ | |
string[] Fields = subParts[j].Split('~'); | |
for (int k = 1; k <= 6; k++) | |
{ | |
string compare_txt = ""; | |
string ctrl_name = "txt" + i.ToString() + k.ToString(); | |
TextBox temp = null;// = (TextBox)findCtrl(ctrl_name); | |
//foreach (Control ctl in this.Controls) | |
//{ | |
// if ((ctl is TextBox) && (ctl.Name == ctrl_name)) | |
// { temp = (TextBox)ctl; } | |
//} | |
Control ctl = this.Controls.Find(ctrl_name, true)[0]; | |
if ((ctl is TextBox) && (ctl.Name == ctrl_name)) | |
{ temp = (TextBox)ctl; } | |
if (j == 1) | |
{ | |
switch (k) | |
{ | |
case 1: | |
compare_txt = temp.Text; | |
temp.Text = ""; | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, "" }); | |
if (Fields.Length >= 9) | |
{ | |
if (!string.IsNullOrEmpty(Fields[8])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, Fields[8] }); | |
temp.Text = Fields[8]; | |
} | |
} | |
if (Fields.Length >= 10) | |
{ | |
if (!string.IsNullOrEmpty(Fields[9])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, temp.Text + "\r\n£" + Fields[9] }); | |
temp.Text = temp.Text + "\r\n£" + Fields[9]; | |
} | |
} | |
if (temp.Text != compare_txt)//check if value has changed, if yes blink | |
{ temp.BackColor = Color.LightGreen; } | |
else | |
{ temp.BackColor = Color.Lavender; } | |
break; | |
case 2: | |
compare_txt = temp.Text; | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, "" }); | |
temp.Text = ""; | |
if (Fields.Length >= 5) | |
{ | |
if (!string.IsNullOrEmpty(Fields[4])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, Fields[4] }); | |
temp.Text = Fields[4]; | |
} | |
} | |
if (Fields.Length >= 6) | |
{ | |
if (!string.IsNullOrEmpty(Fields[5])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, temp.Text + "\r\n£" + Fields[5] }); | |
temp.Text = temp.Text + "\r\n£" + Fields[5]; | |
} | |
} | |
if (temp.Text == compare_txt) | |
{ temp.BackColor = Color.Thistle; } | |
else | |
{ temp.BackColor = Color.LightGreen; } | |
break; | |
case 3: | |
compare_txt = temp.Text; | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, "" }); | |
temp.Text = ""; | |
if (Fields.Length >= 1) | |
{ | |
if (!string.IsNullOrEmpty(Fields[0])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, Fields[0] }); | |
temp.Text = Fields[0]; | |
} | |
} | |
if (Fields.Length >= 2) | |
{ | |
if (!string.IsNullOrEmpty(Fields[1])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, temp.Text + "\r\n£" + Fields[1] }); | |
temp.Text = temp.Text + "\r\n£" + Fields[1]; | |
} | |
} | |
if (temp.Text == compare_txt) | |
{ temp.BackColor = Color.FromArgb(192, 192, 255); } | |
else | |
{ temp.BackColor = Color.LightGreen; } | |
break; | |
} | |
} | |
else if (j == 2) | |
{ | |
switch (k) | |
{ | |
case 4: | |
compare_txt = temp.Text; | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, "" }); | |
temp.Text = ""; | |
if (Fields.Length >= 1) | |
{ | |
if (!string.IsNullOrEmpty(Fields[0])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, Fields[0] }); | |
temp.Text = Fields[0]; | |
} | |
} | |
if (Fields.Length >= 2) | |
{ | |
if (!string.IsNullOrEmpty(Fields[1])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, temp.Text + "\r\n£" + Fields[1] }); | |
temp.Text = temp.Text + "\r\n£" + Fields[1]; | |
} | |
} | |
if (temp.Text == compare_txt) | |
{ temp.BackColor = Color.FromArgb(255, 192, 192); } | |
else | |
{ temp.BackColor = Color.LightGreen; } | |
break; | |
case 5: | |
compare_txt = temp.Text; | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, "" }); | |
temp.Text = ""; | |
if (Fields.Length >= 5) | |
{ | |
if (!string.IsNullOrEmpty(Fields[4])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, Fields[4] }); | |
temp.Text = Fields[4]; | |
} | |
} | |
if (Fields.Length >= 6) | |
{ | |
if (!string.IsNullOrEmpty(Fields[5])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, temp.Text + "\r\n£" + Fields[5] }); | |
temp.Text = temp.Text + "\r\n£" + Fields[5]; | |
} | |
} | |
if (temp.Text == compare_txt) | |
{ temp.BackColor = Color.MistyRose; } | |
else | |
{ temp.BackColor = Color.LightGreen; } | |
break; | |
case 6: | |
compare_txt = temp.Text; | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, "" }); | |
temp.Text = ""; | |
if (Fields.Length >= 9) | |
{ | |
if (!string.IsNullOrEmpty(Fields[8])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, Fields[8] }); | |
temp.Text = Fields[8]; | |
} | |
} | |
if (Fields.Length >= 10) | |
{ | |
if (!string.IsNullOrEmpty(Fields[9])) | |
{ | |
//BeginInvoke(new AddText1(AddText), new object[] { ctrl_name, temp.Text + "\r\n£" + Fields[9] }); | |
temp.Text = temp.Text + "\r\n£" + Fields[9]; | |
} | |
} | |
if (temp.Text == compare_txt) | |
{ temp.BackColor = Color.Lavender; } | |
else | |
{ temp.BackColor = Color.LightGreen; } | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
public delegate void AddText1(string ctrl_n, string text_a); | |
private void AddText(string ctrl_name, string text_assign) | |
{ | |
TextBox temp = null;// = (TextBox)findCtrl(ctrl_name); | |
foreach (Control ctl in this.Controls) | |
{ | |
if ((ctl is TextBox) && (ctl.Name == ctrl_name)) | |
{ temp = (TextBox)ctl; } | |
} | |
temp.Text = text_assign; | |
} | |
private void makeMyRows(int count) | |
{ | |
int X = 10, Y = 23; | |
for (int i = 1; i <= count; i++) | |
{ | |
Label label = new Label(); | |
label.Name = "lbl" + i.ToString(); | |
label.Location = new Point(X, Y); | |
label.BackColor = Color.Transparent; | |
label.Font=new Font("Calibri Sans-Serif", 10); | |
label.Font = new Font(label.Font, FontStyle.Bold); | |
label.ForeColor = Color.White; | |
this.Controls.Add(label); | |
X = X + 118; | |
for (int j = 1; j <= 6; j++) | |
{ | |
TextBox tb = new TextBox(); | |
tb.Name = "txt" + i.ToString() + j.ToString(); | |
tb.ReadOnly = true; | |
tb.Location = new Point(X,Y); | |
tb.Size = new Size(55, 30); | |
tb.Font = new System.Drawing.Font("Arial, Helvetica, sans-serif", (float)7.5); | |
tb.TextAlign = HorizontalAlignment.Center; | |
tb.BorderStyle = BorderStyle.FixedSingle; | |
tb.Font = new Font(tb.Font, FontStyle.Bold); | |
tb.Multiline = true; | |
switch (j) | |
{ | |
case 1: | |
tb.BackColor = Color.Lavender; | |
break; | |
case 2: | |
tb.BackColor = Color.Thistle; | |
break; | |
case 3: | |
tb.BackColor = Color.FromArgb(192, 192, 255); | |
break; | |
case 4: | |
tb.BackColor = Color.FromArgb(255, 192, 192); | |
break; | |
case 5: | |
tb.BackColor = Color.MistyRose; | |
break; | |
case 6: | |
tb.BackColor = Color.Lavender; | |
break; | |
} | |
this.Controls.Add(tb); | |
X = X + 61; | |
} | |
X = 10; Y = Y + 36; | |
} | |
} | |
//************preventing flicker************* | |
int originalExStyle = -1; | |
bool enableFormLevelDoubleBuffering = true; | |
protected override CreateParams CreateParams | |
{ | |
get | |
{ | |
if (originalExStyle == -1) | |
originalExStyle = base.CreateParams.ExStyle; | |
CreateParams cp = base.CreateParams; | |
if (enableFormLevelDoubleBuffering) | |
cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED | |
else | |
cp.ExStyle = originalExStyle; | |
return cp; | |
} | |
} | |
private void TurnOffFormLevelDoubleBuffering() | |
{ | |
enableFormLevelDoubleBuffering = false; | |
this.MaximizeBox = true; | |
} | |
private void Rates_Shown(object sender, EventArgs e) | |
{ | |
TurnOffFormLevelDoubleBuffering(); | |
} | |
//****************************************** | |
private void pictureBox2_Click(object sender, EventArgs e) | |
{ | |
} | |
private void pictureBox1_Click(object sender, EventArgs e) | |
{ | |
this.Refresh(); | |
RefreshRates(marketId1); | |
} | |
private void pictureBox1_MouseLeave(object sender, EventArgs e) | |
{ | |
pictureBox1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Refresh1)); | |
} | |
private void pictureBox1_MouseEnter(object sender, EventArgs e) | |
{ | |
pictureBox1.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Refresh_hover)); | |
} | |
private void Rates_FormClosing(object sender, FormClosingEventArgs e) | |
{ | |
//t.Abort(); | |
//Webservicethread.Abort(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment