Example #1
0
        private void frmWatchlist_Load(object sender, EventArgs e)
        {
            //dgWList.DataSource = pDalTest.LatestValue();
            WatchList_Design();
            string sDM = "", sVM = "", sHTML = "";

            char[]   cfilter = { '\r', '\t' };
            string[] sValues;
            int      iPBValue = 0;

            DataView dtWatchList;

            theParent = (frmMain)this.ParentForm; //To access MDI parent control
            theParent.lblDMMsg.Text  = "All script loading..";
            theParent.pBarDM.Visible = true;

            Cursor = Cursors.WaitCursor;
            try
            {
                dtWatchList = pDalWatchLest.Stocks(ref sDM, ref sVM, 1);

                theParent.pBarDM.Maximum = dtWatchList.Table.Rows.Count;
                //for (int ii = 0; ii < dtWatchList.Table.Rows.Count; ii++)
                foreach (DataRow dtRow in dtWatchList.Table.Rows)
                {
                    Application.DoEvents();
                    dgWList.Rows.Add();
                    dgWList[0, iPBValue].Value = dtRow[2].ToString();
                    theParent.lblDMMsg.Text    = "Reading " + dgWList[0, iPBValue].Value;

                    if (dtRow[5].ToString().Trim() != "")
                    {
                        //Reading from Rediff returns true once the reading successfully
                        if (CommonDoubleM.RediffStockLatestUpdates(dtRow[5].ToString(), ref sHTML))
                        {
                            sHTML   = CommonDoubleM.StripHTML(sHTML);
                            sValues = sHTML.Split(cfilter);
                            for (int i = 0; i < sValues.Length; i++)
                            {
                                switch (sValues[i].Trim())
                                {
                                case "Last traded":
                                    dgWList[1, iPBValue].Value = sValues[i + 1].Trim();
                                    break;

                                case "Change":
                                    dgWList[2, iPBValue].Value = sValues[i + 1].Trim();
                                    break;

                                case "Time":
                                    dgWList[3, iPBValue].Value = sValues[i + 1].Trim();
                                    break;

                                case "Prev Close":
                                    dgWList[4, iPBValue].Value = sValues[i + 1].Trim();
                                    break;

                                case "DaysH/L(Rs)":
                                    dgWList[5, iPBValue].Value = sValues[i + 1].Trim();
                                    break;

                                case "52wkH/L(Rs)":
                                    dgWList[6, iPBValue].Value = sValues[i + 1].Trim();
                                    break;

                                case "Volume":
                                    dgWList[7, iPBValue].Value = sValues[i + 1].Trim();
                                    break;

                                case "MktCap(RsCr)":
                                    dgWList[8, iPBValue].Value = sValues[i + 1].Trim();
                                    break;
                                }
                            }
                            // dgWList[2, iPBValue].Value = sHTML;
                        }
                    }
                    else
                    {
                        dgWList[1, iPBValue].Value = "--";
                    }

                    theParent.pBarDM.Value = iPBValue;
                    iPBValue++;
                    // if (iPBValue == 2) break; //Just for testing only 2 rows
                }
                theParent.pBarDM.Visible = false;
            }
            catch (Exception ex)
            {
                theParent.lblDMMsg.Text = ex.Message;
                CommonDoubleM.LogDM(ex.Message);
            }
            Cursor = Cursors.Default;

            //string s=null, abc=null;
            //if (CommonDoubleM.RediffStockLatestUpdates("10510001", ref s))
            //{
            //    s = s.Substring(s.LastIndexOf("Last traded"), s.LastIndexOf("<img") - s.LastIndexOf("Last traded"));
            //    abc = s;
            //    char[] sp = { '\r', '\t' };
            //    s = CommonDoubleM.StripHTML(s);
            //    CommonDoubleM.LogDM(s);
            //    string[] a = s.Split(sp);

            //}
        }
