C++ 咋想

//设置列表控件的报表显示方式
 m_ctrlList.ModifyStyle(LVS_ICON | LVS_SMALLICON | LVS_LIST, LVS_REPORT);
 
 //设置列表控件使用复选框
 m_ctrlList.SetExtendedStyle(LVS_EX_CHECKBOXES);
 
 //在列表控件中插入列
 for (int n = 0; n < 4; n++)
 {
  CString strColumnHeading = _T("");
  strColumnHeading.Format(_T("Column %d"), n);
  m_ctrlList.InsertColumn(n, strColumnHeading, LVCFMT_LEFT, 100);
 }
 
 //在列表控件中插入行
 for (int m = 0; m < 10; m++)
 {
  m_ctrlList.InsertItem(m, _T(""));
  m_ctrlList.SetCheck(m, TRUE);
  
  for (int n = 1; n < 4; n++)
  {
   CString strText = _T("");
   strText.Format(_T("SubItem %d %d"), m, n);
   m_ctrlList.SetItemText(m, n, strText);
  }
 }

 

//打开文件

CFileDialog.DoModal();
// CFile fileback;
 FileNameArry.RemoveAll();
 CFileDialog mFileDlg(TRUE,NULL,NULL,
  OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,
  "YPD Files (*.ypd)|*ypd|All Files (*.*)|*.*||",AfxGetMainWnd());

 char sBuffer[65000];
 sBuffer[0] = 0;
 mFileDlg.m_ofn.lpstrFile = sBuffer;
 mFileDlg.m_ofn.nMaxFile = 65000;

 

 CString strFileName = _T("");
 DWORD n = GetLastError();
  if(IDOK == mFileDlg.DoModal())
  {
 //  str = mFileDlg.GetPathName( );// 得到完整的文件名,包括目录名和扩展名如:c:\test\test1.txt
//  str = mFileDlg.GetFileName( );// 得到完整的文件名,包括扩展名如:test1.txt
//  CString strFileName(" ",10000);
//  CString strFileName = _T("");
  POSITION mPos = mFileDlg.GetStartPosition( ); //对于选择了多个文件的情况得到第一个文件位置。  
  while(mPos)
  {
   strFileName = mFileDlg.GetNextPathName( mPos ) ;
   FileNameArry.Add(strFileName);
   bakFile(strFileName,_T(""));
  }
 }

/

//分析文件

int CGPSFileUnitDlg::AnalyzeStr(const char* szResource, const char* szDelimit, CStringArray& ayRet)
{
    ayRet.RemoveAll();

 CString str = szResource;

 char * szResourcetemp = str.GetBuffer(str.GetLength()+1);

    char* token = strtok( (char*)szResourcetemp, szDelimit);

    while(token != NULL)
    {
  int nPos = ayRet.GetSize();

  ayRet.Add(CString(token));

        token = strtok( NULL, szDelimit);
    }
 str.ReleaseBuffer();

 return ayRet.GetSize();
}

 

/

//从字符串中解析出字符串数组

void CGPSFileUnitDlg:: GetStringArrayFromCharArr(CString str, CStringArray &arr, CString strSeparator)//从字符串中解析出字符串数组
{
 arr.RemoveAll();
 if (str.GetLength() == 0)
 {
  return;
 }
 CStringArray sa;  
 while (1)
 {  
        int pos = str.Find(strSeparator);  
        if(pos >= 0)
  { 
   CString strValue = str.Left(pos);
   strValue.TrimLeft(' ');
   strValue.TrimRight(' ');
            sa.Add(strValue);  
            str = str.Mid(pos+1);  
        }
  else 
  {  
   CString strValue = str;
   strValue.TrimLeft(' ');
   strValue.TrimRight(' ');
            sa.Add(strValue);  
            break;  
        }  
 }
 arr.Copy(sa);
}

 

//

//写文件

void CGPSFileUnitDlg::WriteIniFile(CStringArray &Array)
{
 CFile IniFile;
 CString m_sFileName =_T("");
 int nCount = FileNameArry.GetSize();
 CString strPathNametemp =_T("");
 if (nCount>0)
 {
  m_sFileName = FileNameArry.GetAt(0);  
  int nPos = m_sFileName.ReverseFind('\\') - 1;  
  strPathName = m_sFileName.Left(nPos+1);  
 }

// strPathName  = strPathName +"\\" +_T("合并") + MainLineName;UnitNumbertemp
 strPathNametemp  = strPathNameG +"\\" + UnitNumbertemp;
 FileNameArry.Add(strPathNametemp);
 UnitNumber = strPathName;
 
 if (!IniFile.Open(strPathNametemp, CFile::modeCreate|CFile::modeReadWrite|CFile::shareDenyNone))
  return ;
 
//  if( IniFile.m_hFile == INVALID_HANDLE_VALUE )
//   return;
//  
 
 CString strline;
 
 char *szBuff;
 int nLen = 0;
// int mn = MainLineArray.GetSize();AddLineArray
// int mn = FileStrAddArray.GetSize();
 int mn = FileStrAddArray.GetSize();
 
 for(int i = 0; i< Array.GetSize(); i++)
 {

  strline = Array[i] + L"\r\n";
  szBuff = strline.GetBuffer(strline.GetLength()+1);
  strline.ReleaseBuffer();  
  nLen = strlen(szBuff);

  TRACE(strline);
  if (szBuff == NULL)
  {
   continue;
  }
  //CStringBuffer buffer;
  //if( ConvertStr(strline,buffer) )
  //{
  // strncpy( szBuff,buffer.m_lpszBuffer, buffer.m_cbBuffer-2 );
  //}
  IniFile.Write( szBuff, nLen );
  szBuff = NULL;
 }
 
 IniFile.Close();
}

 

void CGPSFileUnitDlg::WriteUpdateFile(CStringArray &Array,CString strPath)
{
 CFile IniFile;
 CString m_sFileName =_T("");

 
 if (!IniFile.Open(strPath, CFile::modeCreate|CFile::modeReadWrite|CFile::shareDenyNone))
  return ;
 
 CString strline;
 
 char *szBuff;
 int nLen = 0;
 int mn = FileStrAddArray.GetSize();
 
 for(int i = 0; i< Array.GetSize(); i++)
 {
  
  strline = Array[i] + L"\r\n";
  szBuff = strline.GetBuffer(strline.GetLength()+1);
  strline.ReleaseBuffer();  
  nLen = strlen(szBuff);
  
  TRACE(strline);
  if (szBuff == NULL)
  {
   continue;
  }

  IniFile.Write( szBuff, nLen );
  szBuff = NULL;
 }
 
 IniFile.Close();
}

 

 

 

 

//

//复选框单选

