• 电子元器件管理系统


    使用到的知识点

       在Windows操作系统中读和写excel;

      关闭指定名字的exe进程,打开指定名字的exe进程;

      使生成的exe在windows各个系统中兼容;

    源码下载链接

      http://pan.baidu.com/share/home?uk=369664793&view=share#category/type=0

    说明

      读取excel数据采用的是微软的office COM类库。核心源码在excel.cpp文件中,核心函数为HRESULT AutoWrap(int autoType, VARIANT *pvResult, IDispatch *pDisp, LPOLESTR ptName, int cArgs...);对外接口是CString** GetExcelData(string &fileAddress);输入为excel文件路径名,输出为一个二维数组,对应excel文件中的每个格点的字符串数据。

      写入excel文件采用的是基于COM库实现的basicexcel,参考链接为:http://blog.csdn.net/augusdi/article/details/13295735

      运行IcMatchTool.exe关闭之后,在任务管理器中观察该进程没有关闭,没有去深究原因,直接采用一个新的进程关闭该进程。

      关闭指定名字的exe进程,参考链接:http://blog.csdn.net/caroline_wendy/article/details/29382347

    软件截图

      

    软件说明

       1.IcLibrary.xls和input.xls都需要在最后一行手动加一个end;

      2.IcLibrary为元器件库文件,input为需匹配的元器件文件;

      3.点击“匹配”按钮之后,在弹出的文件选择框中选择input.xls即可;

      4.文件中的close.exe不能删除。

      5.yes.xls是在元器件库中找到的元器件,no.xls是在元器件中没有找到的元器件;

      6.如果需匹配的元器件文件input.xls较大,程序需要运行较长时间,等待有“匹配完成”的弹窗出来即可。

    核心源码

    void CEXCELACESSDlg::OnMath()
    {
        
        //打开库文件
        string LibraryFileAddress("D:\IcManage\icLibrary.xls");
        CString **getLibData = GetExcelData(LibraryFileAddress);
        //row_num
        multimap<string,int> libMap;
        int libRowNum = row_num;
        for(int i = 1;i<libRowNum;i++)
        {
            string tmp(getLibData[i][0].GetBuffer());
            libMap.insert(pair<string,int>(tmp,i));
            getLibData[i][0].ReleaseBuffer();
        }
    
        //打开需要匹配的文件
        _TCHAR strFileFilter[] = "excel 文件(*.xlsx;*.xls)|*.xlsx;*.xls|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||";
        CFileDialog Dlg(TRUE,NULL ,NULL, OFN_HIDEREADONLY,strFileFilter);
        //修改默认打开路径
        Dlg.m_ofn.lpstrInitialDir=_T("D:\IcManage");
        if(Dlg.DoModal()==IDOK)
        {             
            m_FILE=Dlg.GetFileName();
            PathName=Dlg.GetPathName();
            UpdateData(FALSE);
        }
        string mathFileAddress(PathName.GetBuffer());
        CString **getMathData = GetExcelData(mathFileAddress);
        PathName.ReleaseBuffer();
        int mathRowNum = row_num;
    
        //创建输出的Yes.xls和No.xls文件
        BasicExcel eYes,eNo;
        BasicExcelWorksheet *sheetYes,*sheetNo;
        char bufYes[200],bufNo[200];
        CString   yesName,noName; 
        string yesAddress("D:\IcManage\yes.xls");
        string noAddress("D:\IcManage\no.xls");
        yesName.Format("%s", yesAddress.c_str());
        noName.Format("%s", noAddress.c_str());
        int k;
        for(k=0;k<yesName.GetLength();k++)
            bufYes[k]=yesName.GetAt(k);
        bufYes[k]=0;
        for(k=0;k<noName.GetLength();k++)
            bufNo[k]=noName.GetAt(k);
        bufNo[k]=0;
    
        eYes.Load(bufYes);
        eNo.Load(bufNo);
        eYes.New(1);
        eNo.New(1);
        r1 = 0;
        r2 = 0;
        sheetYes = eYes.GetWorksheet("Sheet1");
        sheetNo = eNo.GetWorksheet("Sheet1");
    
        string tmp_yes,tmp_no;
        for(int j = 0;j<3;j++)
        {
            string s(getLibData[0][j].GetBuffer());
            if(j==2)
                tmp_yes.append("");
            tmp_yes.append(s);
            tmp_yes.append(" ");
            tmp_no.append(s);
            tmp_no.append(" ");
        }
        tmp_no.append("");
        tmp_yes.append("需要数量");
        tmp_yes.append("");
        CString newCstring;
        newCstring.Format("%s", tmp_no.c_str());
        sheetFlag = 0;
        fenxi(newCstring,sheetNo);
        sheetFlag = 1;
        newCstring.Format("%s", tmp_yes.c_str());
        fenxi(newCstring,sheetYes);
    
        //匹配
        multimap<string,int>::iterator mapIter;
        for(int i = 1;i<mathRowNum;i++)
        {
            string tmp1(getMathData[i][0].GetBuffer());
        //    mapIter = libMap.find(tmp1);
            mapIter = FindNew(libMap.begin(),libMap.end(),tmp1);
            if(mapIter == libMap.end())//没找到
            {
                string tmp;
                for(int j = 0;j<3;j++)
                {
                    string s(getMathData[i][j].GetBuffer());
                    tmp.append(s);
                    if(j<2)
                        tmp.append(" ");
                    getMathData[i][j].ReleaseBuffer();
                }
    
    //            tmp.append("");
                CString newCstring;
                newCstring.Format("%s", tmp.c_str());
                sheetFlag = 0;
                fenxi(newCstring,sheetNo);
            }
            else//找到
            {
                int pos = (*mapIter).second;
                string tmp;
                int j;
                for(j = 0;j<3;j++)
                {
                    string s(getLibData[pos][j].GetBuffer());
                    tmp.append(s);
    //                if(j<2)
                    tmp.append(" ");
                    getLibData[pos][j].ReleaseBuffer();
                }
                string s(getMathData[i][j].GetBuffer());
                tmp.append(s);
                getMathData[i][j].ReleaseBuffer();
    //            tmp.append("");
                CString newCstring;
                newCstring.Format("%s", tmp.c_str());
                sheetFlag = 1;
                fenxi(newCstring,sheetYes);
            }
            getMathData[i][0].ReleaseBuffer();
        }
        for(int i=0; i<libRowNum; i++)
        {
            delete[] getLibData[i];
        }
    
        delete[] getLibData;
        for(int i=0; i<mathRowNum; i++)
        {
            delete[] getMathData[i];
        }
    
        delete[] getMathData;
        eYes.SaveAs(bufYes);
        eNo.SaveAs(bufNo);
        AfxMessageBox("匹配完成!");
      //打开某exe进程 ShellExecute(NULL,
    "open", "D:\IcManage\close.exe", NULL, NULL, SW_SHOWNORMAL); DestroyWindow(); AfxPostQuitMessage(0); exit(0); }
  • 相关阅读:
    SSH 错误解决案例1:Read from socket failed: Connection reset by peer
    vmware已经全面支持open-vm-tools
    RHEL7.1 安装openstack juno 一个BUG
    web快速开发框架 WebBuilder 8.7发布
    2019年如何选择合适的快速开发平台和框架
    快速开发平台 WebBuilder 8.6发布
    快速开发平台比较
    快速开发平台 WebBuilder 8.4 发布
    快速开发平台 WebBuilder 8 发布
    快速开发平台WebBuilder中ExtJS表格的增删改查
  • 原文地址:https://www.cnblogs.com/tractorman/p/4152922.html
Copyright © 2020-2023  润新知