388 lines
8.2 KiB
C++
388 lines
8.2 KiB
C++
// SchedGrps.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "SchedGrps.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CSchedGrps dialog
|
|
|
|
|
|
CSchedGrps::CSchedGrps(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CSchedGrps::IDD, pParent)
|
|
, m_strSelectedGroup(_T(""))
|
|
{
|
|
//{{AFX_DATA_INIT(CSchedGrps)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_pApp = (CSpApp*)AfxGetApp();
|
|
//Initialize recordset pointer
|
|
rs=m_pApp->rsPool->GetRS("CSchedGrpsDlg");
|
|
m_bAddMode=false;
|
|
}
|
|
|
|
CSchedGrps::~CSchedGrps()
|
|
{
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
}
|
|
|
|
void CSchedGrps::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CSchedGrps)
|
|
DDX_Control(pDX, IDC_EDNAME, m_edName);
|
|
DDX_Control(pDX, IDC_CBTECHS, m_ckcbTechs);
|
|
DDX_Control(pDX, IDC_CBGROUP, m_cbGroups);
|
|
DDX_Control(pDX, IDC_BTNDONE, m_btnDone);
|
|
DDX_Control(pDX, IDC_BTNDELGRP, m_btnDelete);
|
|
DDX_Control(pDX, IDC_BTNADD, m_btnAdd);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CSchedGrps, CDialog)
|
|
//{{AFX_MSG_MAP(CSchedGrps)
|
|
ON_BN_CLICKED(IDC_BTNADD, OnBtnadd)
|
|
ON_BN_CLICKED(IDC_BTNDELGRP, OnBtndelgrp)
|
|
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
|
|
ON_CBN_CLOSEUP(IDC_CBGROUP, OnCloseupCbgroup)
|
|
ON_CBN_CLOSEUP(IDC_CBTECHS, OnCloseupCbtechs)
|
|
ON_EN_KILLFOCUS(IDC_EDNAME, OnKillfocusEdname)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CSchedGrps message handlers
|
|
|
|
BOOL CSchedGrps::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
Security();
|
|
FillTechList();
|
|
FillGroups();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
|
|
|
|
void CSchedGrps::OnOK()
|
|
{}
|
|
|
|
void CSchedGrps::OnBtnadd()
|
|
{
|
|
if(m_bAddMode)//user clicked on save
|
|
{
|
|
CString strData,q;
|
|
long lData;
|
|
m_edName.GetWindowText(strData);
|
|
if(strData.IsEmpty())
|
|
{
|
|
AfxMessageBox("Name can't be blank");
|
|
return;
|
|
}
|
|
|
|
//Good to go...
|
|
q.Format("INSERT INTO schdgrps ( name ) SELECT \"%s\" AS Expr1;",strData);
|
|
rs->Ex(q,&lData);
|
|
m_strSelectedGroup.Format("%u",lData);
|
|
rs->Close();
|
|
m_bAddMode=false;
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_ckcbTechs.EnableWindow(TRUE);
|
|
m_btnDone.ShowWindow(TRUE);
|
|
m_cbGroups.EnableWindow(FALSE);
|
|
FillGroups();
|
|
}
|
|
else//user clicked on ADD
|
|
{
|
|
m_ckcbTechs.SelectAll(FALSE);
|
|
m_bAddMode=true;
|
|
m_edName.SetWindowText("");
|
|
m_edName.EnableWindow(TRUE);
|
|
m_btnAdd.SetWindowText("SAVE");
|
|
m_btnDelete.SetWindowText("CANCEL");
|
|
m_ckcbTechs.SetWindowText("");
|
|
m_ckcbTechs.EnableWindow(FALSE);
|
|
m_btnDone.ShowWindow(FALSE);
|
|
m_cbGroups.EnableWindow(FALSE);
|
|
m_edName.SetFocus();
|
|
}
|
|
|
|
}
|
|
|
|
void CSchedGrps::OnBtndelgrp()
|
|
{
|
|
|
|
if(m_bAddMode)//user clicked on cancel
|
|
{
|
|
|
|
m_bAddMode=false;
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_ckcbTechs.EnableWindow(TRUE);
|
|
m_btnDone.ShowWindow(TRUE);
|
|
m_cbGroups.EnableWindow(FALSE);
|
|
FillGroups();
|
|
OnCloseupCbgroup();
|
|
return;
|
|
}
|
|
|
|
CString q,strGroup;
|
|
strGroup=m_cbGroups.GetCurrentRowID();
|
|
//delete all schdets that match master id first
|
|
q.Format("DELETE schdets.*, schdets.grpid FROM schdets WHERE (((schdets.grpid)=%s));",
|
|
strGroup);
|
|
rs->Ex(q);
|
|
|
|
//delete group itself
|
|
q.Format("DELETE schdgrps.*, schdgrps.id FROM schdgrps WHERE (((schdgrps.id)=%s));",
|
|
strGroup);
|
|
rs->Ex(q);
|
|
rs->Close();
|
|
|
|
FillGroups();
|
|
|
|
}
|
|
|
|
void CSchedGrps::OnBtndone()
|
|
{
|
|
CDialog::OnOK();
|
|
|
|
}
|
|
|
|
void CSchedGrps::OnCloseupCbgroup()
|
|
{
|
|
//if(m_strSelectedGroup==m_cbGroups.GetCurrentRowID()) return;
|
|
m_strSelectedGroup==m_cbGroups.GetCurrentRowID();
|
|
m_edName.SetWindowText(m_cbGroups.GetCurrentRowText());
|
|
UpdateSelections();
|
|
}
|
|
|
|
void CSchedGrps::OnCloseupCbtechs()
|
|
{
|
|
SaveSelections();
|
|
|
|
}
|
|
|
|
//Fill the list of techs
|
|
void CSchedGrps::FillTechList()
|
|
{
|
|
CString strData;
|
|
m_ckcbTechs.SelectAll(FALSE);
|
|
//m_ckcbTechs.Clear();
|
|
|
|
rs->QueryReadOnly(strData="SELECT users.id, [last] & \", \" & [first] & \" id:\" & [id] AS name "
|
|
"FROM users "
|
|
"WHERE (((users.id)<>1) AND ((users.tech)=True)) "
|
|
"ORDER BY users.last;");
|
|
|
|
if(rs->IsEmpty())
|
|
return;
|
|
|
|
do{
|
|
rs->FetchField("name",&strData);
|
|
m_ckcbTechs.AddString(strData);
|
|
|
|
}while(rs->MoveForward());
|
|
|
|
|
|
}
|
|
|
|
void CSchedGrps::FillGroups()
|
|
{
|
|
CString strData,strIndex;
|
|
long lData;
|
|
m_cbGroups.Clear();
|
|
|
|
rs->QueryReadOnly("SELECT schdgrps.name, schdgrps.id FROM schdgrps ORDER BY schdgrps.name;");
|
|
if(rs->IsEmpty())
|
|
{
|
|
m_btnDelete.EnableWindow(FALSE);
|
|
m_cbGroups.EnableWindow(FALSE);
|
|
m_edName.EnableWindow(FALSE);
|
|
m_ckcbTechs.EnableWindow(FALSE);
|
|
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
//if there is data then enable controls
|
|
if(!m_bReadOnly)
|
|
{
|
|
m_btnDelete.EnableWindow(TRUE);
|
|
m_cbGroups.EnableWindow(TRUE);
|
|
m_edName.EnableWindow(TRUE);
|
|
m_ckcbTechs.EnableWindow(TRUE);
|
|
}
|
|
}
|
|
|
|
do{
|
|
rs->FetchField("name",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbGroups.AddRow(strData,strIndex);
|
|
|
|
}while(rs->MoveForward());
|
|
|
|
if(m_strSelectedGroup.IsEmpty())
|
|
{
|
|
m_cbGroups.SetCurSel(0);
|
|
//m_strSelectedGroup=m_cbGroups.GetCurrentRowID();
|
|
}
|
|
else
|
|
m_cbGroups.Select(m_strSelectedGroup);
|
|
|
|
OnCloseupCbgroup();
|
|
}
|
|
|
|
|
|
|
|
|
|
//update selected techs
|
|
void CSchedGrps::UpdateSelections()
|
|
{
|
|
CString q,strTemp;
|
|
long lData;
|
|
long lCurrentTechID;
|
|
int i,nStart,nLength,nChars,nCount;
|
|
//int x=m_ckcbTechs.GetCount();
|
|
|
|
//clear all checks
|
|
m_ckcbTechs.SelectAll(FALSE);
|
|
|
|
//cycle through all sched techs
|
|
q.Format("SELECT schdets.techid FROM schdets WHERE (((schdets.grpid)=%s));",
|
|
m_cbGroups.GetCurrentRowID());
|
|
rs->QueryReadOnly(q);
|
|
if(rs->IsEmpty())
|
|
return;
|
|
nCount=m_ckcbTechs.GetCount();
|
|
//loop through all schdets records and ...
|
|
do{
|
|
rs->FetchField("techid",&lData);
|
|
|
|
//compare id's to checkcombo last characters after "ID:"
|
|
CString str, str2;
|
|
|
|
for (i=0;i < nCount;i++)
|
|
{
|
|
m_ckcbTechs.GetLBText( i, strTemp );
|
|
nLength=strTemp.GetLength();
|
|
nStart=strTemp.ReverseFind(':');
|
|
if(nStart!=-1)
|
|
{
|
|
nChars=nLength-nStart;
|
|
strTemp=strTemp.Right(nChars-1);
|
|
lCurrentTechID=atol(strTemp);
|
|
if(lCurrentTechID==lData)
|
|
{
|
|
m_ckcbTechs.SetCheck(i,TRUE);
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}while(rs->MoveForward());
|
|
|
|
|
|
|
|
}
|
|
|
|
//save selected techs
|
|
void CSchedGrps::SaveSelections()
|
|
{
|
|
CString q,strTemp,strGroup;
|
|
int i,nStart,nLength,nChars,nCount;
|
|
|
|
nCount=m_ckcbTechs.GetCount();
|
|
strGroup=m_cbGroups.GetCurrentRowID();
|
|
//delete all schdets that match master id first
|
|
q.Format("DELETE schdets.*, schdets.grpid FROM schdets WHERE (((schdets.grpid)=%s));",
|
|
strGroup);
|
|
rs->Ex(q);
|
|
|
|
//then put in all the schdets from the list
|
|
|
|
for (i=0;i < nCount;i++)
|
|
{
|
|
if(m_ckcbTechs.GetCheck(i))
|
|
{
|
|
m_ckcbTechs.GetLBText( i, strTemp );
|
|
nLength=strTemp.GetLength();
|
|
nStart=strTemp.ReverseFind(':');
|
|
if(nStart!=-1)
|
|
{
|
|
nChars=nLength-nStart;
|
|
strTemp=strTemp.Right(nChars-1);
|
|
|
|
//insert into query
|
|
q.Format("INSERT INTO schdets ( grpid, techid ) "
|
|
"SELECT %s , %s;",strGroup,strTemp);
|
|
rs->Ex(q);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void CSchedGrps::OnKillfocusEdname()
|
|
{
|
|
if(m_bAddMode) return;//don't do this if adding a new record
|
|
//save new list name
|
|
CString q,strData, strIndex;
|
|
|
|
m_edName.GetWindowText(strData);
|
|
strIndex=m_cbGroups.GetCurrentRowID();
|
|
|
|
if(strData.IsEmpty())
|
|
{
|
|
AfxMessageBox("Name can not be blank");
|
|
return;
|
|
}
|
|
|
|
q.Format("UPDATE schdgrps SET schdgrps.name = \"%s\" WHERE (((schdgrps.id)=%s));",
|
|
strData,strIndex);
|
|
|
|
rs->Ex(q);
|
|
rs->Close();
|
|
FillGroups();
|
|
}
|
|
|
|
|
|
|
|
void CSchedGrps::Security()
|
|
{
|
|
m_bReadOnly=false;
|
|
int x=m_pApp->Allowed(RSCHEDGROUPS,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_edName.SetReadOnly(TRUE);
|
|
m_ckcbTechs.EnableWindow(FALSE);
|
|
|
|
|
|
|
|
}
|
|
}
|