コード例 #1
0
ファイル: InboundData3_SPR.cs プロジェクト: huangss0/GTS0
        private long DownloadFile()
        {
            if (!this.ftpLoggedIn_flag)
            {
                return(-2);
            }
            if (string.IsNullOrEmpty(this.downFile_name))
            {
                return(-1);
            }

            MemoryStream ms  = new MemoryStream();
            long         len = this.remoteSource.DownloadFile(this.downFile_name, ms);

            if (len < 0)
            {
                return(-2);
            }
            else
            {
                ms.Seek(0, SeekOrigin.Begin);
            }

            byte[] fileData_bytes = new byte[len];
            ms.Read(fileData_bytes, 0, fileData_bytes.Length);

            //split and save file to DB
            List <SPR_file> sf_list = SPR_fileControl.SplitRawFile(fileData_bytes);

            foreach (SPR_file sf in sf_list)
            {
                sf.FileName.Value = this.downFile_name;
                this.errLog.Add("CUSIP: " + sf.CUSIP.Value + " " + (sf.Insert_to_DB() ? "Saved" : "Fail in saving"));
            }

            if (sf_list.Count < 1)//save no result file as rejected
            {
                SPR_file sf = new SPR_file();
                sf.SetStatus(HssStatus.Rejected);
                sf.FileName.Value = this.downFile_name;
                sf.FileBinary     = fileData_bytes;
                this.errLog.Add("No Data file saved", sf.Insert_to_DB().ToString());
            }

            return(len);
        }
コード例 #2
0
        /// <summary>
        /// Insert DTC Position using SPR file from DTCC
        /// </summary>
        /// <param name="sf">SPR file</param>
        /// <param name="createNew_flag">append or create new</param>
        public bool Insert_DTC_position(SPR_file sf, bool createNew_flag = true)
        {
            if (sf == null || sf.FileBinary == null)
            {
                MessageBox.Show("Dividend_func4 error 0: No SPR data");
                return(false);
            }

            MemoryStream ms = new MemoryStream(sf.FileBinary);
            StreamReader sr = new StreamReader(ms);

            if (createNew_flag)
            {
                this.Delete_DTC_position();
            }

            List <Position> posList = new List <Position>();
            string          str     = null;

            while ((str = sr.ReadLine()) != null)
            {
                if (str.Length <= 37)
                {
                    continue;
                }

                char recordType_char = str[SPR_fileControl.RecordTypeChar_index];
                if (recordType_char != '2')
                {
                    continue;                         //'2' stands for detail records
                }
                if (str.StartsWith("HDR", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (str.StartsWith("TRL", StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                Position dtcPos = new Position();
                dtcPos.DividendIndex = this.DividendIndex;

                dtcPos.DTC_Number   = str.Substring(19, 8).TrimStart('0');
                dtcPos.Company_Name = str.Substring(27, 10).Trim();

                string  totalPos_str = str.Substring(37).Trim();
                decimal tempDecimal  = -1;
                if (decimal.TryParse(totalPos_str, out tempDecimal))
                {
                    dtcPos.Total_RecDate_Position = tempDecimal;
                }

                posList.Add(dtcPos);
            }

            ParticipantMaster pcMaster = new ParticipantMaster();

            pcMaster.Init_from_dtcPosList(posList);

            Bulk_DBcmd buk_ins = new Bulk_DBcmd();
            List <DTC_Participants> missing_DCTpart_list = new List <DTC_Participants>();

            foreach (Position pos in posList)
            {
                Participant pt = pcMaster.GetParticipant(pos.DTC_Number);
                if (pt == null)
                {
                    DTC_Participants dtcPart = new DTC_Participants();

                    int tempInt = -1;
                    if (!int.TryParse(pos.DTC_Number, out tempInt))
                    {
                        continue;
                    }
                    dtcPart.DTC = tempInt;

                    dtcPart.DTC_Number.Value   = pos.DTC_Number;
                    dtcPart.Company_Name.Value = pos.Company_Name;

                    missing_DCTpart_list.Add(dtcPart);
                }
                else
                {
                    pos.Company_Name = pt.Company_Name; //if exist, change the name to what we have in [DTC_Participants]
                }
                buk_ins.Add_DBcmd(pos.Get_DBinsert());
            }

            int count0 = buk_ins.SaveToDB(Utility.Get_DRWIN_hDB());
            int count1 = DTC_Participants_master.Insert_DTC_Participants(missing_DCTpart_list);

            return(true);
        }