Beispiel #1
0
        /// <summary>
        /// 调用控件线程方法
        /// </summary>
        /// <param name="args">参数</param>
        public void OnInvoke(object args)
        {
            CMessage message = (CMessage)args;

            if (message.m_serviceID == m_quoteService.ServiceID)
            {
                LatestDataInfo            dataInfo = new LatestDataInfo();
                List <SecurityLatestData> datas    = new List <SecurityLatestData>();
                QuoteService.GetLatestDatas(ref dataInfo, datas, message.m_body, message.m_bodyLength);
                int datasSize = datas.Count;
                for (int i = 0; i < datasSize; i++)
                {
                    m_latestDatas[datas[i].m_securityCode] = datas[i];
                }
                datas.Clear();
            }
            else
            {
                List <UserSecurityCategory> categories = new List <UserSecurityCategory>();
                UserSecurityService.GetCategories(categories, message.m_body, message.m_bodyLength);
                UserSecurityCategory category = categories[0];
                switch (message.m_functionID)
                {
                case UserSecurityService.FUNCTIONID_USERSECURITY_ADDCATEGORIES:
                    AddCategoriesToCategoryGrid(categories);
                    break;

                case UserSecurityService.FUNCTIONID_USERSECURITY_DELETECATEGORIES:
                    RemoveCategoriesFromCategoryGrid(categories);
                    break;

                case UserSecurityService.FUNCTIONID_USERSECURITY_UPDATECATEGORIES:
                    UpdateCategoriesToCategoryGrid(categories);
                    break;

                case UserSecurityService.FUNCTIONID_USERSECURITY_ADDSECURITIES:
                case UserSecurityService.FUNCTIONID_USERSECURITY_DELETESECURITIES:
                {
                    String         categoryID       = "";
                    List <GridRow> selectedRows     = m_gridCategory.SelectedRows;
                    int            selectedRowsSize = selectedRows.Count;
                    if (selectedRowsSize > 0)
                    {
                        categoryID = selectedRows[0].GetCell(0).Text;
                    }
                    if (categoryID != null && categoryID == category.m_categoryID)
                    {
                        List <Security> securities = new List <Security>();
                        m_securityService.GetSecuritiesByCodes(category.m_codes, securities);
                        if (message.m_functionID == UserSecurityService.FUNCTIONID_USERSECURITY_ADDSECURITIES)
                        {
                            AddSecuritiesToSecuritiesGrid(securities);
                        }
                        else if (message.m_functionID == UserSecurityService.FUNCTIONID_USERSECURITY_DELETESECURITIES)
                        {
                            RemoveSecuritiesFromSecuritiesGrid(securities);
                        }
                    }
                    break;
                }
                }
            }
            m_window.Invalidate();
        }
        /// <summary>
        /// 接收消息方法
        /// </summary>
        /// <param name="message">消息</param>
        public override void OnReceive(CMessage message)
        {
            if (message.m_functionID == FUNCTIONID_USERSECURITY_GETVISITSCOUNT)
            {
                UserSecurityVisitsCount visitsCount = new UserSecurityVisitsCount();
                Binary br = new Binary();
                br.Write(message.m_body, message.m_bodyLength);
                visitsCount.m_userID = br.ReadInt();
                visitsCount.CodesFromString(br.ReadString());
                m_visitsCount = visitsCount.m_codes;
                br.Close();
            }
            else
            {
                List <UserSecurityCategory> categories = new List <UserSecurityCategory>();
                UserSecurityService.GetCategories(categories, message.m_body, message.m_bodyLength);
                int categoriesSize = categories.Count;
                if (message.m_functionID != FUNCTIONID_USERSECURITY_GETCATEGORIES)
                {
                    message.m_requestID = m_operatorRequestID;
                }
                switch (message.m_functionID)
                {
                case FUNCTIONID_USERSECURITY_GETCATEGORIES:
                {
                    m_categories = categories;
                    m_loaded     = true;
                    break;
                }

                case FUNCTIONID_USERSECURITY_ADDCATEGORIES:
                {
                    bool add = false;
                    for (int i = 0; i < categoriesSize; i++)
                    {
                        UserSecurityCategory category = null;
                        if (!GetCategory(categories[i].m_categoryID, ref category))
                        {
                            m_categories.Add(categories[i]);
                            add = true;
                        }
                    }
                    if (!add)
                    {
                        return;
                    }
                    break;
                }

                case FUNCTIONID_USERSECURITY_DELETECATEGORIES:
                {
                    for (int i = 0; i < categoriesSize; i++)
                    {
                        UserSecurityCategory category = null;
                        if (GetCategory(categories[i].m_categoryID, ref category))
                        {
                            m_categories.Remove(category);
                        }
                    }
                    break;
                }

                case FUNCTIONID_USERSECURITY_UPDATECATEGORIES:
                {
                    for (int i = 0; i < categoriesSize; i++)
                    {
                        UserSecurityCategory updateCategory = categories[i];
                        int curCategoriesSize = m_categories.Count;
                        for (int j = 0; j < curCategoriesSize; j++)
                        {
                            UserSecurityCategory category = m_categories[j];
                            if (category.m_categoryID == updateCategory.m_categoryID)
                            {
                                m_categories[j] = updateCategory;
                                break;
                            }
                        }
                    }
                    break;
                }

                case FUNCTIONID_USERSECURITY_ADDSECURITIES:
                {
                    for (int i = 0; i < categoriesSize; i++)
                    {
                        UserSecurityCategory updateCategory = categories[i];
                        int curCategoriesSize = m_categories.Count;
                        for (int j = 0; j < curCategoriesSize; j++)
                        {
                            UserSecurityCategory category = m_categories[j];
                            if (category.m_categoryID == updateCategory.m_categoryID)
                            {
                                if (category.m_codes != null && category.m_codes.Length > 0)
                                {
                                    updateCategory.m_codes = m_categories[j].m_codes + "," + updateCategory.m_codes;
                                }
                                m_categories[j] = updateCategory;
                                break;
                            }
                        }
                    }
                    break;
                }

                case FUNCTIONID_USERSECURITY_DELETESECURITIES:
                {
                    for (int i = 0; i < categoriesSize; i++)
                    {
                        UserSecurityCategory updateCategory = categories[i];
                        int curCategoriesSize = m_categories.Count;
                        for (int j = 0; j < curCategoriesSize; j++)
                        {
                            UserSecurityCategory category = m_categories[j];
                            if (category.m_categoryID == updateCategory.m_categoryID)
                            {
                                if (updateCategory.m_codes != null && updateCategory.m_codes.Length > 0 && category.m_codes != null && category.m_codes.Length > 0)
                                {
                                    String[] deleteCodes     = updateCategory.m_codes.Split(',');
                                    int      deleteCodesSize = deleteCodes.Length;
                                    Dictionary <String, String> deleteCodesMap = new Dictionary <String, String>();
                                    for (int m = 0; m < deleteCodesSize; m++)
                                    {
                                        deleteCodesMap[deleteCodes[m]] = "";
                                    }
                                    String[] codes     = category.m_codes.Split(',');
                                    int      codesSize = codes.Length;
                                    String   newCodes  = "";
                                    for (int m = 0; m < codesSize; m++)
                                    {
                                        if (!deleteCodesMap.ContainsKey(codes[m]))
                                        {
                                            newCodes += codes[m] + ",";
                                        }
                                    }
                                    if (newCodes != null && newCodes.Length > 0)
                                    {
                                        if (newCodes.Substring(newCodes.Length - 1) == ",")
                                        {
                                            newCodes = newCodes.Substring(0, newCodes.Length - 1);
                                        }
                                    }
                                    updateCategory.m_codes = newCodes;
                                }
                                m_categories[j] = updateCategory;
                                break;
                            }
                        }
                    }
                    break;
                }
                }
            }
            base.OnReceive(message);
        }