void CGPSFileUnitDlg::OnClickListFilename(NMHDR* pNMHDR, LRESULT* pResult)
{
 // TODO: Add your control notification handler code here
 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
 int index = pNMListView->iItem;
 int nCount = m_ctrlList.GetItemCount();
 
 if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
 {
  return;
 }
 
 //CheckBox旧状态
 BOOL bOldChecked = (BOOL)(((pNMListView->uOldState & 0x3000) >> 12) - 1);
 
 //CheckBox新状态
 BOOL bNewChecked = (BOOL)(((pNMListView->uNewState & 0x3000) >> 12) - 1);
 
 BOOL bPrevState = (BOOL)(((pNMListView-> uOldState & LVIS_STATEIMAGEMASK)>> 12)-1);  
 BOOL bChecked=(BOOL)(((pNMListView-> uNewState & LVIS_STATEIMAGEMASK)>> 12)-1);  
 
 
 for (int n=0;n<nCount;n++)
 {
  //   if (m_ctrlList.GetCheck(n) && n!=pNMListView->iItem)
  //   {
  //    m_ctrlList.SetCheck(n,TRUE);
  //   }
  if (m_ctrlList.GetCheck(n) && n != pNMListView->iItem)
   m_ctrlList.SetCheck(n,FALSE);
  
 }
 
 if (bPrevState&&!bChecked) m_ctrlList.SetCheck(pNMListView->iItem);
 
 BOOL b_status = m_ctrlList.GetCheck(pNMListView->iItem);
 if (!b_status)
 {
  int Index = pNMListView->iItem;
  MainLineName = m_ctrlList.GetItemText(Index,1);
  vector < CFileCount > ::iterator itrFile = ivecFileCount.begin();
  //设置主线
  int n = 0;
  for (;itrFile != ivecFileCount.end();itrFile++)
  {
   CString strFileName = _T("");
   strFileName = itrFile->FileName;
   CString strFileNametemp = _T("");
   strFileNametemp = strFileName.Right(strFileName.GetLength() - strFileName.ReverseFind('\\') - 1);  
   if (strFileNametemp == MainLineName)
   {
    itrFile->MainLineindex = n;
    itrFile->index = n;
    n++;
    continue;
   }
   itrFile->MainLineindex = 0;
   itrFile->index = n;
    n++;
  }
 }
 
 if(b_status)
 {
  MainLineName = _T("");
 }

/* NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
 int index = pNMListView->iItem;
 int nCount = FileNameArry.GetSize();

 if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
 {
  return;
 }
 
 //CheckBox旧状态
 BOOL bOldChecked = (BOOL)(((pNMListView->uOldState & 0x3000) >> 12) - 1);
 
 //CheckBox新状态
 BOOL bNewChecked = (BOOL)(((pNMListView->uNewState & 0x3000) >> 12) - 1);
 
 BOOL bPrevState = (BOOL)(((pNMListView-> uOldState & LVIS_STATEIMAGEMASK)>> 12)-1);  
 BOOL bChecked=(BOOL)(((pNMListView-> uNewState & LVIS_STATEIMAGEMASK)>> 12)-1);  
 
 BOOL b_status = m_ctrlList.GetCheck(pNMListView->iItem);

// if (m_ctrlList.GetCheck(n) && n != pNMListView->iItem)
 // m_ctrlList.SetCheck(pNMListView->iItem,FALSE);
 
// if (bPrevState&&!bChecked) m_ctrlList.SetCheck(pNMListView->iItem);
 if (b_status)
 {
  m_ctrlList.SetCheck(pNMListView->iItem,FALSE);
  CString PathAndName = _T("");
  CString strName = m_ctrlList.GetItemText(pNMListView->iItem,1);
  CString strPath = m_ctrlList.GetItemText(pNMListView->iItem,2);
  PathAndName = strPath + "\\" + strName;
  int nCount = FileNameArry.GetSize();
  for (int n =0;n<nCount;n++)
  {
   CString PathAndNametemp = FileNameArry.GetAt(n);
   if (PathAndNametemp == PathAndName)
   {
    FileNameArry.RemoveAt(n);
    break;
   }
  }
 }
 
 else
 {
  m_ctrlList.SetCheck(pNMListView->iItem,TRUE);
  CString PathAndName = _T("");
  CString strName = m_ctrlList.GetItemText(pNMListView->iItem,1);
  CString strPath = m_ctrlList.GetItemText(pNMListView->iItem,2);
  PathAndName = strPath + "\\" + strName;
  int nCount = FileNameArry.GetSize();
  FileNameArry.Add(PathAndName);
 }

// if (bPrevState&&!bChecked)
//  m_ctrlList.SetCheck(pNMListView->iItem);
 
int nm = FileNameArry.GetSize();
 *pResult = 0;*/
}

 

 

///

//写日志

