public void InsertChangeInfo(int rowPos, ExcelLineWriter writer, SameDayChangeInfo sameDayChangeInfo, Worksheet worksheet, List <BordLotSizeChangeInfo> bordLotSizeChangeInfoList)
        {
            InsertNewDeleteChangeInfo(--rowPos, writer, sameDayChangeInfo.DeleteBrokerList, worksheet);
            int curPos = rowPos;

            while (curPos > 0)
            {
                Range r = ExcelUtil.GetRange(curPos - 1, 4, worksheet);
                if (r.Text == null || r.Text.ToString() == "")
                {
                    curPos--;
                    continue;
                }
                else if (DateTimeEqual(sameDayChangeInfo.Date, r.Text.ToString()))
                {
                    curPos--;
                    continue;
                }

                else
                {
                    InsertNameChange(curPos, writer, sameDayChangeInfo.NameChangeToList, worksheet);
                    InsertRicChange(curPos, writer, sameDayChangeInfo.RicChangeToList, worksheet);
                    InsertBordSizeChangeInfo(curPos, writer, sameDayChangeInfo.BordLotSizeChangeList, bordLotSizeChangeInfoList, worksheet);
                    InsertNewDeleteChangeInfo(curPos, writer, sameDayChangeInfo.NewBrokerList, worksheet);
                    break;
                }
            }
            int lastUsedRowNum = worksheet.UsedRange.Row + worksheet.UsedRange.Rows.Count - 1;

            ExcelUtil.GetRange(1, 4, lastUsedRowNum, 4, worksheet).NumberFormat = "MM/dd/yyyy";
        }
        public List <SameDayChangeInfo> GetDifDayChangeInfo()
        {
            List <SameDayChangeInfo> sameDayChangeList = new List <SameDayChangeInfo>();
            SameDayChangeInfo        sameDayChangeInfo = null;
            string date = string.Empty;

            for (int i = 0; i < AllChangedBrokerList.Count; i++)
            {
                BrokerChangeInfo broker = AllChangedBrokerList[i];
                if (broker.Date == date)
                {
                    if (broker.Type.ToLower() == "new")
                    {
                        sameDayChangeInfo.NewBrokerList.Add(broker);
                    }

                    else if (broker.Type.ToLower() == "delete")
                    {
                        sameDayChangeInfo.DeleteBrokerList.Add(broker);
                    }
                    else if (broker.Type.ToLower() == "change")
                    {
                        sameDayChangeInfo.BordLotSizeChangeList.Add(broker);
                    }

                    else if (broker.Type.ToLower() == "name chg to")
                    {
                        sameDayChangeInfo.NameChangeToList.Add(broker);
                    }
                }

                else
                {
                    if (i != 0)
                    {
                        sameDayChangeList.Add(sameDayChangeInfo);
                        sameDayChangeInfo.RicChangeToList = sameDayChangeInfo.GetChangeToList();
                    }
                    sameDayChangeInfo      = new SameDayChangeInfo();
                    sameDayChangeInfo.Date = broker.Date;
                    date = broker.Date;
                    sameDayChangeInfo.NewBrokerList         = new List <BrokerChangeInfo>();
                    sameDayChangeInfo.DeleteBrokerList      = new List <BrokerChangeInfo>();
                    sameDayChangeInfo.NameChangeToList      = new List <BrokerChangeInfo>();
                    sameDayChangeInfo.RicChangeToList       = new List <StockNameRicChange>();
                    sameDayChangeInfo.BordLotSizeChangeList = new List <BrokerChangeInfo>();
                    if (broker.Type.ToLower() == "new")
                    {
                        sameDayChangeInfo.NewBrokerList.Add(broker);
                    }

                    else if (broker.Type.ToLower() == "delete")
                    {
                        sameDayChangeInfo.DeleteBrokerList.Add(broker);
                    }
                    else if (broker.Type.ToLower() == "change")
                    {
                        sameDayChangeInfo.BordLotSizeChangeList.Add(broker);
                    }
                    else if (broker.Type.ToLower() == "name chg to")
                    {
                        sameDayChangeInfo.NameChangeToList.Add(broker);
                    }
                }
            }
            sameDayChangeList.Add(sameDayChangeInfo);
            return(sameDayChangeList);
        }
        public void UpdateHKSEAFile(ChangeInfo ChangedBrokerInfo, List <BordLotSizeChangeInfo> bordLotSizeChangeList)
        {
            using (ExcelApp appSEA = new ExcelApp(false, false))
            {
                string SEAFilePath  = BackupFiles(configObj.HKSEA_Z2_FILE_PATH);
                var    workbookSEA  = ExcelUtil.CreateOrOpenExcelFile(appSEA, SEAFilePath);
                var    worksheetSEA = ExcelUtil.GetWorksheet("Sheet2", workbookSEA);
                int    rowPos       = 1;
                using (ExcelLineWriter writer = new ExcelLineWriter(worksheetSEA, 1, 1, ExcelLineWriter.Direction.Right))
                {
                    int curRowPos = worksheetSEA.UsedRange.Row + worksheetSEA.UsedRange.Rows.Count - 1;
                    for (int i = ChangedBrokerInfo.DifDayChangeInfo.Count - 1; i > -1; i--)
                    {
                        SameDayChangeInfo sameDayChangedInfo = ChangedBrokerInfo.DifDayChangeInfo[i];
                        rowPos = curRowPos;
                        while (rowPos > 0)
                        {
                            if (ExcelUtil.GetRange(rowPos, 4, worksheetSEA).Value2 == null || string.IsNullOrEmpty(ExcelUtil.GetRange(rowPos, 4, worksheetSEA).Value2.ToString()))
                            {
                                rowPos--;
                                continue;
                            }
                            else if (DateTimeCompare(sameDayChangedInfo.Date, ExcelUtil.GetRange(rowPos, 4, worksheetSEA).Text.ToString()))
                            {
                                if (rowPos == curRowPos)
                                {
                                    curRowPos = rowPos;
                                    InsertChangeInfo(rowPos + 1, writer, sameDayChangedInfo, worksheetSEA, bordLotSizeChangeList);
                                    break;
                                }

                                else if (ExcelUtil.GetRange(rowPos + 1, 4, worksheetSEA) == null || (string.IsNullOrEmpty(ExcelUtil.GetRange(rowPos + 1, 4, worksheetSEA).Text.ToString())))
                                {
                                    rowPos--;
                                }
                                else if (!DateTimeCompare(sameDayChangedInfo.Date, ExcelUtil.GetRange(rowPos + 1, 4, worksheetSEA).Text.ToString()))
                                {
                                    curRowPos = rowPos;
                                    InsertChangeInfo(rowPos + 1, writer, sameDayChangedInfo, worksheetSEA, bordLotSizeChangeList);
                                    break;
                                }

                                else
                                {
                                    rowPos--;
                                    continue;
                                }
                            }

                            else
                            {
                                if (rowPos == 1)
                                {
                                    curRowPos = rowPos;
                                    InsertChangeInfo(rowPos + 1, writer, sameDayChangedInfo, worksheetSEA, bordLotSizeChangeList);
                                    break;
                                }

                                else if (ExcelUtil.GetRange(rowPos - 1, 4, worksheetSEA) == null || (ExcelUtil.GetRange(rowPos - 1, 4, worksheetSEA).Text == null))
                                {
                                    rowPos--;
                                }
                                else if (DateTimeCompare(sameDayChangedInfo.Date, ExcelUtil.GetRange(rowPos - 1, 4, worksheetSEA).Text.ToString()))
                                {
                                    curRowPos = rowPos;
                                    InsertChangeInfo(rowPos + 1, writer, sameDayChangedInfo, worksheetSEA, bordLotSizeChangeList);
                                    break;
                                }
                                else
                                {
                                    rowPos--;
                                    continue;
                                }
                            }
                        }
                    }
                }
                //workbookSEA.SaveCopyAs(Path.Combine(Path.GetDirectoryName(workbookSEA.FullName), Path.GetFileName(configObj.HKSEA_Z2_FILE_PATH)));
                workbookSEA.SaveCopyAs(configObj.HKSEA_Z2_FILE_PATH);
                workbookSEA.Close(false, workbookSEA.FullName, false);
                //File.Delete(SEAFilePath);
            }
        }