Example #2
0
        private void frmDataImport_Load(object sender, EventArgs e)
        {
            _theParent = (frmMain)this.ParentForm; //To access MDI parent control
            /*Add Checkbox dynamically to 1st column of each row*/
            c1       = new DataGridViewCheckBoxColumn();
            c1.Width = 30;
            c1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgvImport.Columns.Add(c1);
            dgvImport.Columns[0].Resizable = DataGridViewTriState.False;
            dgvImport.Columns[0].Frozen    = true;
            dgvImport.Columns[0].ReadOnly  = false;

            dgvImport.RowHeadersWidth         = 60;
            dgvImport.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            dgvImport.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            /*Add Checkbox to header*/
            ckBox = new CheckBox();
            //Get the column header cell bounds
            Rectangle rect = dgvImport.GetCellDisplayRectangle(0, -1, true);

            // set checkbox header to center of header cell. +1 pixel to position correctly.
            rect.X = rect.Location.X + (rect.Width / 4);

            ckBox.Size = new Size(18, 18);
            //Change the location of the CheckBox to make it stay on the header
            ckBox.Location        = rect.Location;
            ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);
            //Add the CheckBox into the DataGridView
            dgvImport.Controls.Add(ckBox);
            ckBox.Visible = false;

            GetStocks();

            switch (_ImportWhat)
            {
            case (short)ImportWhat.SingleRates:
                this.Text        = "Data Import of Single Stock";
                lblMsg.Text      = string.Format(initMsg, "Date", "Rate");
                lblMode.Text     = "Stocks";
                ddlStock.Visible = true;

                _MsgSelect = "Selected fields are \n[Dates] = {0}\n[Rates] = {1}";
                _fields    = new string[2];
                _menuItems = new string[] { "Click Column is: Dates", "Clicked Column is: Rates" };
                cmsLoaddata.Items.Add(_menuItems[0]);
                cmsLoaddata.Items.Add(_menuItems[1]);
                break;

            case (short)ImportWhat.MultipleRates:
                this.Text              = "Data Import of Multiple Stock";
                lblMsg.Text            = string.Format(initMsg, "Stocks Code", "Rate");
                lblMode.Text           = "Date\\Time";
                dtpPriceDate.Visible   = true; dtpPriceDate.Value = DateTime.Now;
                chkActiveStock.Visible = true; chkActiveStock.CheckState = CheckState.Indeterminate;
                _MsgSelect             = "Selected fields are \n[Stocks] = {0}\n[Rates] = {1}";
                _fields    = new string[2];
                _menuItems = new string[] { "Click Column is: Stocks", "Clicked Column is: Rates" };
                cmsLoaddata.Items.Add(_menuItems[0]);
                cmsLoaddata.Items.Add(_menuItems[1]);
                break;

            default:
                break;
            }
        }