void Log(CString Msg)
{
 EnterCriticalSection(&g_csLogFile);
 FILE * fp;
 char item[2048];

 CString strFilePath = GetFilePath();
 strFilePath += "\\DataInterface_LOG.txt";

 Sleep(1);

 fp = fopen(strFilePath,  "a");
        
 memset(item, 0, sizeof(item));
 char * szTime = (char*)malloc(16);
 char * szDate = (char*)malloc(16);
 memset(szTime, 0, sizeof(szTime));
 memset(szDate, 0, sizeof(szDate));
 _strdate(szDate);
 _strtime(szTime);
 sprintf(item, "%-10.10s%-12.12s;%s", szDate, szTime, (LPCTSTR)Msg);
 free(szDate);
 free(szTime);

 if (fp != NULL)  //lrb
 {
  fprintf(fp, "%s\n", item);
  fclose(fp);
 }

// fprintf(fp, "%s\n", item);
// fclose(fp);
 LeaveCriticalSection(&g_csLogFile);
}
/*
void Log(CString Msg)
{
 if (Msg == "")
  return;
 
 FILE * fp;
 
 char item[2048];
 
 char szPath[1024];
 memset(szPath, 0, sizeof(szPath));
 GetModuleFileName(NULL, szPath, sizeof(szPath));
 CString strAppPath = szPath;
 int nLen = strAppPath.GetLength();
 int nFind = strAppPath.ReverseFind('\\');
 int nNum = nLen;
 if (nFind > -1)
 {
  nNum = nFind;
  strAppPath = strAppPath.Left(nNum);
 }
 
 CString strOutputPath = strAppPath;
 strOutputPath += "\\Trace.txt";
 
 fp = fopen(strOutputPath,  "a");
 
 
 fprintf(fp, "%s\r\n", (LPCTSTR)Msg);
 fclose(fp);
}

 

/

//目前默认逗号分割
void GetStringArrayFromCharArr(CString str, CStringArray &arr, const CString strSep)//从字符串中解析出字符串数组 mjm  2007 09 04
{
 arr.RemoveAll();
 if (str == "")
  return;
 CStringArray sa;  
 while (1)
 {  
        int pos = str.Find(strSep);  
        if(pos >= 0)
  { 
   CString strValue = str.Left(pos);
   strValue.TrimLeft(' ');
   strValue.TrimRight(' ');
            sa.Add(strValue);  
//            str = str.Mid(pos+1);  
   strValue = str.Mid(pos + 1);
   str = strValue;
        }
  else 
  {  
   CString strValue = str;
   strValue.TrimLeft(' ');
   strValue.TrimRight(' ');
            sa.Add(strValue);  
            break;  
        }  
 }
 arr.Copy(sa);
 sa.RemoveAll();
}

 

/

CString GetMacAdd()  //获取机器的mac地址
{
// 过程:
//      1. 创建一个无名管道。
//      2. 创建一个IPCONFIG 的进程,并将输出重定向到管道。
//      3. 从管道获取命令行返回的所有信息放入缓冲区lpszBuffer。
//      4. 从缓冲区lpszBuffer中获得抽取出MAC串。
//
//  提示:可以方便的由此程序获得IP地址等其他信息。
//        对于其他的可以通过其他命令方式得到的信息只需改变strFetCmd 和
//        str4Search的内容即可。
 CString strMacAdd = "";

 //命令行输出缓冲大小
 const long MAX_COMMAND_SIZE = 10000;

 //获取MAC命令行
 char szFetCmd[] = "ipconfig /all";
 //网卡MAC地址的前导信息
 const CString str4Search = "Physical Address. . . . . . . . . : ";

 SECURITY_ATTRIBUTES sa;
    HANDLE hReadPipe, hWritePipe;

    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;
 
 //创建管道
 BOOL bret = CreatePipe(&hReadPipe, &hWritePipe, &sa, 0);
 if (bret)
 {
  //控制命令行窗口信息
  STARTUPINFO si;
  //返回进程信息
  PROCESS_INFORMATION pi;
  
  si.cb = sizeof(STARTUPINFO);
  GetStartupInfo(&si);
  si.hStdError = hWritePipe;
  si.hStdOutput = hWritePipe;
  si.wShowWindow = SW_HIDE; //隐藏命令行窗口
  si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
  
  //创建获取命令行进程
  bret = CreateProcess(NULL, szFetCmd, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi );
  
  char szBuffer[MAX_COMMAND_SIZE+1]; //放置命令行输出缓冲区
  CString strBuffer = "";
  
  if (bret)
  {
   WaitForSingleObject(pi.hProcess, INFINITE);
   unsigned long count;
   CloseHandle(hWritePipe);
   
   memset(szBuffer, 0x00, sizeof(szBuffer));
   bret = ReadFile(hReadPipe, szBuffer, MAX_COMMAND_SIZE, &count, 0);
   if (!bret)
   {
    //关闭所有的句柄
    CloseHandle(hWritePipe);
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    CloseHandle(hReadPipe);
   }
   else
   {
    strBuffer = szBuffer;
    long ipos;
    ipos = strBuffer.Find(str4Search);
    
    //提取MAC地址串
    CString strTemp = "";
    strTemp = strBuffer.Mid(ipos + str4Search.GetLength());
    strBuffer = strTemp;
    ipos = strBuffer.Find("\n");
    strTemp = strBuffer.Mid(0, ipos);
    strBuffer = strTemp;
    
    //关闭所有的句柄
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    CloseHandle(hReadPipe);
   
    strBuffer.TrimRight("\r\n");
    strMacAdd = strBuffer;
   }
  }
 }

 return strMacAdd;
}

 

//

void ViewFeederFromDNA(long nFeederID, CString strFeederName, CWnd* pWnd)
{
 //如果DNA-D单线图管理系统程序已启动,则发送消息
 HWND hWnd = ::FindWindow("DNA-D单线图管理系统", NULL);
 if (!hWnd)
 {
  _DNASOperInfo* pDNASOperInfo = NULL;
  HANDLE hMapFile = CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0, sizeof(struct _DNASOperInfo), _T("DNAS_LogIn"));
  if (hMapFile)
  {
   pDNASOperInfo = (_DNASOperInfo*)MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, 0);
   
   pDNASOperInfo->nOperType = 1;
   pDNASOperInfo->nDepID = g_LoginUserTypeInfo.DepID;
   memset(pDNASOperInfo->szDepName, 0, sizeof(pDNASOperInfo->szDepName));
   strcpy(pDNASOperInfo->szDepName, g_LoginUserTypeInfo.ComName);
   pDNASOperInfo->nUserID = g_LoginUserTypeInfo.UserId;
   memset(pDNASOperInfo->szUserName, 0, sizeof(pDNASOperInfo->szUserName));
   strcpy(pDNASOperInfo->szUserName, g_LoginUserTypeInfo.UserName);
   pDNASOperInfo->nUserType = g_LoginUserTypeInfo.UserType;
   pDNASOperInfo->nUserRight = g_LoginUserTypeInfo.nUserRight;
   pDNASOperInfo->nFeederID = nFeederID;       //查看的单线图ID
   strcpy(pDNASOperInfo->szFeederName, (LPCTSTR)strFeederName); //查看的单线图名称
   pDNASOperInfo->nVersionID = -1;      //查看最新的单线图版本ID
   
   
   //调用DNA程序
   STARTUPINFO si;
   ZeroMemory(&si, sizeof(si));
   si.cb = sizeof(si);
   si.dwFlags = STARTF_USESHOWWINDOW;
   si.wShowWindow = SW_SHOW;
   
   PROCESS_INFORMATION ProInfo;
   
   char pName[MAX_PATH];
   GetModuleFileName(NULL, pName, MAX_PATH);
   (_tcsrchr(pName, _T('\\')))[1] = 0;
   
   CString str_url = pName;
   str_url += "\\DNA-D.exe";
   
   pWnd->BeginWaitCursor();
   
   if (!CreateProcess(str_url, // No module name (use command line).
    NULL, // Command line.
    NULL,             // Process handle not inheritable.
    NULL,             // Thread handle not inheritable.
    FALSE,            // Set handle inheritance to FALSE.
    0,                // No creation flags.
    NULL,             // Use parent's environment block.
    NULL,             // Use parent's starting directory.
    &si,              // Pointer to STARTUPINFO structure.
    &ProInfo)             // Pointer to PROCESS_INFORMATION structure.
    )
   {
    AfxMessageBox("DNA_D程序不能打开!");
   }    
   
   Sleep(8000);
   UnmapViewOfFile(pDNASOperInfo);
   CloseHandle(hMapFile);
   pWnd->EndWaitCursor();
  }
 }
 else
 {
  _DNASOperInfo DNASOperInfo;
  DNASOperInfo.nOperType = 1;
  DNASOperInfo.nDepID = g_LoginUserTypeInfo.DepID;
  memset(DNASOperInfo.szDepName, 0, sizeof(DNASOperInfo.szDepName));
  strcpy(DNASOperInfo.szDepName, g_LoginUserTypeInfo.ComName);
  DNASOperInfo.nUserID = g_LoginUserTypeInfo.UserId;
  memset(DNASOperInfo.szUserName, 0, sizeof(DNASOperInfo.szUserName));
  strcpy(DNASOperInfo.szUserName, g_LoginUserTypeInfo.UserName);
  DNASOperInfo.nUserType = g_LoginUserTypeInfo.UserType;
  DNASOperInfo.nUserRight = g_LoginUserTypeInfo.nUserRight;
  DNASOperInfo.nFeederID = nFeederID;       //查看的单线图ID
  strcpy(DNASOperInfo.szFeederName, (LPCTSTR)strFeederName); //查看的单线图名称
  DNASOperInfo.nVersionID = -1;      //查看最新的单线图版本ID
  
  COPYDATASTRUCT cpd;                     // 给COPYDATASTRUCT结构赋值
  cpd.dwData = 0;
  cpd.cbData = sizeof(_DNASOperInfo);
  cpd.lpData = &DNASOperInfo;
  ::SendMessage(hWnd, WM_COPYDATA, NULL, (LPARAM)&cpd);
 }
}

 

 

 

BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
 static char szTmp[80];
 static char szBuffer[256];
 CSearchInfo* pInfo = (CSearchInfo*)lParam;
 if (pInfo->bFound)
  return TRUE;

 HWND hFindWnd = ::FindWindow(pInfo->strTitle, NULL);
 if (hFindWnd)
 {
  pInfo->bFound = TRUE;
 }

 return TRUE;
}

 

 

CString FormatDateTime(CString strDateTime)  //将strDateTime标准格式化为日期时间如:YYYY-MM-DD HH24:MI:SS
{
 CString strFormatDT = strDateTime;

 //主要将YYYY-MM-DD,格式化为YYYY-MM-DD HH24:MI:SS
 int nFind = strDateTime.Find(":");
 if (nFind == -1)
 {
  strFormatDT = strDateTime + " 00:00:00";
 }

 return strFormatDT;
}

 

/

 

 

 

 

 

//目前默认逗号分割
void GetStringArrayFromCharArr(CString str, CStringArray &arr, CString strSeparator)//从字符串中解析出字符串数组 mjm  2007 09 04
{
 arr.RemoveAll();
 if (str.GetLength() == 0)
 {
  return;
 }
 CStringArray sa;  
 while (1)
 {  
        int pos = str.Find(strSeparator);  
        if(pos >= 0)
  { 
   CString strValue = str.Left(pos);
   strValue.TrimLeft(' ');
   strValue.TrimRight(' ');
            sa.Add(strValue);  
            str = str.Mid(pos+1);  
        }
  else 
  {  
   CString strValue = str;
   strValue.TrimLeft(' ');
   strValue.TrimRight(' ');
            sa.Add(strValue);  
            break;  
        }  
 }
 arr.Copy(sa);
}

//目前默认逗号分割
void GetStringFromStringArray(CString &str, CStringArray &arr, CString strSeparator)//从字符串数组合并出字符串 xy  2009 12 31
{
 str = _T("");

 int nSize = arr.GetSize();

 if(nSize == 0)
 {
  return;
 }

 for(int i = 0; i < nSize; i ++)
 {
  if(i < nSize - 1)
  {
   str += arr[i] + strSeparator;
  }
  else
  {
   str += arr[i];
  }
 }
}

double GetRadian(double dbDegree)
{
   return dbDegree * PI / 180.0;
}

double GetDistance(double dbLat1, double dbLng1, double dbLat2, double dbLng2)
{
 double dbRadLat1 = GetRadian(dbLat1);
 double dbRadLat2 = GetRadian(dbLat2);

 //纬度弧度差
 double dbLat = dbRadLat1 - dbRadLat2;
 //经度弧度差
 double dbLng = GetRadian(dbLng1) - GetRadian(dbLng2);

 double dbDistance = 2 * asin(sqrt(pow(sin(dbLat/2),2) + cos(dbRadLat1)*cos(dbRadLat2)*pow(sin(dbLng/2),2)));

 dbDistance = dbDistance * EARTH_RADIUS;

 return dbDistance;
}

/* 功能说明:()将地理坐标(wd,jd)转换成绝对的高斯坐标(y,x)

            ()本函数支持基于六度带(或三度带)、克拉索夫斯基椭球进行转换                            */

        /* 适用范围:本函数适用于将地球东半球中北半球(即东经度到东经度,北纬度至度)范围

            内所有地理坐标到高斯坐标的转换           */

        /* 使用说明:调用本函数后返回的结果应在满足精度的条件下进行四舍五入     */

        // double jd;         输入参数: 地理坐标的经度,以秒为单位

        // double wd;         输入参数: 地理坐标的纬度,以秒为单位

        // short  DH;      输入参数: 三度带或六度带的带号

        /*  六度带(三度带)的带号是这样得到的:从东经度到东经度自西向东按每度(3度)顺序编号

        (编号从开始),这个顺序编号就称为六度带(三度带)的带号。因此,六度带的带号的范围是-30,

        三度带的带号的范围是-60。

          如果一个点在图号为TH的图幅中,那麽该点所处的六度带的带号就可以这样得到:将该图号的

        第、位组成的字符串先转换成数字,再减去。例如某点在图幅中,该点所在的带号就

        是-30,即。

          如果调用本函数去进行一般的从地理坐标到基于六度带高斯坐标的变换(非邻带转换),则参

        数DH的选取按前一段的方法去确定。              

          如果调用本函数去进行基于六度带邻带转换,则参数DH的选取先按上述方法去确定,然后看是

        往前一个带还是后一个带进行邻带转换再确定是加还是减。        */

