Files
ayanova7/archive/ayanova 1.9.4 CE final release db schema 171/sp/ConsolidateDlg.cpp

197 lines
4.8 KiB
C++

// ConsolidateDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sp.h"
#include "ConsolidateDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CConsolidateDlg dialog
CConsolidateDlg::CConsolidateDlg(CWnd* pParent /*=NULL*/)
: CDialog(CConsolidateDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CConsolidateDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pApp = (CSpApp*)AfxGetApp();
/*
rs=new GZRset("Error: Consolidate clients dialog");
rs->SetConnect(m_pApp->strConnectString);
*/
//Initialize recordset pointer
rs=m_pApp->rsPool->GetRS("CConsolidateDlg");
}
CConsolidateDlg::~CConsolidateDlg()
{
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
}
void CConsolidateDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConsolidateDlg)
DDX_Control(pDX, IDC_CBTO, m_cbTo);
DDX_Control(pDX, IDC_CBFROM, m_cbFrom);
DDX_Control(pDX, IDC_BTNDONE, m_btnDone);
DDX_Control(pDX, IDC_BTNCONSOLIDATE, m_btnConsolidate);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConsolidateDlg, CDialog)
//{{AFX_MSG_MAP(CConsolidateDlg)
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
ON_BN_CLICKED(IDC_BTNCONSOLIDATE, OnBtnconsolidate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConsolidateDlg message handlers
void CConsolidateDlg::OnOK()
{
//Do nothing enter key workaround
}
void CConsolidateDlg::OnBtndone()
{
CDialog::OnOK();
}
//Doooooo-iiiiiiitttttttt......
void CConsolidateDlg::OnBtnconsolidate()
{
CString q,from,to;
from=m_cbFrom.GetCurrentRowID();
to=m_cbTo.GetCurrentRowID();
//validate the two entries
//something in each one:
if(from.IsEmpty() || to.IsEmpty() || from=="0" || to=="0")
{
AfxMessageBox("You must select a client from each list to proceed.");
return;
}
//Not the same:
if(from==to)
{
AfxMessageBox("Invalid selection (they can't be the same)");
return;
}
//warning:
AfxMessageBox("Warning: all other users must close this program now to avoid database corruption.\r\n"
"This operation will make changes to nearly every table in the entire database\r\n"
"Note: this change will not currently update the Preventive maintenance area of the program\r\n"
"If you use Preventive Maintenance and the client being consolidated is used there\r\n"
"you will need to manually change them\r\n"
"\r\nMake sure you are the only user running this program before clicking on OK");
if(AfxMessageBox("You're absolutely 100% certain no one else is running this program?\r\nClick NO to cancel without consolidating",MB_YESNO)!=IDYES)
return;
//are you sure?
if(AfxMessageBox("Warning: this operation can not be reversed.\r\n"
"You're sure you want to do this?",MB_YESNO|MB_DEFBUTTON2)!=IDYES)
return;
//run the change queries (alphabetical order by table)
//CONTACTS
q.Format("UPDATE contacts SET contacts.clientlink = %s "
"WHERE (((contacts.clientlink)=%s));",to,from);
rs->Ex(q);
/*//PMSCHEDULES
q.Format("UPDATE pmschedules SET pmschedules.client = %s "
"WHERE (((pmschedules.client)=%s));",to,from);
rs->Ex(q);
*/
//RENTALS
q.Format("UPDATE rentals SET rentals.clientlink = %s "
"WHERE (((rentals.clientlink)=%s));",to,from);
rs->Ex(q);
//STATUSVIEWS
q.Format("UPDATE statusviews SET statusviews.client = %s "
"WHERE (((statusviews.client)=%s));",to,from);
rs->Ex(q);
//UNITS
q.Format("UPDATE units SET units.client = %s "
"WHERE (((units.client)=%s));",to,from);
rs->Ex(q);
//Workorders
q.Format("UPDATE wo SET wo.client = %s "
"WHERE (((wo.client)=%s));",to,from);
rs->Ex(q);
AfxMessageBox("All done!\r\nYou might not see the changes take effect on the main\r\n"
"workorder screen until you refresh the display");
}
BOOL CConsolidateDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CString strData, strIndex,q;
long lData;
q="SELECT clients.id, clients.company AS compname FROM clients "
"ORDER BY clients.company;";
rs->Query(q);
if(rs->IsEmpty())
{
AfxMessageBox("Can't find any clients, that's wierd.");
return false;
}
m_cbFrom.AddRow(" Select...","0");
m_cbTo.AddRow(" Select...","0");
do
{
rs->FetchField("compname",&strData);
rs->FetchField("id",&lData);
strIndex.Format("%u",lData);
m_cbFrom.AddRow(strData,strIndex);
m_cbTo.AddRow(strData,strIndex);
}while(rs->MoveForward());
m_cbFrom.Select(0);
m_cbTo.Select(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}