477 lines
10 KiB
C++
477 lines
10 KiB
C++
// ProjectsDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "ProjectsDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CProjectsDlg dialog
|
|
|
|
|
|
CProjectsDlg::CProjectsDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CProjectsDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CProjectsDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_bAddMode=false;
|
|
|
|
m_pstrSelectedProject=NULL;
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
/*
|
|
rs=new GZRset("Projects entry screen");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
//Initialize recordset pointer
|
|
|
|
rs=m_pApp->rsPool->GetRS("CProjectsDlg");
|
|
}
|
|
|
|
|
|
CProjectsDlg::~CProjectsDlg()
|
|
{
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
}
|
|
|
|
void CProjectsDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CProjectsDlg)
|
|
DDX_Control(pDX, IDC_LIST_LABEL, m_lblList);
|
|
DDX_Control(pDX, IDC_PROJECTS_COMBO, m_cbList);
|
|
DDX_Control(pDX, IDC_PROJECT_NAME, m_edName);
|
|
DDX_Control(pDX, IDC_PROJECT_DESCRIPTION, m_edDescription);
|
|
DDX_Control(pDX, IDC_DONE, m_btnDone);
|
|
DDX_Control(pDX, IDC_DELETE, m_btnDelete);
|
|
DDX_Control(pDX, IDC_ADD, m_btnAdd);
|
|
DDX_Control(pDX, IDC_ACTIVE, m_ckActive);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CProjectsDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CProjectsDlg)
|
|
ON_BN_CLICKED(IDC_ACTIVE, OnActive)
|
|
ON_BN_CLICKED(IDC_ADD, OnAdd)
|
|
ON_BN_CLICKED(IDC_DELETE, OnDelete)
|
|
ON_BN_CLICKED(IDC_DONE, OnDone)
|
|
ON_EN_KILLFOCUS(IDC_PROJECT_DESCRIPTION, OnKillfocusProjectDescription)
|
|
ON_EN_KILLFOCUS(IDC_PROJECT_NAME, OnKillfocusProjectName)
|
|
ON_CBN_CLOSEUP(IDC_PROJECTS_COMBO, OnCloseupProjectsCombo)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CProjectsDlg message handlers
|
|
|
|
|
|
BOOL CProjectsDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
FillList();
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
|
|
//************************************************************
|
|
//SAVE EDIT CONTROL FIELD
|
|
//************************************************************
|
|
bool CProjectsDlg::SaveField(CEdit *edControl,CString fldname,bool AllowEmpty)
|
|
{
|
|
|
|
if(m_bAddMode) return true;//dont attempt to update
|
|
CString str;
|
|
//do nothing if not changed
|
|
if(edControl->GetModify()!=TRUE) return true;
|
|
|
|
edControl->GetWindowText(str);
|
|
//dont save empty fields if not allowed to
|
|
if(!AllowEmpty)
|
|
{
|
|
|
|
if(str.IsEmpty())
|
|
{
|
|
edControl->Undo();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
rs->UpdateField(fldname,&str);
|
|
rs->SaveRecord();
|
|
UpdateModified(false);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
//************************************************
|
|
//UPDATE MODIFIED DATA
|
|
//*************************************************
|
|
bool CProjectsDlg::UpdateModified(bool IsNew)
|
|
{
|
|
COleDateTime dtData;
|
|
//updates modified by and modified on fields
|
|
if(IsNew)//update creator and created as well
|
|
{
|
|
rs->UpdateField("creator",&m_pApp->m_lusrID);
|
|
|
|
dtData=COleDateTime::GetCurrentTime();
|
|
rs->UpdateField("created",&dtData);
|
|
}
|
|
|
|
rs->UpdateField("modifier",&m_pApp->m_lusrID);
|
|
|
|
dtData=COleDateTime::GetCurrentTime();
|
|
rs->UpdateField("modified",&dtData);
|
|
rs->SaveRecord();
|
|
|
|
|
|
return true;
|
|
}
|
|
//************************************************************
|
|
//SAVE CheckBox CONTROL FIELD
|
|
//************************************************************
|
|
bool CProjectsDlg::SaveField(CButton *ckControl,CString fldname)
|
|
{
|
|
if(m_bAddMode) return true;//dont attempt to update
|
|
bool bData=false;
|
|
BOOL BData;
|
|
BData=ckControl->GetCheck();
|
|
if(BData==TRUE) bData=true;
|
|
rs->UpdateField(fldname,&bData);
|
|
rs->SaveRecord();
|
|
UpdateModified(false);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//**************************************
|
|
void CProjectsDlg::OnAdd()
|
|
{
|
|
CString strData;
|
|
bool bData;
|
|
if(!m_bAddMode)
|
|
{//go to add mode
|
|
EnableEntry(true);
|
|
m_bAddMode=true;
|
|
m_btnAdd.SetWindowText("Save");
|
|
m_btnDelete.SetWindowText("Cancel");
|
|
m_lblList.ShowWindow(FALSE);
|
|
m_cbList.ShowWindow(FALSE);
|
|
m_edDescription.SetWindowText("");
|
|
m_edName.SetWindowText("");
|
|
m_ckActive.SetCheck(TRUE);
|
|
|
|
|
|
}
|
|
else//save and exit add mode
|
|
{
|
|
m_edName.GetWindowText(strData);
|
|
if(strData.IsEmpty())
|
|
{
|
|
AfxMessageBox("Project name is required.");
|
|
return;
|
|
}
|
|
|
|
//add the record
|
|
if(rs->AddNewRecord())
|
|
{
|
|
rs->UpdateField("name",&strData);
|
|
|
|
m_edDescription.GetWindowText(strData);
|
|
rs->UpdateField("notes",&strData);
|
|
|
|
bData=(m_ckActive.GetCheck() ? true : false);
|
|
rs->UpdateField("active",&bData);
|
|
|
|
|
|
//this will save the record as well
|
|
UpdateModified(true);
|
|
|
|
m_bAddMode=false;
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_lblList.ShowWindow(TRUE);
|
|
m_cbList.ShowWindow(TRUE);
|
|
FillList();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//****************************************
|
|
void CProjectsDlg::OnDelete()
|
|
{
|
|
CString q,strID;
|
|
|
|
|
|
if(m_bAddMode)//user pressed cancel button
|
|
{
|
|
m_bAddMode=false;
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_lblList.ShowWindow(TRUE);
|
|
m_cbList.ShowWindow(TRUE);
|
|
FillList();
|
|
return;
|
|
}
|
|
|
|
|
|
//USER IS REQUESTING TO DELETE RECORD
|
|
//check to see if records exist
|
|
strID=m_cbList.GetCurrentRowID();
|
|
|
|
/* Obsolete, uses 0 for no project
|
|
if(strID.Compare("1")==0)
|
|
{
|
|
AfxMessageBox("You can't delete this item\r\nIt's built in.");
|
|
return;
|
|
}
|
|
*/
|
|
|
|
q.Format("SELECT wo.project FROM wo "
|
|
"WHERE (((wo.project)=%s));",strID);
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())
|
|
{
|
|
AfxMessageBox("DATA INTEGRITY PROTECTION:\r\n"
|
|
"You can't delete this project at this time.\r\n"
|
|
"It is attached to one or more work orders.");
|
|
return;
|
|
|
|
}
|
|
else
|
|
{
|
|
if(AfxMessageBox("Permanently delete?\r\nAre you sure?",MB_YESNO)==IDYES)
|
|
{
|
|
q.Format("DELETE projects.*, projects.id "
|
|
"FROM projects WHERE (((projects.id)=%s));",
|
|
m_cbList.GetCurrentRowID());
|
|
rs->Ex(q);
|
|
//a deleted contact can't be selected
|
|
m_strSelectedProject="";
|
|
FillList();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//***********************************
|
|
void CProjectsDlg::OnDone()
|
|
{
|
|
//set passed in string to selectedproject
|
|
if(m_pstrSelectedProject!=NULL)
|
|
*m_pstrSelectedProject=m_strSelectedProject;
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
|
|
|
|
//********************************
|
|
void CProjectsDlg::OnActive()
|
|
{
|
|
SaveField(&m_ckActive,"active");
|
|
|
|
}
|
|
|
|
|
|
|
|
//*******************************************
|
|
void CProjectsDlg::OnKillfocusProjectDescription()
|
|
{
|
|
SaveField(&m_edDescription,"notes",true);
|
|
}
|
|
|
|
|
|
|
|
//******************************************
|
|
void CProjectsDlg::OnKillfocusProjectName()
|
|
{
|
|
SaveField(&m_edName,"name",false);
|
|
if(!m_bAddMode)
|
|
FillList();
|
|
}
|
|
|
|
|
|
|
|
//*******************************************
|
|
void CProjectsDlg::OnCloseupProjectsCombo()
|
|
{
|
|
|
|
//Fill the fields as this is a simple dialog.
|
|
//user has made a selection, update the visible list
|
|
CString q;
|
|
CString strData;
|
|
bool bData;
|
|
q.Format("SELECT projects.* FROM projects "
|
|
"WHERE (((projects.id)=%s));",m_cbList.GetCurrentRowID());
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())
|
|
{
|
|
|
|
//NAME
|
|
rs->FetchField("name",&strData);
|
|
m_edName.SetWindowText(strData);
|
|
|
|
//DESCRIPTION
|
|
rs->FetchField("notes",&strData);
|
|
m_edDescription.SetWindowText(strData);
|
|
|
|
//ACTIVE
|
|
rs->FetchField("active",&bData);
|
|
m_ckActive.SetCheck(bData ? TRUE : FALSE);
|
|
|
|
}
|
|
//save current selection so that updates and changes
|
|
//will still show what was last selected
|
|
m_strSelectedProject=m_cbList.GetCurrentRowID();
|
|
|
|
}
|
|
|
|
void CProjectsDlg::FillList()
|
|
{
|
|
|
|
CString strData;
|
|
CString strIndex;
|
|
CString q;
|
|
long lData;
|
|
m_cbList.Clear();
|
|
|
|
q="SELECT projects.* FROM projects ORDER BY projects.name;";
|
|
rs->Query(q);
|
|
if(rs->IsEmpty())
|
|
{
|
|
EnableEntry(false);
|
|
return;
|
|
|
|
}
|
|
else
|
|
{
|
|
EnableEntry(true);
|
|
//fill combo box with available projects
|
|
rs->MoveFirst();
|
|
|
|
|
|
rs->FetchField("name",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbList.AddRow(strData,strIndex);
|
|
|
|
while(rs->MoveForward())
|
|
{
|
|
rs->FetchField("name",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbList.AddRow(strData,strIndex);
|
|
}
|
|
|
|
}
|
|
|
|
//pretend user has selected so that other fields get filled in
|
|
if(m_strSelectedProject.IsEmpty()) //first time in
|
|
{
|
|
m_cbList.SetCurSel(0);
|
|
}
|
|
else//something valid was selected before so stick with it
|
|
{
|
|
//try to choose the selected project,
|
|
//if it can't be found then select the first in list
|
|
if(m_cbList.Select(m_strSelectedProject)==false)
|
|
{
|
|
//empty the obviously bad value
|
|
m_strSelectedProject.Empty();
|
|
//just set to first in list
|
|
m_cbList.SetCurSel(0);
|
|
}
|
|
|
|
}
|
|
|
|
OnCloseupProjectsCombo();
|
|
}
|
|
|
|
|
|
void CProjectsDlg::SetPassbackString(CString *pstrPB)
|
|
{
|
|
//m_pstrSelectedProject=NULL;
|
|
m_pstrSelectedProject=pstrPB;
|
|
|
|
//Set selected project to passed if not empty
|
|
if(!m_pstrSelectedProject->IsEmpty())
|
|
m_strSelectedProject=*m_pstrSelectedProject;
|
|
|
|
//on exit of this class, set passed string to
|
|
//selected project.
|
|
//
|
|
}
|
|
|
|
void CProjectsDlg::OnOK()
|
|
{
|
|
//this function to avoid pressing enter in a field causing
|
|
//dialog to close
|
|
|
|
//CDialog::OnOK();
|
|
}
|
|
|
|
void CProjectsDlg::EnableEntry(bool bEnable)
|
|
{
|
|
|
|
if(m_bReadOnly) return;
|
|
BOOL enable = bEnable ? TRUE : FALSE;
|
|
m_btnDelete.EnableWindow(enable);
|
|
m_cbList.EnableWindow(enable);
|
|
m_ckActive.EnableWindow(enable);
|
|
m_edDescription.EnableWindow(enable);
|
|
m_edName.EnableWindow(enable);
|
|
m_lblList.EnableWindow(enable);
|
|
|
|
}
|
|
|
|
void CProjectsDlg::Security()
|
|
{
|
|
m_bReadOnly=false;
|
|
int x=m_pApp->Allowed(RPROJECTS,true);
|
|
if(x==0)//no access allowed
|
|
{
|
|
m_pApp->SecurityWarning();
|
|
CDialog::OnCancel();
|
|
}
|
|
if(x==2)//read only
|
|
{
|
|
m_bReadOnly=true;
|
|
m_btnAdd.ShowWindow(FALSE);
|
|
m_btnDelete.ShowWindow(FALSE);
|
|
m_ckActive.EnableWindow(FALSE);
|
|
m_edDescription.SetReadOnly(TRUE);
|
|
m_edName.SetReadOnly(TRUE);
|
|
|
|
|
|
}
|
|
}
|