/****************************************************************/ /* */ /* ApplicationDlg.cpp */ /* */ /* Implementation of the CDBServerDlg class. */ /* This class is a part of the Date Server. */ /* */ /* Programmed by LYFZ van der Meer */ /* Copyright LYFZ Software Solutions 2002 */ /* http://www.LYFZvandermeer.nl */ /* */ /* Last updated: 10 july 2002 */ /* */ /****************************************************************/ //在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 "DogTimeOutDlg.h" #include "InputAuthDlg.h" #include "ConnectThread.h" #pragma comment(lib, "NETAPI32.LIB ") #include "SelYear.h" /*********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; DWORD GetLastDirTime(CString dir) { try { CString path = dir; path.TrimRight("\\"); path += "\\"; path += "modifytime"; CStdioFile fp; if (::PathFileExists(path)) { fp.Open(path, CFile::modeRead); fp.ReadString(path); fp.Close(); path.TrimLeft(); path.TrimRight(); path.Replace("-", ""); return atoi(path); } else { using namespace helper_coffs; ffsco o; o.dirs(1); o.find(LPCSTR(dir), LPCSTR("*.jpg")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); CString path; DWORD maxdate = 0; for (it = coo.begin(); coo.end() != it; it++) { if (g_pMainWnd->m_bTerminate2)return 99999999; // Jeff.奇葩的返回值! path = (*it).c_str(); maxdate = max(maxdate, atol(GetModifyTime2(path))); } return maxdate; } } catch (...) { WriteTextLog("出错"); } } 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) { //{{AFX_DATA_INIT(CDBServerDlg) //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDI_DBServer); m_bTerminate = false; m_bRunning = false; m_hThread = NULL; m_bTerminate2 = false; m_bRunning2 = false; m_hThread2 = NULL; hInst = NULL; CString version = _T("Version 1.0"); g_bAutoRun = AfxGetApp()->GetProfileInt(version, "brun", 0); 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) //}}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 g_curdb = &g_db; OnButton1(); // Jeff 初始化服务端,内含定时器1; GetFileDate(); // Jeff获取文件信息; //LoadDB(); LoadHistoryDB();//Jeff加载历史数据库; int aaaa = 30; while (aaaa--) AddOneConn();//添加数据库连接; 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; 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 */ /* */ /********************************************************************/ //启动数据服务器,使其在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() { // create Imagelist 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); /* m_OutlookBar.InsertItem(4, "Security", 4);*/ // m_OutlookBar.SetExtendedStyle(LVS_EX_TRACKSELECT); } /********************************************************************/ /* */ /* 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(); ///////////////////// CString logdays; MyLock lock("dbaccessxiao"); CRecordset myset(&g_db); 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(days, 0, 0, 0); tm -= dt; CString date = tm.Format("%Y-%m-%d"); /////////////////// tm = CTime::GetCurrentTime(); CTimeSpan dt2(183, 0, 0, 0); tm -= dt2; date = tm.Format("%Y%m%d%H%M%S"); sql = "delete from sendreg where [status]='OK' and [timestamp]<'" + date + "'"; g_db.ExecuteSQL(sql); ////////////////////////////////// sql = "select version from version"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("version", sql); myset.Close(); m_ConfigurationPage.m_versionno = "00" + sql; m_ConfigurationPage.UpdateData(0); ///////////////////// } catch (...) { WriteTextLog("出错1"); } } 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(); TerminateThread2(); 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 { TerminateThread(); TerminateThread2(); 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; 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("出错在函数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; LoadBranchInfo2(); } 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); DWORD id = FindAppProcessID("MsgServer.exe"); if (id != -1) { HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id); if (ProcessHandle) TerminateProcess(ProcessHandle, 0); } CString autorunpath = g_mainpath + "\\MsgServer.exe"; ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); } 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(); } #if 0 // Jeff.开启定时关机功能 else if ( nIDEvent == 11) { g_curdb=&g_db; CString m_bak6; CString strShutDownTime; CRecordset myset(g_curdb); CString sql="select * from [version]"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFiledVale("ShutDownTime",strShutDownTime); myset.Close(); CTime tShutDownTime( CTime::GetCurrentTime().GetYear(), CTime::GetCurrentTime().GetMonth(), CTime::GetCurrentTime().GetDay(), atoi(strShutDownTime.Left(2)), atoi(strShutDownTime.Right(2)), 0); if (CTime::GetCurrentTime() >= tShutDownTime) { MyExitWindows(); } } #endif } 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文件遍历; using namespace helper_coffs; ffsco o; o.dirs(1); o.find(LPCSTR(dir), LPCSTR("*.jpg")); 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)) { Image *pImg = NULL; ::LoadImageFromBuf(&pImg, path); if (pImg == NULL)continue; if (pImg->GetWidth() == 0)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)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)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("*.jpg")); 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 // 函数: // 描述: // dir:客户原片、修好的片、精修片、设计片目录的订单文件夹路径; // desdir:dir对就的备份目录; // 参数: // 返回: // // 调用关系: // 1. // 2. // 3. //-------------------------------------------------------------------------------- BOOL BakAllPhoto(CString dir, CString desdir, CString g_path1, CString g_path2, CString g_path3, CString g_path4) { try { CString childdir; CString srcdir = dir; srcdir.MakeLower(); if (srcdir.Find(g_path1) != -1) childdir = srcdir.Right(srcdir.GetLength() - g_path1.GetLength()); else if (srcdir.Find(g_path2) != -1) childdir = srcdir.Right(srcdir.GetLength() - g_path2.GetLength()); else if (srcdir.Find(g_path3) != -1) childdir = srcdir.Right(srcdir.GetLength() - g_path3.GetLength()); else if (srcdir.Find(g_path4) != -1) childdir = srcdir.Right(srcdir.GetLength() - g_path4.GetLength()); else { WriteTextLog("备份出错-目录未找到!"); return 0; } /* srcdir.TrimLeft ("\\"); srcdir.Delete (srcdir.Find ('\\')); if(srcdir.Find ('\\')==-1) childdir=""; else childdir=srcdir.Right (srcdir.GetLength ()-srcdir.Find ('\\'));*/ childdir.TrimLeft("\\"); childdir.TrimRight("\\"); while (childdir.Find('\\') != -1) { desdir += "\\"; desdir += childdir.Left(childdir.Find('\\')); //if(CheckFolderFileExist (desdir)==0) { // if(! CreateDirectory(desdir, NULL);//)return; } childdir = childdir.Right(childdir.GetLength() - childdir.Find('\\') - 1); } desdir += "\\"; desdir += childdir; //if(CheckFolderFileExist (desdir)==0) { // if(! CreateDirectory(desdir, NULL);//)return; } desdir += "\\"; // Jeff.进行相片复制操作; using namespace helper_coffs; ffsco o; o.dirs(0); o.find(LPCSTR(dir), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); CString path, temp, despath; for (it = coo.begin(); coo.end() != it; it++) { try { if (g_pMainWnd->m_bTerminate2)return 0; path = (*it).c_str(); temp = path.Right(path.GetLength() - path.ReverseFind('\\') - 1); if (temp.GetAt(0) == 's')continue; despath = desdir + path.Right(path.GetLength() - path.ReverseFind('\\') - 1); if (CheckFileExist(despath)) { /* HANDLE hFile=CreateFile(path,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); HANDLE hFile2=CreateFile(despath,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL); FILETIME ftWrite,ftWrite2; if(GetFileTime(hFile, NULL, NULL, &ftWrite)==0) { CloseHandle(hFile); CloseHandle(hFile2); return; } if(GetFileTime(hFile2, NULL, NULL, &ftWrite2)==0) { CloseHandle(hFile); CloseHandle(hFile2); return; } CloseHandle(hFile); CloseHandle(hFile2); if(ftWrite.dwHighDateTime!=ftWrite2.dwHighDateTime || ftWrite.dwLowDateTime!=ftWrite2.dwLowDateTime) {*/ if (::CopyFile(path, despath, 0)) g_bakphoto = "照片备份成功"; // } } else { if (::CopyFile(path, despath, 0)) g_bakphoto = "照片备份成功"; } } catch (...) { } } } catch (...) { WriteTextLog("出错在函数BakAllPhoto中"); return 0; } return 1; } //-------------------------------------------------------------------------------- // Remark by Jeff 2014.10.22 // 函数: // 描述: // 参数: // 返回: // // 调用关系: // 1. // 2. // 3. //-------------------------------------------------------------------------------- unsigned __stdcall LoadThumbNail(LPVOID lpParam) { BOOL bMphoto = 0; if (g_bSteal == 0) { CRecordset myset(&g_db); CString sql = "select * from version"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("setcheck15", sql); myset.Close(); bMphoto = atoi(sql); } CDBServerDlg *pDlg = (CDBServerDlg*)lpParam; try { CString g_path1; CString g_path2; CString g_path3; CString g_path4; char server[50]; DWORD leng = 50; ::GetComputerName(server, &leng); g_path1 = g_path2 = g_path3 = g_path4 = server; if (g_path2.IsEmpty())return 0; g_path1 = "\\\\" + g_path1 + "\\客户原片(管理软件)$"; g_path2 = "\\\\" + g_path2 + "\\修好的片(管理软件)$"; g_path3 = "\\\\" + g_path3 + "\\设计好的片(管理软件)$"; g_path4 = "\\\\" + g_path4 + "\\精修好的片(管理软件)$"; GetPathFromNetShareName("客户原片(管理软件)$", g_path1); GetPathFromNetShareName("修好的片(管理软件)$", g_path2); GetPathFromNetShareName("设计好的片(管理软件)$", g_path3); GetPathFromNetShareName("精修好的片(管理软件)$", g_path4); CStringArray dirarray; CString path, path2; using namespace helper_coffs; CString patharray[4] = { g_path1, g_path2, g_path3, g_path4 }; // Remark:Jeff. // 遍历原片、修好片、设计片、精修片目录,查看是否有ok或ok.dat文件存在; // 说明:ok文件在客户端再次导入相片时会被删除; // 只有服务端生成小图后,ok才被重新生成; int i = 0; for ( i = 0; i < 4; i++) { if (pDlg->m_bTerminate) { break; } ffsco o; o.dirs(1); o.find(LPCSTR(patharray[i]), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); it = coo.begin(); it++; for (; coo.end() != it; it++) { if (pDlg->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的意义??? if (g_bCheckAll || g_bSteal) { if (FindArray(&dirarray, (*it).c_str()) == -1) dirarray.Add((*it).c_str()); } else if (CheckFileExist(path) == 0) { if (FindArray(&dirarray, (*it).c_str()) == -1) dirarray.Add((*it).c_str()); } } } 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; } //-------------------------------------------------------------------------------- // Remark by Jeff 2014.10.22 // 函数:LoadThumbNail2 // 描述:线程函数,备份相片. // 参数: // 返回: // // 调用关系: // 1. // 2. // 3. //-------------------------------------------------------------------------------- unsigned __stdcall LoadThumbNail2(LPVOID lpParam)//备份 { CDBServerDlg *pDlg = (CDBServerDlg*)lpParam; int step = 1; BOOL bError = 0; try { g_tisks = ::GetTickCount(); WriteTextLog("开始备份照片"); CDatabase *g_curdb = &g_db; // CRstPath rsSt; CString g_path1; CString g_path2; CString g_path3; CString g_path4; g_path1 = g_path2 = g_path3 = g_path4 = g_localname; CString localname = g_localname; g_path1 = "\\\\" + g_path1 + "\\客户原片(管理软件)$"; g_path2 = "\\\\" + g_path2 + "\\修好的片(管理软件)$"; g_path3 = "\\\\" + g_path3 + "\\设计好的片(管理软件)$"; g_path4 = "\\\\" + g_path4 + "\\精修好的片(管理软件)$"; GetPathFromNetShareName("客户原片(管理软件)$", g_path1); GetPathFromNetShareName("修好的片(管理软件)$", g_path2); GetPathFromNetShareName("设计好的片(管理软件)$", g_path3); GetPathFromNetShareName("精修好的片(管理软件)$", g_path4); step = 2; g_path1.MakeLower(); g_path2.MakeLower(); g_path3.MakeLower(); g_path4.MakeLower(); CString m_bak1, m_bak2, m_bak3, m_bak4; // 是否备份(指定的备份目录是否需要备份); CString m_bak11, m_bak22, m_bak33, m_bak44; // 是否备份(集团版的分店备份目录是否需要备份??); CString m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4; // 相片备份目录 ; { MyLock lock("dbaccessxiao"); CRstversion rsSt; rsSt.m_pDatabase = g_curdb; 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_bak11 = rsSt.bak11; m_bak22 = rsSt.bak22; m_bak33 = rsSt.bak33; m_bak44 = rsSt.bak44; } rsSt.Close(); step = 3; } #ifdef CHILD_VERSION if (m_bakserver1.Find(":") == -1 && m_bakserver1 != "") m_bakserver1 = "\\\\" + m_bakserver1 + "\\客户原片备份(儿童管理软件)$"; if (1)//(localname.CompareNoCase (m_bakserver1)==0 || CompareIP(localname, m_bakserver1)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\客户原片备份(儿童管理软件)$")) GetPathFromNetShareName("客户原片备份(儿童管理软件)$", m_bakserver1); if (m_bakserver2.Find(":") == -1 && m_bakserver2 != "") m_bakserver2 = "\\\\" + m_bakserver2 + "\\修好的片备份(儿童管理软件)$"; if (1)//((localname.CompareNoCase (m_bakserver2)==0 || CompareIP(localname, m_bakserver2)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\修好的片备份(儿童管理软件)$")) GetPathFromNetShareName("修好的片备份(儿童管理软件)$", m_bakserver2); if (m_bakserver3.Find(":") == -1 && m_bakserver3 != "") m_bakserver3 = "\\\\" + m_bakserver3 + "\\精修好的片备份(儿童管理软件)$"; if (1)//((localname.CompareNoCase (m_bakserver3)==0 || CompareIP(localname, m_bakserver3)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\精修好的片备份(儿童管理软件)$")) GetPathFromNetShareName("精修好的片备份(儿童管理软件)$", m_bakserver3); if (m_bakserver4.Find(":") == -1 && m_bakserver4 != "") m_bakserver4 = "\\\\" + m_bakserver4 + "\\设计好的片备份(儿童管理软件)$"; if (1)//((localname.CompareNoCase (m_bakserver4)==0 || CompareIP(localname, m_bakserver4)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\设计好的片备份(儿童管理软件)$")) GetPathFromNetShareName("设计好的片备份(儿童管理软件)$", m_bakserver4); #else if (m_bakserver1.Find(":") == -1 && m_bakserver1 != "") m_bakserver1 = "\\\\" + m_bakserver1 + "\\客户原片备份(管理软件)$"; if (1)//((localname.CompareNoCase (m_bakserver1)==0 || CompareIP(localname, m_bakserver1)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\客户原片备份(管理软件)$")) GetPathFromNetShareName("客户原片备份(管理软件)$", m_bakserver1); if (m_bakserver2.Find(":") == -1 && m_bakserver2 != "") m_bakserver2 = "\\\\" + m_bakserver2 + "\\修好的片备份(管理软件)$"; if (1)//((localname.CompareNoCase (m_bakserver2)==0 || CompareIP(localname, m_bakserver2)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\修好的片备份(管理软件)$")) GetPathFromNetShareName("修好的片备份(管理软件)$", m_bakserver2); if (m_bakserver3.Find(":") == -1 && m_bakserver3 != "") m_bakserver3 = "\\\\" + m_bakserver3 + "\\精修好的片备份(管理软件)$"; if (1)//((localname.CompareNoCase (m_bakserver3)==0 || CompareIP(localname, m_bakserver3)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\精修好的片备份(管理软件)$")) GetPathFromNetShareName("精修好的片备份(管理软件)$", m_bakserver3); if (m_bakserver4.Find(":") == -1 && m_bakserver4 != "") m_bakserver4 = "\\\\" + m_bakserver4 + "\\设计好的片备份(管理软件)$"; if (1)//((localname.CompareNoCase (m_bakserver4)==0 || CompareIP(localname, m_bakserver4)==0) && CheckFolderFileExist("\\\\"+m_bakserver1+"\\设计好的片备份(管理软件)$")) GetPathFromNetShareName("设计好的片备份(管理软件)$", m_bakserver4); #endif WriteTextLog(m_bakserver1); WriteTextLog(m_bakserver2); WriteTextLog(m_bakserver3); WriteTextLog(m_bakserver4); step = 4; CStringArray dirarray; CString str, path; using namespace helper_coffs; BOOL bcheck1 = atoi(m_bak1); BOOL bcheck2 = atoi(m_bak2); BOOL bcheck3 = atoi(m_bak3); BOOL bcheck4 = atoi(m_bak4); BOOL bcheck11 = atoi(m_bak11); BOOL bcheck22 = atoi(m_bak22); BOOL bcheck33 = atoi(m_bak33); BOOL bcheck44 = atoi(m_bak44); // 下列4变量应该使用结构体保存; CString patharray[4] = { g_path1, g_path2, g_path4, g_path3 }; BOOL bcheck[4] = { bcheck1, bcheck2, bcheck3, bcheck4 }; // 集团版; BOOL bcheckbranch[4] = { bcheck11, bcheck22, bcheck33, bcheck44 }; CString patharray2[4] = { m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4 }; CArrayposarray; int i = 0; for ( i = 0; i < 4; i++) { if (pDlg->m_bTerminate2) { break; } // if(!CheckFolderFileExist (patharray[i]))continue; // if(!CheckFolderFileExist (patharray2[i]))continue; if (bcheck[i] == 0)continue; // Jeff,跳过没有设置备份要求的相片; if (patharray2[i] == "")continue; // Jeff.跳过没有备份目录的备份; if (!::CheckFolderFileExist(patharray2[i]))continue; // Jeff.跳过备份目录不对的备份; if (!::CheckFolderFileExist(patharray[i]))continue; // Jeff.跳过源目录不对的备份; // 获取订单文件夹路径全名; ffsco o; o.dirs(1); o.find(LPCSTR(patharray[i]), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); it = coo.begin(); it++; for (; coo.end() != it; it++) { if (pDlg->m_bTerminate2) { break; } str = (*it).c_str(); if (str.Find(".ly.com") != -1 && bcheckbranch[i] == 0)continue; if (FindArray(&dirarray, str) == -1) { dirarray.Add(str); posarray.Add(i); } } } step = 5; // Jeff.对每个订单文件夹进行相片复制操作; bError = 0; for (i = 0; im_bTerminate2)break; CTime tm = CTime::GetCurrentTime(); tm -= CTimeSpan(10, 0, 0, 0); CString date = tm.Format("%Y%m%d"); DWORD dirdate = GetLastDirTime(dirarray.ElementAt(i)); if (pDlg->m_bTerminate2)break; CString ss; if (dirdate>atol(date)) { // ss.Format ("%d>%d", dirdate, atol(date)); // WriteTextLog(ss); // WriteTextLog(dirarray.ElementAt (i)); step = 6; if (0 == BakAllPhoto(dirarray.ElementAt(i), patharray2[posarray.ElementAt(i)], g_path1, g_path2, g_path3, g_path4)) bError = 1; CString path = dirarray.ElementAt(i); path.TrimRight("\\"); path += "\\"; path += "modifytime"; CStdioFile fp; if (!::PathFileExists(path)) { fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d")); fp.Close(); } } else { step = 7; CString path = dirarray.ElementAt(i); path.TrimRight("\\"); path += "\\"; path += "modifytime"; CStdioFile fp; if (!::PathFileExists(path)) { step = 8; // CString ss; // ss.Format ("出错在函数备份照片中-step:%d,文件:%s", step, path); // WriteTextLog(ss); fp.Open(path, CFile::modeCreate | CFile::modeWrite); fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d")); fp.Close(); } } } if (bError) g_bakphoto = "照片备份失败"; else g_bakphoto = "照片备份成功"; step = 9; } catch (CException *e) { TCHAR szError[1024] = { 0 }; e->GetErrorMessage(szError, 1024); WriteTextLog(CString(szError)); e->Delete(); if (step != 8) { CString ss; ss.Format("出错在函数备份照片中-step:%d", step); WriteTextLog(ss); g_bakphoto = "照片备份出错"; } else { if (bError) g_bakphoto = "照片备份失败"; else g_bakphoto = "照片备份成功"; } } pDlg->SetTimer(6, 3000, NULL); pDlg->m_bRunning2 = false; pDlg->m_bTerminate2 = false; _endthreadex(0); return 0; } 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); } //-------------------------------------------------------------- // Remark by Jeff 2014.10.22 // 函数:LoadThumbImages2 // 描述: // 参数: // 返回: // // 调用关系: // 1.LoadThumbImages2() 只由 BakPhoto() 调用; // 2.BakPhoto()由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。 // 3.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。 // 4.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用. //-------------------------------------------------------------- void CDBServerDlg::LoadThumbImages2() { if (m_bRunning2)return; TerminateThread2(); m_bRunning2 = true; m_hThread2 = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail2, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID2); } BOOL CDBServerDlg::TerminateThread() { try { if (!m_bRunning) return TRUE; m_bTerminate = true; for (;;) { if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0) break; MSG msg; while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread); m_bRunning = false; return TRUE; } catch (...) { WriteTextLog("出错在函数TerminateThread中"); } } BOOL CDBServerDlg::TerminateThread2() { try { if (!m_bRunning2) return TRUE; m_bTerminate2 = true; for (;;) { if (::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0) break; MSG msg; while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread2); m_bRunning2 = false; return TRUE; } catch (...) { WriteTextLog("出错在函数TerminateThread2中"); } } void CDBServerDlg::InitLia() { if (g_pSkinData) delete[]g_pSkinData; g_pSkinData = NULL; HGLOBAL hGlobal = NULL; HRSRC hSource = NULL; LPVOID lpBuffer = NULL; BOOL bResult = FALSE; // 1.定位我们的自定义资源,这里因为我们是从本模块定位资源,所以将句柄简单地置为NULL即可 hSource = FindResource(NULL, MAKEINTRESOURCE(LIA004), _T("SOFTKEY")); if (hSource == NULL) { WriteTextLog(_T("定位资源失败")); return; } // 2.获取资源的大小; g_SkinLeng = (UINT)SizeofResource(NULL, hSource); // 3.加载资源; hGlobal = LoadResource(NULL, hSource); if (hGlobal == NULL) { WriteTextLog(_T("加载资源失败")); return; } // 4.锁定资源,获取buffer; lpBuffer = LockResource(hGlobal); if (lpBuffer == NULL) { WriteTextLog(_T("锁定资源失败")); return; } g_pSkinData = new BYTE[g_SkinLeng]; memcpy(g_pSkinData, lpBuffer, g_SkinLeng); UnlockResource(hGlobal); FreeResource(hGlobal); } BOOL CheckExistDinDan(CString id) { CRecordset myset(&g_db); 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); /************************************************************************/ /* [函数]:CheckHistoryData /* [描述]:将被检测的数据库已完成的订单数据转到历史数据库中,并删除被检测的数据库已完成的订单; /* [参数]: /* pSrcdb: 源数据库,用于被转历史的数据库; /* nSrcYear: 源数据库的年份; /* bMode2: 转储模式:0=年度完成的订单; 1=年度所有订单,包含未完成订单; /* [返回]:void /* /************************************************************************/ void CDBServerDlg::CheckHistoryData(CDatabase *pSrcdb /* = NULL */, int nSrcYear /* = 0 */, BOOL bMode2 /* = 0*/)//历史备份; { #if JEFF_TEST_ON // 取消转将当前数据库完成订单的记录转到年份数据库中,此步直接返回; return; #endif try { //g_nCurConvertDBName="db"; g_nCurConvertDBName = g_szDBName; if (pSrcdb != NULL) { g_bConvertHisAll = 1; g_nCurConvertDBName.Format("%d", nSrcYear); if (bMode2) { // MessageBox(g_nCurConvertDBName); } } if (g_bConvertHisAll) { DWORD id = FindAppProcessID("AutoRun.exe"); if (id != -1) { HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id); if (ProcessHandle) TerminateProcess(ProcessHandle, 0); } ShowWindow(SW_HIDE); WriteTextLog("全部转历史开始"); } CString sql; g_curdb = &g_db; if (pSrcdb != NULL) g_curdb = pSrcdb; // 1.获取去年年份值 lastyear CTime tm = CTime::GetCurrentTime(); int lastyear = tm.GetYear() - 1; CString strdate, strdate2; strdate.Format("%04d-%02d-%02d", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d", lastyear, 12, 31); CString filter = "time1>='" + strdate + "' and time1<='" + strdate2 + "' and status3='OK'"; DWORD ii = 0; CArray strOrderNumberArray; //用于记录订单单号; // 2.获取得订单号,并存储在CArray if (bMode2)// 存储即将转为历史数据库的所有年度订单的数据库记录(包含未完成); { CString filter = "time1>='" + strdate + "' and time1<='" + strdate2 + "'"; // AfxMessageBox(filter); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from dindan"; // 订单单数; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); // AfxMessageBox(sql); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstDindanForm rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); //if(CheckExistDinDan(rsSt.id)==0) { strOrderNumberArray.ElementAt(ii).Add(rsSt.id); ii++; } rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } else// 存储即将转为历史数据库的已完成订单的年度数据库记录; { // 有多少订单完成的; CRecordset myset(g_curdb); CString sql = "select count(*) as cot from dindan"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstDindanForm rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.id); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } // 3.获取该年份名称的数据库; CDatabase *pLastYeardb = GetDB(lastyear); if (pLastYeardb == NULL) { CheckYear(lastyear); return; } CDatabase *pdb2Transfer = g_curdb; // pdb2Transfer需要转为成历史数据库的数据库; pLastYeardb = GetDB(lastyear); // pLastYeardb往年历史数据库; if (pLastYeardb == NULL) { // Jeff数据库中,没有历史数据库存在,退出历史转换任务; return; } // 4.根据订单号,遍历数据; int i = 0; for ( i = 0; i < strOrderNumberArray.GetSize(); i++) { // if("20121013-005"!=g_List1array.ElementAt (i).ElementAt (0))continue; // TransDinDan返回:1表示正常, 100及以上表示源数据库里记录 > 目标数据库记录; // TransDinDan将源数据库中的订单数据insert into 到目标数据库中; int ret = TransDinDan(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear); if (ret == 1) { // ret == 1表示源数据库将订单数据插入到目标数据库成功,则删除源数据库中的订单数据; sql = "delete from dindan where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from dindansp where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from photoprint where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from dindanbukuan where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from dindanbukuan2 where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from client where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from burncdreg where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from digitalwork where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from mywork where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from dindanjd where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from dindansp2 where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); sql = "delete from dindansp3 where id='" + strOrderNumberArray.ElementAt(i).ElementAt(0) + "'"; MyExecuteSQL(g_curdb, sql); } else { // ret=105,已经转过,但是2014被删除过,然后再次转时发现2014里没有记录;待定; sql.Format("ret:%d", ret); WriteTextLog("转历史失败" + strOrderNumberArray.ElementAt(i).ElementAt(0) + sql); } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } ////////////////////////////支出 //WriteTextLog("支出"); strdate.Format("%04d-%02d-%02d", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d", lastyear, 12, 31); filter = "dat>='" + strdate + "' and dat<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); 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); strOrderNumberArray.SetSize(count, 1); CRstPayOutInput rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.id); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii)break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (TransPayOut(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from gudingfeiyong where id=%d", atol(strOrderNumberArray.ElementAt(i).ElementAt(0))); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } ////////////////////////////其它收入 strdate.Format("%04d-%02d-%02d", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d", lastyear, 12, 31); filter = "dat>='" + strdate + "' and dat<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); 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); strOrderNumberArray.SetSize(count, 1); CRstIncomeInput rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); if (atoi(rsSt.balance) == 0) strOrderNumberArray.ElementAt(ii).Add(rsSt.id); else { rsSt.MoveNext(); continue; } ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii)break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (TransIncome(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from singleincome where id=%d", atol(strOrderNumberArray.ElementAt(i).ElementAt(0))); MyExecuteSQL(g_curdb, sql); sql.Format("delete from singleincomemoney where [id]='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } ////////////////////////////其它二销收款 filter = "id not in(select id from singleincome)"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from singleincomemoney"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstsingleincomemoney rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.id); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } ////////////////////////////其它二销收款 for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (TransIncomeMoney(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from singleincomemoney where [id]='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (i > 100)break; #endif } ///1/////////////////////////client2phonerecord 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from client2phonerecord"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstclient2phonerecord rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transclient2phonerecord(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from client2phonerecord where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////client2phonerecordout 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from client2phonerecordout"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstclient2phonerecordout rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii)break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transclient2phonerecordout(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from client2phonerecordout where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } ///1/////////////////////////client3phonerecord 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from client3phonerecord"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstclient3phonerecord rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transclient3phonerecord(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from client3phonerecord where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////client3phonerecordout 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from client3phonerecordout"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstclient3phonerecordout rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii)break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transclient3phonerecordout(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from client3phonerecordout where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////employeephonerecord 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from employeephonerecord"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstemployeephonerecord rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transemployeephonerecord(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from employeephonerecord where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////employeephonerecordout 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from employeephonerecordout"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstemployeephonerecordout rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transemployeephonerecordout(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from employeephonerecordout where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////phonerecord 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from phonerecord"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstphonerecord rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transphonerecord(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from phonerecord where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////phonerecordout 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from phonerecordout"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstphonerecordout rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii)break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transphonerecordout(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from phonerecordout where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////unknownphonerecord 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from unknownphonerecord"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstunknownphonerecord rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii)break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transunknownphonerecord(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from unknownphonerecord where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////unknownphonerecordout 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from unknownphonerecordout"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstunknownphonerecordout rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transunknownphonerecordout(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from unknownphonerecordout where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////misscallrecord 2010-08-09 16:22:16 strdate.Format("%04d-%02d-%02d 00:00:00", lastyear, 1, 1); strdate2.Format("%04d-%02d-%02d 99:99:99", lastyear, 12, 31); filter = "datetime>='" + strdate + "' and datetime<='" + strdate2 + "'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from misscallrecord"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); CRstmisscallrecord rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.datetime); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii) break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (Transmisscallrecord(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from misscallrecord where datetime='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// ////////////////////////////sendreg strdate.Format("%04d%02d%02d000000", lastyear, 1, 1); strdate2.Format("%04d%02d%02d999999", lastyear, 12, 31); filter = "timestamp>='" + strdate + "' and timestamp<='" + strdate2 + "' and issended='OK'"; { strOrderNumberArray.RemoveAll(); CRecordset myset(g_curdb); CString sql = "select count(*) as cot from sendreg"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); strOrderNumberArray.SetSize(count, 1); RstSendReg rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { strOrderNumberArray.ElementAt(ii).RemoveAll(); strOrderNumberArray.ElementAt(ii).Add(rsSt.m_timestamp); ii++; rsSt.MoveNext(); if (strOrderNumberArray.GetSize() <= ii)break; } rsSt.Close(); strOrderNumberArray.SetSize(ii, 1); } for (i = 0; i < strOrderNumberArray.GetSize(); i++) { if (TransSendReg(pdb2Transfer, pLastYeardb, strOrderNumberArray.ElementAt(i).ElementAt(0), lastyear)) { { sql.Format("delete from sendreg where [timestamp]='%s'", strOrderNumberArray.ElementAt(i).ElementAt(0)); MyExecuteSQL(g_curdb, sql); } } #ifdef LIMITCOUNT if (g_bConvertHisAll == 0) { if (i > 100)break; } #endif } /////////////////////////// } catch (...) { WriteTextLog("出错在函数TransHisData中"); } if (g_bConvertHisAll)WriteTextLog("转换完成!"); g_bConvertHisAll = 0; /////////////////////////生成来电精灵数据 //return; /* g_sendhead.code[0]=80; g_sendhead.code[1]=90; g_sendhead.code[2]=11; g_sendhead.code[3]=138; g_sendhead.code[4]=24; g_sendhead.code[0]=181; g_sendhead.code[0]=65; g_sendhead.code[0]=56;*/ 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 { CArraydbarraytemp; dbarraytemp.Copy(g_dbHistoryArray); dbarraytemp.InsertAt(0, &g_db); for (int aa = 0; aa < dbarraytemp.GetSize(); aa++) { g_curdb = dbarraytemp.ElementAt(aa); savepath.Format("%s\\uphonedata%d.dat", g_path1, aa); ::DeleteFile(savepath); // 删除uphonedata.dat文件; if (fp.Open(savepath, CFile::modeCreate | CFile::modeWrite) == 0) { WriteTextLog("更新来电精灵数据出错"); return; } CConnectSocket consock; consock.m_pConndb = g_curdb; 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(); } g_curdb = &g_db; } catch (CException *e) { TCHAR szError[1024] = { 0 }; e->GetErrorMessage(szError, 1024); WriteTextLog(CString(szError)); WriteTextLog("获取来电精灵数据出错"); e->Delete(); } WriteTextLog("转历史数据完成"); } //------------------------------------------------------------------------------------ // Jeff remark // 函数:CheckYear // 描述: // 1.检查指定年份的历史数据库mdf文件是否存在,存在则直接附加 // 2.不存在,则使用null.mdf文件拷贝创建历史年份数据库mdf并附加; // 参数: // year:被检查年份值; // 返回:void //------------------------------------------------------------------------------------ #if JEFF_TEST_ON void CDBServerDlg::CheckYear(int year) { 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); 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("历史数据库初始化失败!"); 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); 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); 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("历史数据库初始化失败!"); e->Delete(); return; } } } // 附加成功后,修改逻辑名称; sql.Format("alter database [%d] modify file(name='dbnull',newname='%d')", year, year); try { g_db.ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("修改历史数据库主文件逻辑名失败,请手动修改!"); e->Delete(); } sql.Format("alter database [%d] modify file(name='dbnull_log',newname='%d_log')", year, year); try { g_db.ExecuteSQL(sql); } catch (CDBException * e) { WriteTextLog(e->m_strError); WriteTextLog("修改历史数据库日志文件逻辑名失败,请手动修改!"); 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("历史数据库初始化失败!"); 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("历史数据库初始化失败!"); 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中"); } } /************************************************************************/ /* 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中"); 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; CString temp; 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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); 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; CString temp; 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); 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; CString temp; 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); 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; CString temp; 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); 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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; CString temp; 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 { MyLock lock("dbaccessxiao"); pdb->ExecuteSQL(sql); } catch (...) { // WriteTextLog("出错在函数executesql中"); } } void CDBServerDlg::UpdateDate() { try { /* CString tm,sql; tm=CTime::GetCurrentTime ().Format ("%Y-%m-%d"); sql.Format ("update version set curdate='%s'",tm); MyExecuteSQL(&g_db, sql); */ /* CTime tm2=CTime::GetCurrentTime (); CTimeSpan dt2(365, 0, 0, 0); tm2-=dt2; tm=tm2.Format ("%Y%m%d%H%M%S"); sql.Format ("delete from sendreg where timestamp<'%s'",tm); MyExecuteSQL(&g_db, sql);*/ 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); autorunpath = g_mainpath + "\\MsgServer.exe"; ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE); #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; } return 1; ll: return 0; } catch (...) { WriteTextLog("出错"); } } //-------------------------------------------------------------------------- // Remark by Jeff:2014.10.22 // 函数:AutoDelPhoto // 描述:自动删除取件后的订单相片,包括客户原片、初修片、精修片、设计片。(不含备份相片) // 参数:# // 返回:# // // 调用关系: // 1.AutoDelPhoto()由 BakPhoto()调用。 // 2.BakPhoto()由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。 // 3.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。 // 4.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用. // //-------------------------------------------------------------------------- void CDBServerDlg::AutoDelPhoto() // Jeff自动删除取件后的订单相片; { try { #ifdef ENTERPRISE_VERSION GenYLGL(); #endif g_curdb = &g_db; CString m_check1; // 自动删除客人原片; CString m_check2; // 自动删除客人初修片; CString m_check3; // 自动删除客人精修片; CString m_check4; // 自动删除客人设计片; CString m_edit1; // 多少个月后删除原片; CString m_edit2; // 多少个月后删除初修片; CString m_edit3; // 多少个月后删除精修片; CString m_edit4; // 多少个月后删除设计片; CString m_bakserver1; // 自动备份客人原片的备份机器; CString m_bakserver2; // 自动备份客人初修片的备份机器 CString m_bakserver3; // 自动备份客人精修片的备份机器; CString m_bakserver4; // 自动备份客人设计片的备份机器; // CDBServerDlg::m_bakserver5 : 自动备份系统数据的备份机器; // 1.从version表中获取状态信息; CRstversion tableOfVersion; tableOfVersion.m_pDatabase = g_curdb; tableOfVersion.Open(); if (!tableOfVersion.IsEOF()) { m_check1 = tableOfVersion.m_check1; m_check2 = tableOfVersion.m_check2; m_check3 = tableOfVersion.m_check3; m_check4 = tableOfVersion.m_check4; m_edit1 = tableOfVersion.m_edit1; m_edit2 = tableOfVersion.m_edit2; m_edit3 = tableOfVersion.m_edit3; m_edit4 = tableOfVersion.m_edit4; m_bakserver1 = tableOfVersion.m_bakserver1; m_bakserver2 = tableOfVersion.m_bakserver2; m_bakserver3 = tableOfVersion.m_bakserver3; m_bakserver4 = tableOfVersion.m_bakserver4; m_bakserver5 = tableOfVersion.m_bakserver5; } tableOfVersion.Close(); // 2. g_bakinfo = "资料未备份"; g_bakphoto = "照片未备份"; WriteTextLog("开始备份数据库"); if (!m_bakserver5.IsEmpty()) // 自动备份系统数据的备份机器; { CString bakpath; CString localname; localname = g_localname; #ifdef CHILD_VERSION if (m_bakserver5.Find(":") == -1 && m_bakserver5 != "") m_bakserver5 = "\\\\" + m_bakserver5 + "\\数据备份(儿童管理软件)$"; if (1)//localname.CompareNoCase (m_bakserver5)==0 || CompareIP(localname, m_bakserver5)==0) GetPathFromNetShareName("数据备份(儿童管理软件)$", m_bakserver5); #else if (m_bakserver5.Find(":") == -1 && m_bakserver5 != "") m_bakserver5 = "\\\\" + m_bakserver5 + "\\数据备份(管理软件)$"; if (1)//localname.CompareNoCase (m_bakserver5)==0 || CompareIP(localname, m_bakserver5)==0) GetPathFromNetShareName("数据备份(管理软件)$", m_bakserver5); #endif WriteTextLog(m_bakserver5); if (::CheckFolderFileExist(m_bakserver5)) BakData(m_bakserver5, 1, 1); } WriteTextLog("数据库备份完成"); // Jeff:只是备份数据库; BOOL bcheck1 = atoi(m_check1); BOOL bcheck2 = atoi(m_check2); BOOL bcheck3 = atoi(m_check3); BOOL bcheck4 = atoi(m_check4); #if 0 // Jeff:old code; if (!(bcheck1 || bcheck2 || bcheck3 || bcheck4)) { return; } #else // 四个同时为假,退出删除操作; if (!(bcheck1 | bcheck2 | bcheck3 | bcheck4)) { return; } #endif int edit1 = atoi(m_edit1); int edit2 = atoi(m_edit2); int edit3 = atoi(m_edit3); int edit4 = atoi(m_edit4); // path 4种类型相片的存储目录; CStringArray patharray; { char server[50]; DWORD leng = 50; ::GetComputerName(server, &leng); CString spathserver = server; CString g_path1; CString g_path2; CString g_path3; CString g_path4; g_path1 = g_path2 = g_path3 = g_path4 = server; g_path1 = "\\\\" + g_path1 + "\\客户原片(管理软件)$"; g_path2 = "\\\\" + g_path2 + "\\修好的片(管理软件)$"; g_path3 = "\\\\" + g_path3 + "\\设计好的片(管理软件)$"; g_path4 = "\\\\" + g_path4 + "\\精修好的片(管理软件)$"; GetPathFromNetShareName("客户原片(管理软件)$", g_path1); GetPathFromNetShareName("修好的片(管理软件)$", g_path2); GetPathFromNetShareName("设计好的片(管理软件)$", g_path3); GetPathFromNetShareName("精修好的片(管理软件)$", g_path4); patharray.Add(g_path1); patharray.Add(g_path2); patharray.Add(g_path4); patharray.Add(g_path3); } if (patharray.GetSize() == 0) return; CArraydbarray2; dbarray2.Copy(g_dbHistoryArray); dbarray2.InsertAt(0, &g_db); //------------------------------------------------------------------------------------------------------------------------ WriteTextLog("开始删除取件后照片"); for (int n = 0; n < min(3, dbarray2.GetSize()); n++) { g_curdb = dbarray2.ElementAt(n); CArraystrArrayOfPhoto2BeDel; CString filter = "status3='OK' and time5 is not null and time5<>''"; CRecordset myset(g_curdb); CString sql = "select count(*) as cot from dindan"; if (!filter.IsEmpty()) sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); if (count == 0)continue; strArrayOfPhoto2BeDel.SetSize(count, 1); CRstDindanForm rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty()) rsSt.m_strFilter = filter; rsSt.Open(); INT_PTR nIndex = 0; while (!rsSt.IsEOF()) { strArrayOfPhoto2BeDel.ElementAt(nIndex).RemoveAll(); strArrayOfPhoto2BeDel.ElementAt(nIndex).Add(rsSt.id); strArrayOfPhoto2BeDel.ElementAt(nIndex).Add(rsSt.time5); nIndex++; rsSt.MoveNext(); if (strArrayOfPhoto2BeDel.GetSize() <= nIndex)break; } rsSt.Close(); strArrayOfPhoto2BeDel.SetSize(nIndex, 1); CString time5; CString id; CTime curtm = CTime::GetCurrentTime(); CString strtime; for (int i = 0; i < strArrayOfPhoto2BeDel.GetSize(); i++) { id = strArrayOfPhoto2BeDel.ElementAt(i).ElementAt(0); time5 = strArrayOfPhoto2BeDel.ElementAt(i).ElementAt(1); if (bcheck1)//原片 { CTimeSpan sp(edit1 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) // Jeff,这种比较是否正确??? { if (DelPhoto1(patharray.ElementAt(0), strArrayOfPhoto2BeDel.ElementAt(i).ElementAt(0))) WriteTextLog("原片" + patharray.ElementAt(0) + "\\" + strArrayOfPhoto2BeDel.ElementAt(i).ElementAt(0)); // DelPhoto1(patharray2.ElementAt (0),g_List1array.ElementAt (i).ElementAt (0)); } } if (bcheck2) { CTimeSpan sp(edit2 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(1), strArrayOfPhoto2BeDel.ElementAt(i).ElementAt(0)); // DelPhoto1(patharray2.ElementAt (2),g_List1array.ElementAt (i).ElementAt (0)); } } if (bcheck3) { CTimeSpan sp(edit3 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(2), strArrayOfPhoto2BeDel.ElementAt(i).ElementAt(0)); // DelPhoto1(patharray2.ElementAt (2),g_List1array.ElementAt (i).ElementAt (0)); } } if (bcheck4) { CTimeSpan sp(edit4 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(3), strArrayOfPhoto2BeDel.ElementAt(i).ElementAt(0)); } } } } //------------------------------------------------------------------------------------------------------------------------ g_curdb = &g_db; #ifdef ENTERPRISE_VERSION // Jeff:若是集团版,会再次删除本店已取件的历史订单一次。多操作了一次! WriteTextLog("本店查完,开始检查分店"); 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; CTime curtm = CTime::GetCurrentTime(); CString strtime; for (int i = 0; i < g_List1array.GetSize(); i++) { g_domain = "\\" + g_List1array.ElementAt(i).ElementAt(0); if (g_domain.Find(".ly.com") == -1)continue; id = g_List1array.ElementAt(i).ElementAt(1); time5 = g_List1array.ElementAt(i).ElementAt(2); if (bcheck1)//原片 { CTimeSpan sp(edit1 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { if (DelPhoto1(patharray.ElementAt(0) + g_domain, id)) WriteTextLog("分店原片" + patharray.ElementAt(0) + g_domain + "\\" + id); } } if (bcheck2) { CTimeSpan sp(edit2 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(1) + g_domain, id); // DelPhoto1(patharray2.ElementAt (2),id); } } if (bcheck3) { CTimeSpan sp(edit3 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(2) + g_domain, id); // DelPhoto1(patharray2.ElementAt (2),id); } } if (bcheck4) { CTimeSpan sp(edit4 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(3) + g_domain, id); } } } g_curdb = &g_db; #endif WriteTextLog("检查删除照片完成"); } catch (...) { WriteTextLog("出错在函数AutoDelPhoto中"); } g_curdb = &g_db; } //------------------------------------------------------------------ // Remark by Jeff:2014.10.11 // 函数:DelPhoto1 // 描述:删除指定路径下的订单文件夹; // 参数: // path: 指定要删除文件的根目录; // strOrderNumber: 将要删除的订单号文件夹; // 返回: //----------------------------------------------------------------- BOOL CDBServerDlg::DelPhoto1(CString path, CString strOrderNumber) { if (path == "") return 0; if (::CheckFolderFileExist(path + "\\" + strOrderNumber)) { DeleteDirectory(path + "\\" + strOrderNumber); return 1; } } //----------------------------------------------------------------------- // 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 { g_curdb = &g_db; 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 = g_curdb; 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(g_curdb); 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()) { int i = 0; CString sql; for ( i = 0; i < array.GetSize(); i++) { sql = "update sendregreceive set [status]='' where [timestamp]='" + timearray.ElementAt(i) + "'"; MyExecuteSQL(&g_db, sql); } CArrayList11array; CArrayList2array; CArrayList3array; CArrayother2salearray; CArraymemberarray; CString strdate = CTime::GetCurrentTime().Format("%Y-%m-%d"); CArraydbarraytemp; dbarraytemp.Copy(g_dbHistoryArray); while (dbarraytemp.GetSize()>1) { int last = dbarraytemp.GetSize() - 1; dbarraytemp.RemoveAt(last); } dbarraytemp.InsertAt(0, &g_db); for (int a = dbarraytemp.GetSize() - 1; a >= 0; a--) { g_curdb = dbarraytemp.ElementAt(a); CString filter = "[dat]='" + strdate + "'"; filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')"; { CRecordset myset(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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); } }// g_curdb = &g_db; 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(&g_db, 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(g_curdb); 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"); CArraydbarraytemp; dbarraytemp.Copy(g_dbHistoryArray); while (dbarraytemp.GetSize() > 1) { int last = dbarraytemp.GetSize() - 1; dbarraytemp.RemoveAt(last); } dbarraytemp.InsertAt(0, &g_db); for (int a = dbarraytemp.GetSize() - 1; a >= 0; a--) { g_curdb = dbarraytemp.ElementAt(a); CString filter = "[dat]='" + strdate + "'"; filter = "[dat]='" + strdate + "' and ([sale2type] is null or [sale2type]='')"; { CRecordset myset(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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); } }// g_curdb = &g_db; 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; 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); } 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; 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(&g_db, sql); } } } BOOL bcheck1 = atoi(m_bak1); BOOL bcheck2 = atoi(m_bak2); BOOL bcheck3 = atoi(m_bak3); BOOL bcheck4 = atoi(m_bak4); int hour; hour = CTime::GetCurrentTime().GetHour(); // Jeff.这里不合理.如果条件不成立,那当天的数据就不会执行。存在一定安全问题。 if (atoi(m_baktime) <= hour) { CStdioFile fp; if (fp.Open(g_mainpath + "\\log.txt", CFile::modeRead)) { CString date; fp.ReadString(date); date.TrimRight("\r\n"); if (date == CTime::GetCurrentTime().Format("%Y-%m-%d")) { fp.Close(); return; } fp.Close(); } if (g_bConvertHisAll) { WriteTextLog("转历史数据中, 备份退出"); return; } g_bakdate = CTime::GetCurrentTime().Format("%Y-%m-%d"); KillTimer(4); WriteTextLog("备份开始..."); AutoDelPhoto(); AutoDelBakPhoto(); LoadThumbImages2(); } } catch (...) { WriteTextLog("出错在函数bakphoto中"); } } void CDBServerDlg::ShutDown() //Jeff:备份完毕后执行的关机函数; { try { g_curdb = &g_db; CString m_bak6; { CRecordset myset(g_curdb); CString sql = "select * from [version]"; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("bak6", m_bak6); myset.Close(); } OnServerStop(); // 停止服务; // Jeff.关闭数据库连接,若关机前关闭了数据库的连接,则客户端进行订单无法实现数据库的操作; // Jeff.在关机前,不能关闭数据库连接; g_db.Close(); for (int i = 0; i < g_dbHistoryArray.GetSize(); i++) { g_dbHistoryArray.ElementAt(i)->Close(); delete g_dbHistoryArray.ElementAt(i); } ReleaseBranchDB(); WriteTextLog("备份完成"); while (m_bRunning) { ::Sleep(1000); } //////////////// 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)) { #if 1 // Jeff.关闭运行中的线程; TerminateThread(); TerminateThread2(); // 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 // Jeff.开启定时关机功能; SetTimer(11, 60000, NULL);// 1分钟检测一次是否到达关机时间; #endif } else//重启 { TerminateThread(); TerminateThread2(); 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 ( 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() { } void CDBServerDlg::ReleaseBranchDB() { } //savebranchinfo void CDBServerDlg::LoadBranchInfo2() { } 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 { g_curdb = &g_db; CString sql = "delete from sendreg where [log]='0/0'"; MyExecuteSQL(&g_db, 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(g_curdb); 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(&g_db, sql); sql.Format("delete from sendregdelay where [autoid]=%d", atol(idarray.ElementAt(i))); MyExecuteSQL(&g_db, sql); } } int covertrate = 100; CString spoint; { CRecordset myset(g_curdb); 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(g_curdb); 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 = g_curdb; 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(g_curdb); 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 = g_curdb; 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 ( 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(&g_db, sql); mark1 = "," + mark1 + ","; sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent1 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')"; MyExecuteSQL(&g_db, 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(&g_db, sql); mark2 = "," + mark2 + ","; sql = "insert into sendreg([phones],[content],[timestamp],[msgcount],[status],[issended],[isautosend],[ren]) values('" + phone + "','" + rulecontent2 + "','" + timestamp + "','" + scount + "','0','0','0','系统自动发送')"; MyExecuteSQL(&g_db, sql); bSended = 1; } } } } #if 1 catch (...) { WriteTextLog("出错2"); } #else // Jeff.add catch (CDBException *e) { WriteTextLog(e->m_strError); e->Delete(); } #endif } void CDBServerDlg::CheckBakState() // Jeff.检查数据库bakstate表; { try { g_curdb = &g_db; CString filter; CArray strArray; CRecordset myset(g_curdb); 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 = g_curdb; 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(); strArray.SetSize(ii, 1); while (strArray.GetSize() > 7) { CString sql = "delete from bakstate where [date]='" + strArray.ElementAt(0).ElementAt(0) + "'"; MyExecuteSQL(&g_db, sql); strArray.RemoveAt(0); } CString path; 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 ( 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(&g_db, 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(&g_db, 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(&g_db, 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(&g_db, 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(&g_db, sql); } } catch (...) { WriteTextLog("出错3"); } } //数据备份 CString CDBServerDlg::GetRegCode(int m_id, int m_time1, int m_time2) { return ""; } int g_ndogtimes = 0; void CDBServerDlg::CheckRegCode() // 检查注册码信息; { } 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); } } AfxMessageBox("完成"); } break; #endif case VK_F2: 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); 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 return 1; } } return CDialog::PreTranslateMessage(pMsg); } void CDBServerDlg::GenUPhoneData() { return; 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; g_curdb = &g_db; 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 = &g_db; 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("获取来电精灵数据出错"); } } //initlia void CDBServerDlg::LoadHistoryDB() // 加载历史数据库; { CString path; CString sql; sql = "delete from historydb"; MyExecuteSQL(&g_db, sql); CDatabase g_masterdb; try { CString strCon; strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=master;%s"), g_strdbServrename, g_strdbpsw); g_masterdb.OpenEx(strCon, CDatabase::noOdbcDialog); } catch (CDBException * e) { e->Delete(); } for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--) { CDatabase *db = new CDatabase; try { CString strCon; strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=%d;%s"), g_strdbServrename, i, g_strdbpsw); 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) { 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); 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); 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->Delete(); break; } } } g_masterdb.Close(); } void CDBServerDlg::AddOneConn() { 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; 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); } g_nDBCount++; } catch (...) { WriteTextLog("AddOneConn error"); } } void GetOneConn(CDatabase **m_pdb, CArray*m_dbarray, CConnectThread *pThread) { 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; } 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; g_curdb = &g_db; DWORD ii = 0; CArrayg_List1array; { CRecordset myset(g_curdb); 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 = g_curdb; 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(g_curdb); 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(g_curdb); 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); g_db.ExecuteSQL(sql); } } } void CDBServerDlg::ManagePhoto() { // CClientCenter dlg1; // dlg1.DoModal (); ShowPic3 dlg; dlg.DoModal(); } //数据备份(管理软件)$ //-------------------------------------------------------------------------- // Remark by Jeff:2014.10.22 // 函数:AutoDelBakPhoto // 描述:自动删除取件后的订单备份相片,包括客户备份原片、备份初修片、备份精修片、备份设计片。 // 参数:# // 返回:# // // 调用关系: // 1.AutoDelBakPhoto()由 BakPhoto()调用。 // 2.BakPhoto() 由CDBServerDlg::SetTimer(4) 调用,调用频率2分钟,周期数直到程序结束。 // 3.CDBServerDlg::SetTimer(4) 由 CDBServerDlg::SetTimer(2) 调用,调用频率10毫秒,只有一个周期。 // 4.CDBServerDlg::SetTimer(2) 由 CDBServerDlg::OnInitDialog() 调用. // //-------------------------------------------------------------------------- void CDBServerDlg::AutoDelBakPhoto() { try { g_curdb = &g_db; CString m_check1, m_check2, m_check3, m_check4; CString m_edit1, m_edit2, m_edit3, m_edit4; CString g_path1; CString g_path2; CString g_path3; CString g_path4; CString m_bakserver1, m_bakserver2, m_bakserver3, m_bakserver4; { CRstversion rsSt; rsSt.m_pDatabase = g_curdb; rsSt.Open(); if (!rsSt.IsEOF()) { m_check1 = rsSt.m_delcheck1; m_check2 = rsSt.m_delcheck2; m_check3 = rsSt.m_delcheck3; m_check4 = rsSt.m_delcheck4; m_edit1 = rsSt.m_deledit1; m_edit2 = rsSt.m_deledit2; m_edit3 = rsSt.m_deledit3; m_edit4 = rsSt.m_deledit4; g_path1 = rsSt.m_bakserver1; g_path2 = rsSt.m_bakserver2; g_path4 = rsSt.m_bakserver3; g_path3 = rsSt.m_bakserver4; } rsSt.Close(); } BOOL bcheck1 = atoi(m_check1); BOOL bcheck2 = atoi(m_check2); BOOL bcheck3 = atoi(m_check3); BOOL bcheck4 = atoi(m_check4); if (!(bcheck1 || bcheck2 || bcheck3 || bcheck4)) { return; } int edit1 = atoi(m_edit1); int edit2 = atoi(m_edit2); int edit3 = atoi(m_edit3); int edit4 = atoi(m_edit4); //path CStringArray patharray; { #ifdef CHILD_VERSION if (g_path1.Find(":") == -1 && g_path1 != "") g_path1 = "\\\\" + g_path1 + "\\客户原片备份(儿童管理软件)$"; if (1)//(localname.CompareNoCase (g_path1)==0 || CompareIP(localname, g_path1)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\客户原片备份(儿童管理软件)$")) GetPathFromNetShareName("客户原片备份(儿童管理软件)$", g_path1); if (g_path2.Find(":") == -1 && g_path2 != "") g_path2 = "\\\\" + g_path2 + "\\修好的片备份(儿童管理软件)$"; if (1)//((localname.CompareNoCase (g_path2)==0 || CompareIP(localname, g_path2)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\修好的片备份(儿童管理软件)$")) GetPathFromNetShareName("修好的片备份(儿童管理软件)$", g_path2); if (g_path4.Find(":") == -1 && g_path4 != "") g_path4 = "\\\\" + g_path4 + "\\精修好的片备份(儿童管理软件)$"; if (1)//((localname.CompareNoCase (g_path4)==0 || CompareIP(localname, g_path4)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\精修好的片备份(儿童管理软件)$")) GetPathFromNetShareName("精修好的片备份(儿童管理软件)$", g_path4); if (g_path3.Find(":") == -1 && g_path3 != "") g_path3 = "\\\\" + g_path3 + "\\设计好的片备份(儿童管理软件)$"; if (1)//((localname.CompareNoCase (g_path3)==0 || CompareIP(localname, g_path3)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\设计好的片备份(儿童管理软件)$")) GetPathFromNetShareName("设计好的片备份(儿童管理软件)$", g_path3); #else if (g_path1.Find(":") == -1 && g_path1 != "") g_path1 = "\\\\" + g_path1 + "\\客户原片备份(管理软件)$"; if (1)//((localname.CompareNoCase (g_path1)==0 || CompareIP(localname, g_path1)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\客户原片备份(管理软件)$")) GetPathFromNetShareName("客户原片备份(管理软件)$", g_path1); if (g_path2.Find(":") == -1 && g_path2 != "") g_path2 = "\\\\" + g_path2 + "\\修好的片备份(管理软件)$"; if (1)//((localname.CompareNoCase (g_path2)==0 || CompareIP(localname, g_path2)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\修好的片备份(管理软件)$")) GetPathFromNetShareName("修好的片备份(管理软件)$", g_path2); if (g_path4.Find(":") == -1 && g_path4 != "") g_path4 = "\\\\" + g_path4 + "\\精修好的片备份(管理软件)$"; if (1)//((localname.CompareNoCase (g_path4)==0 || CompareIP(localname, g_path4)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\精修好的片备份(管理软件)$")) GetPathFromNetShareName("精修好的片备份(管理软件)$", g_path4); if (g_path3.Find(":") == -1 && g_path3 != "") g_path3 = "\\\\" + g_path3 + "\\设计好的片备份(管理软件)$"; if (1)//((localname.CompareNoCase (g_path3)==0 || CompareIP(localname, g_path3)==0) && CheckFolderFileExist("\\\\"+g_path1+"\\设计好的片备份(管理软件)$")) GetPathFromNetShareName("设计好的片备份(管理软件)$", g_path3); #endif patharray.Add(g_path1); patharray.Add(g_path2); patharray.Add(g_path4); patharray.Add(g_path3); } if (patharray.GetSize() == 0)return; CArraydbarray2; dbarray2.Copy(g_dbHistoryArray); dbarray2.InsertAt(0, &g_db); WriteTextLog("开始删除取件后的备份照片"); for (int n = 0; n < min(3, dbarray2.GetSize()); n++) { g_curdb = dbarray2.ElementAt(n); DWORD ii = 0; CArrayg_List1array; { CString filter = "status3='OK' and time5 is not null and time5<>''"; CRecordset myset(g_curdb); CString sql = "select count(*) as cot from dindan"; if (!filter.IsEmpty())sql += " where " + filter; myset.Open(CRecordset::forwardOnly, sql); myset.GetFieldValue("cot", sql); myset.Close(); int count = atol(sql); if (count == 0)continue; g_List1array.SetSize(count, 1); CRstDindanForm rsSt; rsSt.m_pDatabase = g_curdb; if (!filter.IsEmpty())rsSt.m_strFilter = filter; rsSt.Open(); ii = 0; while (!rsSt.IsEOF()) { g_List1array.ElementAt(ii).RemoveAll(); g_List1array.ElementAt(ii).Add(rsSt.id); g_List1array.ElementAt(ii).Add(rsSt.time5); ii++; rsSt.MoveNext(); if (g_List1array.GetSize() <= ii)break; } rsSt.Close(); g_List1array.SetSize(ii, 1); CString time5, id; CTime curtm = CTime::GetCurrentTime(); CString strtime; for (int i = 0; i < g_List1array.GetSize(); i++) { id = g_List1array.ElementAt(i).ElementAt(0); time5 = g_List1array.ElementAt(i).ElementAt(1); if (bcheck1)//原片 { CTimeSpan sp(edit1 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { if (DelPhoto1(patharray.ElementAt(0), g_List1array.ElementAt(i).ElementAt(0))) WriteTextLog("原片备份" + patharray.ElementAt(0) + "\\" + g_List1array.ElementAt(i).ElementAt(0)); // DelPhoto1(patharray2.ElementAt (0),g_List1array.ElementAt (i).ElementAt (0)); } } if (bcheck2) { CTimeSpan sp(edit2 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(1), g_List1array.ElementAt(i).ElementAt(0)); // DelPhoto1(patharray2.ElementAt (2),g_List1array.ElementAt (i).ElementAt (0)); } } if (bcheck3) { CTimeSpan sp(edit3 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(2), g_List1array.ElementAt(i).ElementAt(0)); // DelPhoto1(patharray2.ElementAt (2),g_List1array.ElementAt (i).ElementAt (0)); } } if (bcheck4) { CTimeSpan sp(edit4 * 30, 0, 0, 0); CTime tm = curtm - sp; strtime = tm.Format("%Y-%m-%d"); if (strtime > time5) { DelPhoto1(patharray.ElementAt(3), g_List1array.ElementAt(i).ElementAt(0)); } } } } } g_curdb = &g_db; #ifdef ENTERPRISE_VERSION WriteTextLog("本店查完,开始检查分店备份"); 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; iitime5) { if(DelPhoto1(patharray.ElementAt (0)+g_domain,id)) WriteTextLog("分店原片备份"+ patharray.ElementAt (0)+g_domain+"\\"+id ); } } if(bcheck2) { CTimeSpan sp(edit2*30, 0, 0, 0); CTime tm=curtm-sp; strtime=tm.Format ("%Y-%m-%d"); if(strtime>time5) { DelPhoto1(patharray.ElementAt (1)+g_domain,id); // DelPhoto1(patharray2.ElementAt (2),id); } } if(bcheck3) { CTimeSpan sp(edit3*30, 0, 0, 0); CTime tm=curtm-sp; strtime=tm.Format ("%Y-%m-%d"); if(strtime>time5) { DelPhoto1(patharray.ElementAt (2)+g_domain,id); // DelPhoto1(patharray2.ElementAt (2),id); } } if(bcheck4) { CTimeSpan sp(edit4*30, 0, 0, 0); CTime tm=curtm-sp; strtime=tm.Format ("%Y-%m-%d"); if(strtime>time5) { DelPhoto1(patharray.ElementAt (3)+g_domain,id); } } } g_curdb = &g_db; #endif WriteTextLog("检查删除备份照片完成"); } catch (...) { WriteTextLog("出错在函数AutoDelBakPhoto中"); } g_curdb = &g_db; } //10.lia //---------------------------------------------------------------------------- // Remark by Jeff 2014.10.22 // 函数:GenYLGL // 描述:调用本地客户端; // 参数:# // 返回:# // // 调用关系: // 1.只由AutoDelPhoto()主动调用。 // // 说明:传递genbranchdata给客户端,使客户端能够自动遍历branchinfo.dat里的分店信息, // 客户端顺序连接所有分店并获取分店历史订单已完成取件的订单。最终将所有分店历史 // 订单已完成取件的送回服务端,保存在branchdindan.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 CRstUpdate rsSt; rsSt.m_pDatabase = &g_db; 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