Example #1
0
        private void GetPriceRecord(MSFL.MSFLSecurityInfo msflSecurityInfo)
        {
            IntPtr hSecurity = msflSecurityInfo.hSecurity;

            int iErr = MSFL.MSFL1_LockSecurity(hSecurity, MSFL.MSFL_LOCK_PREV_WRITE_LOCK);

            if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
            {
                return;
            }

            ushort wPriceRecCount = 0;

            iErr = MSFL.MSFL1_GetDataRecordCount(hSecurity, ref wPriceRecCount);
            if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
            {
                return;
            }

            if (wPriceRecCount > 0)
            {
                iErr = MSFL.MSFL1_SeekBeginData(hSecurity);
                if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
                {
                    return;
                }

                MSFL.DateTime sDateTime = new MSFL.DateTime();
                m_PriceRecordArray = new MSFL.MSFLPriceRecord[wPriceRecCount];

                iErr = MSFL.MSFL2_ReadMultipleRecs(hSecurity, m_PriceRecordArray, ref sDateTime, ref wPriceRecCount, (int)MSFL.MSFL_FIND.MSFL_FIND_USE_CURRENT_POS);
                if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
                {
                    return;
                }

                // Unlock the security (we're done using it)
                iErr = MSFL.MSFL1_UnlockSecurity(hSecurity);
            }
        }