Example #3
0
        private void frmCumulAvg_Load(object sender, EventArgs e)
        {
            frmMain theParent = (frmMain)this.ParentForm; //To access MDI parent control

            theParent.lblDMMsg.Text = "Please wait data loading..";

            try
            {
                dblTotal = 0;
                dblGain  = 0;
                dblValue = 0;
                decimal dicAvgPrice = 0, dicPerct = 0;

                DataTable dtQuickView = new DataTable();
                theParent.pBarDM.Visible = true;
                Application.DoEvents();

                if (_Caller == 1) //Avg
                {
                    dtQuickView = _pdalStock_CA.StockAvgAfterSale();

                    /*Adding Columns Header to Datagrid*/

                    /*foreach (DataColumn dtcol in dtQuickView.Columns)
                     *  dgViewQ.Columns.Add(dtcol.ColumnName, dtcol.ColumnName);*/

                    dgViewQ.Columns.Add("Stock Name", "Stock Name");
                    dgViewQ.Columns.Add("Shrs", "Shrs");
                    dgViewQ.Columns.Add("Current", "Current");
                    dgViewQ.Columns.Add("SID", "SID");
                    dgViewQ.Columns.Add("AvgPrice", "Avg");
                    dgViewQ.Columns.Add("Percentage", "%");
                    dgViewQ.Columns.Add("Gain", "T Gain");
                    dgViewQ.Columns.Add("PricePaid", "Paid");
                }

                else
                {
                    dtQuickView = _pdalStock_CA.LatestValue();
                    //dtQuickView.con
                    /*Adding Columns Header to Datagrid*/
                    foreach (DataColumn dtcol in dtQuickView.Columns)
                    {
                        dgViewQ.Columns.Add(dtcol.ColumnName, dtcol.ColumnName);
                    }

                    dgViewQ.Columns.Add("AvgPrice", "Avg");
                    dgViewQ.Columns.Add("Percentage", "%");
                    dgViewQ.Columns.Add("Gain", "T Gain");
                    dgViewQ.Columns.Add("PricePaid", "Paid");
                }
                /* Data grid format display*/

                dgViewQ.Columns[0].Width   = 180;   //Name
                dgViewQ.Columns[1].Width   = 40;    //Total Stock
                dgViewQ.Columns[2].Width   = 60;    //Current Price
                dgViewQ.Columns[3].Visible = false; // StockID

                dgViewQ.Columns[4].Width = 60;      //Avg. Price
                dgViewQ.Columns[5].Width = 45;      //%
                dgViewQ.Columns[6].Width = 50;      //Gain
                dgViewQ.Columns[7].Width = 60;      // TCost

                int iCount = 0;

                theParent.pBarDM.Maximum = dtQuickView.Rows.Count;

                foreach (DataRow dtrow in dtQuickView.Rows)
                {
                    dgViewQ.Rows.Add();
                    dgViewQ.Columns[1].InheritedStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    dgViewQ.Columns[2].InheritedStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    dgViewQ.Columns[3].InheritedStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                    if (_Caller == 2)
                    {
                        dgViewQ[0, iCount].Value = dtrow[0];
                        dgViewQ[1, iCount].Value = dtrow[1];
                        dgViewQ[2, iCount].Value = dtrow[2];

                        dicAvgPrice = _pdalStock_CA.StockAvg((int)dtrow[3]);
                        dgViewQ[4, iCount].Value = dicAvgPrice;

                        dgViewQ[6, iCount].Value = ((decimal)(dgViewQ[2, iCount].Value) - dicAvgPrice) * (decimal)(double)(dgViewQ[1, iCount].Value);
                        dgViewQ[7, iCount].Value = dicAvgPrice * (decimal)(double)dgViewQ[1, iCount].Value;

                        //dgViewQ[0, 0].Style.BackColor = Color.RoyalBlue;
                    }
                    else if (_Caller == 1)
                    {
                        dgViewQ[0, iCount].Value = dtrow[1];
                        dgViewQ[1, iCount].Value = dtrow[2];
                        dgViewQ[2, iCount].Value = dtrow[4];
                        dgViewQ[3, iCount].Value = dtrow[0];
                        dgViewQ[4, iCount].Value = dtrow[3];
                        dgViewQ[5, iCount].Value = dtrow[5];
                        dgViewQ[6, iCount].Value = dtrow[6];
                        dgViewQ[7, iCount].Value = dtrow[7];
                    }
                    //dgViewQ[3, iCount].Value = dtrow[3];

                    //dgViewQ[4, iCount].Value = dtrow[4];
                    //double tmpValue = Convert.ToDouble(dgViewQ[4, iCount].Value);
                    dicPerct = (decimal)((Convert.ToDouble(dgViewQ[2, iCount].Value) / Convert.ToDouble(dgViewQ[4, iCount].Value)) - 1) * 100;
                    dicPerct = decimal.Round(dicPerct, 2);
                    dgViewQ[5, iCount].Value = dicPerct;

                    int iR = 255, iG = 255, iB = 255;
                    int iMax = 0, iMin = 0;

                    //http://www.flounder.com/csharp_color_table.htm (for color coding)
                    if (dicPerct < 0)
                    {
                        iMin = 255 - (int)(dicPerct * -4);
                        if ((iMin < 0) || (iMin > 255))
                        {
                            iMin = 0;
                        }

                        iG = iMin;
                        iB = iMin;
                    }
                    else
                    {
                        iMax = 255 - (int)(dicPerct * 4);
                        if ((iMax < 0) || (iMax > 255))
                        {
                            iMax = 0;
                        }
                        iR = iMax;
                        iB = iMax;
                    }
                    dgViewQ[5, iCount].Style.BackColor = Color.FromArgb(iR, iG, iB);

                    dblValue = dblValue +
                               Convert.ToDouble(dgViewQ[1, iCount].Value) *
                               Convert.ToDouble(dgViewQ[2, iCount].Value);

                    dblGain  = dblGain + Convert.ToDouble(dgViewQ[6, iCount].Value);
                    dblTotal = dblTotal + Convert.ToDouble(dgViewQ[7, iCount].Value);


                    iCount++;
                    theParent.pBarDM.Value = iCount;
                }
                //dgViewQ.Rows[iCount].Selected = true;
                /*Summary at bottom*/
                dgViewQ[0, iCount].Value = "Summary";
                dgViewQ[2, iCount].Value = dblValue;
                dgViewQ[5, iCount].Value = decimal.Round(((decimal)((dblValue / dblTotal) - 1) * 100), 2);
                dgViewQ[6, iCount].Value = dblGain;
                dgViewQ[7, iCount].Value = dblTotal;

                theParent.lblDMMsg.Text = "Done..";
            }
            catch (Exception ex)
            {
                theParent.lblDMMsg.Text = ex.Message;
            }
            finally
            {
                theParent.pBarDM.Visible = false;
            }
        }
Example #4
0
 private void frmAc_Load(object sender, EventArgs e)
 {
     //lblMsg.Text = "Total Quantity " + _iSellQuantity.ToString();
     dgvAc.RowHeadersWidth = 25;
     _theParent            = (frmMain)this.ParentForm;
 }