从FTP取文件,并解析

numbertab文件内容,第一列首字母为关键字,其余数据插入到ListBox显示
#本SAG负责的号段(跟业务能力相关)
001138              123456
001021              123456
004138              123456
004021              123456
006138              123456
006021              123456
008138              123456
008021              123456
009138              123456
009021              123456
#第三方发起呼叫时,选择网关(基于网关移动、固定、NGN)
11              CAP
10217777        INAP
10218888        SIP
#数据类SE的路由数据
909             http://192.168.2.221/mm7
911             http://192.168.2.221/le
912             http://192.168.2.221/pap
#短信过滤关键字
#F+关键字GBK码经bcdtoasc后的内容     关键字GBK吗
F2bcbac2b                             布什
F1beb0cda5b7c                         本拉登
void CNumberTabCtrl::OnBtOut() 

     // TODO: Add your control notification handler code here
    CString file_content_before;
    CString file_content_behind;
    ListBox1.DeleteAllItems();
        remove("numbertab");
    if(m_bGet)
        return;
    m_bGet = true;
    LoadProfile(pPage->GetValue("FTPConfig"));
    CInternetSession sess (_T("CIN-VAS/3.0"));
    CFtpConnection* pConnect = NULL;
    try
    {
        pConnect = sess.GetFtpConnection(LPCTSTR(g_FtpHost),LPCTSTR(g_FtpUser),LPCTSTR(g_FtpPass),g_uiPort);
        if(!pConnect)
        {
            sess.Close();
            return;
        }
    }
    catch (CInternetException* pEx)
    {
        TCHAR sz[1024];
        pEx->GetErrorMessage(sz, 1024);
        pEx->Delete();
        m_bGet = false;
        MessageBox("无法连接SAG服务器。");
        return;
    }
    pConnect->SetCurrentDirectory(g_FtpPath);
    pConnect->GetFile("RemoteFile","LocalFile",FALSE);
    sess.Close();
    FILE *hResFile = fopen("LocalFile","rb");
    if(hResFile==NULL)
    {
        m_bGet = false;
        MessageBox("无法连接SAG服务器。");
        return;
    }
    int ilenofline=100;
    char textout[3000],sTemp[100],number[2][40];
    CString file_content;
    int ibefore=0,ibehind=0,icurrent=0;
    bool bcurrent=false;
    for(int i=1,iline=0;;i++)                     //每个循环是一行记录
    {
        textout[0]=0x00;
        if(!fgets(textout,ilenofline,hResFile))
        {
            break;
        }
        if(textout[0]==0x00||textout[0]=='/r')
            break;
        //格式化,读取部分以前的内容保存在file_content_before,以后内容保存在file_content_behind
        if(textout[0]!=keyword)
        {
            if(bcurrent==false)
                file_content_before+=textout;
            else
                file_content_behind+=textout;
            continue;    //有用吗?时间长,忘了:-(
        }
        else//读取内容保存在file_content
        {
            //读取内容分成两列,分别保存到number[0]和number[1],然后插入到ListBox1显示
            for(int i=0,j=0,k=0; i<=ilenofline; i++)
            {
                if(textout[i] == 0x00)
                {
                    if(j != 0)
                    {
                        sTemp[j] = 0;
                        strcpy(number[k],sTemp);
                        k++;
                    }
                    break;
                }
                if(textout[i] == ' '||textout[i] == '/t'||textout[i] == '/n')
                {
                    if(j != 0)
                    {
                        sTemp[j] = 0;
                        strcpy(number[k],sTemp);
                        k++;
                    }
                    j = 0;
                    continue;
                }
                sTemp[j] = textout[i];
                j++;
            }
            if(keyword=='0')
            {
                //读取内容再细分
                char sTemp2[3]="/0/0";
                strncpy(sTemp2,&number[0][1],2);
                if(strcmp(CString(sTemp2),pPage->GetValue("NumTabType"))<0)
                    file_content_before+=textout;
                if(strcmp(pPage->GetValue("NumTabType"),CString(sTemp2))==0)
                {
                    file_content+=textout;
                    ListBox1.InsertItem(iline++,&number[0][3]);
                    GetDlgItem(IDC_EDIT_CONTENT2)->SetWindowText(number[1]);
                    bcurrent=true;
                }
                if(strcmp(CString(sTemp2),pPage->GetValue("NumTabType"))>0)
                { 
                    file_content_behind+=textout;
                    bcurrent=true;
                }
            }
            else
            { 
                file_content+=textout;
                ListBox1.InsertItem(iline,&number[0][1]);
                ListBox1.SetItemText(iline++,1,number[1]);
                bcurrent=true;
            }
        }
    } //end of for(i=1;i<=MAX_ONEDAY;i++)
    if(strcmp(file_content,"")==0)
        MessageBox("没有您要查找的记录。");
    fclose(hResFile);
    m_bGet=false;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值