Example #2
0
        private void ListViewSecurity_SelectedIndexChanged(object sender, EventArgs e)
        {
            Point        cursorPoint  = this.ListViewSecurity.PointToClient(Cursor.Position);
            ListViewItem listViewItem = this.ListViewSecurity.GetItemAt(cursorPoint.X, cursorPoint.Y);

            if (listViewItem == null)
            {
                return;
            }
            else
            {
                this.ListViewPrice.VirtualListSize = 0;
                this.ListViewPrice.Items.Clear();
            }

            IntPtr hSecurity = IntPtr.Zero;

            if (m_SecurityDictionary.TryGetValue(listViewItem, out hSecurity) == false)
            {
                return;
            }

            int iErr = MSFL.MSFL1_LockSecurity(hSecurity, MSFL.MSFL_LOCK_PREV_WRITE_LOCK);

            if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
            {
                return;
            }

            ushort wPriceRecCount = 0;

            iErr = MSFL.MSFL1_GetDataRecordCount(hSecurity, ref wPriceRecCount);
            if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
            {
                return;
            }

            if (wPriceRecCount > 0)
            {
                iErr = MSFL.MSFL1_SeekBeginData(hSecurity);
                if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
                {
                    return;
                }

                MSFL.DateTime          sDateTime = new MSFL.DateTime();
                MSFL.MSFLPriceRecord[] pPriceRec = new MSFL.MSFLPriceRecord[wPriceRecCount];

                iErr = MSFL.MSFL2_ReadMultipleRecs(hSecurity, pPriceRec, ref sDateTime, ref wPriceRecCount, (int)MSFL.MSFL_FIND.MSFL_FIND_USE_CURRENT_POS);
                if (iErr != (int)MSFL.MSFL_ERR.MSFL_NO_ERR)
                {
                    return;
                }

                // Unlock the security (we're done using it)
                iErr = MSFL.MSFL1_UnlockSecurity(hSecurity);

                // numbers for summing price info
                float fOpenSum = 0.0f, fHighSum = 0.0f, fLowSum = 0.0f, fCloseSum = 0.0f, fVolumeSum = 0.0f, fOpenIntSum = 0.0f;

                List <ListViewItem> listViewItemList = new List <ListViewItem>(2048);

                StringBuilder szBuf = new StringBuilder(MSFL.MSFL_MAX_NAME_LENGTH + 1);
                for (int iIndex = 0; iIndex < pPriceRec.Length; iIndex++)
                {
                    MSFL.MSFLPriceRecord msflPriceRecord = pPriceRec[iIndex];

                    listViewItem = new ListViewItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_DATE) == MSFL.MSFL_DATA_DATE)
                    {
                        MSFL.MSFL1_FormatDate(szBuf, (ushort)szBuf.Capacity, msflPriceRecord.lDate);
                        listViewItem.Text = szBuf.ToString();
                    }
                    else
                    {
                        listViewItem.Text = "N/A";
                    }

                    ListViewItem.ListViewSubItem subListViewItem1 = new ListViewItem.ListViewSubItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_TIME) == MSFL.MSFL_DATA_TIME)
                    {
                        MSFL.MSFL1_FormatTime(szBuf, (ushort)szBuf.Capacity, msflPriceRecord.lTime, true);
                        subListViewItem1.Text = szBuf.ToString();
                    }
                    else
                    {
                        subListViewItem1.Text = "N/A";
                    }

                    ListViewItem.ListViewSubItem subListViewItem2 = new ListViewItem.ListViewSubItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_OPEN) == MSFL.MSFL_DATA_OPEN)
                    {
                        fOpenSum += msflPriceRecord.fOpen;
                        subListViewItem2.Text = msflPriceRecord.fOpen.ToString("0.00", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        subListViewItem2.Text = "N/A";
                    }

                    ListViewItem.ListViewSubItem subListViewItem3 = new ListViewItem.ListViewSubItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_HIGH) == MSFL.MSFL_DATA_HIGH)
                    {
                        fHighSum += msflPriceRecord.fHigh;
                        subListViewItem3.Text = msflPriceRecord.fHigh.ToString("0.00", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        subListViewItem3.Text = "N/A";
                    }

                    ListViewItem.ListViewSubItem subListViewItem4 = new ListViewItem.ListViewSubItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_LOW) == MSFL.MSFL_DATA_LOW)
                    {
                        fLowSum += msflPriceRecord.fLow;
                        subListViewItem4.Text = msflPriceRecord.fLow.ToString("0.00", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        subListViewItem4.Text = "N/A";
                    }

                    ListViewItem.ListViewSubItem subListViewItem5 = new ListViewItem.ListViewSubItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_CLOSE) == MSFL.MSFL_DATA_CLOSE)
                    {
                        fCloseSum            += msflPriceRecord.fClose;
                        subListViewItem5.Text = msflPriceRecord.fClose.ToString("0.00", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        subListViewItem5.Text = "N/A";
                    }

                    ListViewItem.ListViewSubItem subListViewItem6 = new ListViewItem.ListViewSubItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_VOLUME) == MSFL.MSFL_DATA_VOLUME)
                    {
                        fVolumeSum           += msflPriceRecord.fVolume;
                        subListViewItem6.Text = msflPriceRecord.fVolume.ToString("0.", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        subListViewItem6.Text = "N/A";
                    }

                    ListViewItem.ListViewSubItem subListViewItem7 = new ListViewItem.ListViewSubItem();
                    if ((msflPriceRecord.wDataAvailable & MSFL.MSFL_DATA_OPENINT) == MSFL.MSFL_DATA_OPENINT)
                    {
                        fOpenIntSum          += msflPriceRecord.fOpenInt;
                        subListViewItem7.Text = msflPriceRecord.fOpenInt.ToString("0.00", CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        subListViewItem7.Text = "N/A";
                    }

                    listViewItem.SubItems.Add(subListViewItem1);
                    listViewItem.SubItems.Add(subListViewItem2);
                    listViewItem.SubItems.Add(subListViewItem3);
                    listViewItem.SubItems.Add(subListViewItem4);
                    listViewItem.SubItems.Add(subListViewItem5);
                    listViewItem.SubItems.Add(subListViewItem6);
                    listViewItem.SubItems.Add(subListViewItem7);

                    //this.ListViewPrice.Items.Add( listViewItem );
                    listViewItemList.Add(listViewItem);
                }

                m_PriceArray = listViewItemList.ToArray();
                this.ListViewPrice.VirtualListSize = m_PriceArray.Length;
            }
        }