Ejemplo n.º 1
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            var counter    = printerTable.Rows[printCounter]["ClientAcct"].ToString().Split(',').ToList();
            var newCounter = new List <string>();

            foreach (string str in counter)
            {
                newCounter.Add(str.Trim());
            }



            FindExistingTrades finder = new FindExistingTrades(printerTable.Rows[printCounter]["Symbol"].ToString(), printerTable.Rows[printCounter]["Side"].ToString(), Convert.ToInt32(printerTable.Rows[printCounter]["Quantity"]), Convert.ToDecimal(printerTable.Rows[printCounter]["Avg_Price"]), "", 1);

            float point      = 257;
            var   brush      = Brushes.Black;
            var   background = Color.FromArgb(180, 150, 40, 27);
            var   _regFont   = new Font("Courier New", 10, FontStyle.Regular);
            var   _boldFont  = new Font("Courier New", 16, FontStyle.Bold);

            //TRADE DATA
            var issuer       = finder.getIssuer();
            var settlement   = finder.GetSettlementDate();
            var symbol       = finder.GetPwatchTicker();
            var currency     = finder.GetCurrency();
            var commission   = Convert.ToDecimal(printerTable.Rows[printCounter]["Commission"]);
            var titlePrice   = Convert.ToDecimal(printerTable.Rows[printCounter]["Avg_Price"]);
            var securityName = finder.GetSecurityName();



            var image = new Bitmap(600, 30);

            e.Graphics.FillRectangle(Brushes.LightGray, new Rectangle(60, 237, 650, 20));

            e.Graphics.DrawRectangle(Pens.Black, 60, 237, 150, 20);
            e.Graphics.DrawRectangle(Pens.Black, 210, 237, 220, 20);
            e.Graphics.DrawRectangle(Pens.Black, 430, 237, 160, 20);
            e.Graphics.DrawRectangle(Pens.Black, 590, 237, 120, 20);
            e.Graphics.DrawString("Portfolio Manager", _regFont, Brushes.Black, 60, 240);
            e.Graphics.DrawString("Portfolio", _regFont, Brushes.Black, 220, 240);
            e.Graphics.DrawString("Action", _regFont, Brushes.Black, 440, 240);
            e.Graphics.DrawString("Shares", _regFont, Brushes.Black, 600, 240);



            e.Graphics.DrawString("[Trade Ticket " + DateTime.Today.ToString("MMMM dd, yyyy") + "] - [" + printerTable.Rows[printCounter]["Side"].ToString() + "] Shares of " + symbol + " @ System Price Of " + titlePrice.ToString("C4") + "]" + Environment.NewLine + Environment.NewLine + "Printed On: " + DateTime.Now + "  |  By: " + Environment.UserName + "  |  Settlement Date: " + settlement + Environment.NewLine + Environment.NewLine + "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" + Environment.NewLine + "Security: " + securityName + " [" + symbol + "] " + Environment.NewLine + "System Broker: Instinet |  System Commission: " + (commission / 100).ToString("C4") + " " + currency + " Per Share" + Environment.NewLine + Environment.NewLine + Environment.NewLine + " Manual Price: ____________" + "     Manual Broker: _____________________" + "     Manual Commission: ________", new Font("Tahoma", 10, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, 20, 50);



            if (printerTable.Rows[printCounter]["Side"].ToString().Contains("BUY"))
            {
                brush      = Brushes.Green;
                background = Color.FromArgb(80, 0, 102, 0);
            }
            else
            {
                brush = Brushes.Red; background = Color.FromArgb(80, 255, 40, 40);
            }



            foreach (string str in newCounter)
            {
                FindExistingTrades finder2 = new FindExistingTrades(printerTable.Rows[printCounter]["Symbol"].ToString(), printerTable.Rows[printCounter]["Side"].ToString(), Convert.ToInt32(printerTable.Rows[printCounter]["Quantity"]), Convert.ToDecimal(printerTable.Rows[printCounter]["Avg_Price"]), str, 1);
                var _shares = finder2.GetShares();
                e.Graphics.DrawRectangle(Pens.Black, 60, point, 150, 20);
                e.Graphics.DrawRectangle(Pens.Black, 210, point, 220, 20);
                e.Graphics.DrawRectangle(Pens.Black, 430, point, 160, 20);
                e.Graphics.DrawRectangle(Pens.Black, 590, point, 120, 20);
                e.Graphics.DrawString(issuer, new Font("Courier New", 10), Brushes.Black, 60, point + 2);
                e.Graphics.DrawString(str, new Font("Courier New", 10), brush, 220, point + 2);
                e.Graphics.DrawString(printerTable.Rows[printCounter]["Side"].ToString(), new Font("Courier New", 10), brush, 440, point + 2);
                e.Graphics.DrawString((_shares.ToString("N0")), new Font("Courier New", 10), brush, 600, point + 2);
                point = Convert.ToInt32(point + 20);
            }


            if (printCounter < printerTable.Rows.Count - 1)
            {
                e.HasMorePages = true;
                printCounter++;
            }
            else
            {
                printCounter = 0;
                printerTable.Dispose();
                e.HasMorePages = false;
            }
        }