void GeoToGauss(double jd, double wd, short DH, short DH_width, double* y, double* x, double LP)
{
 double t;     //  t=tgB

 double L;     //  中央经线的经度

 double l0;    //  经差

 double jd_hd, wd_hd;  //  将jd、wd转换成以弧度为单位

 double et2;    //  et2 = (e' ** 2) * (cosB ** 2)

 double N;     //  N = C / sqrt(1 + et2)

 double X;     //  克拉索夫斯基椭球中子午弧长

 double m;     //  m = cosB * PI/180 * l0

 double tsin, tcos;   //  sinB,cosB


 //double PI = 3.14159265358979;

 double b_e2 = 0.0067385254147;

 double b_c = 6399698.90178271;

 

 jd_hd = jd / 3600.0 * PI / 180.0;    // 将以秒为单位的经度转换成弧度

 wd_hd = wd / 3600.0 * PI / 180.0;    // 将以秒为单位的纬度转换成弧度

 

 // 如果不设中央经线(缺省参数: -1000),则计算中央经线,

 // 否则,使用传入的中央经线,不再使用带号和带宽参数

 //L = (DH - 0.5) * DH_width ;      // 计算中央经线的经度

 if (LP == -1000)

 {

  L = (DH - 0.5) * DH_width;      // 计算中央经线的经度

 }

 else

 {

  L = LP;

 }

 l0 = jd / 3600.0 - L;       // 计算经差

 tsin = sin(wd_hd);        // 计算sinB

 tcos = cos(wd_hd);        // 计算cosB

 // 计算克拉索夫斯基椭球中子午弧长X

 X = 111134.8611 / 3600.0 * wd - (32005.7799 * tsin + 133.9238 * pow(tsin, 3)

  + 0.6976 * pow(tsin, 5) + 0.0039 * pow(tsin, 7)) * tcos;

 et2 = b_e2 * pow(tcos, 2);      //  et2 = (e' ** 2) * (cosB ** 2)

 N = b_c / sqrt(1 + et2);      //  N = C / sqrt(1 + et2)

 t = tan(wd_hd);         //  t=tgB

 m = PI / 180 * l0 * tcos;       //  m = cosB * PI/180 * l0

 *x = X + N * t * (0.5 * pow(m, 2)

  + (5.0 - pow(t, 2) + 9.0 * et2 + 4 * pow(et2, 2)) * pow(m, 4) / 24.0

  + (61.0 - 58.0 * pow(t, 2) + pow(t, 4)) * pow(m, 6) / 720.0);

 *y = N * (m + (1.0 - pow(t, 2) + et2) * pow(m, 3) / 6.0

  + (5.0 - 18.0 * pow(t, 2) + pow(t, 4) + 14.0 * et2

  - 58.0 * et2 * pow(t, 2)) * pow(m, 5) / 120.0);
}

