コード例 #1
0
        private string getFidValueForEnglishVersionFile(BrokerInfo brokerInfo)
        {
            string value = string.Empty;

            value += "\"";
            value += brokerInfo.hall.PadRight(9).Substring(0, 9);
            value += brokerInfo.terminal.PadRight(10).Substring(0, 10);
            if (!string.IsNullOrEmpty(brokerInfo.longName))
            {
                value += brokerInfo.longName.PadRight(45).Substring(0, 45);
                value += brokerInfo.shortName.PadRight(16).Substring(0, 16);
            }
            else
            {
                value += brokerInfo.originalName.PadRight(45).Substring(0, 45);
                value += brokerInfo.originalName.PadRight(16).Substring(0, 16);
            }
            value += "\"";
            return(value);
        }
コード例 #2
0
        private string getFidValueForChineseVersionFile(BrokerInfo brokerInfo)
        {
            string value = string.Empty;

            value += "\"";
            value += brokerInfo.hall.PadRight(9).Substring(0, 8);
            value += brokerInfo.terminal.PadRight(10).Substring(0, 10);
            if (!string.IsNullOrEmpty(brokerInfo.ChineseName))
            {
                if (!string.IsNullOrEmpty(brokerInfo.ChineseLongName))
                {
                    value += formatStringForChinese(brokerInfo.ChineseLongName, 42, 58);

                    int bytesNumForChineseShortName = 96 - Encoding.UTF8.GetBytes(value).Length + 1;
                    value += formatStringForChinese(brokerInfo.ChineseShortName, 24, bytesNumForChineseShortName);
                }
                if (string.IsNullOrEmpty(brokerInfo.ChineseLongName))
                {
                    value += formatStringForChinese(brokerInfo.ChineseName, 42, 58);
                    int bytesNumForChineseShortName = 96 - Encoding.UTF8.GetBytes(value).Length + 1;
                    value += formatStringForChinese(brokerInfo.ChineseName, 24, bytesNumForChineseShortName);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(brokerInfo.longName))
                {
                    value += formatStringForChinese(brokerInfo.longName, 42, 58);
                    int bytesNumForChineseShortName = 96 - Encoding.UTF8.GetBytes(value).Length + 1;
                    value += formatStringForChinese(brokerInfo.shortName, 24, bytesNumForChineseShortName);
                }
                else
                {
                    value += formatStringForChinese(brokerInfo.originalName, 42, 58);
                    int bytesNumForChineseShortName = 96 - Encoding.UTF8.GetBytes(value).Length + 1;
                    value += formatStringForChinese(brokerInfo.originalName, 24, bytesNumForChineseShortName);
                }
            }
            value += "\"";
            return(value);
        }
コード例 #3
0
        //Get all the broker information from the current csv file
        public List <BrokerInfo> GetBrokerList(string currentCSVFilePath)
        {
            List <BrokerInfo> brokerList = new List <BrokerInfo>();

            using (ExcelApp app = new ExcelApp(false))
            {
                var       workbook  = ExcelUtil.CreateOrOpenExcelFile(app, currentCSVFilePath);
                Worksheet worksheet = workbook.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
                if (worksheet == null)
                {
                    LogMessage(string.Format("Cannot get worksheet {0} from workbook {1}", Path.GetFileNameWithoutExtension(currentCSVFilePath), workbook.Name));
                }
                int lastUsedRow = worksheet.UsedRange.Row + worksheet.UsedRange.Rows.Count - 1;
                using (ExcelLineWriter reader = new ExcelLineWriter(worksheet, 2, 1, ExcelLineWriter.Direction.Down))
                {
                    while (reader.Row < lastUsedRow)
                    {
                        try
                        {
                            if (!string.IsNullOrEmpty(ExcelUtil.GetRange(reader.Row, 1, worksheet).Text.ToString()))
                            {
                                string brokerNumbers = ExcelUtil.GetRange(reader.Row, 2, worksheet).Text.ToString();
                                if ((brokerNumbers != null) && (brokerNumbers != ""))
                                {
                                    string originalName = ExcelUtil.GetRange(reader.Row, 3, worksheet).Text.ToString().Trim();
                                    string ChineseName  = ExcelUtil.GetRange(reader.Row, 4, worksheet).Text.ToString().Trim();
                                    if (brokerList.Count == 0 || originalName != brokerList[brokerList.Count - 1].originalName)
                                    {
                                        if (brokerList.Count != 0 && brokerNumbers == brokerList[brokerList.Count - 1].brokerNumbers)
                                        {
                                            reader.PlaceNext(reader.Row + 1, 1);
                                            continue;
                                        }
                                        Dictionary <int, BrokerInfo> brokerGroupMap = new Dictionary <int, BrokerInfo>();
                                        foreach (string id in brokerNumbers.Split(','))
                                        {
                                            int curId = int.Parse(id.Trim());
                                            int part1 = curId / 10;
                                            int part2 = curId % 10;

                                            if (brokerGroupMap.ContainsKey(part1))
                                            {
                                                brokerGroupMap[part1].IdList.Add(part2);
                                            }
                                            else
                                            {
                                                BrokerInfo brokerInfo = new BrokerInfo();
                                                brokerInfo.ChineseName   = ChineseName.Trim();
                                                brokerInfo.originalName  = originalName;
                                                brokerInfo.brokerNumbers = brokerNumbers;
                                                brokerInfo.GetBrokerLongAndShortName();
                                                if (brokerInfo.err != string.Empty)
                                                {
                                                    Logger.Log(brokerInfo.err);
                                                    brokerInfo.err = string.Empty;
                                                }
                                                brokerInfo.GetBrokerChineseLongAndShortName();
                                                if (brokerInfo.err != string.Empty)
                                                {
                                                    Logger.Log(brokerInfo.err);
                                                    brokerInfo.err = string.Empty;
                                                }
                                                brokerInfo.GroupId = part1;
                                                brokerInfo.IdList  = new List <int>();
                                                brokerInfo.IdList.Add(part2);
                                                brokerGroupMap.Add(part1, brokerInfo);
                                            }
                                        }

                                        foreach (BrokerInfo broker in brokerGroupMap.Values)
                                        {
                                            broker.hall     = broker.GetHallInfo();
                                            broker.terminal = broker.GetTerminalInfo();
                                            if (!brokerList.Contains(broker))
                                            {
                                                brokerList.Add(broker);
                                            }
                                        }
                                    }
                                }

                                reader.PlaceNext(reader.Row + 1, 1);
                            }
                            else
                            {
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            LogMessage(string.Format("msg:{0}", ex.Message));
                        }
                    }
                }
                workbook.Close(false, workbook.FullName, false);
            }
            brokerList.Sort();
            return(brokerList);
        }