Ejemplo n.º 2
0
        //List<int[]> results = new List<int[]>();

        //List<Task<int[]>> T = new List<Task<int[]>>();

        #region Main Events
        private async void btnPaste_Click(object sender, EventArgs e)
        {
            DGVUpload.Rows.Clear();
            DGVUpload.Refresh();
            DGVUpload.Columns.Clear();
            // initialize datagridview columns

            addColumns();

            findAccounts();

            // List<Task<FindExistingTrades>> findTradeTask = new List<Task<FindExistingTrades>>();

            // Check if any similar trades exist

            //List<FindExistingTrades> JobList = new List<FindExistingTrades>();
            //foreach(DataGridViewRow row in DGVUpload.Rows)
            //{
            //    JobList.Add(new FindExistingTrades(row.Cells["Symbol"].Value.ToString(), row.Cells["Side"].Value.ToString(), Convert.ToInt32(row.Cells["Quantity"].Value), Convert.ToDecimal(row.Cells["Avg_Price"].Value), row.Cells["ClientAcct"].Value.ToString(), row.Index));
            //}


            //foreach(FindExistingTrades jobs in JobList)
            //{
            //    T.Add(new Task<int[]>(jobs.Find));
            //}


            //foreach(Task<int[]> tasks in T)
            //{

            //    tasks.Start();
            //    results.Add(tasks.Result);
            //}

            progressBar1.Maximum = DGVUpload.Rows.Count;
            progressBar1.Value   = 0;
            label2.Text          = "Matching...";
            foreach (DataGridViewRow row in DGVUpload.Rows)
            {
                FindExistingTrades findExisting = new FindExistingTrades(row.Cells["Symbol"].Value.ToString(), row.Cells["Side"].Value.ToString(), Convert.ToInt32(row.Cells["Quantity"].Value), Convert.ToDecimal(row.Cells["Avg_Price"].Value), row.Cells["ClientAcct"].Value.ToString(), row.Index);
                progressBar1.Increment(1);
                var searchVal = await findExisting.Find();


                if (searchVal == 2)
                {
                    row.DefaultCellStyle.BackColor = Color.LightBlue;
                    row.Cells["Status"].Value      = "Found";
                }
                else if (searchVal == 3)
                {
                    row.DefaultCellStyle.BackColor = Color.LightGreen;
                    row.Cells["Status"].Value      = "Potential trade matched";
                }
                else if (searchVal == 1)
                {
                    row.DefaultCellStyle.BackColor = Color.Yellow;
                    row.Cells["Status"].Value      = "Found similar trade, follow prompts - Price did not match";
                }
                else
                {
                    row.Cells["Status"].Value = "New trade details";
                }


                //await findExisting.Find().ContinueWith(r =>
                //{
                //    var searchVal = r.Result;
                //    if (searchVal == 2)
                //    {
                //        row.DefaultCellStyle.BackColor = Color.LightBlue;
                //        row.Cells["Status"].Value = "Found";
                //    }
                //    else if (searchVal == 3)
                //    {
                //        row.DefaultCellStyle.BackColor = Color.LightGreen;
                //        row.Cells["Status"].Value = "Found incomplete Trade";
                //    }
                //    else if (searchVal == 1)
                //    {
                //        row.DefaultCellStyle.BackColor = Color.Yellow;
                //        row.Cells["Status"].Value = "Found similar trade, follow prompts";
                //    }
                //    else
                //    {
                //        row.Cells["Status"].Value = "No Trades found";
                //    }

                //

                //}, TaskScheduler.FromCurrentSynchronizationContext());
            }



            foreach (DataGridViewRow row in DGVUpload.Rows)
            {
                FindExistingTrades finder = new FindExistingTrades(row.Cells["Symbol"].Value.ToString(), row.Cells["Side"].Value.ToString(), Convert.ToInt32(row.Cells["Quantity"].Value), Convert.ToDecimal(row.Cells["Avg_Price"].Value), row.Cells["ClientAcct"].Value.ToString(), row.Index);
                var portfolios            = finder.FindPortfolios();

                if (portfolios.Count > 1)
                {
                    row.Cells["ClientAcct"].Value = String.Join(", ", portfolios.ToArray());
                }
                else if (portfolios.Count == 1)
                {
                    if (portfolios[0] != "")
                    {
                        row.Cells["ClientAcct"].Value = portfolios[0];
                    }
                }

                row.Cells["Commission"].Value = finder.getCommission() * 100;
            }
            try
            {
                modifyColumns();
                if (DGVUpload.Controls.Find("chk", true).Count() == 0)
                {
                    addCheckBox();
                }
            }
            catch
            {
                return;
            }

            label2.Text         = "Done";
            btnUpload.Enabled   = true;
            btnUpload.ForeColor = Color.White;
            //DGVUpload.Columns["chkBoxCol"].Width = 20;
            foreach (DataGridViewRow row in DGVUpload.Rows)
            {
                if (row.DefaultCellStyle.BackColor == Color.LightBlue)
                {
                    btnPrint.Enabled = true;
                    return;
                }
            }
        }