CString ConvertGPSPositonFromDToDMS(CString strDPosition)
{
 CString strDMSPosition = _T("");

 double dbPos = _tcstod(strDPosition, NULL);

 CString strTemp = _T("");

 int nValue = 0;

 nValue = (int)dbPos;
 strTemp.Format(_T("%d"), nValue);
 strDMSPosition += strTemp + _T("'");

 nValue = (int)((dbPos - nValue) * 60);
 strTemp.Format(_T("%d"), nValue);
 strDMSPosition += strTemp + _T("'");

 nValue = (int)(((dbPos - (int)dbPos) * 60 - nValue) * 60);
 strTemp.Format(_T("%d"), nValue);
 strDMSPosition += strTemp;

 return strDMSPosition;
}

CString ConvertGPSPositonFromDToDMS(double dbDPosition)
{
 CString strDMSPosition = _T("");

 CString strTemp = _T("");

 int nValue = 0;

 nValue = (int)dbDPosition;
 strTemp.Format(_T("%d"), nValue);
 strDMSPosition += strTemp + _T("'");

 nValue = (int)((dbDPosition - nValue) * 60);
 strTemp.Format(_T("%d"), nValue);
 strDMSPosition += strTemp + _T("'");

 nValue = (int)(((dbDPosition - (int)dbDPosition) * 60 - nValue) * 60);
 strTemp.Format(_T("%d"), nValue);
 strDMSPosition += strTemp;

 return strDMSPosition;
}

 

///

//打开网页

void CLongDisView::OnZZ()
{
 char buffer[256];
 char * pLastPath;
 int pathIndex;
 ::GetModuleFileName(NULL, buffer, 256); //*获取当前执行的文件路径
 pLastPath = _tcsrchr(buffer,'\\'); //*反向查找
 pathIndex = pLastPath - buffer;
 buffer[pathIndex +1] = 0;
 CString Vpath = buffer;
 Vpath+="Config.ini";

 LPCTSTR strPath = Vpath;

 char m_szFilePath[MAX_PATH];
 ZeroMemory(m_szFilePath,MAX_PATH);


  GetPrivateProfileString("Config","郑州局","http://localhost//wleam",m_szFilePath,MAX_PATH,strPath);
  if (0 == strcmp(m_szFilePath, ""))
  {
   strcpy(m_szFilePath,"http://localhost//wleam");
  }
   // TODO: Add your control notification handler code here
  HKEY hkRoot,hSubKey; //定义注册表根关键字及子关键字
  char ValueName[256];
  unsigned char DataValue[256];
  ZeroMemory(DataValue,MAX_PATH);
  unsigned long cbValueName=256;
  unsigned long cbDataValue=256;
  char ShellChar[256]; //定义命令行
  DWORD dwType;
 
  //打开注册表根关键字
  if(RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkRoot)==ERROR_SUCCESS)
  {
   //打开子关键字
   if(RegOpenKeyEx(hkRoot,
    "htmlfile\\shell\\open\\command",
    0,
    KEY_ALL_ACCESS,
    &hSubKey)==ERROR_SUCCESS)
    {
      //读取注册表,获取默认浏览器的命令行 
      RegEnumValue(hSubKey, 
    0,
    ValueName,
    &cbValueName,
    NULL,
    &dwType,
    DataValue,
    &cbDataValue);
      // 调用参数(主页地址)赋值
      strcpy(ShellChar,(char *)DataValue);
      strcat(ShellChar,m_szFilePath);
      // 启动浏览器
      WinExec(ShellChar,SW_SHOW);
  
    }
   else
  MessageBox("WEB浏览器打开错误!","错误",MB_OK);
  }
  else
  MessageBox("WEB浏览器打开错误!","错误",MB_OK);
  //关闭注册表
  RegCloseKey(hSubKey);
  RegCloseKey(hkRoot);
}
///

if ((1 == nIDEvent)&&(m_Rendraw[0]==FALSE))
{
 if (((CLongDisApp*)AfxGetApp())->m_Init[0])
 {

  if (m_bShining)
  {
   dc.Ellipse(ClientRect.Width()*815/1060-7,ClientRect.Height()*218/795-7,
    ClientRect.Width()*815/1060+7,ClientRect.Height()*218/795+7);
   m_bShining = FALSE;
  }
  else
  {
   dc.Ellipse(ClientRect.Width()*815/1060-5,ClientRect.Height()*218/795-5,
    ClientRect.Width()*815/1060+5,ClientRect.Height()*218/795+5);
   m_bShining = TRUE;
  }
  Invalidate(FALSE);

 }
}

 

 

/

//

///沈阳局
  char m_syFilePath[MAX_PATH];
  ZeroMemory(m_syFilePath,MAX_PATH);
  GetPrivateProfileString("Config","沈阳","",m_syFilePath,MAX_PATH,strPath);
  if (0 != strcmp(m_syFilePath, ""))
  {
 try
  {
 
   m_pConnection[1].CreateInstance(__uuidof(Connection));
   m_pConnection[1]->ConnectionTimeout=30;
   _bstr_t strConnect = m_syFilePath;
   HRESULT m = m_pConnection[1]->Open((_bstr_t)strConnect,"","",adModeUnknown);
  }
 catch(_com_error e)
  {
   hr[1] = -1;
  }

if (hr[1] == 0)
 {
 m_pCommand[1].CreateInstance(__uuidof(Command));
 m_pCommand[1]->ActiveConnection = m_pConnection[1];   // 将库连接赋于它
 m_pCommand[1]->CommandText = "select * from tf2_reportresult where ISCLOSED = 1 and statistic_type = 2 or statistic_type = 1";   // SQL语句
 m_pRecordset[1] = m_pCommand[1]->Execute(NULL, NULL,adCmdText);   // 执行SQL语句,返回记录集

   
 
 while(m_pRecordset[1]->adoEOF)
  {
   KillTimer(2);
   m_Rendraw[1] = FALSE;
   break;
  }
 while(!m_pRecordset[1]->adoEOF)
  {
  if (errorinfo == NULL)
   {
    errorinfo=new CErrorMessage();
    errorinfo->Create(IDD_ERROR,this);
    AfxGetMainWnd()->SendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,0);//最大化显示
    errorinfo->ShowWindow(SW_SHOW);
   }
   else if( ::IsWindowVisible(errorinfo->GetSafeHwnd()) == FALSE)
   {
    AfxGetMainWnd()->SendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,0);//最大化显示
       errorinfo->ShowWindow(SW_SHOW);
   }

   if (!m_Rendraw[1])
   {
    SetTimer(2,1000,0);
    m_Rendraw[1] = TRUE;
   }
   break;
  }
  m_pRecordset[1]->Close();
  m_pConnection[1]->Close();
 }

 }

 

 

//

 

