//在ApplicationDlg.cpp文件中实现主窗口界面的设计。及其主窗口相应控件的功能和参数的映射。 D4F876E2-w78F-22D5-q98A-Y0B0D07B847C #include "stdafx.h" #include "DBServer.h" #include "theDBServer.h" #include "DBServerDlg.h" //#include "UserAccountsDlg.h" //#include "WizardPages.h" #include "AboutDlg.h" #include #include //#include "Shlwapi.h" #include "ClientCenter.h" #include "MyLock.h" #include "mysqldata.h" #include "./helper/ffsco.h" //#include #include "ShowPic3.h" #include "my32.h" #include "SoftKey.h" #include "DogTimeOutDlg.h" #include "InputAuthDlg.h" #include "AdoImplSvr.h" #include "CreateSmallPhoto.h" #include "PhotoBackupMgr.h" #include #include "ConnectThread.h" #pragma comment(lib, "NETAPI32.LIB ") #include "SelYear.h" #include "BranchInfo.h" using namespace helper_coffs; /*********ErrorExit(...)函数头文件************/ //#include /***********************************/ #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define LIMITCOUNT 1 //历史数据每次转10个 autorun extern BOOL g_bSteal; extern BOOL g_bConvertHisAll; extern CDBServer theApp; extern CtheDBServer theServer; #define WM_ICON_NOTIFY WM_USER+12 CDBServerDlg *g_pMainWnd = NULL; //#define IPC_CUSTOM_MSG2 _T("{D4F876E2-w78F-22D5-q98A-Y0B0D07B847C}") #define IPC_CUSTOM_MSG2 _T("{E4F876E2-Q78F-22D5-C98A-Y0B0D07B847C}") UINT g_wmClose = RegisterWindowMessage(IPC_CUSTOM_MSG2); //extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword); //extern CStringArray g_conniparray; CArrayg_pHistoryDBarray[200]; CDatabase *g_pDB[200]; CConnectThread *g_pThreadPt[200]; int g_nDBCount = 0; ///////////////////////////////////////////////////////////////////////////// // CDBServerDlg dialog #pragma comment(lib, "Shlwapi.lib") extern DWORD g_nSendCode; extern BOOL g_bReturned; static UINT auIDStatusBar[] = { ID_SEPARATOR, ID_INDICATOR_DATA_RECEIVED, ID_INDICATOR_DATA_SEND, ID_INDICATOR_ONLINELED, ID_INDICATOR_OFFLINELED }; /********************************************************************/ /* */ /* Function name : CDBServerDlg::CDBServerDlg */ /* Description : Constructor */ /* */ /********************************************************************/ CDBServerDlg::CDBServerDlg(CWnd* pParent /*=NULL*/): CDialog(CDBServerDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDI_DBServer); m_bTerminate = false; m_bRunning = false; m_hThread = NULL; hInst = NULL; CString version = _T("Version 1.0"); g_bAutoRun = AfxGetApp()->GetProfileInt(version, "brun", 0); m_hExitCheckSvc = NULL; m_hWaitTimeOut = NULL; m_hCheckSvcThread = NULL; m_bStartCheckSvc = FALSE; for (int i = 0; i < 200; i++) { g_pDB[i] = NULL; g_pThreadPt[i] = NULL; } } /********************************************************************/ /* */ /* Function name : CDBServerDlg::~CDBServerDlg */ /* Description : Destructor */ /* */ /********************************************************************/ CDBServerDlg::~CDBServerDlg() { for (int i = 0; i < 200; i++) { CDatabase *db = g_pDB[i]; if (db) { db->Close(); delete db; } for (int j = 0; j < g_pHistoryDBarray[i].GetSize(); j++) { CDatabase *db = g_pHistoryDBarray[i].ElementAt(j); if (db) { db->Close(); delete db; } } g_pHistoryDBarray[i].RemoveAll(); } } /********************************************************************/ /* */ /* Function name : CDBServerDlg::DoDataExchange */ /* Description : Called by the framework to exchange and validate */ /* dialog data. */ /* */ /********************************************************************/ void CDBServerDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDBServerDlg) DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl); DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDBServerDlg, CDialog) //{{AFX_MSG_MAP(CDBServerDlg) ON_WM_DESTROY() ON_COMMAND(ID_SERVER_START, OnServerStart) ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnUpdateServerStart) ON_COMMAND(ID_SERVER_STOP, OnServerStop) ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnUpdateServerStop) ON_COMMAND(ID_SERVER_EXIT, OnServerExit) ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar) ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar) ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts) ON_WM_CLOSE() ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace) ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers) ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration) ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace) ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers) ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration) ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics) ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics) ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity) ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity) ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard) ON_WM_TIMER() ON_COMMAND(IDM_OPEN, OnOpen) ON_COMMAND(IDM_EXIT, OnExit) ON_COMMAND(IDM_AUTORUN, OnAutorun) ON_COMMAND(IDM_STARTBAKSVC, OnStartBackupSvc) ON_COMMAND(IDM_STARTDELSVC, OnStartDelPhotoSvc) ON_COMMAND(IDM_STOPBAKSVC, OnStopBackupSvc) ON_COMMAND(IDM_STOPDELSVC, OnStopDelPhotoSvc) ON_COMMAND(IDM_AUTOCHECKSVC, OnAutoCheckSvc) //}}AFX_MSG_MAP ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification) ON_REGISTERED_MESSAGE(g_wmClose, OnAbortClose) END_MESSAGE_MAP() LRESULT CDBServerDlg::OnAbortClose(WPARAM wParam, LPARAM lParam) { if (wParam == 2) { WriteTextLog("连接失败,服务将重启"); OnExit2(); } else if (wParam == 3)//更新分店 { LoadBranchInfo(); } return 1; } BOOL CDBServerDlg::OnInitDialog() { g_pMainWnd = this; CDialog::OnInitDialog(); char server[50]; DWORD leng = 50; ::GetComputerName(server, &leng); g_localip = server; MyGetIPByName(g_localip); // setup listview ctrl, so that it looks like the outbar control SetupOutlookBar(); // Add statusbar to the dialog CreateStatusbar(); CRect rect; GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); ScreenToClient(rect); rect.right += 4; GetDlgItem(IDC_STATIC1)->MoveWindow(rect); // create property pages m_TracePage.Create(IDD_PROPPAGE_TRACE, this); m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this); m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this); m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this); m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this); // activate main page ActivatePage(0); // Set the icon for this dialog. SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // get registry values ENCODE_START #ifndef _DEBUG #ifdef TIMEDOG_VERSION try { CheckRegCode(); // 检查注册码; DWORD id; TCHAR HKey[50]="ffffffff",LKey[50]="ffffffff"; TCHAR OutTime[50]; TCHAR DevicePath[ 260]; if(FindPort(0,DevicePath)!=0) exit(1); //LIBC.LIB,libcp.lib,msvcprt.lib TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10]; ReadTimeAuthFromEprom(HKey,LKey, OutTime, &id, 30128, HKey, LKey, DevicePath); CString str=OutTime; CString temp="年"; int pos=str.Find (temp); temp=str.Left (pos); str=str.Right (str.GetLength ()-pos-2); strcpy(year, temp.GetBuffer (0));temp.ReleaseBuffer (); temp="月"; pos=str.Find (temp); temp=str.Left (pos); str=str.Right (str.GetLength ()-pos-2); strcpy(month, temp.GetBuffer (0));temp.ReleaseBuffer (); temp="日"; pos=str.Find (temp); temp=str.Left (pos); str=str.Right (str.GetLength ()-pos-2); strcpy(day, temp.GetBuffer (0));temp.ReleaseBuffer (); temp="小时"; pos=str.Find (temp); temp=str.Left (pos); str=str.Right (str.GetLength ()-pos-4); strcpy(hour, temp.GetBuffer (0));temp.ReleaseBuffer (); temp="分钟"; pos=str.Find (temp); temp=str.Left (pos); str=str.Right (str.GetLength ()-pos-4); strcpy(minute, temp.GetBuffer (0));temp.ReleaseBuffer (); temp="0"; strcpy(second, temp.GetBuffer (0));temp.ReleaseBuffer (); long time1=ConvertStringToTimerReal(year, month, day, hour, minute, second); GetRunTimer(year, month, day, hour, minute, second, DevicePath); long time2=ConvertStringToTimerReal(year, month, day, hour, minute, second); // 软件可运行时间; g_dwSoftRunTime = time1 - time2; if( (time1-time2) <0) { AfxMessageBox("加密锁已过期, 请与经销商联系!!!"); InputAuthDlg authdlg; authdlg.m_id=id; authdlg.m_time1=time1; authdlg.m_time2=time2; if(authdlg.DoModal ()!=IDOK) { CDialog::OnCancel (); return false; } } else if((time1-time2) < 288000 ) // 10天 = 10*8*3600=360000 能用天数小于10个工作日(8小时一工作日). { DogTimeOutDlg dlg; dlg.hour=(time1-time2)/3600; if(dlg.DoModal ()==IDOK) { InputAuthDlg authdlg; authdlg.m_id=id; authdlg.m_time1=time1; authdlg.m_time2=time2; authdlg.DoModal (); } } BOOL bOK=1; int d[8];double f[8]; char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]=""; //运行自定义函数 // SoftKey ytSoftKey; int ret=0;//ytSoftKey.Ini(); ret=ytSoftKey.checktime(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7], &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7], s0,s1,s2,s3,s4,s5,s6,s7); if(ret!=0 && ret!=-43) { bOK=0; } ////////////////////////写申请码 if(bOK) { str=GetRegCode(id, time1, time2); char path[MAX_PATH]; ::GetSystemDirectory (path, MAX_PATH); CString sysdir=path; sysdir+="\\regcode.txt"; CStdioFile fp; if(fp.Open (sysdir, CFile::modeWrite|CFile::modeCreate)) { fp.WriteString (str); fp.Close (); } } ///////////////////////// } catch(...) { } #endif #endif ENCODE_END OnButton1(); // Jeff 初始化服务端,内含定时器1; GetFileDate(); // Jeff获取文件信息; LoadHistoryDB();//Jeff加载历史数据库; SetTimer(4, 1000, NULL); SetTimer(2, 10, NULL); //CheckBakState();// 检查相片备份情况 hInst = LoadLibrary("SENSAPI.DLL"); //加载动态库 ; if (hInst) { typedef BOOL(WINAPI *MYFUNC)(LPDWORD); MYFUNC IsNetworkConnect = NULL; //取得IsNetworkAlive函数指针; IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive"); if (IsNetworkConnect) { DWORD dwActiveWan = 1; if (IsNetworkConnect(&dwActiveWan)) m_bNetWorkOK = 1; else m_bNetWorkOK = 0; SetTimer(5, 10000, NULL); } else m_bNetWorkOK = 0; } else m_bNetWorkOK = 0; if ( !CBranchInfo::GetInstance() ) { AfxMessageBox(_T("内存分配错误")); return FALSE; } if ( !CBranchInfo::GetInstance()->InitCatalog(g_dwDBServerPort, g_szDBSource, g_szDBAccount, g_szDBPassWord, g_szDBName) ) { AfxMessageBox(_T("初始化数据库连接对象失败")); return FALSE; } CBranchInfo::GetInstance()->GetTblVersion(); CBranchInfo::GetInstance()->GetTblCatalogInfo(); CBranchInfo::GetInstance()->GetTblNetShareInfo(); // 1小时检测一次自动备份和自动删除服务是否启动 // 是否自动检查服务 if(g_bAutoCheckSvc == TRUE) { m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL); m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL); SetEvent(m_hWaitTimeOut); unsigned int nThreadID = 0; m_bStartCheckSvc = TRUE; m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID); } return TRUE; } /********************************************************************/ /* */ /* Function name : OnDestroy */ /* Description : Handle WM_DESTROY message */ /* */ /********************************************************************/ void CDBServerDlg::OnDestroy() { OnServerStop(); KillTimer(1); KillTimer(2); KillTimer(3); KillTimer(4); KillTimer(5); KillTimer(6); KillTimer(7); KillTimer(8); CDialog::OnDestroy(); } /********************************************************************/ /* */ /* Function name : OnServerStart */ /* Description : Start Date Server -> start listening on port 21 */ /* */ /********************************************************************/ //启动数据服务器,使其在指定端口侦听 void CDBServerDlg::OnServerStart() { ServerStart(); } BOOL CDBServerDlg::ServerStart() { if (theServer.Start()) { m_wndStatusBar.SetPaneText(0, "数据服务已启动", TRUE); SetOnlineLed(TRUE); SetOfflineLed(FALSE); WriteTextLog("启动成功"); return 1; } else { WriteTextLog("启动失败"); CDialog::OnCancel(); return 0; } } /********************************************************************/ /* */ /* Function name : OnUpdateServerStart */ /* Description : Update 'Start' status */ /* */ /********************************************************************/ void CDBServerDlg::OnUpdateServerStart(CCmdUI* pCmdUI) { pCmdUI->Enable(!theServer.IsActive()); } /********************************************************************/ /* */ /* Function name : OnServerStop */ /* Description : Stop Date Server */ /* */ /********************************************************************/ //停止服务器 void CDBServerDlg::OnServerStop() { theServer.Stop(); m_wndStatusBar.SetPaneText(0, "数据服务已停止", TRUE); SetOnlineLed(FALSE); SetOfflineLed(TRUE); } /********************************************************************/ /* */ /* Function name : OnUpdateServerStop */ /* Description : Update 'Stop' status */ /* */ /********************************************************************/ void CDBServerDlg::OnUpdateServerStop(CCmdUI* pCmdUI) { pCmdUI->Enable(theServer.IsActive()); } /********************************************************************/ /* */ /* Function name : OnServerExit */ /* Description : Let's get out of here... */ /* */ /********************************************************************/ void CDBServerDlg::OnServerExit() { OnCancel(); } /********************************************************************/ /* */ /* Function name : CDBServerDlg::SetupOutlookBar */ /* Description : Initialize listview, change color/iconspacing to */ /* make it look a little bit like the outlook bar. */ /* */ /********************************************************************/ void CDBServerDlg::SetupOutlookBar() { m_ImageList.Create(32, 32, ILC_COLOR16 | ILC_MASK, 1, 4); HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG)); m_ImageList.Add(hIcon); hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS)); m_ImageList.Add(hIcon); hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION)); m_ImageList.Add(hIcon); hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY)); m_ImageList.Add(hIcon); hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS)); m_ImageList.Add(hIcon); m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL); CRect rc; m_OutlookBar.GetClientRect(rc); // set new icon spacing m_OutlookBar.SetIconSpacing(rc.Width(), 64); // change colors m_OutlookBar.SetTextColor(RGB(255, 255, 255)); m_OutlookBar.SetTextBkColor(RGB(128, 128, 128)); m_OutlookBar.SetBkColor(RGB(128, 128, 128)); // insert items m_OutlookBar.InsertColumn(0, "OutlookBar"); m_OutlookBar.InsertItem(0, "服务器日志", 0); m_OutlookBar.InsertItem(1, "在线用户", 1); m_OutlookBar.InsertItem(2, "关于", 2); m_OutlookBar.InsertItem(3, "功能区", 3); } /********************************************************************/ /* */ /* Function name : CDBServerDlg::MoveChilds */ /* Description : Move child windows into place holder area. */ /* */ /********************************************************************/ void CDBServerDlg::MoveChilds() { // position property pages CRect rcDlgs; // get dialog area rect GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs); ScreenToClient(rcDlgs); m_ConfigurationPage.MoveWindow(rcDlgs); m_TracePage.MoveWindow(rcDlgs); m_OnlineUsersPage.MoveWindow(rcDlgs); m_StatisticsPage.MoveWindow(rcDlgs); m_SecurityPage.MoveWindow(rcDlgs); } /********************************************************************/ /* */ /* Function name : CDBServerDlg::ActivatePage */ /* Description : Called when an icon on the outlookbar is pressed.*/ /* */ /********************************************************************/ void CDBServerDlg::ActivatePage(int nIndex) { switch (nIndex) { case 0: m_OnlineUsersPage.ShowWindow(SW_HIDE); m_ConfigurationPage.ShowWindow(SW_HIDE); m_StatisticsPage.ShowWindow(SW_HIDE); m_SecurityPage.ShowWindow(SW_HIDE); m_TracePage.ShowWindow(SW_SHOW); m_InfobarCtrl.SetText("服务器日志"); break; case 1: m_TracePage.ShowWindow(SW_HIDE); m_ConfigurationPage.ShowWindow(SW_HIDE); m_StatisticsPage.ShowWindow(SW_HIDE); m_SecurityPage.ShowWindow(SW_HIDE); m_OnlineUsersPage.RefreshData(); m_OnlineUsersPage.ShowWindow(SW_SHOW); m_InfobarCtrl.SetText("在线用户"); break; case 2: m_OnlineUsersPage.ShowWindow(SW_HIDE); m_TracePage.ShowWindow(SW_HIDE); m_StatisticsPage.ShowWindow(SW_HIDE); m_SecurityPage.ShowWindow(SW_HIDE); m_ConfigurationPage.ShowWindow(SW_SHOW); m_InfobarCtrl.SetText("关于"); break; case 4: m_OnlineUsersPage.ShowWindow(SW_HIDE); m_TracePage.ShowWindow(SW_HIDE); m_ConfigurationPage.ShowWindow(SW_HIDE); m_SecurityPage.ShowWindow(SW_HIDE); m_StatisticsPage.ShowWindow(SW_SHOW); m_InfobarCtrl.SetText("Statistics"); break; case 3: m_OnlineUsersPage.ShowWindow(SW_HIDE); m_TracePage.ShowWindow(SW_HIDE); m_ConfigurationPage.ShowWindow(SW_HIDE); m_SecurityPage.ShowWindow(SW_SHOW); m_StatisticsPage.ShowWindow(SW_HIDE); m_InfobarCtrl.SetText("功能区"); break; default: break; } MoveChilds(); } /********************************************************************/ /* */ /* Function name : CDBServerDlg::OnClickOutlookBar */ /* Description : User clicked on our listview -> activate page. */ /* */ /********************************************************************/ void CDBServerDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult) { // get index of selected item int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); if (nIndex == -1) return; ActivatePage(nIndex); *pResult = 0; } /********************************************************************/ /* */ /* Function name : CDBServerDlg::OnKeydownOutlookBar */ /* Description : User pressed a key -> activate page. */ /* */ /********************************************************************/ void CDBServerDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult) { LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR; // get index of selected item int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); if (nIndex == -1) return; if (pLVKeyDow->wVKey == VK_DOWN) { if (m_OutlookBar.GetItemCount() - 1 > nIndex) { ActivatePage(nIndex + 1); } } else if (pLVKeyDow->wVKey == VK_UP) { if (nIndex > 0) { ActivatePage(nIndex - 1); } } else if (pLVKeyDow->wVKey == VK_NEXT) { ActivatePage(m_OutlookBar.GetItemCount() - 1); } else if (pLVKeyDow->wVKey == VK_PRIOR) { ActivatePage(0); } *pResult = 0; } /********************************************************************/ /* */ /* Function name : CreateStatusbar */ /* Description : This function creates a statusbar on a dialogbox.*/ /* */ /********************************************************************/ BOOL CDBServerDlg::CreateStatusbar() { // Create the Toolbar and attach the resource if (!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1)) { TRACE0("Failed to Create Dialog Toolbar\n"); return FALSE; } m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY); // Make it flat. m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle() | TBSTYLE_FLAT); // Create status bar at the bottom of the dialog window if (m_wndStatusBar.Create(this)) { m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar) / sizeof(UINT)); m_wndStatusBar.SetPaneText(0, "Date Server is offline", TRUE); // Make a sunken or recessed border around the first pane m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL); SetOnlineLed(FALSE); SetOfflineLed(FALSE); m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14); // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), "This status light is green when the server is online"); m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14); // m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), "This status light is green when the server is online"); } // We need to resize the dialog to make room for control bars. // First, figure out how big the control bars are. CRect rcClientStart; CRect rcClientNow; GetClientRect(rcClientStart); RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow); // Now move all the controls so they are in the same relative // position within the remaining client area as they would be // with no control bars. CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top); CRect rcChild; CWnd* pwndChild = GetWindow(GW_CHILD); while (pwndChild) { pwndChild->GetWindowRect(rcChild); ScreenToClient(rcChild); rcChild.OffsetRect(ptOffset); pwndChild->MoveWindow(rcChild, FALSE); pwndChild = pwndChild->GetNextWindow(); } // Adjust the dialog window dimensions CRect rcWindow; GetWindowRect(rcWindow); rcWindow.right += rcClientStart.Width() - rcClientNow.Width(); rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height(); MoveWindow(rcWindow, FALSE); // And position the control bars RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); return TRUE; } /********************************************************************/ /* */ /* Function name : OnUserAccounts */ /* Description : Show user accounts. */ /* */ /********************************************************************/ void CDBServerDlg::OnUserAccounts() { /* CUserAccountsDlg dlg; theServer.m_UserManager.GetUserList(dlg.m_UserArray); if (dlg.DoModal() == IDOK) { theServer.m_UserManager.UpdateUserList(dlg.m_UserArray); }*/ } /********************************************************************/ /* */ /* Function name : OnFTPUserConnected */ /* Description : A user has connected to our server. */ /* */ /********************************************************************/ void CDBServerDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress) { m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress); } /********************************************************************/ /* */ /* Function name : OnFTPUserDisconnected */ /* Description : A user has disconnected from our server. */ /* */ /********************************************************************/ void CDBServerDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser) { m_OnlineUsersPage.RemoveUser(nThreadID); } /********************************************************************/ /* */ /* Function name : OnFTPStatusChange */ /* Description : FTP Status changed. */ /* */ /********************************************************************/ void CDBServerDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText) { m_TracePage.AddTraceLine(nType, lpszText); switch (nType) { case 3: theApp.m_LogFile << error_lvl << date << time << lpszText << endl; break; default: theApp.m_LogFile << trace_lvl << date << time << lpszText << endl; break; } } /********************************************************************/ /* */ /* Function name : OnFTPReceivedBytesChange */ /* Description : Number of received bytes has changed. */ /* */ /********************************************************************/ void CDBServerDlg::OnFTPReceivedBytesChange(int nBytes) { m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0)); CString strStatus; strStatus.Format("%s received", FormatSize(nBytes, 0)); m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE); CClientDC dc(this); CSize size = dc.GetTextExtent(strStatus); m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), ID_INDICATOR_DATA_RECEIVED, SBPS_NORMAL, size.cx); } /********************************************************************/ /* */ /* Function name : OnFTPSentBytesChange */ /* Description : Number of sent bytes has changed. */ /* */ /********************************************************************/ void CDBServerDlg::OnFTPSentBytesChange(int nBytes) { m_StatisticsPage.SetValue(7, FormatSize(nBytes, 0)); CString strStatus; strStatus.Format("%s sent", FormatSize(nBytes, 0)); m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), strStatus, TRUE); CClientDC dc(this); CSize size = dc.GetTextExtent(strStatus); m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_SEND), ID_INDICATOR_DATA_SEND, SBPS_NORMAL, size.cx); } /********************************************************************/ /* */ /* Function name : OnViewTrace */ /* Description : Handle menu selection. */ /* */ /********************************************************************/ void CDBServerDlg::OnViewTrace() { ActivatePage(0); } /********************************************************************/ /* */ /* Function name : OnViewOnlineUsers */ /* Description : Handle menu selection. */ /* */ /********************************************************************/ void CDBServerDlg::OnViewOnlineUsers() { ActivatePage(1); } /********************************************************************/ /* */ /* Function name : OnViewConfiguration */ /* Description : Handle menu selection. */ /* */ /********************************************************************/ void CDBServerDlg::OnViewConfiguration() { ActivatePage(2); } /********************************************************************/ /* */ /* Function name : OnViewStatistics */ /* Description : Handle menu selection. */ /* */ /********************************************************************/ void CDBServerDlg::OnViewStatistics() { ActivatePage(3); } /********************************************************************/ /* */ /* Function name : OnViewSecurity */ /* Description : Handle menu selection. */ /* */ /********************************************************************/ void CDBServerDlg::OnViewSecurity() { ActivatePage(4); } /********************************************************************/ /* */ /* Function name : OnUpdateViewTrace */ /* Description : Update menu state of Trace item. */ /* */ /********************************************************************/ void CDBServerDlg::OnUpdateViewTrace(CCmdUI* pCmdUI) { pCmdUI->SetRadio(m_TracePage.IsWindowVisible()); } /********************************************************************/ /* */ /* Function name : OnUpdateViewOnlineUsers */ /* Description : Update menu state of Online Users item. */ /* */ /********************************************************************/ void CDBServerDlg::OnUpdateViewOnlineUsers(CCmdUI* pCmdUI) { pCmdUI->SetRadio(m_OnlineUsersPage.IsWindowVisible()); } /********************************************************************/ /* */ /* Function name : OnUpdateViewConfiguration */ /* Description : Update menu state of Configuration item. */ /* */ /********************************************************************/ void CDBServerDlg::OnUpdateViewConfiguration(CCmdUI* pCmdUI) { pCmdUI->SetRadio(m_ConfigurationPage.IsWindowVisible()); } /********************************************************************/ /* */ /* Function name : OnUpdateViewStatistics */ /* Description : Update menu state of Statistics item. */ /* */ /********************************************************************/ void CDBServerDlg::OnUpdateViewStatistics(CCmdUI* pCmdUI) { pCmdUI->SetRadio(m_StatisticsPage.IsWindowVisible()); } /********************************************************************/ /* */ /* Function name : OnUpdateViewSecurity */ /* Description : Update menu state of Security item. */ /* */ /********************************************************************/ void CDBServerDlg::OnUpdateViewSecurity(CCmdUI* pCmdUI) { pCmdUI->SetRadio(m_SecurityPage.IsWindowVisible()); } /********************************************************************/ /* */ /* Function name : SetOnlineLed */ /* Description : Turn online LED on/off. */ /* */ /********************************************************************/ void CDBServerDlg::SetOnlineLed(BOOL bOnline) { HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(), bOnline ? MAKEINTRESOURCE(IDI_LED_GREEN) : MAKEINTRESOURCE(IDI_LED_OFF), IMAGE_ICON, 16, 16, LR_SHARED); m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), hIcon); m_wndStatusBar.GetStatusBarCtrl().Invalidate(); m_wndStatusBar.GetStatusBarCtrl().UpdateWindow(); DestroyIcon(hIcon); } /********************************************************************/ /* */ /* Function name : SetOfflineLed */ /* Description : Turn offline LED on/off. */ /* */ /********************************************************************/ void CDBServerDlg::SetOfflineLed(BOOL bOffline) { HICON hIcon = (HICON)::LoadImage(AfxGetInstanceHandle(), bOffline ? MAKEINTRESOURCE(IDI_LED_RED) : MAKEINTRESOURCE(IDI_LED_OFF), IMAGE_ICON, 16, 16, LR_SHARED); m_wndStatusBar.GetStatusBarCtrl().SetIcon(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), hIcon); m_wndStatusBar.GetStatusBarCtrl().Invalidate(); m_wndStatusBar.GetStatusBarCtrl().UpdateWindow(); DestroyIcon(hIcon); } void CDBServerDlg::OnFTPStatisticChange(int nType, int nValue) { m_StatisticsPage.SetValue(nType, nValue); } /********************************************************************/ /* */ /* Function name : FormatSize */ /* Description : Format size, the way explorer diplays it */ /* */ /********************************************************************/ char* CDBServerDlg::FormatSize(DWORD dwSizeLow, DWORD dwSizeHigh) { static char szBuff[100]; unsigned __int64 nFileSize = ((unsigned __int64)(((DWORD)(dwSizeLow)) | ((unsigned __int64)((DWORD)(dwSizeHigh))) << 32)); unsigned __int64 kb = 0; if (nFileSize > 1024) { kb = nFileSize / 1024; if (nFileSize % 1024) kb++; } // make it a string _ui64tot(kb, szBuff, 10); // add thousand seperators int nLength = lstrlen(szBuff); if (nLength > 3) { LPCTSTR ptr = szBuff; ptr += (nLength - 1); char szTemp[100]; LPTSTR ptrTemp = szTemp; for (int i = 0; i < nLength; i++) { if (i && ((i % 3) == 0)) { if (*ptrTemp != ',') { *ptrTemp = ','; ptrTemp = _tcsinc(ptrTemp); } } *ptrTemp = *ptr; ptrTemp = _tcsinc(ptrTemp); ptr = _tcsdec(szBuff, ptr); } // terminate string *ptrTemp = '\0'; // reverse string _tcsrev(szTemp); lstrcpy(szBuff, szTemp); } // add 'KB' to it lstrcat(szBuff, " KB"); return szBuff; } /********************************************************************/ /* */ /* Function name : OnAccountWizard */ /* Description : Launch New Account Wizard */ /* */ /********************************************************************/ void CDBServerDlg::OnAccountWizard() {/* CBitmap bmpHeader, bmpWatermark; VERIFY(bmpHeader.LoadBitmap(IDB_BANNER)); VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK)); // show windows 2000-like wizard CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader); wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL); if (wizSheet.DoModal() == ID_WIZFINISH) { CArray m_UserArray; theServer.m_UserManager.GetUserList(m_UserArray); int nIndex = -1; for (int i = 0; i < m_UserArray.GetSize(); i++) { // if it already exists -> update it if (m_UserArray[i].m_strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0) { nIndex = i; break; } } // add new account ? if (nIndex == -1) { CUser user; nIndex = m_UserArray.Add(user); } m_UserArray[nIndex].m_bAccountDisabled = FALSE; m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName; m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword; // add home directory CDirectory directory; directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory; directory.m_strAlias = ""; directory.m_bIsHomeDir = TRUE; directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory; directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete; directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload; directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename; directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload; directory.m_strAlias = ""; m_UserArray[nIndex].m_DirectoryArray.Add(directory); // update theServer.m_UserManager.UpdateUserList(m_UserArray); }*/ } void CDBServerDlg::OnCancel() { } void CDBServerDlg::OnOK() { } void CDBServerDlg::OnButton1() // 启动服务; { // TODO: Add your control notification handler code here try { theServer.Initialize(this); if (ServerStart() == 0) return; if (g_pSkinData == NULL) InitLia(); ///////////////////// //MyLock lock("dbaccessxiao"); CDatabase *pdb = NULL; ODBCConnGuard ConnGuard(pdb, -1, 3000); if ( pdb == NULL) return; CRecordset myset(pdb); #if 0 CString logdays; CString sql = "select logdays from version"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("logdays", logdays); myset.Close(); int days = 180; if (logdays == "1个月") days = 31; else if (logdays == "2个月") days = 61; else if (logdays == "3个月") days = 92; else days = 183; CTime tm = CTime::GetCurrentTime(); CTimeSpan dt(240, 0, 0, 0); // Jeff 不使用days,固定使用天数; tm -= dt; CString date = tm.Format("%Y-%m-%d"); // 删除日志前,取消触发器;2015-06-10 sql = _T("DROP TRIGGER ON_DELETE_USER_LOGS"); pdb->ExecuteSQL(sql); sql = "delete from [log] where [date]<'" + date + "'"; pdb->ExecuteSQL(sql); // 删除日志后,恢复触发器;2015-06-10 sql = _T("CREATE TRIGGER ON_DELETE_USER_LOGS ON [dbo].[log] FOR DELETE AS BEGIN rollback; END"); pdb->ExecuteSQL(sql); #endif /////////////////// CTime tm = CTime::GetCurrentTime(); CTimeSpan dt2(183, 0, 0, 0); tm -= dt2; CString date = tm.Format("%Y%m%d%H%M%S"); CString sql = "delete from sendreg where [status]='OK' and [timestamp]<'" + date + "'"; pdb->ExecuteSQL(sql); ////////////////////////////////// sql = "select version from version"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("version", sql); myset.Close(); m_ConfigurationPage.m_versionno = sql; m_ConfigurationPage.UpdateData(0); ///////////////////// } catch (CException *e) { TCHAR szError[1024] = { 0 }; e->GetErrorMessage(szError, 1024); WriteTextLog(CString(szError)); e->Delete(); } } void CDBServerDlg::OnClose() { m_TrayIcon.Create(this, WM_ICON_NOTIFY, "影楼管理系统服务器", m_hIcon, IDR_MENUtray); //构造 ShowWindow(SW_HIDE); //隐藏窗口 } LRESULT CDBServerDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam) { return m_TrayIcon.OnTrayNotification(wParam, lParam); } void CDBServerDlg::OnOpen() { ShowWindow(SW_SHOW); } void CDBServerDlg::OnExit2() { try { TerminateThread(); m_TrayIcon.RemoveIcon(); if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL; //g_db.Close(); for (int i = 0; i < g_dbHistoryArray.GetSize(); i++) { g_dbHistoryArray.ElementAt(i)->Close(); delete g_dbHistoryArray.ElementAt(i); } ReleaseBranchDB(); } catch (...) { WriteTextLog("出错在函数OnExit2中"); } CDialog::OnCancel(); } void CDBServerDlg::OnExit() { try { // 结束检查服务线程 TerminateCheckWork(); //结束一键生成小图线程 if(CreateSmallPhoto::GetInstance()->IsCreating()) { if(AfxMessageBox("温馨提示:生成小图还未完成确定要退出程序吗", MB_YESNO|MB_ICONSTOP) == IDNO) return; CreateSmallPhoto::GetInstance()->TerminateThread(); } TerminateThread(); DWORD id = FindAppProcessID("AutoRun.exe"); if (id != -1) { HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id); if (ProcessHandle)TerminateProcess(ProcessHandle, 0); } m_TrayIcon.RemoveIcon(); if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL; ReleaseBranchDB(); } catch (...) { WriteTextLog("出错在函数OnExit中"); } CDialog::OnCancel(); } void CDBServerDlg::OnTimer(UINT nIDEvent) //定时器; { try { if (nIDEvent == 1) {// 生成小图; KillTimer(nIDEvent); LoadThumbImages(); } else if (nIDEvent == 2) { KillTimer(nIDEvent); OnClose();// 托盘显示; try { CheckHistoryData(); // Jeff:back history db data; LoadBranchInfo(); } catch (...) { } SetTimer(1, 2 * 60 * 1000, NULL); SetTimer(4, 1000 * 60 * 2, NULL); SetTimer(7, 1000 * 60 * 60 * 1, NULL); SetTimer(8, 3000, NULL); SetTimer(9, 10000, NULL); } else if (nIDEvent == 3) { g_pMainWnd->KillTimer(3); HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle")); if (GetLastError() == ERROR_FILE_NOT_FOUND) { CString autorunpath = g_mainpath + _T("\\SMSHandle.exe"); ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); } if(hMutex) CloseHandle(hMutex); } else if (nIDEvent == 4) //Jeff.这里也有自动启动MsgServer.exe服务处理,而且是2分钟/次的频率; { UpdateDate(); CheckMemberMsg(); BakPhoto(); } else if (nIDEvent == 5) { typedef BOOL(WINAPI *MYFUNC)(LPDWORD); MYFUNC IsNetworkConnect = NULL; //取得IsNetworkAlive函数指针 IsNetworkConnect = (MYFUNC)GetProcAddress(hInst, "IsNetworkAlive"); if (IsNetworkConnect) { DWORD dwActiveWan = 1; BOOL state; if (IsNetworkConnect(&dwActiveWan)) state = 1; else state = 0; if (m_bNetWorkOK != state) { KillTimer(nIDEvent); WriteTextLog("网络断开"); OnExit2(); } } } else if (nIDEvent == 6) { KillTimer(nIDEvent); ShutDown(); } else if (nIDEvent == 7) { //CheckBakState(); GenUPhoneData(); } else if (nIDEvent == 8) { CheckConnCount(); } } catch (...) { WriteTextLog("出错在函数Timer中"); } } void LoadImageFromBuf(Image **img, BYTE *pData, DWORD leng)//g_bakserver1 { try { if (pData == NULL)return; if (*img)delete *img; *img = NULL; // Allocate global memory on which to create stream HGLOBAL m_hMem = GlobalAlloc(GMEM_MOVEABLE, leng); if (m_hMem == NULL)return; BYTE* pmem = (BYTE*)GlobalLock(m_hMem); memcpy(pmem, pData, leng); IStream* pstm; CreateStreamOnHGlobal(m_hMem, TRUE, &pstm); // load from stream *img = Gdiplus::Image::FromStream(pstm); // free/release stuff GlobalUnlock(m_hMem); pstm->Release(); } catch (...) { } } void LoadImageFromBuf(Image **img, CString path) { try { CFile fp; if (fp.Open(path, CFile::modeRead)) { DWORD leng = fp.GetLength(); BYTE *pData = new BYTE[leng]; fp.Read(pData, leng); fp.Close(); LoadImageFromBuf(img, pData, leng); delete[]pData; } } catch (...) { } } void LoadImageFromRes(Image **img, LPCTSTR lpszResourceName, LPCTSTR ResourceType) { try { HGLOBAL hGlobal = NULL; HRSRC hSource = NULL; LPVOID lpVoid = NULL; int nSize = 0; BOOL bResult = FALSE; hSource = FindResource(NULL, lpszResourceName, ResourceType); if (hSource == NULL)return; hGlobal = LoadResource(NULL, hSource); if (hGlobal == NULL)return; lpVoid = LockResource(hGlobal); if (lpVoid == NULL)return; nSize = (UINT)SizeofResource(NULL, hSource); LoadImageFromBuf(img, (BYTE*)hGlobal, nSize); UnlockResource(hGlobal); // 16Bit Windows Needs This FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release) } catch (...) { } } // --------------------------------------------------------------------------------------------------------------------------------------------------------------- // TimeAt: 2014-09-15 AM; // Remark: Jeff; // 函数:GenSPhoto // 描述:对指定文件夹内的相片生成S或M缩略图; // 参数: // dir: 需要生成缩略图的文件目录; // bMPhoto: 是否生成M缩略图; // 其它: // 在生成缩略图前,记录jpg文件总数nOldCount,每生成一个缩略图nOldCount++; // 最后全部图生成完毕,获取新的jpg文件总数nNewCount,if(nOldCount == nNewCount)则表示所有相片已生成缩略图完毕,生成ok文件表示成功生成缩略图; // // 函数调用全局参数: // g_bSteal:意义未明! // // 注意:该函数非线程安全! // 非线程安全: // 获取文件总数nOldCount结束后,若有新文件在本函数以外其他函数或进程、线程被添加,则生成缩略图完成后再次获取文件总数nNewCount就不会与nOldCount++后的结果相等; // 而实际上本次缩略图已生成完毕。 // --------------------------------------------------------------------------------------------------------------------------------------------------------------- void GenSPhoto(CString dir, BOOL bMPhoto) // 参数:bMPhoto:是否生成M缩略图; { // 如果是公告附件目录退出; if (dir.Find("公告附件") != -1)return; // 如果不是客户原片或修好的片目录,设置bMPhoto参数为0,不生成M缩略图; if (dir.Find("客户原片(管理软件)$") != -1 || dir.Find("修好的片(管理软件)$") != -1) { } else bMPhoto = 0; // 对指定文件目录dir进行指定后缀jpg文件遍历; ffsco o; o.dirs(1); o.find(LPCSTR(dir), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); int oldsize = coo.size(); CString path, temp, spath, mpath; for (it = coo.begin(); coo.end() != it; it++) { try { if (g_pMainWnd->m_bTerminate)return; // 遍历到的jpg文件如果是缩略图则不处理,继续遍历; path = (*it).c_str(); spath = path.Left(path.ReverseFind('\\') + 1); mpath = spath; spath += "s"; mpath += "m"; temp = path.Right(path.GetLength() - path.ReverseFind('\\') - 1); if (temp.GetAt(0) == 's')continue; if (temp.GetAt(0) == 'm')continue; spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1); mpath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1); if (g_bSteal) { Image *pImg = NULL; ::LoadImageFromBuf(&pImg, path); if (pImg == NULL)continue; if (pImg->GetWidth() == 0)continue; // Jeff.continue前未释放pImg; delete pImg; EncryptFile3(path); if (path.Find("客户原片") != -1) { int pos = path.Find("管理软件)$"); if (pos != -1) { path = g_bakserver1 + path.Right(path.GetLength() - pos - 10); EncryptFile3(path); } } else if (path.Find("修好的片") != -1) { int pos = path.Find("管理软件)$"); if (pos != -1) { path = g_bakserver2 + path.Right(path.GetLength() - pos - 10); EncryptFile3(path); } } else if (path.Find("精修好的片") != -1) { int pos = path.Find("管理软件)$"); if (pos != -1) { path = g_bakserver3 + path.Right(path.GetLength() - pos - 10); EncryptFile3(path); } } else if (path.Find("设计好的片") != -1) { int pos = path.Find("管理软件)$"); if (pos != -1) { path = g_bakserver4 + path.Right(path.GetLength() - pos - 10); EncryptFile3(path); } } oldsize++; } else if (!CheckFileExist(spath)) // 没有判断后续是否为jpg或jpeg. { Image *pImg = NULL; ::LoadImageFromBuf(&pImg, path); if (pImg == NULL)continue; if (pImg->GetWidth() == 0) { // 由于没有判断spath是否是jpg或jpeg的相片文件,导致这里泄漏; if (pImg) delete pImg; pImg = NULL; continue; // Jeff.返回前未释放pImg; } CRect rc(0, 0, 100, 90); RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc); Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL); if (simg == NULL) { if (pImg) delete pImg; pImg = NULL; continue;// Jeff.返回前未释放pImg; } Image *simg2 = NULL; if (bMPhoto) { CRect rc2(0, 0, 2000, 2000); RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc2); simg2 = pImg->GetThumbnailImage(rc2.Width(), rc2.Height(), NULL, NULL); if (simg2 == NULL) { if (pImg) delete pImg; pImg = NULL; continue;// Jeff.返回前未释放pImg; } } Graphics graphic(simg);//防止GetThumbnailImage影响质量 graphic.Clear(Color(255, 255, 255, 255)); graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight()); if (bMPhoto) { Graphics graphic2(simg2);//防止GetThumbnailImage影响质量 graphic2.Clear(Color(255, 255, 255, 255)); graphic2.DrawImage(pImg, 0, 0, simg2->GetWidth(), simg2->GetHeight()); } /////////////////////////////// UINT totalBufferSize; UINT numProperties; pImg->GetPropertySize(&totalBufferSize, &numProperties); // Allocate the buffer that will receive the property items. PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize); // Fill the buffer. pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems); // Print the id data member of each property item. for (UINT j = 0; j < numProperties; ++j) { if (PropertyTagOrientation == pAllItems[j].id) { short* ptrLong = (short*)(pAllItems[j].value); int ret = (int)*ptrLong; // CString str; // str.Format ("%d", ret); // AfxMessageBox(str); if (ret == 8) { if (simg2)simg2->RotateFlip(Rotate270FlipNone); simg->RotateFlip(Rotate270FlipNone); } else if (ret == 6) { if (simg2)simg2->RotateFlip(Rotate90FlipNone); simg->RotateFlip(Rotate90FlipNone); } break; } } free(pAllItems); /////////////////////////////// ::SaveImageToFile(simg, spath); oldsize++; delete simg; delete pImg; if (bMPhoto) { ::SaveImageToFile2(simg2, mpath, 100); oldsize++; delete simg2; } } } catch (...) { WriteTextLog("出错在函数GenSPhoto中"); } } try { ffsco o; o.dirs(1); o.find(LPCSTR(dir), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); int newsize = coo.size(); if (oldsize == newsize) { path = dir + "\\ok"; CFile fp; fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.Close(); } } catch (...) { WriteTextLog("出错在函数GenSPhoto2中"); } } //-------------------------------------------------------------------------------- // Remark by Jeff 2014.10.22 // 函数:LoadThumbNail // 描述:S或M缩略图线程 // 参数: // 返回: // // 调用关系:SetTimer(1); // 1. // 2. // 3. //-------------------------------------------------------------------------------- unsigned __stdcall LoadThumbNail(LPVOID lpParam) { BOOL bMphoto = 0; if (g_bSteal == 0) { CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb , -1, 3000); if ( pMaindb ) { try { CRecordset myset(pMaindb); CString sql = "select * from version"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("setcheck15", sql); // 选片时是否使用m缩略图来代替原片放大使用; myset.Close(); bMphoto = atoi(sql); } catch (CDBException* e) { WriteTextLog(_T("LoadThumbNail:%s"),e->m_strError); e->Delete(); } } } CString initialPhotoPath = _T(""); CString initialModifyPath = _T(""); CString designPhotoPath = _T(""); CString excellentModifyPath = _T(""); char server[50] = {0}; DWORD leng = 50; ::GetComputerName(server, &leng); initialPhotoPath = initialModifyPath = designPhotoPath = excellentModifyPath = server; initialPhotoPath = "\\\\" + initialPhotoPath + "\\客户原片(管理软件)$"; initialModifyPath = "\\\\" + initialModifyPath + "\\修好的片(管理软件)$"; designPhotoPath = "\\\\" + designPhotoPath + "\\设计好的片(管理软件)$"; excellentModifyPath = "\\\\" + excellentModifyPath + "\\精修好的片(管理软件)$"; GetPathFromNetShareName("客户原片(管理软件)$", initialPhotoPath); GetPathFromNetShareName("修好的片(管理软件)$", initialModifyPath); GetPathFromNetShareName("设计好的片(管理软件)$", designPhotoPath); GetPathFromNetShareName("精修好的片(管理软件)$", excellentModifyPath); int i = 0; CDBServerDlg *pDlg = (CDBServerDlg*)lpParam; try { CStringArray dirarray; // Remark:Jeff. // 遍历原片、修好片、设计片、精修片目录,查看是否有ok或ok.dat文件存在; // 说明:ok文件在客户端再次导入相片时会被删除; // 只有服务端生成小图后,ok才被重新生成; if(CBranchInfo::GetInstance()->m_TblNetShareInfo.size() != 0) { vector::iterator iter = CBranchInfo::GetInstance()->m_TblNetShareInfo.begin(); for(; iter != CBranchInfo::GetInstance()->m_TblNetShareInfo.end();) { TblNetShareInfo* p = (*iter); if(p != NULL) { CString strDir = p->szShareDirectory; if(strDir.Find(_T("$\\")) != -1) strDir = strDir.TrimRight(_T("\\")); pDlg->CheckOkFileExistence(strDir, dirarray); } ++iter; } CString patharray[2] = { designPhotoPath, excellentModifyPath }; //int i = 0; for (i = 0; i < 2; i++) { if (pDlg->m_bTerminate) break; pDlg->CheckOkFileExistence(patharray[i], dirarray); } } else { CString patharray[4] = { initialPhotoPath, initialModifyPath, designPhotoPath, excellentModifyPath }; for (i = 0; i < 4; i++) { if (pDlg->m_bTerminate) break; pDlg->CheckOkFileExistence(patharray[i], dirarray); } } for (i = 0; i < dirarray.GetSize(); i++) { if (pDlg->m_bTerminate) break; GenSPhoto(dirarray.ElementAt(i), bMphoto); } } catch (...) { WriteTextLog("出错在函数GenThumb中"); } pDlg->m_bRunning = false; pDlg->m_bTerminate = false; pDlg->SetTimer(1, 60 * 1000, NULL); _endthreadex(0); return 0; } //-------------------------------------------------------------------------------- // 函数:CheckOkFileExistence // 描述:OK文件是否存在 // 参数: // const CString& strPath 需要搜索的目录 // CStringArray& arr 返回文件目录 // 返回:TRUE成功,FALSE失败 //-------------------------------------------------------------------------------- BOOL CDBServerDlg::CheckOkFileExistence(const CString& strPath, CStringArray& arr) { CString path(_T("")), path2(_T("")); if(strPath == _T("")) return FALSE; ffsco o; o.dirs(1); o.find(LPCSTR(strPath), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); it = coo.begin(); it++; for(; coo.end() != it; it++) { if (m_bTerminate) break; path = (*it).c_str(); path.TrimRight("\\"); path2 = path; path2 += "\\ok2.dat"; path += "\\ok"; if (CheckFileExist(path2) && path2.Find(".ly.com") == -1) { ::DeleteFile(path); // 删除ok文件; ::DeleteFile(path2); // 删除ok.dat文件; } // g_bCheckAll g_bSteal的意义??? // g_bCheckAll没有任何其他赋值的代码,只有最开始初始化值0;下这if不执行; if (g_bCheckAll || g_bSteal) { if (FindArray(&arr, (*it).c_str()) == -1) arr.Add((*it).c_str()); } else if (CheckFileExist(path) == 0) { if (FindArray(&arr, (*it).c_str()) == -1) arr.Add((*it).c_str()); } } return 1; } //自动生成小图线程; void CDBServerDlg::LoadThumbImages() // 自动生成小图线程; { if (m_bRunning)return; TerminateThread(); m_bRunning = true; m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID); } BOOL CDBServerDlg::TerminateThread() { try { if (!m_bRunning) return TRUE; m_bTerminate = true; for (;;) { if (::WaitForSingleObject(m_hThread, INFINITE) == WAIT_OBJECT_0) break; } ::CloseHandle(m_hThread); m_bRunning = false; return TRUE; } catch (...) { WriteTextLog("出错在函数TerminateThread中"); } return TRUE; } void CDBServerDlg::InitLia() { try { // Jeff:逆天的变量命名!!!局部变量竟然用g_开头!!! //BYTE *g_pData=NULL;DWORD g_nLeng; DWORD count2; BYTE *pReturnData = NULL; DWORD dwReturnLen; DWORD count2; BYTE byCode = 104; CConnectSocket consock; ODBCConnGuard ConnGuard(consock.m_pConndb, -1, 3000); if ( consock.m_pConndb == NULL ) return; consock.GetDataFromCode(byCode, &pReturnData, dwReturnLen, count2, ""); if (pReturnData == NULL || dwReturnLen == 0) return; DWORD readbytes = 0; CArray ArrayOfLen; CArray ArrayOfBtnLen; BYTE *pArrayPointer = NULL; DWORD dwPointerLen = 0; DWORD leng; memcpy(&leng, pReturnData + readbytes, sizeof(DWORD)); readbytes += sizeof(DWORD); BYTE *pFtData = new BYTE[leng]; memcpy(pFtData, pReturnData + readbytes, leng); readbytes += leng; CMemFile memfile; memfile.Attach(pFtData, leng); CArchive ar(&memfile, CArchive::load); ArrayOfLen.Serialize(ar); ar.Close(); memfile.Detach(); memcpy(&leng, pReturnData + readbytes, sizeof(DWORD)); readbytes += sizeof(DWORD); BYTE *pFtData2 = new BYTE[leng]; memcpy(pFtData2, pReturnData + readbytes, leng); readbytes += leng; CMemFile memfile2; memfile2.Attach(pFtData2, leng); CArchive ar2(&memfile2, CArchive::load); ArrayOfBtnLen.Serialize(ar2); ar2.Close(); memfile2.Detach(); delete[]pFtData; delete[]pFtData2; DWORD count; memcpy(&count, pReturnData + readbytes, sizeof(DWORD)); readbytes += sizeof(DWORD); dwPointerLen = count*sizeof(RESDATA2); pArrayPointer = new BYTE[dwPointerLen]; int i = 0; for (i = 0; i < count; i++) { memcpy(pArrayPointer + i*sizeof(RESDATA2), pReturnData + readbytes, sizeof(RESDATA2)); readbytes += sizeof(RESDATA2); } for (i = 0; i < ArrayOfLen.GetSize(); i += 8) { DWORD leng1, leng2, leng3, leng4, leng5, leng6, leng7, leng8; leng1 = ArrayOfLen.ElementAt(i); leng2 = ArrayOfLen.ElementAt(i + 1); leng3 = ArrayOfLen.ElementAt(i + 2); leng4 = ArrayOfLen.ElementAt(i + 3); leng5 = ArrayOfLen.ElementAt(i + 4); leng6 = ArrayOfLen.ElementAt(i + 5); leng7 = ArrayOfLen.ElementAt(i + 6); leng8 = ArrayOfLen.ElementAt(i + 7); if (i % 4 == 0) DeCodelong1((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8); else if (i % 4 == 1) DeCodelong2((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8); else if (i % 4 == 2) DeCodelong3((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8); else DeCodelong4((int&)leng1, (int&)leng2, (int&)leng3, (int&)leng4, (int&)leng5, (int&)leng6, (int&)leng7, (int&)leng8); ArrayOfLen.SetAt(i, leng1); ArrayOfLen.SetAt(i + 1, leng2); ArrayOfLen.SetAt(i + 2, leng3); ArrayOfLen.SetAt(i + 3, leng4); ArrayOfLen.SetAt(i + 4, leng5); ArrayOfLen.SetAt(i + 5, leng6); ArrayOfLen.SetAt(i + 6, leng7); ArrayOfLen.SetAt(i + 7, leng8); } delete[]pReturnData; if (g_pSkinData) delete[]g_pSkinData; g_pSkinData = NULL; DWORD length; BYTE *pData; DWORD length2; BYTE *pData2; CMemFile mStoreFile; CArchive arStore(&mStoreFile, CArchive::store); ArrayOfLen.Serialize(arStore); arStore.Close(); length = mStoreFile.GetLength(); pData = mStoreFile.Detach(); CMemFile mStoreFile1; CArchive arStore1(&mStoreFile1, CArchive::store); ArrayOfBtnLen.Serialize(arStore1); arStore1.Close(); length2 = mStoreFile1.GetLength(); pData2 = mStoreFile1.Detach(); g_SkinLeng = length + length2 + dwPointerLen + 3 * sizeof(DWORD); g_pSkinData = new BYTE[g_SkinLeng]; readbytes = 0; memcpy(g_pSkinData + readbytes, &length, sizeof(DWORD)); readbytes += sizeof(DWORD); memcpy(g_pSkinData + readbytes, pData, length); readbytes += length; memcpy(g_pSkinData + readbytes, &length2, sizeof(DWORD)); readbytes += sizeof(DWORD); memcpy(g_pSkinData + readbytes, pData2, length2); readbytes += length2; memcpy(g_pSkinData + readbytes, &dwPointerLen, sizeof(DWORD)); readbytes += sizeof(DWORD); memcpy(g_pSkinData + readbytes, pArrayPointer, dwPointerLen); readbytes += dwPointerLen; delete[]pArrayPointer; } catch (...) { WriteTextLog("出错在函数InitLia中"); } } BOOL CheckExistDinDan(CString id) { CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb, -1, 30000); if ( pMaindb == NULL ) return FALSE; CRecordset myset(pMaindb); CString sql = "select count(*) as cot from dindan where id='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); return atol(sql); } //CString g_nCurConvertDBName="db"; // Jeff.deal CString g_nCurConvertDBName(g_szDBName); DWORD CDBServerDlg::ThreadCallerElves(LPVOID lpPara) { CArraycodearray; codearray.Add(80); codearray.Add(90); codearray.Add(11); codearray.Add(138); codearray.Add(24); codearray.Add(181); codearray.Add(65); codearray.Add(56); codearray.Add(179); codearray.Add(53); CFile fp; CString savepath, strPath1; char server[50]; DWORD leng = 50; ::GetComputerName(server, &leng); strPath1 = server; strPath1 = "\\\\" + strPath1 + "\\电话录音(管理软件)$"; GetPathFromNetShareName("电话录音(管理软件)$", strPath1); if (strPath1.IsEmpty()) return 0; try { CDatabase *pMaindb = NULL; for ( int i = 0; i < g_dbpool.GetSize(); i++ ) { ODBCConnGuard ConnGuard(pMaindb, i-1, 3000); if ( !pMaindb ) continue; savepath.Format("%s\\uphonedata%d.dat", strPath1, i); ::DeleteFile(savepath); // 删除uphonedata.dat文件; if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0) { WriteTextLog("更新来电精灵数据出错"); return 0; } CConnectSocket consock; consock.m_pConndb = pMaindb; for (int i = 0; i < codearray.GetSize(); i++) { BYTE code = codearray.ElementAt(i); DWORD length, arraysize; BYTE *pReturn = NULL; consock.GetDataFromCode(code, &pReturn, length, arraysize, ""); fp.Write(&code, sizeof(BYTE)); fp.Write(&length, sizeof(DWORD)); fp.Write(&arraysize, sizeof(DWORD)); fp.Write(pReturn, length); } fp.Close(); } } catch (CException *e) { TCHAR szError[1024] = { 0 }; e->GetErrorMessage(szError, 1024); WriteTextLog(CString(szError)); WriteTextLog("获取来电精灵数据出错1"); e->Delete(); } return 0; } /************************************************************************/ /* [函数]:CheckHistoryData /* [描述]:将被检测的数据库已完成的订单数据转到历史数据库中,并删除被检测的数据库已完成的订单; /* [参数]: /* pSrcdb: 源数据库,用于被转历史的数据库; /* nSrcYear: 源数据库的年份; /* bMode2: 转储模式:0=年度完成的订单; 1=年度所有订单,包含未完成订单; /* [返回]:void /* /************************************************************************/ void CDBServerDlg::CheckHistoryData(CDatabase *pSrcdb /* = NULL */, int nSrcYear /* = 0 */, BOOL bMode2 /* = 0*/)//历史备份; { #if 0 // 取消转将当前数据库完成订单的记录转到年份数据库中,此步直接返回; /////////////////////////生成来电精灵数据 MyLock lock("processChatMessageRequestxiao"); CArraycodearray; codearray.Add(80); codearray.Add(90); codearray.Add(11); codearray.Add(138); codearray.Add(24); codearray.Add(181); codearray.Add(65); codearray.Add(56); codearray.Add(179); codearray.Add(53); CFile fp; CString savepath, g_path1; char server[50]; DWORD leng = 50; ::GetComputerName(server, &leng); g_path1 = server; g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$"; GetPathFromNetShareName("电话录音(管理软件)$", g_path1); if (g_path1.IsEmpty())return; try { CDatabase *pdb = NULL; for ( int i = 0; i < g_dbpool.GetSize(); i++ ) { ODBCConnGuard ConnGuard(pdb, i-1, 3000); if ( !pdb ) continue; savepath.Format("%s\\uphonedata%d.dat", g_path1, i); ::DeleteFile(savepath); // 删除uphonedata.dat文件; if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0) { WriteTextLog("更新来电精灵数据出错"); return; } CConnectSocket consock; consock.m_pConndb = pdb; for (int i = 0; i < codearray.GetSize(); i++) { BYTE code = codearray.ElementAt(i); DWORD length, arraysize; BYTE *pReturn = NULL; consock.GetDataFromCode(code, &pReturn, length, arraysize, ""); fp.Write(&code, sizeof(BYTE)); fp.Write(&length, sizeof(DWORD)); fp.Write(&arraysize, sizeof(DWORD)); fp.Write(pReturn, length); } fp.Close(); } } catch (CException *e) { TCHAR szError[1024] = { 0 }; e->GetErrorMessage(szError, 1024); WriteTextLog(CString(szError)); WriteTextLog("获取来电精灵数据出错1"); e->Delete(); } #endif HANDLE h = CreateThread(NULL, 0, ThreadCallerElves, this, 0, NULL); if ( h )CloseHandle(h); } //------------------------------------------------------------------------------------ // Jeff remark // 函数:CheckYear // 描述: // 1.检查指定年份的历史数据库mdf文件是否存在,存在则直接附加 // 2.不存在,则使用null.mdf文件拷贝创建历史年份数据库mdf并附加; // 参数: // year:被检查年份值; // 返回:void //------------------------------------------------------------------------------------ #if JEFF_TEST_ON void CDBServerDlg::CheckYear(int year) { CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb, -1, 3000); if ( pMaindb == NULL ) return; pMaindb->SetQueryTimeout(6000); try { #ifdef SQLSERVER_VERSION CString sql; // 1.判断年份数据库是否存在; CString strPathOfYearmdf; CString strPathOfYearldf; strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year); strPathOfYearldf.Format("%s\\数据\\%d_log.ldf", g_mainpath, year); CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf"; CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.ldf"; if (PathFileExists(strPathOfYearmdf) == TRUE) { if (PathFileExists(strPathOfYearldf) == TRUE) { sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf); } else { // 此时要删除dbnull_log.ldf文件; // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件; // 这样造成其他数据库在使用dbnull时会产生错误; DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件; sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf); } try { pMaindb->ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("历史数据库初始化失败!"); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); return; } } else { // 判断dbnull.mdf文件是否存在; if (PathFileExists(strPathOfnulldbmdf) == FALSE) { WriteTextLog("空数据库丢失!"); return; } // 判断拷贝mdf文件是否失败; if (FALSE == CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1)) { DWORD dwError = ::GetLastError(); CString strDescription; strDescription.Format("dbnull.mdf拷贝为%d.mdf失败", year); ErrorExit(strDescription, dwError); return; } else { DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件; if (PathFileExists(strPathOfnulldbldf) == TRUE) { if (FALSE == CopyFile(strPathOfnulldbldf, strPathOfYearldf, 1)) { DWORD dwError = ::GetLastError(); CString strDescription; strDescription.Format("null.mdf拷贝为%d.mdf", year); ErrorExit(strDescription, dwError); // 此时要删除dbnull_log.ldf文件; // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件; // 这样造成其他数据库在使用dbnull时会产生错误; DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件; sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf); } else { sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf); } } else { // 此时要删除dbnull_log.ldf文件; // 因为如果2015没有对应的ldf文件,在逻辑名仍为dbnull没有改为2015时,他会使用dbnull_log.ldf做为2015数据库的日志文件; // 这样造成其他数据库在使用dbnull时会产生错误; DeleteFile(strPathOfnulldbldf);//删除dbnull_log.ldf文件; sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf); } try { pMaindb->ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("历史数据库初始化失败!"); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); return; } } } // 附加成功后,修改逻辑名称; sql.Format("alter database [%d] modify file(name='dbnull',newname='%d')", year, year); try { pMaindb->ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("修改历史数据库主文件逻辑名失败,请手动修改!"); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } sql.Format("alter database [%d] modify file(name='dbnull_log',newname='%d_log')", year, year); try { pMaindb->ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("修改历史数据库日志文件逻辑名失败,请手动修改!"); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } OnExit2(); #else CString path,sql; path.Format ("%s\\数据\\%d.mdb", g_mainpath, year); if(::PathFileExists (path)==0) { CString nulldb=g_mainpath+"\\数据\\dbnull.mdb"; ::CopyFile (nulldb, path, 1); CDatabase *db=new CDatabase; CString strCon; strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path); if(db->OpenEx(strCon,CDatabase::noOdbcDialog)) { g_nYearArray.Add (year); g_dbHistoryArray.Add (db); sql.Format ("insert into historydb([year])values('%d')", year); MyExecuteSQL(&g_db, sql); } else delete db; } #endif } catch (...) { WriteTextLog("出错在函数CheckYear中"); } } #else void CDBServerDlg::CheckYear(int year) { try { #ifdef SQLSERVER_VERSION CString strPathOfYearmdf; CString strPathOfYearldf; CString sql; strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, year); strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, year); ::DeleteFile(strPathOfYearldf); // 删除%d_log.LDF文件; { CString strPathOfnulldbmdf = g_mainpath + "\\数据\\dbnull.mdf"; CString strPathOfnulldbldf = g_mainpath + "\\数据\\dbnull_log.LDF"; ::DeleteFile(strPathOfnulldbldf); // 删除%d_log.LDF文件; // 1.判断null.mdf文件是否存在; if (::PathFileExists(strPathOfnulldbmdf) == 0) { WriteTextLog("空数据库丢失!"); return; } // 2.若年份mdf文件不存在,用null.mdf复制一份年份mdf数据库文件; BOOL bCopyed = 0; if (::PathFileExists(strPathOfYearmdf) == 0) { #if 0 ::CopyFile(nulldb, path, 1); bCopyed=1; #else // Jeff add:判断拷贝文件失败的原因; if (!::CopyFile(strPathOfnulldbmdf, strPathOfYearmdf, 1)) { DWORD dwError = ::GetLastError(); CString strDescription; strDescription.Format("null.mdf拷贝为%d.mdf", year); ErrorExit(strDescription, dwError); // return;//直接返回; } else { bCopyed = 1; } #endif } if (::PathFileExists(strPathOfYearmdf) == 0) { WriteTextLog("拷贝数据库文件失败!"); return; } BOOL bLog = 0; if (::PathFileExists(strPathOfnulldbldf)) { bLog = 1; } // .将年份数据库mdf附加到数据库里; CString sql; if (bCopyed) { if (bLog) sql.Format("exec sp_attach_db '%s',@filename1='%s',@filename2='%s'", "dbnull", strPathOfYearmdf, strPathOfYearldf); else sql.Format("exec sp_attach_db '%s',@filename1='%s'", "dbnull", strPathOfYearmdf); g_db.SetQueryTimeout(600); try { g_db.ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("历史数据库初始化失败!"); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } sql.Format("exec sp_renamedb '%s','%d'", "dbnull", year); g_db.ExecuteSQL(sql); } else // 没有执行CopyFile,年份mdf原本就存在; { if (bLog) sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", year, strPathOfYearmdf, strPathOfYearldf); else sql.Format("exec sp_attach_db '%d',@filename1='%s'", year, strPathOfYearmdf); g_db.SetQueryTimeout(600); try { g_db.ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("历史数据库初始化失败!"); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } } OnExit2(); /* g_db.SetQueryTimeout(100); CDatabase *db=new CDatabase; try { CString strCon; strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_sservrename,year,g_sdbpsw); db->OpenEx(strCon,CDatabase::noOdbcDialog); g_nYearArray.Add (year); dbarray.Add (db); sql.Format ("insert into [historydb]([year])values('%d')", year); MyExecuteSQL(&g_db, sql); } catch(CDBException * e) { delete db; WriteTextLog(e->m_strError); WriteTextLog("历史数据库打开失败!"); }*/ } #else CString path,sql; path.Format ("%s\\数据\\%d.mdb", g_mainpath, year); if(::PathFileExists (path)==0) { CString nulldb=g_mainpath+"\\数据\\dbnull.mdb"; ::CopyFile (nulldb, path, 1); CDatabase *db=new CDatabase; CString strCon; strCon.Format("DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=%s;PWD=lijialyfz",path); if(db->OpenEx(strCon,CDatabase::noOdbcDialog)) { g_nYearArray.Add (year); g_dbHistoryArray.Add (db); sql.Format ("insert into historydb([year])values('%d')", year); MyExecuteSQL(&g_db, sql); } else delete db; } #endif } catch (...) { WriteTextLog("出错在函数CheckYear中"); } } #endif CDatabase* CDBServerDlg::GetDB(int year) { try { for (int i = 0; i < g_nYearArray.GetSize(); i++) { if (g_nYearArray.ElementAt(i) == year) { return g_dbHistoryArray.ElementAt(i); } } return NULL; } catch (...) { WriteTextLog("出错在函数GetDB中"); } return NULL; } /************************************************************************/ /* mark by Jeff; /* 函数:CheckDinDanExist /* 描述: /* 参数: /* pBeConverted_db:(源) /* pToConverted_db:(目标) /* strOderNumber: /* pRetArray: /* /* 返回:1表示正常,100及以上表示源数据库里记录 > 目标数据库记录; /* /************************************************************************/ BOOL CDBServerDlg::CheckDinDanExist(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOderNumber, CStringArray *pRetArray) { try { pRetArray->RemoveAll(); int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from dindan where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//100 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from dindansp where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//101 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from dindanbukuan where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//102 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from dindanbukuan2 where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//103 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from photoprint where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//104 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from client where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from client where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//105 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from burncdreg where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//7 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from digitalwork where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//8 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from mywork where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//9 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from dindanjd where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)//10 pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from dindansp2 where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2) pRetArray->Add("0"); else pRetArray->Add("1"); { CRecordset myset(pBeConverted_db); sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pToConverted_db); sql = "select count(*) as cot from dindansp3 where id='" + strOderNumber + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2) pRetArray->Add("0"); else pRetArray->Add("1"); for (int i = 0; i < pRetArray->GetSize(); i++) { if (pRetArray->ElementAt(i) == "0")return 100 + i; } return 1; } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("出错在函数check1中"); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } return 100; } BOOL CDBServerDlg::CheckPayOutExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql.Format("select count(*) as cot from gudingfeiyong where [id]=%d", atol(id)); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from gudingfeiyong where [id]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check2中"); } return 0; } BOOL CDBServerDlg::CheckIncomeExist(CDatabase *pdb1, CDatabase *pdb2, CString id, CStringArray *pretarray) { try { pretarray->RemoveAll(); int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql.Format("select count(*) as cot from singleincome where [id]=%d", atol(id)); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from singleincome where [id]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2) pretarray->Add("0"); else pretarray->Add("1"); { CRecordset myset(pdb1); sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2) pretarray->Add("0"); else pretarray->Add("1"); for (int i = 0; i < pretarray->GetSize(); i++) { if (pretarray->ElementAt(i) == "0")return 0; } return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::CheckIncomeMoneyExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql.Format("select count(*) as cot from singleincomemoney where [id]='%s'", id); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } /************************************************************************/ /* mark by Jeff /* 函数:TransDinDan /* 描述: /* 参数: /* pBeConverted_db:被转换的数据库(源); /* pToConverted_db:要转到的数据库(目标); /* strOrderNumber: 订单号; /* nYear: 要转换的年份; /* /* 返回: /************************************************************************/ int CDBServerDlg::TransDinDan(CDatabase *pBeConverted_db, CDatabase *pToConverted_db, CString strOrderNumber, int nYear) { int step = 0; CStringArray retarray; try { CString sql, str; // CheckDinDanExist返回:1表示正常, 100及以上表示源数据库里记录 > 目标数据库记录; if (CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray) == 1) return 1; step = 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; int ret = 1; // 以下全是insert into 到目录数据库中; CRecordset myset(pBeConverted_db); try { if (retarray.ElementAt(0) == "0") { sql.Format("insert into [%d].[dbo].[dindan] select * from [%s].[dbo].[dindan] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step2" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 2; } step = 2; try { if (retarray.ElementAt(1) == "0") { sql.Format("insert into [%d].[dbo].[dindansp] select * from [%s].[dbo].[dindansp] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step3" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 3; } step = 3; try { if (retarray.ElementAt(2) == "0") { sql.Format("insert into [%d].[dbo].[dindanbukuan] ([autoid],[id],[money],[ren],[date],[bz],[kind],[ren2],[item],[paytype],[jdd],[financecheck]) select [autoid],[id],[money],[ren],[date],[bz],[kind],[ren2],[item],[paytype],[jdd],[financecheck] from [%s].[dbo].[dindanbukuan] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step4" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 4; } step = 4; try { if (retarray.ElementAt(3) == "0") { sql.Format("insert into [%d].[dbo].[dindanbukuan2] ([autoid],[id],[money],[ren],[date],[bz],[kind],[ren2]) select [autoid],[id],[money],[ren],[date],[bz],[kind],[ren2] from [%s].[dbo].[dindanbukuan2] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step5" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 5; } step = 5; try { if (retarray.ElementAt(4) == "0") { sql.Format("insert into [%d].[dbo].[photoprint] select * from [%s].[dbo].[photoprint] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step6" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 6; } step = 6; try { if (retarray.ElementAt(5) == "0") { sql.Format("insert into [%d].[dbo].[client] select * from [%s].[dbo].[client] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step7" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 7; } step = 7; try { if (retarray.ElementAt(6) == "0") { sql.Format("insert into [%d].[dbo].[burncdreg] select * from [%s].[dbo].[burncdreg] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step8" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 8; } step = 8; try { if (retarray.ElementAt(7) == "0") { sql.Format("insert into [%d].[dbo].[digitalwork] select * from [%s].[dbo].[digitalwork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step9" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 9; } step = 9; try { if (retarray.ElementAt(8) == "0") { sql.Format("insert into [%d].[dbo].[mywork] select * from [%s].[dbo].[mywork] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step10" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 10; } step = 10; try { if (retarray.ElementAt(9) == "0") { sql.Format("insert into [%d].[dbo].[dindanjd] select * from [%s].[dbo].[dindanjd] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step11" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 11; } step = 11; try { if (retarray.ElementAt(10) == "0") { sql.Format("insert into [%d].[dbo].[dindansp2] select * from [%s].[dbo].[dindansp2] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step12" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 12; } step = 12; try { if (retarray.ElementAt(11) == "0") { sql.Format("insert into [%d].[dbo].[dindansp3] select * from [%s].[dbo].[dindansp3] where id='%s'", nYear, g_nCurConvertDBName, strOrderNumber); MyExecuteSQL(pBeConverted_db, sql); } } catch (CDBException * e) { WriteTextLog("step13" + e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 13; } if (ret != 1)return 200 + ret; // 插入到目标数据库后再到目标数据库里查询是否存在; return CheckDinDanExist(pBeConverted_db, pToConverted_db, strOrderNumber, &retarray); } catch (...) { CString str; str.Format("%d size:%d", step, retarray.GetSize()); WriteTextLog("出错在函数trans1中-" + str); } return 0; } BOOL CDBServerDlg::TransPayOut(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckPayOutExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[gudingfeiyong] select * from [%s].[dbo].[gudingfeiyong] where id=%d", year, g_nCurConvertDBName, atol(id)); MyExecuteSQL(pdb1, sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 0; } if (ret == 0)return 0; return CheckPayOutExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans2中"); } return 0; } //singleincome BOOL CDBServerDlg::TransIncome(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; CStringArray retarray; if (CheckIncomeExist(pdb1, pdb2, id, &retarray))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { if (retarray.ElementAt(0) == "0") { sql.Format("insert into [%d].[dbo].[singleincome] select * from [%s].[dbo].[singleincome] where id=%d", year, g_nCurConvertDBName, atol(id)); MyExecuteSQL(pdb1, sql); } } catch (...) { ret = 0; } try { if (retarray.ElementAt(1) == "0") { sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } } catch (CDBException * e) { WriteTextLog(e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 0; } if (ret == 0)return 0; return CheckIncomeExist(pdb1, pdb2, id, &retarray); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::TransIncomeMoney(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckIncomeMoneyExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[singleincomemoney] select * from [%s].[dbo].[singleincomemoney] where id='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); ret = 0; } if (ret == 0)return 0; return CheckIncomeMoneyExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::Checkclient2phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from client2phonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transclient2phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (Checkclient2phonerecordExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[client2phonerecord] select * from [%s].[dbo].[client2phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return Checkclient2phonerecordExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::Checkclient3phonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from client3phonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transclient3phonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (Checkclient3phonerecordExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[client3phonerecord] select * from [%s].[dbo].[client3phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return Checkclient3phonerecordExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::Checkclient2phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from client2phonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transclient2phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (Checkclient2phonerecordoutExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[client2phonerecordout] select * from [%s].[dbo].[client2phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return Checkclient2phonerecordoutExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::Checkclient3phonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from client3phonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transclient3phonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (Checkclient3phonerecordoutExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[client3phonerecordout] select * from [%s].[dbo].[client3phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return Checkclient3phonerecordoutExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckemployeephonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from employeephonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transemployeephonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckemployeephonerecordExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[employeephonerecord] select * from [%s].[dbo].[employeephonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckemployeephonerecordExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckemployeephonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from employeephonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transemployeephonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckemployeephonerecordoutExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[employeephonerecordout] select * from [%s].[dbo].[employeephonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckemployeephonerecordoutExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from phonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckphonerecordExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[phonerecord] select * from [%s].[dbo].[phonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckphonerecordExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from phonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckphonerecordoutExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[phonerecordout] select * from [%s].[dbo].[phonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckphonerecordoutExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckunknownphonerecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from unknownphonerecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transunknownphonerecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckunknownphonerecordExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[unknownphonerecord] select * from [%s].[dbo].[unknownphonerecord] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckunknownphonerecordExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckunknownphonerecordoutExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from unknownphonerecordout where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transunknownphonerecordout(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckunknownphonerecordoutExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[unknownphonerecordout] select * from [%s].[dbo].[unknownphonerecordout] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckunknownphonerecordoutExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckmisscallrecordExist(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql = "select count(*) as cot from misscallrecord where [datetime]='" + id + "'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::Transmisscallrecord(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckmisscallrecordExist(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[misscallrecord] select * from [%s].[dbo].[misscallrecord] where [datetime]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckmisscallrecordExist(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } BOOL CDBServerDlg::CheckSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id) { try { int count1 = 0; int count2 = 0; CString sql; { CRecordset myset(pdb1); sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count1 = atoi(sql); } { CRecordset myset(pdb2); sql.Format("select count(*) as cot from sendreg where [timestamp]='%s'", id); myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); count2 = atoi(sql); } if (count1 > count2)return 0; return 1; } catch (...) { WriteTextLog("出错在函数check3中"); } return 0; } BOOL CDBServerDlg::TransSendReg(CDatabase *pdb1, CDatabase *pdb2, CString id, int year) { try { CString sql; if (CheckSendReg(pdb1, pdb2, id))return 1; int i; CString temp; int colcount; CODBCFieldInfo fieldinfo; BOOL ret = 1; CRecordset myset(pdb1); try { sql.Format("insert into [%d].[dbo].[sendreg] select * from [%s].[dbo].[sendreg] where [timestamp]='%s'", year, g_nCurConvertDBName, id); MyExecuteSQL(pdb1, sql); } catch (...) { ret = 0; } if (ret == 0)return 0; return CheckSendReg(pdb1, pdb2, id); } catch (...) { WriteTextLog("出错在函数trans3中"); } return 0; } void CDBServerDlg::MyExecuteSQL(CDatabase* pdb, CString sql) { try { pdb->ExecuteSQL(sql); } catch ( CDBException *e) { WriteTextLog(_T("执行SQL语句出错,系统描述:%s"),e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } } void CDBServerDlg::MyExecuteSQL(const TCHAR* pfile, const int& nline, const TCHAR* pfunction, CDatabase* pdb, CString sql) { try { pdb->ExecuteSQL(sql); } catch ( CDBException *e) { WriteTextLog(_T("%s-<%d>-%s,执行SQL语句出错,系统描述:%s"), pfile, nline, pfunction,e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } } void CDBServerDlg::UpdateDate() { try { HWND hwnd = ::FindWindow(NULL, "AutoRun.exe - 应用程序错误"); if (hwnd) { HWND child = ::FindWindowEx(hwnd, 0, NULL, "确定"); CWnd *pWnd = CWnd::FromHandle(child); ::PostMessage(hwnd, WM_COMMAND, pWnd->GetDlgCtrlID(), (LPARAM)child); } CString autorunpath = g_mainpath + "\\AutoRun.exe"; if (0 == g_bConvertHisAll) ShellExecute(NULL, _T("open"), g_mainpath + "\\AutoRun.exe", NULL, NULL, SW_HIDE); HANDLE hMutex = ::OpenMutex(NULL, FALSE, _T("lyfzSMSHandle")); if (GetLastError() == ERROR_FILE_NOT_FOUND) { autorunpath = g_mainpath + "\\SMSHandle.exe"; ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); } if (hMutex) CloseHandle(hMutex); #ifdef ENTERPRISE_VERSION autorunpath = g_mainpath + "\\DataSyncReceive.exe"; ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); autorunpath = g_mainpath + "\\DataSyncSend.exe"; ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); autorunpath = g_mainpath + "\\CPhotoFTPReceive.exe"; ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); autorunpath = g_mainpath + "\\CPhotoFTPSend.exe"; ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); #endif } catch (...) { WriteTextLog("出错在函数UpdateDate中"); } } BOOL CheckDateOK(CString str) { try { CString tip; int i; CString demo = CTime::GetCurrentTime().Format("%Y-%m-%d"); if (str.GetLength() != demo.GetLength()) goto ll; //2009-01-01 if (str.GetAt(4) != '-') goto ll; if (str.GetAt(7) != '-') goto ll; for (i = 0; i < str.GetLength(); i++) { if (i == 4 || i == 7)continue; if (str.GetAt(i) < '0' || str.GetAt(i) > '9') goto ll; } } catch (...) { WriteTextLog("出错"); } return 1; ll: return 0; } //------------------------------------------------------------------ // Remark by Jeff:2014.10.11 // 函数:DelPhoto1 // 描述:删除指定路径下的订单文件夹; // 参数: // path: 指定要删除文件的根目录; // strOrderNumber: 将要删除的订单号文件夹; // 返回: //----------------------------------------------------------------- BOOL CDBServerDlg::DelPhoto1(CString path, CString strOrderNumber) { if ( path.IsEmpty() || !PathFileExists(path) ) { //WriteTextLog(_T("路径不存在!")); return FALSE; } path += _T("\\") + strOrderNumber; if (PathFileExists(path)) { DeleteDirectory(path); return TRUE; } //WriteTextLog(_T("路径不存在!")); return FALSE; } //----------------------------------------------------------------------- // Remark by Jeff 2014.10.22 // 函数:BakPhoto // 描述:对影楼相片进行备份和删除取件相片 // 参数:# // 返回:# // // 调用关系: // 1.BakPhoto()由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。 // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。 // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用. //----------------------------------------------------------------------- void CDBServerDlg::BakPhoto() // Jeff:备份相片/删除取件相片; { try { CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb, -1, 3000); if ( pMaindb == NULL ) return; CString m_bak1, m_bak2, m_bak3, m_bak4, m_bak6, m_baktime; // Jeff:m_bak6自动备份完毕后自动关机; CString m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4; CString msgcheck4, msgtime, msgphones, msgphones2, msgcompanyname; CString balance, msgaccount; { MyLock lock("dbaccessxiao"); CRstversion rsSt; rsSt.m_pDatabase = pMaindb; rsSt.Open(); if (!rsSt.IsEOF()) { m_bak1 = rsSt.m_bak1; m_bak2 = rsSt.m_bak2; m_bak3 = rsSt.m_bak3; m_bak4 = rsSt.m_bak4; m_bakserver1 = rsSt.m_bakserver1; m_bakserver2 = rsSt.m_bakserver2; m_bakserver3 = rsSt.m_bakserver3; m_bakserver4 = rsSt.m_bakserver4; m_bak6 = rsSt.m_bak6; m_baktime = rsSt.m_baktime; msgcheck4 = rsSt.msgcheck4; msgtime = rsSt.msgtime; msgphones = rsSt.msgphones; msgphones2 = rsSt.msgphones2; msgcompanyname = rsSt.msgcompanyname; balance = rsSt.msgbalance; msgaccount = rsSt.msgaccount; } rsSt.Close(); } /////////////检测发短信回财务 if (msgphones2.IsEmpty() == 0) { MyLock lock("dbaccessxiao"); CStringArray array, timearray; CString timestamp; timestamp = CTime::GetCurrentTime().Format("%Y-%m-%d"); timestamp += "%"; CRecordset myset(pMaindb); CString sql = "select phones,timestamp from sendregreceive where [timestamp] like '" + timestamp + "' and [content]='001' and [status]='OK'"; myset.Open(CRecordset::forwardOnly, sql); CString phones; while (!myset.IsEOF()) { myset.GetFieldValue("phones", phones); myset.GetFieldValue("timestamp", timestamp); if (msgphones2.Find(phones) != -1) { array.Add(phones); timearray.Add(timestamp); } myset.MoveNext(); } myset.Close(); if (array.GetSize()) { CString sql; int i = 0; //for (int i = 0; i < array.GetSize(); i++) for ( i = 0; i < array.GetSize(); i++) { sql = "update sendregreceive set [status]='' where [timestamp]='" + timearray.ElementAt(i) + "'"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } CArrayList11array; CArrayList2array; CArrayList3array; CArrayother2salearray; CArraymemberarray; CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d"); for( int a = g_dbpool.GetSize(); a >= 0 ;a-- ) { CDatabase *pCurdb = NULL; ODBCConnGuard ConnGuard1(pCurdb , a - 1, 3000); if ( pCurdb == NULL ) continue; CString filter = "[dat]='" + strdate + "'"; filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = List2array.GetSize(); List2array.SetSize(oldsize + count, 1); CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { List2array.ElementAt(oldsize + ii).RemoveAll(); List2array.ElementAt(oldsize + ii).Add(rsSt.id); List2array.ElementAt(oldsize + ii).Add(rsSt.name); List2array.ElementAt(oldsize + ii).Add(rsSt.money); List2array.ElementAt(oldsize + ii).Add(rsSt.date); List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1); List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2); List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3); List2array.ElementAt(oldsize + ii).Add(rsSt.bz); List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type); ii++; rsSt.MoveNext(); if (List2array.GetSize() <= ii)break; } rsSt.Close(); List2array.SetSize(oldsize + ii, 1); } filter = "[dat]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = List3array.GetSize(); List3array.SetSize(oldsize + count, 1); CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { List3array.ElementAt(oldsize + ii).RemoveAll(); List3array.ElementAt(oldsize + ii).Add(rsSt.id); List3array.ElementAt(oldsize + ii).Add(rsSt.name); List3array.ElementAt(oldsize + ii).Add(rsSt.money); List3array.ElementAt(oldsize + ii).Add(rsSt.date); List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1); List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2); List3array.ElementAt(oldsize + ii).Add(rsSt.bz); ii++; rsSt.MoveNext(); if (List3array.GetSize() <= ii)break; } rsSt.Close(); List3array.SetSize(oldsize + ii, 1); } filter = "[date]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = List11array.GetSize(); List11array.SetSize(oldsize + count, 1); CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { List11array.ElementAt(oldsize + ii).RemoveAll(); List11array.ElementAt(oldsize + ii).Add(rsSt.m_id); List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren); List11array.ElementAt(oldsize + ii).Add(rsSt.m_money); List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz); List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind); List11array.ElementAt(oldsize + ii).Add(rsSt.m_date); ii++; rsSt.MoveNext(); if (List11array.GetSize() <= ii)break; } rsSt.Close(); List11array.SetSize(oldsize + ii, 1); } filter = "[date]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = other2salearray.GetSize(); other2salearray.SetSize(oldsize + count, 1); CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { other2salearray.ElementAt(oldsize + ii).RemoveAll(); other2salearray.ElementAt(oldsize + ii).Add(rsSt.name); other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1); other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3); other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type); other2salearray.ElementAt(oldsize + ii).Add(rsSt.money); other2salearray.ElementAt(oldsize + ii).Add(rsSt.date); other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk); other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype); other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid); other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck); ii++; rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break; } rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1); } filter = "[date]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from memberview"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = memberarray.GetSize(); memberarray.SetSize(oldsize + count, 1); memberviewReg rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); DWORD ii = 0; while (!rsSt.IsEOF()) { memberarray.ElementAt(oldsize + ii).RemoveAll(); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype); ii++; rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break; } rsSt.Close(); memberarray.SetSize(oldsize + ii, 1); } }// CString str; int pos = 0; int dindanshu = 0; float income = 0; float incomedd = 0; float incomebk = 0; float incomehq = 0; float incomeqt = 0; float payout = 0; for (i = 0; i < List11array.GetSize(); i++) { str = List11array.ElementAt(i).ElementAt(2); income += atof(str); // income2+=atof(str); if (List11array.ElementAt(i).ElementAt(3) == "预约收款") { incomedd += atof(str); dindanshu++; } else if (List11array.ElementAt(i).ElementAt(3) == "预约补款") { incomebk += atof(str); } else { incomehq += atof(str); } pos++; } for (i = 0; i < List2array.GetSize(); i++) { str = List2array.ElementAt(i).ElementAt(2); income += atof(str); /* if(List2array.ElementAt (i).ElementAt (8)!="") { income2+=atof(str); }*/ if (List2array.ElementAt(i).ElementAt(8) == "") { incomeqt += atof(str); } pos++; } for (i = 0; i < List3array.GetSize(); i++) { str = List3array.ElementAt(i).ElementAt(2); payout += atof(str); pos++; } for (i = 0; i < other2salearray.GetSize(); i++) { str = other2salearray.ElementAt(i).ElementAt(4); income += atof(str); incomehq += atof(str); pos++; } for (i = 0; i < memberarray.GetSize(); i++) { str = memberarray.ElementAt(i).ElementAt(3); income += atof(str); pos++; } CTime tm = CTime::GetCurrentTime(); CString content = msgcompanyname + tm.Format("%Y-%m-%d"); content += "财报:"; str.Format("%d", (int)income); ::ConvertToPrice(str); content += "收:" + str; str.Format("%d", (int)incomedd); ::ConvertToPrice(str); content += "定:" + str; str.Format("%d", (int)incomebk); ::ConvertToPrice(str); content += "补:" + str; str.Format("%d", (int)incomehq); ::ConvertToPrice(str); content += "后:" + str; str.Format("%d", (int)incomeqt); ::ConvertToPrice(str); content += "其它:" + str; str.Format("%d", (int)payout); ::ConvertToPrice(str); content += "支出:" + str; str.Format("%d", (int)(income - payout)); ::ConvertToPrice(str); content += "净收:" + str; str.Format("%d", dindanshu); content += "定单:" + str; if (msgaccount != "") { if (atoi(balance) < 200) { content += "您的余额小于两百条,请及时充值。联系电话4006067068"; } else if (atoi(balance) < 500) { content += "您的余额小于五百条,请及时充值。联系电话4006067068"; } else if (atoi(balance) < 800) { content += "您的余额小于八百条,请及时充值。联系电话4006067068"; } else if (atoi(balance) < 1000) { content += "您的余额小于一千条,请及时充值。联系电话4006067068"; } } int count = GetLengthEx(content) / MSG_LENGTH; if (GetLengthEx(content) % MSG_LENGTH) count++; int phonenum = 0; phonenum = 1; count *= phonenum; CString scount; scount.Format("%d", count); CString timestamp = tm.Format("%Y%m%d%H%M%S"); for (i = 0; i < 1; i++) { sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + array.ElementAt(i) + "','" + content + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } } } ///////////// if (atoi(msgcheck4) && msgphones != "") {//发老板短信 if (atoi(msgtime) <= CTime::GetCurrentTime().GetHour()) { MyLock lock("dbaccessxiao"); CString timestamp; timestamp = CTime::GetCurrentTime().Format("%Y%m%d"); timestamp += "%"; CRecordset myset(pMaindb); CString sql = "select count(*) as cot from sendreg where [timestamp] like '" + timestamp + "' and [phones]='" + msgphones + "' and [isautosend]='3'"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); if (count == 0) { CArrayList11array; CArrayList2array; CArrayList3array; CArrayother2salearray; CArraymemberarray; CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d"); for (int a = g_dbpool.GetSize() - 1; a >= 0; a--) { CDatabase *pCurdb = NULL; ODBCConnGuard ConnGuard(pCurdb , a - 1, 3000); if ( pCurdb == NULL ) continue; CString filter = "[dat]='" + strdate + "'"; filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from singleincome"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = List2array.GetSize(); List2array.SetSize(oldsize + count, 1); CRstIncomeInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { List2array.ElementAt(oldsize + ii).RemoveAll(); List2array.ElementAt(oldsize + ii).Add(rsSt.id); List2array.ElementAt(oldsize + ii).Add(rsSt.name); List2array.ElementAt(oldsize + ii).Add(rsSt.money); List2array.ElementAt(oldsize + ii).Add(rsSt.date); List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan1); List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan2); List2array.ElementAt(oldsize + ii).Add(rsSt.renyuan3); List2array.ElementAt(oldsize + ii).Add(rsSt.bz); List2array.ElementAt(oldsize + ii).Add(rsSt.sale2type); ii++; rsSt.MoveNext(); if (List2array.GetSize() <= ii)break; } rsSt.Close(); List2array.SetSize(oldsize + ii, 1); } filter = "[dat]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from gudingfeiyong"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = List3array.GetSize(); List3array.SetSize(oldsize + count, 1); CRstPayOutInput rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { List3array.ElementAt(oldsize + ii).RemoveAll(); List3array.ElementAt(oldsize + ii).Add(rsSt.id); List3array.ElementAt(oldsize + ii).Add(rsSt.name); List3array.ElementAt(oldsize + ii).Add(rsSt.money); List3array.ElementAt(oldsize + ii).Add(rsSt.date); List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan1); List3array.ElementAt(oldsize + ii).Add(rsSt.renyuan2); List3array.ElementAt(oldsize + ii).Add(rsSt.bz); ii++; rsSt.MoveNext(); if (List3array.GetSize() <= ii)break; } rsSt.Close(); List3array.SetSize(oldsize + ii, 1); } filter = "[date]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from dindanbukuan"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = List11array.GetSize(); List11array.SetSize(oldsize + count, 1); CRstBuKuan rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { List11array.ElementAt(oldsize + ii).RemoveAll(); List11array.ElementAt(oldsize + ii).Add(rsSt.m_id); List11array.ElementAt(oldsize + ii).Add(rsSt.m_ren); List11array.ElementAt(oldsize + ii).Add(rsSt.m_money); List11array.ElementAt(oldsize + ii).Add(rsSt.m_bz); List11array.ElementAt(oldsize + ii).Add(rsSt.m_kind); List11array.ElementAt(oldsize + ii).Add(rsSt.m_date); List11array.ElementAt(oldsize + ii).Add(rsSt.paytype); ii++; rsSt.MoveNext(); if (List11array.GetSize() <= ii)break; } rsSt.Close(); List11array.SetSize(oldsize + ii, 1); } filter = "[date]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from singleincomemoneyview"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = other2salearray.GetSize(); other2salearray.SetSize(oldsize + count, 1); CRstsingleincomemoneyview rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { other2salearray.ElementAt(oldsize + ii).RemoveAll(); other2salearray.ElementAt(oldsize + ii).Add(rsSt.name); other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan1); other2salearray.ElementAt(oldsize + ii).Add(rsSt.renyuan3); other2salearray.ElementAt(oldsize + ii).Add(rsSt.sale2type); other2salearray.ElementAt(oldsize + ii).Add(rsSt.money); other2salearray.ElementAt(oldsize + ii).Add(rsSt.date); other2salearray.ElementAt(oldsize + ii).Add(rsSt.clerk); other2salearray.ElementAt(oldsize + ii).Add(rsSt.paytype); other2salearray.ElementAt(oldsize + ii).Add(rsSt.autoid); other2salearray.ElementAt(oldsize + ii).Add(rsSt.financecheck); ii++; rsSt.MoveNext(); if (other2salearray.GetSize() <= ii)break; } rsSt.Close(); other2salearray.SetSize(oldsize + ii, 1); } filter = "[date]='" + strdate + "'"; { CRecordset myset(pCurdb); CString sql = "select count(*) as cot from memberview"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); int oldsize = memberarray.GetSize(); memberarray.SetSize(oldsize + count, 1); memberviewReg rsSt; rsSt.m_pDatabase = pCurdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); DWORD ii = 0; while (!rsSt.IsEOF()) { memberarray.ElementAt(oldsize + ii).RemoveAll(); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_id); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_memberno); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_name); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_money); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_date); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_clerk); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_financecheck); memberarray.ElementAt(oldsize + ii).Add(rsSt.m_moneytype); ii++; rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break; } rsSt.Close(); memberarray.SetSize(oldsize + ii, 1); } }// CString str; int pos = 0; int dindanshu = 0; float income = 0; float incomedd = 0; float incomebk = 0; float incomehq = 0; float incomeqt = 0; float fStoredCardSpending = 0.0; // 储值卡扣款 float payout = 0; int i = 0; for ( i = 0; i < List11array.GetSize(); i++) { str = List11array.ElementAt(i).ElementAt(2); income += atof(str); // income2+=atof(str); if (List11array.ElementAt(i).ElementAt(3) == "预约收款") { incomedd += atof(str); dindanshu++; } else if (List11array.ElementAt(i).ElementAt(3) == "预约补款") { incomebk += atof(str); } else { incomehq += atof(str); } #if JEFF_TEST_ON // 去除储值卡扣费; if (List11array.ElementAt(i).ElementAt(6) == "储值卡扣款" || List11array.ElementAt(i).ElementAt(6) == "代金券") { fStoredCardSpending += atof(str); } #endif pos++; } for (i = 0; i < List2array.GetSize(); i++) { str = List2array.ElementAt(i).ElementAt(2); income += atof(str); /* if(List2array.ElementAt (i).ElementAt (8)!="") { income2+=atof(str); }*/ if (List2array.ElementAt(i).ElementAt(8) == "") { incomeqt += atof(str); } pos++; } for (i = 0; i < List3array.GetSize(); i++) { str = List3array.ElementAt(i).ElementAt(2); payout += atof(str); pos++; } for (i = 0; i < other2salearray.GetSize(); i++) { str = other2salearray.ElementAt(i).ElementAt(4); income += atof(str); incomehq += atof(str); pos++; } for (i = 0; i < memberarray.GetSize(); i++) { str = memberarray.ElementAt(i).ElementAt(3); income += atof(str); pos++; } CTime tm = CTime::GetCurrentTime(); CString content = msgcompanyname + tm.Format("%Y-%m-%d"); content += "财报:"; income -= fStoredCardSpending; str.Format("%d", (int)(income)); // 去除储值卡扣款和代金券; ::ConvertToPrice(str); content += "收:" + str; str.Format("%d", (int)incomedd); ::ConvertToPrice(str); content += "定:" + str; str.Format("%d", (int)incomebk); ::ConvertToPrice(str); content += "补:" + str; str.Format("%d", (int)incomehq); ::ConvertToPrice(str); content += "后:" + str; str.Format("%d", (int)incomeqt); ::ConvertToPrice(str); content += "其它:" + str; str.Format("%d", (int)payout); ::ConvertToPrice(str); content += "支出:" + str; str.Format("%d", (int)(income - payout)); ::ConvertToPrice(str); content += "净收:" + str; str.Format("%d", dindanshu); content += "定单:" + str; if (msgaccount != "") { if (atoi(balance) < 200) { content += "您的余额小于两百条,请及时充值。联系电话4006067068"; } else if (atoi(balance) < 500) { content += "您的余额小于五百条,请及时充值。联系电话4006067068"; } else if (atoi(balance) < 800) { content += "您的余额小于八百条,请及时充值。联系电话4006067068"; } else if (atoi(balance) < 1000) { content += "您的余额小于一千条,请及时充值。联系电话4006067068"; } } int count = GetLengthEx(content) / MSG_LENGTH; if (GetLengthEx(content) % MSG_LENGTH) count++; int phonenum = 0; str = msgphones; pos = str.Find(","); if (pos != -1) { while (pos != -1) { phonenum++; str = str.Right(str.GetLength() - pos - 1); pos = str.Find(","); } phonenum++; } else phonenum = 1; count *= phonenum; CString scount; scount.Format("%d", count); timestamp = tm.Format("%Y%m%d%H%M%S"); sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + msgphones + "','" + content + "','" + timestamp + "','" + scount + "','0','0','3','系统自动发送')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } } } BOOL bcheck1 = atoi(m_bak1); BOOL bcheck2 = atoi(m_bak2); BOOL bcheck3 = atoi(m_bak3); BOOL bcheck4 = atoi(m_bak4); } catch (CException *e) { TCHAR szError[1024] = { 0 }; e->GetErrorMessage(szError, 1024); WriteTextLog(CString(szError)); e->Delete(); WriteTextLog("出错在函数bakphoto中"); } } void CDBServerDlg::ShutDown() //Jeff:备份完毕后执行的关机函数; { try { // 结束检查服务线程 TerminateCheckWork(); CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb, -1, 3000); if ( pMaindb == NULL ) return; CString m_bak6; { CRecordset myset(pMaindb); CString sql = "select * from [version]"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("bak6", m_bak6); myset.Close(); } OnServerStop(); // 停止服务; // Jeff.关闭数据库连接,若关机前关闭了数据库的连接,则客户端进行订单无法实现数据库的操作; // Jeff.在关机前,不能关闭数据库连接; for (int i = 0; i < g_dbHistoryArray.GetSize(); i++) { g_dbHistoryArray.ElementAt(i)->Close(); delete g_dbHistoryArray.ElementAt(i); } ReleaseBranchDB(); WriteTextLog("备份完成"); //////////////// g_tisks = ::GetTickCount() - g_tisks; CString str; str.Format("耗时:%d分钟", g_tisks / 60000); CStdioFile fp; fp.Open(g_mainpath + "\\log.txt", CFile::modeCreate | CFile::modeWrite); CTime tm = CTime::GetCurrentTime(); if (0)//tm.GetHour ()<5) { CTimeSpan sp(1, 0, 0, 0); tm -= sp; fp.WriteString(tm.Format("%Y-%m-%d")); fp.WriteString("\r\n"); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S")); fp.WriteString(str); } else { fp.WriteString(g_bakdate); fp.WriteString("\r\n"); fp.WriteString(tm.Format("%Y-%m-%d %H:%M:%S")); fp.WriteString(str); } fp.WriteString("\r\n"); fp.WriteString(g_bakinfo); fp.WriteString("\r\n"); fp.WriteString(g_bakphoto); fp.Close(); // OnButton3(); // Jeff.备份完成后自动关机; if (atoi(m_bak6)) { // Jeff.关闭运行中的线程; TerminateThread(); // Jeff.关闭AutoRun.exe程序; DWORD id = FindAppProcessID("AutoRun.exe"); if (id != -1) { HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id); if (ProcessHandle)TerminateProcess(ProcessHandle, 0); } // Jeff.移除托盘图标; m_TrayIcon.RemoveIcon(); if (g_pSkinData)delete[]g_pSkinData; g_pSkinData = NULL; // Jeff.关闭计算机; MyExitWindows(); } else//重启 { TerminateThread(); m_TrayIcon.RemoveIcon(); if (g_pSkinData) delete[]g_pSkinData; g_pSkinData = NULL; WriteTextLog("备份完成,服务器重启"); CDialog::OnCancel(); } } catch (...) { WriteTextLog("出错在函数shutdown中"); } } void CDBServerDlg::MyExitWindows() { try { UINT t = EWX_SHUTDOWN | EWX_FORCE; OSVERSIONINFO osv; //定义一个操作系统信息的结构体 osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO; GetVersionEx(&osv); //查询当前操作系统 if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) //判断是否是2000/NT { //下面为向操作系统获取权限操作 HANDLE hProcess, hToken; TOKEN_PRIVILEGES Privileges; LUID luid; hProcess = GetCurrentProcess(); //下面为打开当前进程对话 OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken); Privileges.PrivilegeCount = 1; LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &luid); Privileges.Privileges[0].Luid = luid; Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; AdjustTokenPrivileges(hToken, FALSE, &Privileges, NULL, NULL, NULL); ExitWindowsEx(t, 0); } else { ExitWindowsEx(t, 0);//调用ExitWindowsEx关闭机器。 PostQuitMessage(0); } } catch (...) { WriteTextLog("出错在函数exitwindows中"); } } void CDBServerDlg::OnAutorun() { // TODO: Add your command handler code here g_bAutoRun = !g_bAutoRun; CString version = _T("Version 1.0"); AfxGetApp()->WriteProfileInt(version, "brun", g_bAutoRun); TCHAR szKey[MAX_PATH]; HKEY hKey = 0; DWORD disp = 0; lstrcpy(szKey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); if (g_bAutoRun) { int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp); if (lResult == ERROR_SUCCESS) { TCHAR szDir[MAX_PATH]; ::GetModuleFileName(NULL, szDir, MAX_PATH); lResult = RegSetValueEx(hKey, "YLGLDBSERVER", 0, REG_SZ, (const unsigned char*)szDir, lstrlen(szDir)); RegCloseKey(hKey); } } else { int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp); if (lResult == ERROR_SUCCESS) { RegDeleteValue(hKey, "YLGLDBSERVER"); RegDeleteKey(hKey, "YLGLDBSERVER"); RegCloseKey(hKey); } } } void CDBServerDlg::GetFileDate() { CStringArray filesarray; CStringArray filesarray2; filesarray.Add("AutoUpdate.exe"); // 1. filesarray.Add("skin\\1.lia"); filesarray.Add("skin\\2.lia"); filesarray.Add("skin\\3.lia"); filesarray.Add("skin\\4.lia"); filesarray.Add("skin\\10.lia"); filesarray.Add("skin\\logo.jpg"); filesarray.Add("skin\\标题-选片.jpg"); filesarray.Add("skin\\标题-看设计.jpg"); filesarray.Add("图片\\欢迎.jpg"); // 10. filesarray.Add("图片\\连接.jpg"); filesarray.Add("图片\\标题.jpg"); filesarray.Add("图片\\背景.jpg"); filesarray.Add("图片-红色风格\\欢迎.jpg"); filesarray.Add("图片-红色风格\\连接.jpg"); filesarray.Add("图片-红色风格\\标题.jpg"); filesarray.Add("图片-红色风格\\背景.jpg"); filesarray.Add("图片-红色风格\\选片.jpg"); filesarray.Add("图片-红色风格\\看设计.jpg"); filesarray.Add("skin\\1-red.lia"); // 20. filesarray.Add("skin\\2-red.lia"); filesarray.Add("skin\\10-red.lia"); filesarray.Add("skin\\6.lia"); filesarray.Add("图片\\掌中宝.jpg"); filesarray.Add("regsvr32.exe"); // 25. filesarray.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递; /////////////// filesarray2.Add("AutoUpdate.exe"); filesarray2.Add("skin\\1.lia"); filesarray2.Add("skin\\2.lia"); filesarray2.Add("skin\\3.lia"); filesarray2.Add("skin\\4.lia"); filesarray2.Add("skin\\5.lia"); filesarray2.Add("skin\\10.lia"); filesarray2.Add("skin\\5-red.lia"); filesarray2.Add("skin\\10-red.lia"); filesarray2.Add("图片\\logo.jpg"); filesarray2.Add("图片\\标题-选片.jpg"); filesarray2.Add("图片\\标题-看设计.jpg"); filesarray2.Add("图片\\选片.jpg"); filesarray2.Add("图片\\看设计.jpg"); filesarray2.Add("图片\\欢迎.jpg"); filesarray2.Add("图片\\连接.jpg"); filesarray2.Add("图片\\标题.jpg"); filesarray2.Add("图片\\背景.jpg"); filesarray2.Add("图片-红色风格\\欢迎.jpg"); filesarray2.Add("图片-红色风格\\连接.jpg"); filesarray2.Add("图片-红色风格\\标题.jpg"); filesarray2.Add("图片-红色风格\\背景.jpg"); filesarray2.Add("skin\\6.lia"); filesarray2.Add("图片\\掌中宝.jpg"); filesarray2.Add("regsvr32.exe"); filesarray2.Add("MSCHRT20.OCX"); // 26. // Jeff.2014.09.06.添加MSCHRT20.OCX,由服务器传递; int i = 0; //for (int i = 0; i < filesarray.GetSize(); i++) for ( i = 0; i < filesarray.GetSize(); i++) { g_filedatearray.Add(GetModifyTime(g_mainpath + "\\系统文件\\" + filesarray.ElementAt(i))); } g_filedatearraynew.Copy(filesarray2); for (i = 0; i < filesarray2.GetSize(); i++) { g_filedatearraynew.Add(GetFileSize(g_mainpath + "\\系统文件\\" + filesarray2.ElementAt(i))); } } //extern CString g_sdomain; #ifdef ENTERPRISE_VERSION CString g_bMain; #endif void CDBServerDlg::LoadBranchInfo() { #ifdef ENTERPRISE_VERSION try { ReleaseBranchDB(); CArrayg_List1array; { MyLock lock("savebranchinfo"); CFile fp; CString path = g_mainpath + "\\branchinfo.dat"; if (::PathFileExists(path) == 0) return; fp.Open(path, CFile::modeRead); DWORD leng = fp.GetLength(); if (leng < sizeof(DWORD) * 2) { fp.Close(); return; } DWORD flag = 0; //fp.Seek(-sizeof(DWORD), CFile::end); fp.Seek(-(int)sizeof(DWORD), CFile::end); fp.Read(&flag, sizeof(DWORD)); if (flag != 889900) { fp.Close(); return; } fp.SeekToBegin(); DWORD arraysize; fp.Read(&arraysize, sizeof(DWORD)); if (arraysize > 20) { fp.Close(); return; } BYTE *pData = new BYTE[leng - sizeof(DWORD)]; fp.Read(pData, leng - sizeof(DWORD)); fp.Close(); CMemFile memfile; memfile.Attach(pData, leng - sizeof(DWORD)); CArchive ar(&memfile, CArchive::load); g_List1array.SetSize(arraysize, 1); for (int ii = 0; ii < g_List1array.GetSize(); ii++) g_List1array.ElementAt(ii).Serialize(ar); ar.Close(); memfile.Detach(); delete[]pData; } if (g_List1array.GetSize() == 0) return; // SoftKey ytSoftKey; // if(ytSoftKey.Ini()==0) { int value[8]; double f[8]; TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T(""); //运行自定义函数 int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7], &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { g_sdomain = ""; } else g_sdomain = s1; } CString str, str2, localname, rights; int i = 0; for (/*int*/ i = 0; i < g_List1array.GetSize(); i++) { if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0)) { if (g_List1array.ElementAt(i).GetSize()>5) rights = g_List1array.ElementAt(i).ElementAt(5); break; } } for (i = 0; i < g_List1array.GetSize(); i++) { CString branchname = g_List1array.ElementAt(i).ElementAt(1); CString branchip = g_List1array.ElementAt(i).ElementAt(2); CString domain = g_List1array.ElementAt(i).ElementAt(0); CString dir = g_mainpath + "\\数据\\" + branchname; if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0)) { localname = branchname; g_bMain = g_List1array.ElementAt(i).ElementAt(3); continue; } CString branchname2 = "," + branchname + ","; if (rights.Find(branchname2) == -1) continue; #ifdef SQLSERVER_VERSION if (1)//::PathFileExists (dir)) { ///////////////////////// g_branchdbarray.Add(NULL); g_branchnamearray.Add(branchname); g_branchdb2array.Add(NULL); g_branchname2array.Add(branchname); g_branchiparray.Add(branchip); g_branchdomainarray.Add(domain); // WriteTextLog(_T("添加分店:")+branchname); } #endif } //WriteTextLog(_T("添加本店:")+localname); g_branchdbarray.Add(NULL); g_branchnamearray.Add(localname); g_branchiparray.Add("xxx"); g_branchdomainarray.Add(g_sdomain); } catch (...) { } #endif } void CDBServerDlg::ReleaseBranchDB() { #ifdef ENTERPRISE_VERSION try { for (int i = 0; i < g_branchdbarray.GetSize(); i++) { if (g_branchdbarray.ElementAt(i)) { g_branchdbarray.ElementAt(i)->Close(); delete g_branchdbarray.ElementAt(i); } } g_branchdbarray.RemoveAll(); g_branchdb2array.RemoveAll(); g_branchnamearray.RemoveAll(); g_branchname2array.RemoveAll(); g_branchiparray.RemoveAll(); g_branchdomainarray.RemoveAll(); } catch (...) { WriteTextLog("ReleaseBranchDB出错"); } #endif } //savebranchinfo void CDBServerDlg::LoadBranchInfo2() { #ifdef ENTERPRISE_VERSION try { ReleaseBranchDB(); CArrayg_List1array; { MyLock lock("savebranchinfo"); CFile fp; CString path = g_mainpath + "\\branchinfo.dat"; if (::PathFileExists(path) == 0) return; fp.Open(path, CFile::modeRead); DWORD leng = fp.GetLength(); if (leng < sizeof(DWORD) * 2) { fp.Close(); return; } DWORD flag; //fp.Seek(-sizeof(DWORD), CFile::end); fp.Seek(-(int)sizeof(DWORD), CFile::end); fp.Read(&flag, sizeof(DWORD)); if (flag != 889900) { fp.Close(); return; } fp.SeekToBegin(); DWORD arraysize; fp.Read(&arraysize, sizeof(DWORD)); if (arraysize > 20) { fp.Close(); return; } BYTE *pData = new BYTE[leng - sizeof(DWORD)]; fp.Read(pData, leng - sizeof(DWORD)); fp.Close(); CMemFile memfile; memfile.Attach(pData, leng - sizeof(DWORD)); CArchive ar(&memfile, CArchive::load); g_List1array.SetSize(arraysize, 1); for (int ii = 0; ii < g_List1array.GetSize(); ii++) { g_List1array.ElementAt(ii).Serialize(ar); } ar.Close(); memfile.Detach(); delete[]pData; } if (g_List1array.GetSize() == 0)return; // SoftKey ytSoftKey; // if(ytSoftKey.Ini()==0) { int value[8]; double f[8]; TCHAR s0[50] = _T(""), s1[50] = _T(""), s2[50] = _T(""), s3[50] = _T(""), s4[50] = _T(""), s5[50] = _T(""), s6[50] = _T(""), s7[50] = _T(""); //运行自定义函数 int ret = ytSoftKey.getdata(&value[0], &value[1], &value[2], &value[3], &value[4], &value[5], &value[6], &value[7], &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { g_sdomain = ""; } else g_sdomain = s1; } CString str, str2, localname, rights; int i = 0; for (/*int*/ i = 0; i < g_List1array.GetSize(); i++) { if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0)) { if (g_List1array.ElementAt(i).GetSize()>5) rights = g_List1array.ElementAt(i).ElementAt(5); break; } } for (i = 0; i < g_List1array.GetSize(); i++) { CString branchname = g_List1array.ElementAt(i).ElementAt(1); CString branchip = g_List1array.ElementAt(i).ElementAt(2); CString domain = g_List1array.ElementAt(i).ElementAt(0); CString dir = g_mainpath + "\\数据\\" + branchname; if (g_sdomain == g_List1array.ElementAt(i).ElementAt(0)) { localname = branchname; g_bMain = g_List1array.ElementAt(i).ElementAt(3); continue; } CString branchname2 = "," + branchname + ","; if (rights.Find(branchname2) == -1) continue; #ifdef SQLSERVER_VERSION if (1)//::PathFileExists (dir)) { //////////////////////// g_branchdbarray.Add(NULL); g_branchnamearray.Add(branchname); g_branchdb2array.Add(NULL); g_branchname2array.Add(branchname); g_branchiparray.Add(branchip); g_branchdomainarray.Add(domain); } #endif } g_branchdbarray.Add(NULL); g_branchnamearray.Add(localname); g_branchiparray.Add("xxx"); g_branchdomainarray.Add(g_sdomain); } catch (...) { } #endif } int __cdecl CompareByLabel6(const void *elem1, const void *elem2) { CStringArray *p1 = (CStringArray*)elem1; CStringArray *p2 = (CStringArray*)elem2; return atoi(p1->ElementAt(5)) > atoi(p2->ElementAt(5)); } //-------------------------------------------------------------- // Remark by Jeff 2014.12.16 // 函数:CheckMemberMsg // 描述: // 参数: // 返回: // // 调用关系: // 1.CheckMemberMsg() 只由 CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。 // 2.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。 // 3.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用. //-------------------------------------------------------------- void CDBServerDlg::CheckMemberMsg() // Jeff.由定时器SetTimer两分钟执行一次 { try { CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard( pMaindb, -1, 3000); if ( pMaindb == NULL ) return; CString sql = "delete from sendreg where [log]='0/0'"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); { CStringArray idarray; CString timestamp; CTime tm = CTime::GetCurrentTime(); tm -= CTimeSpan(0, 1, 0, 0); timestamp = tm.Format("%Y%m%d%H%M%S"); CRecordset myset(pMaindb); CString sql = "select [autoid] from sendregdelay where [timestamp]<'" + timestamp + "'"; myset.Open(CRecordset::forwardOnly, sql); while (!myset.IsEOF()) { myset.GetFieldValue("autoid", sql); idarray.Add(sql); myset.MoveNext(); } myset.Close(); for (int i = 0; i < idarray.GetSize(); i++) { // Jeff.deal //sql.Format("insert into [db].[dbo].sendreg([timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren]) select [timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren] from [db].[dbo].sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i))); sql.Format("insert into sendreg([msgtype],[timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren]) select [msgtype],[timestamp],[msgcount],[log],[status],[issended],[isautosend],[phones],[content],[ren] from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i))); MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); sql.Format("delete from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i))); MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } } int covertrate = 100; CString spoint; { CRecordset myset(pMaindb); CString sql = "select * from version"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("rate2", sql); myset.Close(); covertrate = atoi(sql); if (covertrate == 0)covertrate = 100; } CString filter; CArrayrulearray; CArraymemberarray; { CRecordset myset(pMaindb); CString sql = "select count(*) as cot from msgtemp2"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); rulearray.SetSize(count, 1); CRstmsgtemp2 rsSt; rsSt.m_pDatabase = pMaindb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); DWORD ii = 0; while (!rsSt.IsEOF()) { rulearray.ElementAt(ii).RemoveAll(); rulearray.ElementAt(ii).Add(rsSt.name); rulearray.ElementAt(ii).Add(rsSt.content1); rulearray.ElementAt(ii).Add(rsSt.content2); rulearray.ElementAt(ii).Add(rsSt.check1); rulearray.ElementAt(ii).Add(rsSt.check2); rulearray.ElementAt(ii).Add(rsSt.point); ii++; rsSt.MoveNext(); if (rulearray.GetSize() <= ii)break; } rsSt.Close(); rulearray.SetSize(ii, 1); } if (rulearray.GetSize() == 0)return; qsort(static_cast(&rulearray[0]), rulearray.GetSize(), sizeof(rulearray[0]), CompareByLabel6); ///////////// { CRecordset myset(pMaindb); CString sql = "select count(*) as cot from membermanage"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); memberarray.SetSize(atol(sql), 1); RstMemberReg rsSt; rsSt.m_pDatabase = pMaindb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); DWORD ii = 0; if (covertrate != 100) { while (!rsSt.IsEOF()) { memberarray.ElementAt(ii).RemoveAll(); memberarray.ElementAt(ii).Add(rsSt.m_memberno); memberarray.ElementAt(ii).Add(rsSt.m_name); memberarray.ElementAt(ii).Add(rsSt.m_sex); memberarray.ElementAt(ii).Add(rsSt.m_phone); spoint.Format("%d", atoi(rsSt.m_money)*covertrate / 100); memberarray.ElementAt(ii).Add(spoint); memberarray.ElementAt(ii).Add(rsSt.m_sendmark1); memberarray.ElementAt(ii).Add(rsSt.m_sendmark2); ii++; rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break; } } else { while (!rsSt.IsEOF()) { memberarray.ElementAt(ii).RemoveAll(); memberarray.ElementAt(ii).Add(rsSt.m_memberno); memberarray.ElementAt(ii).Add(rsSt.m_name); memberarray.ElementAt(ii).Add(rsSt.m_sex); memberarray.ElementAt(ii).Add(rsSt.m_phone); memberarray.ElementAt(ii).Add(rsSt.m_money); memberarray.ElementAt(ii).Add(rsSt.m_sendmark1); memberarray.ElementAt(ii).Add(rsSt.m_sendmark2); ii++; rsSt.MoveNext(); if (memberarray.GetSize() <= ii)break; } } rsSt.Close(); memberarray.SetSize(ii, 1); } CString memberno, name, sex, phone, point, mark1, mark2, rulename, rulecheck1, rulecheck2, rulepoint, rulecontent1, rulecontent2; for (int i = 0; i < memberarray.GetSize(); i++) { memberno = memberarray.ElementAt(i).ElementAt(0); name = memberarray.ElementAt(i).ElementAt(1); sex = memberarray.ElementAt(i).ElementAt(2); phone = memberarray.ElementAt(i).ElementAt(3); point = memberarray.ElementAt(i).ElementAt(4); mark1 = "," + memberarray.ElementAt(i).ElementAt(5) + ","; mark2 = "," + memberarray.ElementAt(i).ElementAt(6) + ","; if (atoi(point) == 0)continue; if (phone.IsEmpty())continue; if (-1 == CheckPhoneType(phone))continue; int j = 0; for (/*int*/ j = 0; j < rulearray.GetSize(); j++) { if (mark1.GetLength()>4000)break; rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ","; rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1); rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2); rulecheck1 = rulearray.ElementAt(j).ElementAt(3); rulecheck2 = rulearray.ElementAt(j).ElementAt(4); rulepoint = rulearray.ElementAt(j).ElementAt(5); if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue; if (atoi(rulecheck1)) { if (rulecontent1.IsEmpty())continue; if (mark1.Find(rulename) != -1)break; if (atoi(point) >= atoi(rulepoint))continue; if (atoi(point) < atoi(rulepoint) * 80 / 100)continue; // if(sex=="男") // rulecontent1.Replace ("xxx先生/女士", name+"先生"); // else // rulecontent1.Replace ("xxx先生/女士", name+"女士"); int count = GetLengthEx(rulecontent1) / MSG_LENGTH; if (GetLengthEx(rulecontent1) % MSG_LENGTH) count++; int phonenum = 1; count *= phonenum; CString scount; scount.Format("%d", count); CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S"); CString sql; mark1.TrimLeft(","); mark1.TrimRight(","); if (mark1.IsEmpty() == 0) mark1 += ","; rulename.TrimLeft(","); rulename.TrimRight(","); mark1 += rulename; sql = "update membermanage set sendmark1='" + mark1 + "' where memberno='" + memberno + "'"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); mark1 = "," + mark1 + ","; sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent1 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } } /////////////////// BOOL bSended = 0; for (j = 0; j < rulearray.GetSize(); j++) { if (mark2.GetLength() > 4000)break; if (bSended)break; rulename = "," + rulearray.ElementAt(j).ElementAt(0) + ","; rulecontent1 = name + rulearray.ElementAt(j).ElementAt(1); rulecontent2 = name + rulearray.ElementAt(j).ElementAt(2); rulecheck1 = rulearray.ElementAt(j).ElementAt(3); rulecheck2 = rulearray.ElementAt(j).ElementAt(4); rulepoint = rulearray.ElementAt(j).ElementAt(5); if (atoi(rulecheck1) == 0 && atoi(rulecheck2) == 0)continue; if (atoi(rulecheck2)) { if (rulecontent2.IsEmpty())continue; if (mark2.Find(rulename) != -1)break; if (atoi(point) < atoi(rulepoint))continue; // if(sex=="男") // rulecontent2.Replace ("xxx先生/女士", name+"先生"); // else // rulecontent2.Replace ("xxx先生/女士", name+"女士"); int count = GetLengthEx(rulecontent2) / MSG_LENGTH; if (GetLengthEx(rulecontent2) % MSG_LENGTH) count++; int phonenum = 1; count *= phonenum; CString scount; scount.Format("%d", count); CString timestamp = CTime::GetCurrentTime().Format("%Y%m%d%H%M%S"); CString sql; mark2.TrimLeft(","); mark2.TrimRight(","); if (mark2.IsEmpty() == 0) mark2 += ","; rulename.TrimLeft(","); rulename.TrimRight(","); mark2 += rulename; sql = "update membermanage set sendmark2='" + mark2 + "' where memberno='" + memberno + "'"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); mark2 = "," + mark2 + ","; sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent2 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); bSended = 1; } } } } catch (CDBException *e) { WriteTextLog(_T("%s-<%d>-%s,%s"), __FILE__, __LINE__, __FUNCTION__, e->m_strError); #ifdef _DEBUG e->ReportError(); #endif e->Delete(); } } void CDBServerDlg::CheckBakState() // Jeff.检查数据库bakstate表; { try { CDatabase* pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb, -1, 3000); if ( pMaindb == NULL ) return; CString filter = _T(""); CArray strArray; CRecordset myset(pMaindb); CString sql = "select count(*) as cot from bakstate"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strArray.SetSize(count, 1); //备份记录 CRstbakstate rsSt; rsSt.m_pDatabase = pMaindb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); int ii = 0; while (!rsSt.IsEOF()) { strArray.ElementAt(ii).RemoveAll(); strArray.ElementAt(ii).Add(rsSt.date); strArray.ElementAt(ii).Add(rsSt.photo); strArray.ElementAt(ii).Add(rsSt.info); ii++; rsSt.MoveNext(); if (strArray.GetSize() <= ii) break; } rsSt.Close(); //只保存7天记录 strArray.SetSize(ii, 1); while (strArray.GetSize() > 7) { CString sql = "delete from bakstate where [date]='" + strArray.ElementAt(0).ElementAt(0) + "'"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); strArray.RemoveAt(0); } CString path = _T(""); path.Format("%s\\log.txt", g_mainpath); if (::PathFileExists(path)) { CString str; CStdioFile fp; if (fp.Open(path, CFile::modeRead)) { CString temp; fp.ReadString(temp); CString date = temp; date.TrimRight(); while(!feof(fp.m_pStream)) { fp.ReadString(temp); str += temp; } fp.Close(); if (date.GetLength() != 10) return; BOOL bBak = 0; int i = 0; for (int i = 0; i < strArray.GetSize(); i++) { if (date == strArray.ElementAt(i).ElementAt(0)) { bBak = 1; break; } } if (bBak == 0) { CString state1 = "0"; CString state2 = "0"; if (str.Find("照片备份成功") != -1)state1 = "1"; if (str.Find("资料备份成功") != -1)state2 = "1"; sql = "insert into bakstate([date],[photo],[info])values('" + date + "','" + state1 + "','" + state2 + "')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } else { CString state1 = "0"; CString state2 = "0"; if (str.Find("照片备份成功") != -1)state1 = "1"; if (str.Find("资料备份成功") != -1)state2 = "1"; sql = "update bakstate set [photo]='" + state1 + "',[info]='" + state2 + "' where [date]='" + date + "'"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } //判断昨天 CTime tm = CTime::GetCurrentTime(); CTimeSpan dt(1, 0, 0, 0); tm -= dt; CString yesterday = tm.Format("%Y-%m-%d"); for (i = 0; i < strArray.GetSize(); i++) { if (yesterday == strArray.ElementAt(i).ElementAt(0))return; } if (yesterday == date)return; sql = "insert into bakstate([date],[photo],[info])values('" + yesterday + "','0','0')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } else { CTime tm = CTime::GetCurrentTime(); CTimeSpan dt(1, 0, 0, 0); tm -= dt; sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } } else { //昨天没备份,插入一条没有备份的记录 CTime tm = CTime::GetCurrentTime(); CTimeSpan dt(1, 0, 0, 0); tm -= dt; for (int i = 0; i < strArray.GetSize(); i++) { if (tm.Format("%Y-%m-%d") == strArray.ElementAt(i).ElementAt(0)) return; } sql = "insert into bakstate([date],[photo],[info])values('" + tm.Format("%Y-%m-%d") + "','0','0')"; MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pMaindb, sql); } } catch (...) { WriteTextLog("出错3"); } } //数据备份 CString CDBServerDlg::GetRegCode(int m_id, int m_time1, int m_time2) { TCHAR DevicePath[260]; if (FindPort(0, DevicePath) != 0) return ""; int version; GetIDVersion((DWORD*)&m_id, &version, DevicePath); int d[8]; double f[8]; int idtemp = 123456; char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = ""; //运行自定义函数 // SoftKey ytSoftKey; int ret = 0;//ytSoftKey.Ini(); if (ret != 0) { return ""; } ////////////////////////////////////////////////////////////////////////// // timedog1是对d0,d1,d2,d3进行3DES加密; // 对锁id加密; // 对123456加密; // 对m_time1可运行时间加密; // 对m_time2已运行时间加密; ret = ytSoftKey.timedog1(&m_id, &idtemp, &m_time1, &m_time2, &d[4], &d[5], &d[6], &d[7], &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { return ""; } CString str = ""; CString temp, temp2; ///////////////////////////////////////// temp.Format("%d", abs(m_id)); int leng = temp.GetLength(); if (m_id < 0) temp2 = "1"; else temp2 = "0"; temp = temp2 + temp; temp2.Format("%02d", leng); temp = temp2 + temp; str += temp; //////////////////////////////////两位长度, 1为负, 0为正, 数据区 temp.Format("%d", abs(m_time1)); leng = temp.GetLength(); if (m_time1 < 0) temp2 = "1"; else temp2 = "0"; temp = temp2 + temp; temp2.Format("%02d", leng); temp = temp2 + temp; str += temp; //////////////////////////////////两位长度, 1为负, 0为正, 数据区 temp.Format("%d", abs(m_time2)); leng = temp.GetLength(); if (m_time2 < 0) temp2 = "1"; else temp2 = "0"; temp = temp2 + temp; temp2.Format("%02d", leng); temp = temp2 + temp; str += temp; //////////////////////////////////两位长度, 1为负, 0为正, 数据区 temp.Format("%d", abs(idtemp)); leng = temp.GetLength(); if (idtemp < 0) temp2 = "1"; else temp2 = "0"; temp = temp2 + temp; temp2.Format("%02d", leng); temp = temp2 + temp; str += temp; return str; } int g_ndogtimes = 0; void CDBServerDlg::CheckRegCode() // 检查注册码信息; { char path[MAX_PATH]; ::GetSystemDirectory(path, MAX_PATH); CString sysdir = path; sysdir += "\\authcode.txt"; CStdioFile fp; CString authcode; if (fp.Open(sysdir, CFile::modeRead)) { fp.ReadString(authcode); fp.Close(); } ::DeleteFile(sysdir); // 删除authcode.txt文件; authcode.TrimLeft(); authcode.TrimRight(); authcode.Replace("\n", ""); authcode.Replace("\r", ""); if (authcode.GetLength() != 240) { return; } TCHAR DevicePath[260]; if (FindPort(0, DevicePath) != 0) return; DWORD OutID; int version; GetIDVersion(&OutID, &version, DevicePath); CString str1, str2, str3, str4, str5; str1 = authcode.Mid(0, 48); str2 = authcode.Mid(48, 48); str3 = authcode.Mid(96, 48); str4 = authcode.Mid(144, 48); str5 = authcode.Mid(192, 48); // SoftKey ytSoftKey; int ret = 0;//ytSoftKey.Ini(); if (ret != 0) { return; } int d[8]; double f[8]; char s0[50] = "", s1[50] = "", s2[50] = "", s3[50] = "", s4[50] = "", s5[50] = "", s6[50] = "", s7[50] = ""; //运行自定义函数 sprintf(s0, "%s", str1); sprintf(s1, "%s", str2); sprintf(s2, "%s", str3); sprintf(s3, "%s", str4); sprintf(s4, "%s", str5); //运行自定义函数 ret = ytSoftKey.timedog2(&d[0], &d[1], &d[2], &d[3], &d[4], &d[5], &d[6], &d[7], &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], s0, s1, s2, s3, s4, s5, s6, s7); if (ret != 0 && ret != -43) { return; } str1 = s0; str2 = s1; str3 = s2; str4 = s3; str5 = s4; authcode = str1; authcode += str2; authcode += str3; authcode += str4; authcode += str5; str1 += str2; str3 += str4; DWORD id = atoi(str5.Right(8)); str5 = str5.Left(12); if (id != OutID) { return; } TCHAR HKey[50] = "ffffffff", LKey[50] = "ffffffff"; TCHAR WHKey[41] = "0", WLKey[41] = "0"; TCHAR year[10], month[10], day[10], hour[10], minute[10], second[10]; sprintf(WHKey, "%s", str1); sprintf(WLKey, "%s", str3); CString temp; temp = str5.Left(4); str5 = str5.Right(8); sprintf(year, "%s", temp); temp = str5.Left(2); str5 = str5.Right(6); sprintf(month, "%s", temp); temp = str5.Left(2); str5 = str5.Right(4); sprintf(day, "%s", temp); temp = str5.Left(2); str5 = str5.Right(2); sprintf(hour, "%s", temp); sprintf(minute, "%s", str5); sprintf(second, "%s", "0"); ret = WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id, year, month, day, hour, minute, DevicePath); if (ret == 0) { TCHAR year2[10], month2[10], day2[10], hour2[10], minute2[10], second2[10]; GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath); DWORD time1, time2; time1 = ConvertStringToTimerReal(year, month, day, hour, minute, second); sprintf(second2, "%s", "0"); time2 = ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2); if (time1 > time2) ConvertTimerToStringReal(time1 - time2, year, month, day, hour, minute, second); else { sprintf(year, "%s", "0"); sprintf(month, "%s", "0"); sprintf(day, "%s", "0"); sprintf(hour, "%s", "0"); sprintf(minute, "%s", "0"); } g_ndogtimes++; // str1.Format ("写入%d次 %d 年 %d 月 %d 日 %d 小时 %d 分", g_ndogtimes, atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute)); // WriteTextLog(str1); // AfxMessageBox((str1)); } else { // AfxMessageBox(("授权申请码错误, 请重新向经销商索取!")); return; } } BOOL IsCtrlDown() { short state = GetKeyState(VK_LCONTROL); BYTE sta = (BYTE)(state >> 8); state = GetKeyState(VK_RCONTROL); BYTE sta2 = (BYTE)(state >> 8); if (sta || sta2) return 1; else return 0; } //extern CTime GetTmFromStr(CString date); BOOL CDBServerDlg::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN) { switch (pMsg->wParam) { case 67: AfxMessageBox("c"); break; case VK_F8: if (IsCtrlDown())GenYLGL(); break; case VK_F9: if (IsCtrlDown()) { CString g_domain; CArrayg_List1array; CString autorunpath = g_mainpath + "\\branchdindan.dat"; CFile fp; if (fp.Open(autorunpath, CFile::modeRead)) { int nMessageLen = fp.GetLength(); BYTE *pData = new BYTE[nMessageLen]; fp.Read(pData, nMessageLen); fp.Close(); BYTE *szChatMessage = pData; int count; memcpy(&count, szChatMessage + (nMessageLen - sizeof(int)), sizeof(int)); CMemFile memfile; memfile.Attach(szChatMessage, nMessageLen); CArchive ar(&memfile, CArchive::load); g_List1array.SetSize(count); for (int ii = 0; ii < g_List1array.GetSize(); ii++) { g_List1array.ElementAt(ii).Serialize(ar); } ar.Close(); memfile.Detach(); delete[]pData; } CString time5, id; for (int i = 0; i < g_List1array.GetSize(); i++) { g_domain = "\\" + g_List1array.ElementAt(i).ElementAt(0); id = g_List1array.ElementAt(i).ElementAt(1); time5 = g_List1array.ElementAt(i).ElementAt(2); WriteTextLog(g_domain + "\\" + id + time5); } } break; #ifdef LYFZ_VERSION case VK_F7: if (IsCtrlDown()) { if (AfxMessageBox("是否继续?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1; CStringArray array1; CRstDindanForm rsSt; rsSt.m_pDatabase = &g_db; rsSt.Open(); while (!rsSt.IsEOF()) { array1.Add(rsSt.id); rsSt.MoveNext(); } rsSt.Close(); CString id, sql; sql.Format("update dindan set status5='%s'", "无"); MyExecuteSQL(&g_db, sql); BOOL bHasPhoto = 0; for (int i = 0; i < array1.GetSize(); i++) { id = array1.ElementAt(i); bHasPhoto = 0; CRstClientPhoto rsSt; rsSt.m_strFilter = "id='" + id + "'"; rsSt.Open(); if (rsSt.photo.m_dwDataLength>0) { bHasPhoto = 1; } rsSt.Close(); if (bHasPhoto) { sql.Format("update dindan set status5='%s' where id='%s'", "有", id); MyExecuteSQL(&g_db, sql); } } /* CStringArray array1,array2; CRstDindanForm rsSt; rsSt.m_pDatabase=&g_db; rsSt.Open(); while(!rsSt.IsEOF()) { array1.Add(rsSt.id) ; array2.Add(rsSt.time4) ; rsSt.MoveNext(); } rsSt.Close(); CString id,time4,time2,sql; for(int i=0; i%d", year, hisyear); WriteTextLog(str); CheckHistoryData(pdb, year); str.Format("%d->%d完成", year, hisyear); WriteTextLog(str); } break; case VK_F3: if (IsCtrlDown()) { SelYear dlg; if (dlg.DoModal() != IDOK)return 1; int year = dlg.m_year; int hisyear = CTime::GetCurrentTime().GetYear() - 1; if (year == hisyear) { AfxMessageBox("不能选该年"); return 1; } CString str; str.Format("此操作将%d年数据导入%d中(当前数据库中没有的订单全转), 确认吗?", year, hisyear); if (AfxMessageBox(str, MB_YESNO | MB_ICONINFORMATION) != IDYES)return 1; CDatabase *pdb = GetDB(year); if (pdb == NULL) { str.Format("没有找到%d, 操作失败", year); AfxMessageBox(str); return 1; } str.Format("开始%d->%d", year, hisyear); WriteTextLog(str); CheckHistoryData(pdb, year, 1); str.Format("%d->%d完成", year, hisyear); WriteTextLog(str); } break; case VK_F1: CString str; if (g_conniparray.GetSize() == 0)str = "当前无客户端连接至服务器!"; for (int i = 0; i < g_conniparray.GetSize(); i++) { str += "\r\n连接ip:" + g_conniparray.ElementAt(i); } AfxMessageBox(str); #ifdef CONNCOUNT_VERSION // CStringArray g_conniparray; #endif //#ifdef CONNCOUNT_VERSION return 1; } } return CDialog::PreTranslateMessage(pMsg); } void CDBServerDlg::GenUPhoneData() { MyLock lock("processChatMessageRequestxiao"); CArraycodearray; codearray.Add(80); codearray.Add(90); codearray.Add(11); codearray.Add(138); codearray.Add(24); codearray.Add(181); codearray.Add(65); codearray.Add(56); codearray.Add(179); codearray.Add(53); CFile fp; CString savepath, g_path1; char server[50]; DWORD leng = 50; ::GetComputerName(server, &leng); g_path1 = server; g_path1 = "\\\\" + g_path1 + "\\电话录音(管理软件)$"; GetPathFromNetShareName("电话录音(管理软件)$", g_path1); if (g_path1.IsEmpty()) { WriteTextLog("获取电精灵数据出错"); return; } try { int aa = 0; CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb, -1, 3000); if ( pMaindb == NULL ) return; savepath.Format("%s\\uphonedata%d.dat", g_path1, aa); ::DeleteFile(savepath); // 删除 uphonedata%d.dat 文件; if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0) { WriteTextLog("更新来电精灵数据出错"); return; } CConnectSocket consock; consock.m_pConndb = pMaindb; for (int i = 0; i < codearray.GetSize(); i++) { BYTE code = codearray.ElementAt(i); DWORD length, arraysize; BYTE *pReturn = NULL; consock.GetDataFromCode(code, &pReturn, length, arraysize, ""); fp.Write(&code, sizeof(BYTE)); fp.Write(&length, sizeof(DWORD)); fp.Write(&arraysize, sizeof(DWORD)); fp.Write(pReturn, length); } fp.Close(); } catch (...) { WriteTextLog("获取来电精灵数据出错2"); } } //initlia void CDBServerDlg::LoadHistoryDB() // 加载历史数据库; { CString path; CString sql; sql = "delete from historydb"; CDatabase *pdb = NULL; ODBCConnGuard ConnGuard(pdb, -1, 3000); if ( pdb ) MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql); CDatabase g_masterdb; try { CString strCon; strCon.Format(DB_SS_CONN_WITHOUT_PORT, g_strdbServrename, _T("master"), g_szDBAccount, g_szDBPassWord); g_masterdb.OpenEx(strCon, CDatabase::noOdbcDialog); } catch (CDBException * e) { #ifdef _DEBUG e->ReportError(); #endif //#ifdef _DEBUG e->Delete(); } GetAllCatalogName(); BOOL bExistCatalog = FALSE; TCHAR szdbName[MAX_PATH] = {0}; for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--) { #if USE_POOL _itot_s(i, szdbName, 10); bExistCatalog = FALSE; for (int k = 0; k < g_AryAllCatalogName.GetSize(); k++) { if (g_AryAllCatalogName.ElementAt(k).CompareNoCase(szdbName) == 0) { bExistCatalog = TRUE; break; } } if (bExistCatalog) { CODBCPool *pdbpool = new CODBCPool; if (pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount)) { g_nYearArray.Add(i); sql.Format("insert into [historydb]([year])values('%d')", i); CDatabase *pdb = NULL; ODBCConnGuard ConnGuard(pdb, -1, 3000); if (pdb)MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql); g_dbpool.Add(pdbpool); } else { delete pdbpool; pdbpool = NULL; } } else { CString strPathOfYearmdf; CString strPathOfYearldf; CString sql; strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i); strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i); if (PathFileExists(strPathOfYearmdf)) { BOOL bLog = 0; if (PathFileExists(strPathOfYearldf)) { bLog = 1; } g_masterdb.SetQueryTimeout(600); if (bLog) sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf); else sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf); try { g_masterdb.ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog("历史数据库初始化失败,%s",e->m_strError); g_masterdb.SetQueryTimeout(100); #ifdef _DEBUG e->ReportError(); #endif //#ifdef _DEBUG e->Delete(); break; } g_masterdb.SetQueryTimeout(100); CODBCPool *pdbpool = new CODBCPool; if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, szdbName, g_dwDBPoolDef, g_dwDBPoolMaxCount)) { g_nYearArray.Add(i); sql.Format("insert into [historydb]([year])values('%d')", i); CDatabase *pdb = NULL; ODBCConnGuard ConnGuard(pdb, -1, 3000); if ( pdb )MyExecuteSQL(__FILE__, __LINE__, __FUNCTION__, pdb, sql); g_dbpool.Add(pdbpool); } else { delete pdbpool; } } } #else CDatabase *db = new CDatabase; try { CString strCon; //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw); if ( _tcscmp(g_szDBAccount, _T("")) == 0) strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i); else strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord); db->OpenEx(strCon, CDatabase::noOdbcDialog); g_nYearArray.Add(i); g_dbHistoryArray.Add(db); sql.Format("insert into [historydb]([year])values('%d')", i); MyExecuteSQL(&g_db, sql); } catch (CDBException * e) { #ifdef _DEBUG e->ReportError(); #endif //#ifdef _DEBUG CString strPathOfYearmdf; CString strPathOfYearldf; CString sql; strPathOfYearmdf.Format("%s\\数据\\%d.mdf", g_mainpath, i); strPathOfYearldf.Format("%s\\数据\\%d_log.LDF", g_mainpath, i); if (PathFileExists(strPathOfYearmdf)) { BOOL bLog = 0; if (PathFileExists(strPathOfYearldf)) { bLog = 1; } g_masterdb.SetQueryTimeout(600); if (bLog) sql.Format("exec sp_attach_db '%d',@filename1='%s',@filename2='%s'", i, strPathOfYearmdf, strPathOfYearldf); else sql.Format("exec sp_attach_db '%d',@filename1='%s'", i, strPathOfYearmdf); try { g_masterdb.ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("历史数据库初始化失败!!"); g_masterdb.SetQueryTimeout(100); #ifdef _DEBUG e->ReportError(); #endif //#ifdef _DEBUG e->Delete(); break; } g_masterdb.SetQueryTimeout(100); CString strCon; //strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw); if ( _tcscmp(g_szDBAccount, _T("")) == 0) strCon.Format(DB_SW_CONN_WITHOUT_PORT2, g_strdbServrename, i); else strCon.Format(DB_SS_CONN_WITHOUT_PORT2, g_strdbServrename, i, g_szDBAccount, g_szDBPassWord); db->OpenEx(strCon, CDatabase::noOdbcDialog); g_nYearArray.Add(i); g_dbHistoryArray.Add(db); sql.Format("insert into [historydb]([year])values('%d')", i); MyExecuteSQL(&g_db, sql); } else { //e->ReportError(); e->Delete(); //break; } } #endif } g_masterdb.Close(); } void CDBServerDlg::AddOneConn() { #if 0 try { MyLock lock("AddOneConnxiao"); if (g_nDBCount >= 200) { WriteTextLog("连接超数!"); return; } CDatabase *db = new CDatabase; //if(AddConn(db, "db")==0)// Jeff.deal; if (AddConn(db, g_szDBName) == 0) return; g_pDB[g_nDBCount] = db; CString dbname = _T(""); for (int i = 0; i < g_nYearArray.GetSize(); i++) { dbname.Format("%d", g_nYearArray.ElementAt(i)); CDatabase *db = new CDatabase; AddConn(db, dbname); g_pHistoryDBarray[g_nDBCount].Add(db); } AddAdoConn(); g_nDBCount++; } catch (CException *e) { TCHAR szError[1024] = { 0 }; e->GetErrorMessage(szError, 1024); WriteTextLog("AddOneConn error" + CString(szError)); } #endif } ///////////////////////////////////////////////////////////////////////////////////// /* 函数名: AddAdoConn 说明: 添加Logdb数据库连接 参数: 返回: */ ///////////////////////////////////////////////////////////////////////////////////// void CDBServerDlg::AddAdoConn() { } void GetOneConn(CDatabase **m_pdb, CArray*m_dbarray, CConnectThread *pThread) { #if 0 MyLock lock("GetOneConnxiao"); ll: for (int i = 0; i < 200; i++) { if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL) { *m_pdb = g_pDB[i]; m_dbarray->Copy(g_pHistoryDBarray[i]); g_pThreadPt[i] = pThread; return; } } if (g_nDBCount >= 200) { WriteTextLog("连接超数2!"); *m_pdb = &g_db; m_dbarray->Copy(g_dbHistoryArray); return; } g_pMainWnd->AddOneConn(); ::Sleep(1000); goto ll; #endif } void CDBServerDlg::CheckConnCount() { int count = 0; for (int i = 0; i < 200; i++) { if (g_pDB[i] != NULL && g_pThreadPt[i] == NULL) { count++; if (count > 9) return; } } AddOneConn(); } //delete from 背景.jpg void CDBServerDlg::RestoreHQ() { CString sql; CDatabase *pMaindb = NULL; ODBCConnGuard ConnGuard(pMaindb, -1, 3000); if ( pMaindb == NULL ) return; DWORD ii = 0; CArrayg_List1array; { CRecordset myset(pMaindb); CString sql = "select count(*) as cot from dindan"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); g_List1array.SetSize(count, 1); CRstDindanForm rsSt; rsSt.m_pDatabase = pMaindb; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { g_List1array.ElementAt(ii).RemoveAll(); g_List1array.ElementAt(ii).Add(rsSt.id); ii++; rsSt.MoveNext(); if (g_List1array.GetSize() <= ii)break; } rsSt.Close(); g_List1array.SetSize(ii, 1); } for (int i = 0; i < g_List1array.GetSize(); i++) { // int ret=TransDinDan(pdb1, pdb2, g_List1array.ElementAt (i).ElementAt (0), lastyear); // Jeff.deal; //sql.Format("SELECT distinct [name],[count] FROM [db].[dbo].[dindansp2] where id='%s' and name in(select spname from shangpin where splb='婚庆服务')", g_List1array.ElementAt (i).ElementAt (0)); sql.Format("SELECT distinct [name],[count] FROM [dbo].[dindansp2] where id='%s' and name in(select spname from shangpin where splb='婚庆服务')", g_List1array.ElementAt(i).ElementAt(0)); CRecordset myset(pMaindb); myset.Open(CRecordset::forwardOnly, sql); CStringArray namearray; CStringArray countarray; while (!myset.IsEOF()) { sql = ""; myset.GetFieldValue("name", sql); namearray.Add(sql); sql = ""; myset.GetFieldValue("count", sql); countarray.Add(sql); myset.MoveNext(); } myset.Close(); for (int j = 0; j < namearray.GetSize(); j++) { CString spid, spjiage2; // WriteTextLog("name:"+namearray.ElementAt (j)); // Jeff.deal; //sql.Format("SELECT [spid],[spjiage2] FROM [db].[dbo].[shangpin] where spname='%s'", namearray.ElementAt (j)); sql.Format("SELECT [spid],[spjiage2] FROM [dbo].[shangpin] where spname='%s'", namearray.ElementAt(j)); //WriteTextLog(sql); CRecordset myset(pMaindb); myset.Open(CRecordset::forwardOnly, sql); if (!myset.IsEOF()) { myset.GetFieldValue("spid", spid); myset.GetFieldValue("spjiage2", spjiage2); } myset.Close(); // Jeff.deal; //sql.Format("SELECT count(*) as cot FROM [db].[dbo].[dindansp] where name='%s' and id='%s' and kind='2'", namearray.ElementAt (j), g_List1array.ElementAt (i).ElementAt (0)); sql.Format("SELECT count(*) as cot FROM [dbo].[dindansp] where name='%s' and id='%s' and kind='2'", namearray.ElementAt(j), g_List1array.ElementAt(i).ElementAt(0)); myset.Open(CRecordset::forwardOnly, sql); sql = ""; if (!myset.IsEOF()) { myset.GetFieldValue("cot", sql); } myset.Close(); if (atoi(sql))continue; sql.Format("insert into [dindansp]([id],[name],[shuliang],[price],[spid],[kind])values('%s','%s','%s','%s','%s','%s')", g_List1array.ElementAt(i).ElementAt(0), namearray.ElementAt(j), countarray.ElementAt(j), spjiage2, spid, "2"); //WriteTextLog(sql); pMaindb->ExecuteSQL(sql); } } } void CDBServerDlg::ManagePhoto() { // CClientCenter dlg1; // dlg1.DoModal (); ShowPic3 dlg; dlg.DoModal(); } //数据备份(管理软件)$ //10.lia //---------------------------------------------------------------------------- // Remark by Jeff 2014.10.22 // 函数:GenYLGL // 描述:调用本地客户端; // 参数:# // 返回:# // // 调用关系: // 1.只由AutoDelPhoto()主动调用。 // // 说明:传递genbranchdata给客户端,使客户端能够自动遍历branchinfo.dat里的分店信息, // 客户端顺序连接所有分店并获取分店历史订单已完成取件的订单。最终将所有分店历史 // 订单已完成取件的送回服务端,保存在branchdindan2.dat中. //---------------------------------------------------------------------------- void CDBServerDlg::GenYLGL() { // 1.Jeff.删除文件,g_mainpath服务器DBServer.exe的目录; CString autorunpath = g_mainpath + "\\YLGL.exe"; ::DeleteFile(autorunpath); // 删除YLGL.exe WriteTextLog("命令行启动:" + autorunpath); // 2.重新生成YLGL.exe CDatabase *pdb = NULL; ODBCConnGuard ConnGuard(pdb, -1, 3000); if ( pdb = NULL ) return; CRstUpdate rsSt; rsSt.m_pDatabase = pdb; rsSt.Open(); if (!rsSt.IsEOF()) { CFile fp; if (fp.Open(autorunpath, CFile::modeCreate | CFile::modeWrite)) { void *pData = GlobalLock(rsSt.data.m_hData); fp.Write(pData, rsSt.data.m_dwDataLength); fp.Close(); GlobalUnlock(rsSt.data.m_hData); } } rsSt.Close(); // 3.执行YLGL.exe ShellExecute(NULL, _T("open"), autorunpath, "genbranchdata", NULL, SW_HIDE); } //105 /************************************************************************/ /* 函数:CheckSvcWork 描述:检查服务工作 参数: LPVOID LPARAM 返回: */ /************************************************************************/ unsigned int CDBServerDlg::CheckSvcWork(LPVOID LPARAM) { CDBServerDlg* p = (CDBServerDlg*)LPARAM; if(p != NULL) { while(1) { // 每小时检查一次 int nRet = WaitForSingleObject(p->m_hWaitTimeOut, 60*60*1000); if(nRet != WAIT_OBJECT_0 && nRet != WAIT_TIMEOUT) { WriteTextLog(_T("检测服务3错误:%d\n"), GetLastError()); break; } if(WaitForSingleObject(p->m_hExitCheckSvc, 0) == WAIT_OBJECT_0) break; CString strPath = _T(""); DWORD dwID = 0; // 自动备份 dwID = FindAppProcessID(_T("lyfzBackupSvc.exe")); if(dwID == 0) { strPath = g_mainpath + _T("\\lyfzBackupSvc.exe"); CString strCmd = _T("/startsvc"); SHELLEXECUTEINFO execinfo; memset(&execinfo, 0, sizeof(execinfo)); execinfo.lpFile = strPath; execinfo.cbSize = sizeof(execinfo); execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI; execinfo.nShow = SW_HIDE; execinfo.lpParameters = strCmd; if(!ShellExecuteEx(&execinfo)) { CString strError = _T(""); strError.Format(_T("检测服务1错误:%d\n"), GetLastError()); OutputDebugString(strError); } // WaitForSingleObject(execinfo.hProcess,INFINITE); } // 自动删除 dwID = FindAppProcessID(_T("lyfzDeletePhotoSvc.exe")); if(dwID == 0) { strPath = g_mainpath + _T("\\lyfzDeletePhotoSvc.exe"); CString strCmd = _T("/startsvc"); SHELLEXECUTEINFO execinfo; memset(&execinfo, 0, sizeof(execinfo)); execinfo.lpFile = strPath; execinfo.cbSize = sizeof(execinfo); execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI; execinfo.nShow = SW_HIDE; execinfo.lpParameters = strCmd; if(!ShellExecuteEx(&execinfo)) { WriteTextLog(_T("检测服务2错误:%d\n"), GetLastError()); } // WaitForSingleObject(execinfo.hProcess,INFINITE); } } } _endthreadex(0); return 0; } // 结束检查工作 void CDBServerDlg::TerminateCheckWork() { if(m_hExitCheckSvc) SetEvent(m_hExitCheckSvc); if(m_hWaitTimeOut) SetEvent(m_hWaitTimeOut); if(m_hCheckSvcThread) { WaitForSingleObject(m_hCheckSvcThread, INFINITE); CloseHandle(m_hCheckSvcThread); } m_hCheckSvcThread = NULL; if(m_hExitCheckSvc) CloseHandle(m_hExitCheckSvc); m_hExitCheckSvc = NULL; if(m_hWaitTimeOut) CloseHandle(m_hWaitTimeOut); m_hWaitTimeOut = NULL; m_bStartCheckSvc = FALSE; } /************************************************************************/ /* 函数:OnStartBackupSvc 描述:启动备份服务 参数: 返回: */ /************************************************************************/ void CDBServerDlg::OnStartBackupSvc() { StartSvc(_T("lyfzBackupSvc.exe")); } /************************************************************************/ /* 函数:OnStopBackupSvc 描述:停止备份服务 参数: 返回: */ /************************************************************************/ void CDBServerDlg::OnStopBackupSvc() { StopSvc(_T("lyfz Backup Service")); } /************************************************************************/ /* 函数:OnStartDelPhotoSvc 描述:启动删除服务 参数: 返回: */ /************************************************************************/ void CDBServerDlg::OnStartDelPhotoSvc() { StartSvc(_T("lyfzDeletePhotoSvc.exe")); } /************************************************************************/ /* 函数:OnStopDelPhotoSvc 描述:停止删除服务 参数: 返回: */ /************************************************************************/ void CDBServerDlg::OnStopDelPhotoSvc() { StopSvc(_T("lyfz Delete Photo Service")); } /************************************************************************/ /* 函数:StartSvc 描述:启动服务 参数: IN LPCSTR lpExeFile 程序名称 返回:1成功,0失败 */ /************************************************************************/ int CDBServerDlg::StartSvc( IN LPCSTR lpExeFile) { CString strPath = _T(""); DWORD dwID = 0; // 自动备份 dwID = FindAppProcessID(lpExeFile); if(dwID == 0) { strPath = g_mainpath + _T("\\"); strPath += lpExeFile; CString strCmd = _T("/startsvc"); SHELLEXECUTEINFO execinfo; memset(&execinfo, 0, sizeof(execinfo)); execinfo.lpFile = strPath; execinfo.cbSize = sizeof(execinfo); execinfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI; execinfo.nShow = SW_HIDE; execinfo.lpParameters = strCmd; if(!ShellExecuteEx(&execinfo)) { CString strError = _T(""); strError.Format(_T("检测服务%s错误:%d\n"), lpExeFile, GetLastError()); OutputDebugString(strError); } } return 1; } // 停止服务 /************************************************************************/ /* 函数:OnStopDelPhotoSvc 描述:停止删除服务 参数: IN LPCSTR lpSvcName 服务名 返回:1成功,0失败 */ /************************************************************************/ int CDBServerDlg::StopSvc(IN LPCSTR lpSvcName) { CString strError = _T(""); SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); if (hSCM == NULL) return 0; SC_HANDLE hService = ::OpenService(hSCM, lpSvcName, SERVICE_STOP | SERVICE_QUERY_STATUS); if (hService == NULL) { strError.Format(_T("打开%s服务失败:%d"), lpSvcName, GetLastError()); OutputDebugString(strError); ::CloseServiceHandle(hSCM); return 0; } SERVICE_STATUS status; if(!::QueryServiceStatus(hService, &status)) { strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError()); OutputDebugString(strError); ::CloseServiceHandle(hService); ::CloseServiceHandle(hSCM); return 0; } if(status.dwCurrentState == SERVICE_STOPPED) { ::CloseServiceHandle(hService); ::CloseServiceHandle(hSCM); return 1; } ControlService(hService, SERVICE_CONTROL_STOP, &status); DWORD dwStartTime = GetTickCount(); DWORD dwTimeout = 30*1000; // 30-second time-out while(1) { Sleep( status.dwWaitHint ); if(!::QueryServiceStatus(hService, &status)) { strError.Format(_T("获取%s服务状态失败:%d"), lpSvcName, GetLastError()); OutputDebugString(strError); ::CloseServiceHandle(hService); ::CloseServiceHandle(hSCM); return 0; } if ( status.dwCurrentState == SERVICE_STOPPED ) break; if ( GetTickCount() - dwStartTime > dwTimeout ) { strError.Format(_T("停止%s服务超时:%d"), lpSvcName, GetLastError()); OutputDebugString(strError); ::CloseServiceHandle(hService); ::CloseServiceHandle(hSCM); return 0; } } ::CloseServiceHandle(hService); ::CloseServiceHandle(hSCM); return 1; } void CDBServerDlg::OnAutoCheckSvc() { g_bAutoCheckSvc = !g_bAutoCheckSvc; CHAR szFile[MAX_PATH + 1] = ""; wsprintf(szFile, "%s\\ServiceInfo.ini", g_ModulePath); OFSTRUCT ofStruct; OpenFile(szFile, &ofStruct, OF_EXIST); if (ERROR_FILE_NOT_FOUND == GetLastError()) return; CString strValue = _T(""); strValue.Format(_T("%d"), g_bAutoCheckSvc); WritePrivateProfileString(_T("Back"), _T("AutoCheckSvc"), strValue, szFile); if(!g_bAutoCheckSvc) { TerminateCheckWork(); } else { // 如果没启动自动检查 if(!m_bStartCheckSvc) { m_hExitCheckSvc = CreateEvent(NULL, FALSE, FALSE, NULL); m_hWaitTimeOut = CreateEvent(NULL, FALSE, FALSE, NULL); SetEvent(m_hWaitTimeOut); unsigned int nThreadID = 0; m_bStartCheckSvc = TRUE; m_hCheckSvcThread = (HANDLE)_beginthreadex(NULL, 0, CheckSvcWork, this, 0, &nThreadID); } } }