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 System.Threading;
namespace Ticker_Simulation
{
public partial class Conditions : Form
{
int TargetRow;
int TargetColumn;
static volatile bool StartStop;
double intPriceChange;
double intPrice;
double OldPrice;
double intVolatility;
public Conditions()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
btnEnter.Text = "Running";
string price = txtPrice.Text;
intPrice = Convert.ToDouble(price);
string volatility = txtVolatility.Text;
intVolatility = Convert.ToDouble(volatility);
intPriceChange = ((intVolatility / 10) / 100) * intPrice;
StartStop = false;
Thread myThread = new Thread(myThreadedMethod);
myThread.Start();
//this.Hide();
}
public void myThreadedMethod()
{
while (!StartStop)
{
Random firstRandomNumber = new Random();
double x = firstRandomNumber.Next() % 100;
if (x % 2 == 0)
{
if (Globals.ThisAddIn.Application.ActiveSheet.Cells(TargetRow, TargetColumn).Value == null)
{
OldPrice = intPrice;
}
else
{
OldPrice = Globals.ThisAddIn.Application.ActiveSheet.Cells(TargetRow, TargetColumn).Value;
}
try
{
double NewPrice = OldPrice - intPriceChange;
Globals.ThisAddIn.Application.ActiveSheet.Cells(TargetRow, TargetColumn).Value = NewPrice;
}
catch
{
}
}
else
{
if (Globals.ThisAddIn.Application.ActiveSheet.Cells(TargetRow, TargetColumn).Value == null)
{
OldPrice = intPrice;
}
else
{
OldPrice = Globals.ThisAddIn.Application.ActiveSheet.Cells(TargetRow, TargetColumn).Value;
}
double NewPrice = OldPrice + intPriceChange;
Globals.ThisAddIn.Application.ActiveSheet.Cells(TargetRow, TargetColumn).Value = NewPrice;
}
Thread.Sleep(500);
}
}
private void txtPrice_TextChanged(object sender, EventArgs e)
{
}
private void txtVolatility_TextChanged(object sender, EventArgs e)
{
}
private void txtTargetCellRow_TextChanged(object sender, EventArgs e)
{
try
{
string strTargetRow = txtTargetCellRow.Text;
TargetRow = Convert.ToInt32(strTargetRow);
}
catch
{
txtTargetCellRow.Text = "";
Error theError = new Error();
theError.Show();
}
}
private void btnStop_Click_1(object sender, EventArgs e)
{
//Globals.ThisAddIn.Application.ActiveSheet.Cells(TargetRow +1, TargetColumn+1).Value = StartStop;
}
private void btnStop_Click(object sender, EventArgs e)
{
btnEnter.Text = "Enter";
StartStop = true;
}
private void txtTargetCellColumn_TextChanged_1(object sender, EventArgs e)
{
try
{
string strTargetColumn = txtTargetCellColumn.Text;
TargetColumn = Convert.ToInt32(strTargetColumn);
}
catch
{
txtTargetCellColumn.Text = "";
Error theError = new Error();
theError.Show();
}
}
}
}