_ConnectionPtr m_pConnection[18];
 _RecordsetPtr m_pRecordset[18];
 _CommandPtr m_pCommand[18];
 HRESULT hr[18];

 

 

 char buffer[256];
 char * pLastPath;
 int pathIndex;
 ::GetModuleFileName(NULL, buffer, 256); //*获取当前执行的文件路径
 pLastPath = _tcsrchr(buffer,'\\'); //*反向查找
 pathIndex = pLastPath - buffer;
 buffer[pathIndex +1] = 0;
 CString Vpath = buffer;
 Vpath+="Config.ini";

 LPCTSTR strPath = Vpath;

 char m_statFilePath[MAX_PATH];
 ZeroMemory(m_statFilePath,MAX_PATH);
 GetPrivateProfileString("Config","故障统计","",m_statFilePath,MAX_PATH,strPath);
 CString sqlconnect = _T("");
 sqlconnect = m_statFilePath;
 
 try
 {
  m_pConnectiontemp.CreateInstance(__uuidof(Connection));
  m_pConnectiontemp->ConnectionTimeout=30;
  _bstr_t strConnect = sqlconnect;
  hre = m_pConnectiontemp->Open((_bstr_t)strConnect,"","",adModeUnknown);
 }
 catch(_com_error e)
 {
  CString errormessage;
  errormessage.Format("故障信息表连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
  AfxMessageBox(errormessage);///显示错误信息
  AfxMessageBox(e.Description());
 }
 //获取自定义数据库的报警序列数ID

 
   if (SUCCEEDED(hre))
  {
  m_pCommandtemp.CreateInstance(__uuidof(Command));
   m_pCommandtemp->ActiveConnection = m_pConnectiontemp;   // 将库连接赋于它
  m_pCommandtemp->CommandText = "select * from ta1_error_list order by ID desc";
  HRESULT pt = m_pRecordsettemp.CreateInstance(__uuidof(Recordset));
  m_pRecordsettemp=m_pCommandtemp->Execute(NULL, NULL,adCmdText);
   while(!m_pRecordsettemp->adoEOF)
    {
    _variant_t varValueNum = m_pRecordsettemp->GetCollect("ID");
    if (varValueNum.vt != VT_NULL)
    num = varValueNum;
    else
    num = 1;
     break;
    }
 }
 
 //获取OFFICEID
 CString OffeceID = _T("");;
  _variant_t varValueoff = record->GetCollect("OFFICE_ID");
  LONG officeID = 0;
  if (varValueoff.vt != VT_NULL)
  officeID = varValueoff;
 else
  officeID = atoi(OffeceID);

 //获取SEGMENTID//
 CString SegmentID = _T("");;
 _variant_t varValueseng = record->GetCollect("SEGMENT_ID");
 LONG segmentID = 0;
 if (varValueseng.vt != VT_NULL)
  segmentID = varValueseng;
 else
  segmentID = atoi(OffeceID);

 //获取STATIONID
 CString StationID = _T("");;
 _variant_t varValuesta = record->GetCollect("STATION_ID");
 LONG stationID = 0;
 if (varValuesta.vt != VT_NULL)
  stationID = varValuesta;
 else
  stationID = atoi(OffeceID);

 //获取报警信息
 CString errormsg = _T("");
 _variant_t varerrormsg = record->GetCollect("TROUBLE_CONTENT");
 if (varerrormsg.vt !=VT_NULL)
  errormsg = (char*)(_bstr_t)varerrormsg;
 else errormsg = _T("");
  //errormsg = (char*)(_bstr_t)record->GetCollect("TROUBLE_CONTENT");

 //获取报警类型
 CString errortype = _T("");
 _variant_t varerrortype = record->GetCollect("statistic_type");
 if (varerrortype.vt != VT_NULL)
  errortype = (char*)(_bstr_t)varerrortype;
 else errortype = _T("");
// errortype = (char*)(_bstr_t)record->GetCollect("statistic_type");

 CString suggest = _T("");
 _variant_t varsuggest = record->GetCollect("SUGGEST");
 if (varsuggest.vt != VT_NULL)
  suggest = (char*)(_bstr_t)varsuggest;
 else
  suggest = _T("");
 
// suggest = (char*)(_bstr_t)record->GetCollect("SUGGEST");

 //获取时间
  CString ErrorTime;
 ErrorTime = (char*)(_bstr_t)record->GetCollect("TROUBLE_START");
 
 CString temp_Office;
 temp_Office.Format("select * from ta3_office where ID = %d",officeID);
 
 CString temp_Segment;
 temp_Segment.Format("select * from ta3_segment where ID = %d",segmentID);
 
 CString temp_Station;
 temp_Station.Format("select * from ta3_station where ID = %d",stationID);
 
 CString Station_Type;
 Station_Type.Format("select * from ta3_station where ID = %d",stationID);
 
 //局信息
 if (officeID != 0)
 {
  command->CommandText = (_bstr_t)temp_Office;   // SQL语句
  m_pRecordsettemp = command->Execute(NULL, NULL,adCmdText);   // 执行SQL语句,返回记录集
  temp_Office = (char*)(_bstr_t)m_pRecordsettemp->GetCollect("SNAME");
  m_pRecordsettemp->Close();
 }
 else
 {
  temp_Office = "";
 }
 
 //添加段信息
 if (segmentID != 0)
 {
  command->CommandText = (_bstr_t)temp_Segment;   // SQL语句
  m_pRecordsettemp = command->Execute(NULL, NULL,adCmdText);   // 执行SQL语句,返回记录集
  temp_Segment = (char*)(_bstr_t)m_pRecordsettemp->GetCollect("SNAME");
  m_pRecordsettemp->Close();
 }
 else
 {
  temp_Segment = "";
 }
 
 //添加站信息
 if (stationID != 0)
 {
  command->CommandText = (_bstr_t)temp_Station;   // SQL语句
  m_pRecordsettemp = command->Execute(NULL, NULL,adCmdText);   // 执行SQL语句,返回记录集
  temp_Station = (char*)(_bstr_t)m_pRecordsettemp->GetCollect("SNAME");
  m_pRecordsettemp->Close();
 }
 else
 {
  temp_Station = "";
 }
 
 //添加站设备型号
 if (stationID != 0)
 {
  command->CommandText = (_bstr_t)Station_Type;   // SQL语句
  m_pRecordsettemp = command->Execute(NULL, NULL,adCmdText);   // 执行SQL语句,返回记录集
  _variant_t Station_type = m_pRecordsettemp->GetCollect("DEF_STR7");
//  CString stationtype = "";
  if (Station_type.vt != VT_NULL)
   Station_Type = (char*)(_bstr_t)Station_type;
  else
  Station_Type = "";
  m_pRecordsettemp->Close();
 }
 else
 {
  Station_Type = "";
 }

 //*********************
 //往自定义数据库中添加信息
 char buffer1[256];
 char * pLastPath1;
 int pathIndex1;
 ::GetModuleFileName(NULL, buffer1, 256); //*获取当前执行的文件路径
 pLastPath1 = _tcsrchr(buffer1,'\\'); //*反向查找
 pathIndex1 = pLastPath1 - buffer1;
 buffer1[pathIndex1 +1] = 0;
 CString Vpath1 = buffer1;
 Vpath1+="Config.ini";

 LPCTSTR strPath1 = Vpath1;

 char m_statFilePath1[MAX_PATH];
 ZeroMemory(m_statFilePath1,MAX_PATH);
 GetPrivateProfileString("Config","故障统计","",m_statFilePath1,MAX_PATH,strPath1);
 CString sqlconnect1 = _T("");
 sqlconnect1 = m_statFilePath1;
 try
 {
  m_pConnectiontemp.CreateInstance(__uuidof(Connection));
  m_pConnectiontemp->ConnectionTimeout=30;
  _bstr_t strConnect1 = sqlconnect1;
  hre = m_pConnectiontemp->Open((_bstr_t)strConnect1,"","",adModeUnknown);
 }
 catch(_com_error e)
 {
  CString errormessage;
  errormessage.Format("故障信息数据库连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
  AfxMessageBox(errormessage);///显示错误信息
  AfxMessageBox(e.Description());
 }
  if (SUCCEEDED(hre))
  {
   m_pCommandtemp.CreateInstance(__uuidof(Command));
   m_pCommandtemp->ActiveConnection = m_pConnectiontemp;   // 将库连接赋于它
  // m_pCommandtemp->CommandText = "select * from ta1_error_list";   // SQL语句
  _bstr_t bstrSQL = "select * from ta1_error_list";
  HRESULT pt = m_pRecordsettemp.CreateInstance(__uuidof(Recordset));
   m_pRecordsettemp->Open(bstrSQL,m_pConnectiontemp.GetInterfacePtr(),adOpenDynamic,
    adLockOptimistic,adCmdText);
  Num.Format("%d",num+1);
   m_pRecordsettemp->AddNew();
   m_pRecordsettemp->PutCollect("ID", _bstr_t(Num));
   m_pRecordsettemp->PutCollect("DATASTART",_variant_t(ErrorTime));
   m_pRecordsettemp->PutCollect("OFFICE",_variant_t(temp_Office));
   m_pRecordsettemp->PutCollect("SEGMENT",_variant_t(temp_Segment));
   m_pRecordsettemp->PutCollect("STATION",_variant_t(temp_Station));
   m_pRecordsettemp->PutCollect("SVALUE",_variant_t(errormsg));
  m_pRecordsettemp->PutCollect("TPYE",_variant_t(errortype));
  m_pRecordsettemp->PutCollect("DEF_STR1",_variant_t(Station_Type));
  m_pRecordsettemp->PutCollect("SUGGENT",_variant_t(suggest));
   m_pRecordsettemp->Update();
  m_pRecordsettemp->Close();
  m_pConnectiontemp->Close();
  num++;

 }
//将状态置为1
  CString ErrorID = (char*)(_bstr_t)record->GetCollect("ID");
  long errorID = atoi(ErrorID);
  CString SQL;
  SQL.Format("UPDATE tf2_reportresult SET ISGET = '1' WHERE ID = %d",errorID);
  _variant_t recordsAffected;
  connect->Execute((_bstr_t)SQL, &recordsAffected, adCmdText);
}

 

 

//导出excle

void CLendInfo::OnBtnPrint()
{
 // TODO: Add your control notification handler code here
 CDatabase database;
 CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // Excel安装驱动
 CString sPath;
 CString eDriver;
 CString sExcelFile;
 //判断是否安装excel驱动
 eDriver = GetExcelDriver();
    if (eDriver.IsEmpty())// 没有发现Excel驱动
    {
        AfxMessageBox("没有安装Excel驱动!");
        return;
    }
 
 GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
 sPath.ReleaseBuffer ();
 int nPos;
 nPos=sPath.ReverseFind ('\\');
 sPath=sPath.Left (nPos);
 
 sExcelFile = sPath + "\\领借信息.xls";
 
 if (IsFileActive())
 {
  CFile file;
  file.Remove(sExcelFile);
 }
 
 CString sSql;
 TRY
 {
  // 创建进行存取的字符串
  sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s",sDriver, sExcelFile, sExcelFile);
  if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )// 创建数据库 (既Excel表格文件)
  {
   // 创建表结构
   sSql = "CREATE TABLE Equipment (序号 TEXT,日期 TEXT,材料名称 TEXT,规格型号 TEXT,单位 TEXT,数量 TEXT,签名 TEXT,状态 TEXT,备注 TEXT)";
   database.ExecuteSQL(sSql);
   
   // 插入数值
   //   sSql = "delete from Equipment";
   //   database.ExecuteSQL(sSql);
   int n = m_LendInfo.GetItemCount();
   for (int m=0;m<n;m++)
   {
    char idtemp[64];
    char kardtemp[64];
    char timetemp[MAX_PATH];
    char nametemp[MAX_PATH];
    char numbertemp1[MAX_PATH];
    char typetemp[MAX_PATH];
    char unittemp[MAX_PATH];
    char numbertemp[MAX_PATH];
    char writetemp[MAX_PATH];
    char lendnumbertemp[MAX_PATH];
    char leavnumbertemp[MAX_PATH];
    char statustemp[MAX_PATH];
    char remarktemp[MAX_PATH];
    int k =0;
    m_LendInfo.GetItemText(m,k,idtemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,kardtemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,timetemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,nametemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,numbertemp1,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,typetemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,unittemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,numbertemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,writetemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,lendnumbertemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,leavnumbertemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,statustemp,MAX_PATH);
    k++;
    m_LendInfo.GetItemText(m,k,remarktemp,MAX_PATH);
    
    CString idstr = idtemp;
    CString kardstr = kardtemp;
    CString time = timetemp;
    CString name = nametemp;
    CString number1 = numbertemp1;
    CString type = typetemp;
    CString unit = unittemp;
    CString numbe = numbertemp;
    CString write = writetemp;
    CString lendnumber = lendnumbertemp;
    CString leavnumber = leavnumbertemp;
    CString status = statustemp;
    CString remark = remarktemp;
    
    CString sSqltemp = _T("");
    sSqltemp.Format("'%s','%s','%s','%s','%s','%s','%s','%s','%s'",idstr,time,name,type,unit,numbe,write,status,remark);
    sSql = "INSERT INTO Equipment (序号,日期,材料名称,规格型号,单位,数量,签名,状态,备注) VALUES ("+sSqltemp+")";
    database.ExecuteSQL(sSql);
   }
   
  }     
  // 关闭数据库
  database.Close();
  MessageBox("Excel文件写入成功!","导出设备资料");
 }
 CATCH_ALL(e)
 {
  e->ReportError();
  MessageBox("Excel文件写入失败!","导出设备资料");
  TRACE1("数据插入失败: %s",sDriver);
 }
  END_CATCH_ALL;

//  if(m_pRecordset!=NULL)
//  {
//   m_pRecordset->Close();
//  }
/* _ConnectionPtr m_pConnection1;
 _RecordsetPtr m_pRecordset1;
  if (m_pConnection1 !=NULL)
  {
   m_pConnection1->Close();
  }
 

 //先清空打印数据库表
 try
  {
   //创建连接对象实例
   m_pConnection1.CreateInstance("ADODB.Connection");
   //设置连接字符串
   CString strConnect="DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=;DBQ=MangerSysPrint.mdb;";
   //使用Open方法连接数据库
   m_pConnection1->Open((_bstr_t)strConnect,"","",adModeUnknown);
  // MessageBox("数据库连接成功");
  }
 catch(_com_error e)
  {
   MessageBox("数据库连接失败!");
   CString errormessage;
     errormessage.Format("数据库连接失败!\r\n错误信息:%s",e.ErrorMessage());
     AfxMessageBox(errormessage);///显示错误信息
     AfxMessageBox(e.Description());
   
  }

 _bstr_t bstrSQLP = "select * from lendinfo order by 日期 asc";  //设置查询字符串
 
 m_pRecordset1.CreateInstance(__uuidof(Recordset)); //创建记录集指针对象实例
 
 //打开记录集
 
 int nump = 0;

 while( m_pRecordset1->Open(bstrSQLP,m_pConnection1.GetInterfacePtr(),adOpenDynamic,
  adLockOptimistic,adCmdText),!m_pRecordset1->adoEOF)
  
   
  { 
   
   m_pRecordset1->Move(nump,vtMissing);
   m_pRecordset1->Delete(adAffectCurrent);
  // m_pRecordset->MoveNext();
   
   m_pRecordset1->Update();
  // nump++;
   m_pRecordset1->Close();
  
  
  }

 m_pRecordset1->Close();


///
 //将CListCtrl中的数据添加到打印数据库中
 struct member
 { 
  char data[256];
  char name[256];
  char type[256];
  char unit[256];
  char num[256];
  char write[256];
  char remark[256];
 }buffer[100];


 int n = m_LendInfo.GetItemCount();
 int m=0;
 m_pRecordset1->Open(bstrSQLP,m_pConnection1.GetInterfacePtr(),adOpenDynamic,
         adLockOptimistic,adCmdText);
 for (int s=0; s <n; s++)
  {
   
  
//    LVITEM oldinfo;
//    oldinfo.iItem=s;
//    oldinfo.mask = LVIF_PARAM | LVIF_TEXT;

     m_LendInfo.GetItemText(s,0,buffer[m].data,256);
     m_LendInfo.GetItemText(s,1,buffer[m].name,256);
     m_LendInfo.GetItemText(s,2,buffer[m].type,256);
     m_LendInfo.GetItemText(s,3,buffer[m].unit,256);
     m_LendInfo.GetItemText(s,4,buffer[m].num,256);
     m_LendInfo.GetItemText(s,5,buffer[m].write,256);
     m_LendInfo.GetItemText(s,6,buffer[m].remark,256);
   
// 写入各字段值
    
     
     m_pRecordset1->AddNew();
     m_pRecordset1->PutCollect("日期", _bstr_t(buffer[m].data));
     m_pRecordset1->PutCollect("材料名称", _bstr_t(buffer[m].name));
     m_pRecordset1->PutCollect("规格型号", _bstr_t(buffer[m].type));
     m_pRecordset1->PutCollect("单位", _bstr_t(buffer[m].unit));
     m_pRecordset1->PutCollect("数量", _bstr_t(buffer[m].num));
     m_pRecordset1->PutCollect("签名", _bstr_t(buffer[m].write));
     m_pRecordset1->PutCollect("备注", _bstr_t(buffer[m].remark));
     m_pRecordset1->Update();
     m++;
    continue;
   
 
  }
 if(m_pRecordset1!=NULL)
  m_pRecordset1->Close();
 m_pConnection1->Close();

  // 写入各字段值

 

 

 

 
 _Application app;   
 Workbooks books;
 _Workbook book;
 Worksheets sheets;
 _Worksheet sheet;
 Range range;

 //创建Excel 2000服务器(启动Excel)
 if (!app.CreateDispatch("Excel.Application",NULL))
 {
  AfxMessageBox("创建Excel服务失败!");
  exit(1);
 }
  app.SetVisible(false);
 //利用模板文件建立新文档
 char path[MAX_PATH];
 GetCurrentDirectory(MAX_PATH,path);
 CString strPath = path;
 strPath += "\\ExcelPrint2";
 books.AttachDispatch(app.GetWorkbooks(),true);
 book.AttachDispatch(books.Add(_variant_t(strPath)));
 //得到Worksheets
 sheets.AttachDispatch(book.GetWorksheets(),true); 
 //得到sheet1
 sheet.AttachDispatch(sheets.GetItem(_variant_t("sheet1")),true);
 CString str1;
 str1 = "第1页";
 sheet.SetName(str1);
 for( int i=0;i<sheets.GetCount()-1;i++)
 {
  sheet = sheet.GetNext();
  str1.Format("第%d页",i+2);
  sheet.SetName(str1);
 }
 sheet.AttachDispatch(sheets.GetItem(_variant_t("第1页")),true);
 //得到全部Cells,此时,rgMyRge是cells的集合
 range.AttachDispatch(sheet.GetCells(),true);
 CString sText;
// OnInitADOConn();

  m_pConnection1.CreateInstance("ADODB.Connection");
   //设置连接字符串
   CString strConnect="DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=;DBQ=MangerSysPrint.mdb;";
   //使用Open方法连接数据库
   m_pConnection1->Open((_bstr_t)strConnect,"","",adModeUnknown);
 _bstr_t bstrSQL;
 bstrSQL = "select * from lendinfo order by 日期 asc";
 m_pRecordset1.CreateInstance(__uuidof(Recordset));
 m_pRecordset1->Open(bstrSQL,m_pConnection1.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
 Fields* fields=NULL;
 long countl;
 BSTR bstr;
 enum DataTypeEnum stype;
 m_pRecordset1->get_Fields(&fields);
 countl = fields->Count;
 _variant_t sField[10];
 for(long num=0;num<countl;num++)
 {
  sText.Format("%d",num);
  fields->Item[(long)num]->get_Name(&bstr);
  sField[num] = (_variant_t)bstr;
  range.SetItem(_variant_t((long)(2)),_variant_t((long)(num+1)),
   _variant_t(sField[num]));
 }
 int setnum=2;
 while(!m_pRecordset1->adoEOF)
 {
  for(long num=0;num<m_pRecordset1->GetFields()->GetCount();num++)
  {
   sText.Format("%d",num);
   range.SetItem(_variant_t((long)(setnum+1)),_variant_t((long)(num+1)),
    _variant_t(m_pRecordset1->GetCollect(sField[num])));
  }
  m_pRecordset1->MoveNext();
  setnum++;
 }
// ExitConnect();

  if(m_pRecordset1!=NULL)
  m_pRecordset1->Close();
 m_pConnection1->Close();
 
 app.SetVisible(true);
 book.PrintPreview(_variant_t(false));
 //释放对象
 range.ReleaseDispatch();
 sheet.ReleaseDispatch();
 sheets.ReleaseDispatch();
 book.ReleaseDispatch();
 books.ReleaseDispatch();
 app.ReleaseDispatch();
 */
}

 

CString CLendInfo::GetExcelDriver()
{
 char szBuf[2001];
    WORD cbBufMax = 2000;
    WORD cbBufOut;
    char *pszBuf = szBuf;
    CString sDriver;
    // 获取已安装驱动的名称(涵数在odbcinst.h里)
    if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
        return "";
    // 检索已安装的驱动是否有Excel
    do
    {
        if (strstr(pszBuf, "Excel") != 0)
        {
            sDriver = CString(pszBuf);
            break;
        }
        pszBuf = strchr(pszBuf, '\0') + 1;
    }
    while (pszBuf[1] != '\0');
    return sDriver;
}

 

//

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值