804 lines
19 KiB
C++
804 lines
19 KiB
C++
// GroupsDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "GroupsDlg.h"
|
|
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGroupsDlg dialog
|
|
|
|
|
|
CGroupsDlg::CGroupsDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CGroupsDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CGroupsDlg)
|
|
//}}AFX_DATA_INIT
|
|
k=new GZK;
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
|
|
/*
|
|
rs=new GZRset("Group rights dialog error:");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
lbrs=new GZRset("Group rights dialog reports listbox recordset error:");
|
|
lbrs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
//Initialize recordset pointer
|
|
|
|
|
|
rs=m_pApp->rsPool->GetRS("CGroupsDlg (RS)");
|
|
lbrs=m_pApp->rsPool->GetRS("CGroupsDlg (LBRS)");
|
|
|
|
m_strGroupsReports.Empty();
|
|
}
|
|
|
|
CGroupsDlg::~CGroupsDlg()
|
|
{
|
|
delete k;
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
m_pApp->rsPool->ReleaseRS(&lbrs->m_nID);
|
|
}
|
|
|
|
void CGroupsDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CGroupsDlg)
|
|
DDX_Control(pDX, IDC_26, m_26);
|
|
DDX_Control(pDX, IDC_25, m_25);
|
|
DDX_Control(pDX, IDC_24, m_24);
|
|
DDX_Control(pDX, IDC_23, m_23);
|
|
DDX_Control(pDX, IDC_BTNDONE, m_btnDone);
|
|
DDX_Control(pDX, IDC_LBRPTPOOL, m_lbReportsPool);
|
|
DDX_Control(pDX, IDC_LBRPTGROUP, m_lbReportsGroup);
|
|
DDX_Control(pDX, IDC_9, m_9);
|
|
DDX_Control(pDX, IDC_8, m_8);
|
|
DDX_Control(pDX, IDC_21, m_21);
|
|
DDX_Control(pDX, IDC_22, m_22);
|
|
DDX_Control(pDX, IDC_20, m_20);
|
|
DDX_Control(pDX, IDC_19, m_19);
|
|
DDX_Control(pDX, IDC_18, m_18);
|
|
DDX_Control(pDX, IDC_17, m_17);
|
|
DDX_Control(pDX, IDC_16, m_16);
|
|
DDX_Control(pDX, IDC_15, m_15);
|
|
DDX_Control(pDX, IDC_14, m_14);
|
|
DDX_Control(pDX, IDC_13, m_13);
|
|
DDX_Control(pDX, IDC_12, m_12);
|
|
DDX_Control(pDX, IDC_11, m_11);
|
|
DDX_Control(pDX, IDC_10, m_10);
|
|
DDX_Control(pDX, IDC_7, m_7);
|
|
DDX_Control(pDX, IDC_6, m_6);
|
|
DDX_Control(pDX, IDC_5, m_5);
|
|
DDX_Control(pDX, IDC_4, m_4);
|
|
DDX_Control(pDX, IDC_3, m_3);
|
|
DDX_Control(pDX, IDC_2, m_2);
|
|
DDX_Control(pDX, IDC_1, m_1);
|
|
DDX_Control(pDX, IDC_0, m_0);
|
|
DDX_Control(pDX, IDC_GROUPNAME, m_edName);
|
|
DDX_Control(pDX, IDC_GROUP_LIST_LABEL, m_lblGroupList);
|
|
DDX_Control(pDX, IDC_GROUP_COMBO, m_cbGroup);
|
|
DDX_Control(pDX, IDC_DELETE, m_btnDelete);
|
|
DDX_Control(pDX, IDC_ADD, m_btnAdd);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CGroupsDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CGroupsDlg)
|
|
ON_BN_CLICKED(IDC_ADD, OnAdd)
|
|
ON_BN_CLICKED(IDC_DELETE, OnDelete)
|
|
ON_CBN_CLOSEUP(IDC_GROUP_COMBO, OnCloseupGroupCombo)
|
|
ON_BN_CLICKED(IDOK, OnOk)
|
|
ON_EN_KILLFOCUS(IDC_GROUPNAME, OnKillfocusGroupname)
|
|
ON_WM_RBUTTONDBLCLK()
|
|
ON_BN_CLICKED(IDC_BTNREMOVERPT, OnBtnremoverpt)
|
|
ON_BN_CLICKED(IDC_BTNADDRPT, OnBtnaddrpt)
|
|
ON_LBN_DBLCLK(IDC_LBRPTGROUP, OnDblclkLbrptgroup)
|
|
ON_LBN_DBLCLK(IDC_LBRPTPOOL, OnDblclkLbrptpool)
|
|
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGroupsDlg message handlers
|
|
|
|
|
|
void CGroupsDlg::FillListBox()
|
|
{
|
|
//fill list box with different groups
|
|
CString strData;
|
|
CString strIndex;
|
|
long lData;
|
|
m_cbGroup.Clear();
|
|
|
|
|
|
|
|
rs->Query("SELECT groups.* FROM groups;");
|
|
if(!rs->IsEmpty())
|
|
{
|
|
//fill combo box with available zones
|
|
rs->MoveFirst();
|
|
rs->FetchField("a",&strData);
|
|
|
|
//decrypt the name
|
|
k->GZDecrypt(&strData,false);
|
|
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbGroup.AddRow(strData,strIndex);
|
|
while(rs->MoveForward())
|
|
{
|
|
rs->FetchField("a",&strData);
|
|
//decrypt the name
|
|
k->GZDecrypt(&strData,false);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbGroup.AddRow(strData,strIndex);
|
|
}
|
|
|
|
}
|
|
|
|
//pretend user has selected so that other fields get filled in
|
|
if(m_strSelectedGroup.IsEmpty()) //first time in
|
|
{
|
|
m_cbGroup.Select(1);
|
|
//set last selected because were probably
|
|
//here due to a delete and so whatever it was set
|
|
//to is now invalid and will cause havoc on the
|
|
//next save call.
|
|
m_strLastComboID=m_cbGroup.GetCurrentRowID();
|
|
|
|
}
|
|
else//something valid was selected before so stick with it
|
|
m_cbGroup.Select(m_strSelectedGroup);
|
|
|
|
|
|
SetFields();
|
|
|
|
|
|
|
|
}
|
|
|
|
void CGroupsDlg::SetFields()
|
|
{
|
|
//user has made a selection, update the visible list
|
|
CString q;
|
|
CString strName;
|
|
CString strRights;
|
|
CString strHash;
|
|
BOOL enable=TRUE;
|
|
//save current selection so that updates and changes
|
|
//will still show what was last selected
|
|
m_strSelectedGroup=m_cbGroup.GetCurrentRowID();
|
|
if(m_strSelectedGroup=="1" || m_bReadOnly) enable= FALSE;
|
|
long lID;
|
|
q.Format("SELECT groups.* FROM groups WHERE (((groups.id)=%s));",m_strSelectedGroup);
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())
|
|
{
|
|
m_strGroupsReports.Empty();
|
|
|
|
rs->FetchField("id",&lID);//id number
|
|
rs->FetchField("a",&strName);//name string
|
|
rs->FetchField("b",&strRights);//rights string
|
|
rs->FetchField("c",&strHash);//checksum/hash
|
|
rs->FetchField("d",&m_strGroupsReports);
|
|
//decrypt if there is something there
|
|
if(!m_strGroupsReports.IsEmpty())
|
|
k->GZDecrypt(&m_strGroupsReports,false);
|
|
|
|
//used by save routine to see if user has made
|
|
//report selection changes
|
|
m_strGroupsReportsInitialValue=m_strGroupsReports;
|
|
//stuff em all together and compare the hash value
|
|
//to make sure no one has been screwing with the security
|
|
//settings
|
|
q.Format("%u%s%s",lID,strName,strRights);
|
|
k->GZHash(&q);
|
|
if(q.Compare(strHash)!=0 && m_bMasterMode==false)
|
|
{
|
|
AfxMessageBox("Security breach!\r\nGroup rights corrupted.");
|
|
//PostQuitMessage(WM_QUIT);
|
|
return;
|
|
}
|
|
|
|
//take the rightmost numrights characters and set the rights buttons
|
|
//accordingly
|
|
k->GZDecrypt(&strRights,false);
|
|
q=strRights.Right(NUMRIGHTS);
|
|
}
|
|
//initialize the rights buttons
|
|
for(int x=0;x<NUMRIGHTS;x++)
|
|
{
|
|
strRights=q.Mid(x,1);
|
|
if(m_pRight[x]!=NULL)
|
|
m_pRight[x]->Set(strRights,true);
|
|
m_pRight[x]->EnableWindow(enable);
|
|
|
|
}
|
|
|
|
//display the list name
|
|
k->GZDecrypt(&strName,false);
|
|
m_edName.SetWindowText(strName);
|
|
m_edName.EnableWindow(enable);
|
|
m_btnDelete.ShowWindow(enable);
|
|
m_lbReportsGroup.EnableWindow(enable);
|
|
m_lbReportsPool.EnableWindow(enable);
|
|
if(enable)
|
|
DisplayReportLists();
|
|
|
|
}
|
|
|
|
//************************************
|
|
void CGroupsDlg::OnAdd()
|
|
{
|
|
CString str;
|
|
if(m_bAddMode)//user is requesting to save
|
|
{
|
|
m_edName.GetWindowText(str);
|
|
if(str.IsEmpty())
|
|
{
|
|
AfxMessageBox("You must enter a group name");
|
|
return;
|
|
}
|
|
|
|
//bugbug: sometimes it complains about
|
|
//adding a duplicate record when
|
|
//not doing that. Could be add mode is
|
|
//not resetting so it thinks it's adding
|
|
//rather than updating.
|
|
|
|
//Seems to happen when you add a new record
|
|
//edit then add a second.
|
|
//seems to have started since adding code
|
|
//to select newly added record automatically.
|
|
|
|
//Also is not clearing old values on add new properly.
|
|
|
|
m_bAddMode=false;
|
|
m_cbGroup.ShowWindow(TRUE);
|
|
m_lblGroupList.ShowWindow(TRUE);
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_btnDone.ShowWindow(TRUE);
|
|
//save the new record
|
|
Save(false);
|
|
FillListBox();
|
|
}
|
|
else//not add mode
|
|
{
|
|
Save(true);
|
|
//DO: set default values of controls.
|
|
m_edName.EnableWindow(TRUE);
|
|
m_btnDelete.ShowWindow(TRUE);
|
|
m_cbGroup.ShowWindow(FALSE);
|
|
m_lblGroupList.ShowWindow(FALSE);
|
|
m_btnAdd.SetWindowText("SAVE");
|
|
m_btnDelete.SetWindowText("Cancel");
|
|
m_btnDone.ShowWindow(FALSE);
|
|
m_edName.SetWindowText("");
|
|
m_edName.SetFocus();
|
|
m_bAddMode=true;
|
|
}
|
|
}
|
|
|
|
|
|
//*******************************************
|
|
void CGroupsDlg::OnDelete()
|
|
{
|
|
CString strGroupID;
|
|
if(m_bAddMode==true)//then this is the cancel button
|
|
{
|
|
m_bAddMode=false;
|
|
m_cbGroup.ShowWindow(TRUE);
|
|
m_lblGroupList.ShowWindow(TRUE);
|
|
m_btnAdd.SetWindowText("Add");
|
|
m_btnDelete.SetWindowText("Delete");
|
|
m_btnDone.ShowWindow(TRUE);
|
|
FillListBox();
|
|
return;
|
|
}
|
|
|
|
//otherwise, delete the record
|
|
|
|
strGroupID=m_cbGroup.GetCurrentRowID();
|
|
if(strGroupID=="1" && m_bMasterMode==false)
|
|
{
|
|
//AfxMessageBox("To protect your access the <MANAGERS> group can not be deleted.");
|
|
return;
|
|
}
|
|
CString q,strData;
|
|
q.Format("SELECT [first] & \" \" & [last] AS name "
|
|
"FROM users WHERE (((users.c)=%s));",strGroupID);
|
|
|
|
|
|
|
|
|
|
|
|
rs->Query(q);
|
|
if(rs->IsEmpty())//no clients in that zone
|
|
{
|
|
|
|
q.Format("DELETE groups.*, groups.id "
|
|
"FROM groups WHERE (((groups.id)=%s));",m_cbGroup.GetCurrentRowID());
|
|
|
|
if(AfxMessageBox("Delete this group?",MB_YESNO)==IDYES)
|
|
{
|
|
rs->Ex(q);
|
|
//a deleted zone can't be selected
|
|
m_strSelectedGroup="";
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
q="DATA INTEGRITY PROTECTION:\r\nYou cannot delete this security group because\r\nthe following users are set to it:\r\n";
|
|
|
|
//fill combo box with available zones
|
|
rs->MoveFirst();
|
|
rs->FetchField("name",&strData);
|
|
q=q+strData+"\r\n";
|
|
|
|
|
|
while(rs->MoveForward())
|
|
{
|
|
rs->FetchField("name",&strData);
|
|
q=q+strData+"\r\n";
|
|
}
|
|
AfxMessageBox(q);
|
|
}
|
|
FillListBox();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//****************************************************
|
|
BOOL CGroupsDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
ShowWindow(SW_SHOWMAXIMIZED);
|
|
m_bAddMode=false;
|
|
|
|
|
|
|
|
m_pRight[0]=&m_0;
|
|
m_pRight[1]=&m_1;
|
|
m_pRight[2]=&m_2;
|
|
m_pRight[3]=&m_3;
|
|
m_pRight[4]=&m_4;
|
|
m_pRight[5]=&m_5;
|
|
m_pRight[6]=&m_6;
|
|
m_pRight[7]=&m_7;
|
|
m_pRight[8]=&m_8;
|
|
m_pRight[9]=&m_9;
|
|
m_pRight[10]=&m_10;
|
|
m_pRight[11]=&m_11;
|
|
m_pRight[12]=&m_12;
|
|
m_pRight[13]=&m_13;
|
|
m_pRight[14]=&m_14;
|
|
m_pRight[15]=&m_15;
|
|
m_pRight[16]=&m_16;
|
|
m_pRight[17]=&m_17;
|
|
m_pRight[18]=&m_18;
|
|
m_pRight[19]=&m_19;
|
|
m_pRight[20]=&m_20;
|
|
m_pRight[21]=&m_21;
|
|
m_pRight[22]=&m_22;
|
|
m_pRight[23]=&m_23;
|
|
m_pRight[24]=&m_24;
|
|
m_pRight[25]=&m_25;
|
|
m_pRight[26]=&m_26;
|
|
|
|
//ASSUMPTION: can only get here from the main
|
|
//menu bar, so either you can't get here at all
|
|
//or you have read only access, so onlyt
|
|
//have to set readonly here not check for
|
|
//no access since that's taken care of in the
|
|
//CspApp->switchview function
|
|
if(m_pApp->Allowed(RSECURITY,true)==2)//read only?
|
|
m_bReadOnly=true;
|
|
else
|
|
m_bReadOnly=false;
|
|
|
|
FillListBox();
|
|
m_strLastComboID=m_cbGroup.GetCurrentRowID();
|
|
|
|
// m_lblHead1.SetFontName("Arial").SetFontSize(12).SetFontBold(TRUE).SetFontUnderline(TRUE).SetTextColor(RGB(0,0,0));
|
|
// m_lblHead2.SetFontName("Arial").SetFontSize(12).SetFontBold(TRUE).SetFontUnderline(TRUE).SetTextColor(RGB(0,0,0));
|
|
|
|
m_bMasterMode=false;
|
|
//===================================================
|
|
// SET WINDOW SIZE TO MATCH WORK AREA
|
|
ShowWindow(SW_SHOWMAXIMIZED);
|
|
CRect workarea;
|
|
SystemParametersInfo(SPI_GETWORKAREA,0,&workarea,0);
|
|
SetWindowPos(NULL,workarea.left,workarea.top,workarea.Width(),workarea.Height(),SWP_NOZORDER);
|
|
//===================================================
|
|
|
|
//DisplayReportLists();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CGroupsDlg::OnCloseupGroupCombo()
|
|
{
|
|
|
|
//call save
|
|
if(m_strLastComboID!="1")
|
|
Save(true);
|
|
//set to current selection
|
|
//when save is called before this line
|
|
//it will be able to see if the combo has changed
|
|
//and can use the last combo ID value instead
|
|
//during the save
|
|
m_strLastComboID=m_cbGroup.GetCurrentRowID();
|
|
SetFields();
|
|
|
|
}
|
|
|
|
|
|
//********************************************
|
|
//if update==true then update existing record
|
|
//else create new record
|
|
void CGroupsDlg::Save(bool Update/*or new*/)
|
|
{
|
|
CString q;
|
|
CString strItem;
|
|
CString strName;
|
|
CString strRights;
|
|
CString strHash;
|
|
CString strGroupID;
|
|
CString strReports;
|
|
bool HereFromCBCloseup=false;
|
|
long lID;
|
|
int x;
|
|
bool ThereAreChanges=false;
|
|
|
|
|
|
if(Update)
|
|
{
|
|
//check the rights buttons
|
|
for(x=0;x<NUMRIGHTS;x++)
|
|
{
|
|
if(m_pRight[x]->IsChanged())
|
|
{
|
|
ThereAreChanges=true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//check the group name box
|
|
if(m_edName.GetModify()==TRUE)
|
|
ThereAreChanges=true;
|
|
|
|
//check reports
|
|
if(m_strGroupsReports!=m_strGroupsReportsInitialValue)
|
|
ThereAreChanges=true;
|
|
|
|
//no changes? then exit routine
|
|
if(ThereAreChanges==false)
|
|
return;
|
|
|
|
}
|
|
|
|
//save changes
|
|
m_edName.GetWindowText(strName);
|
|
if(strName.IsEmpty())
|
|
{
|
|
AfxMessageBox("You must enter a group name");
|
|
return;
|
|
}
|
|
|
|
strRights=strName;
|
|
for(x=0;x<NUMRIGHTS;x++)
|
|
{
|
|
m_pRight[x]->Get(&strItem);
|
|
//tell the controls that they are now
|
|
//at their default value
|
|
//since they are, this prevents
|
|
//later updates from thinking a save is
|
|
//necessary
|
|
m_pRight[x]->Set(strItem,true);
|
|
strRights=strRights+strItem;
|
|
}
|
|
|
|
//encrypt
|
|
k->GZEncrypt(&strName,false);
|
|
k->GZEncrypt(&strRights,false);
|
|
strReports=m_strGroupsReports;
|
|
|
|
if(!strReports.IsEmpty())
|
|
k->GZEncrypt(&strReports,false);
|
|
|
|
if(Update)
|
|
{
|
|
//Get the hash
|
|
strGroupID=m_cbGroup.GetCurrentRowID();
|
|
|
|
//get id, or previous id if combo is in the
|
|
//middle of changing
|
|
if(strGroupID.Compare(m_strLastComboID)!=0)
|
|
{
|
|
strGroupID=m_strLastComboID;
|
|
//flag so filllistbox doesn't get called later
|
|
HereFromCBCloseup=true;
|
|
}
|
|
|
|
if(strGroupID=="1" && m_bMasterMode==false)
|
|
{
|
|
//AfxMessageBox("To protect your access the <MANAGERS> group can not be modified.");
|
|
return;
|
|
}
|
|
|
|
//check if attempting to use the same group name
|
|
//as another record users
|
|
q.Format("SELECT groups.id, groups.a FROM groups "
|
|
"WHERE (((groups.id)<>%s) AND ((groups.a)=\"%s\"));",strGroupID,strName);
|
|
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())//group name already exists
|
|
{
|
|
AfxMessageBox("That group name is already in use!");
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
strHash=strGroupID;
|
|
strHash=strHash+strName+strRights;
|
|
k->GZHash(&strHash);
|
|
//make up the execute query string
|
|
q.Format("UPDATE groups SET groups.a = \"%s\", groups.b = \"%s\", "
|
|
"groups.c = \"%s\", groups.d = \"%s\" WHERE (((groups.id)=%s));"
|
|
,strName,strRights,strHash,strReports, strGroupID);
|
|
//run the execute query
|
|
rs->Ex(q);
|
|
|
|
|
|
if(!HereFromCBCloseup)
|
|
FillListBox();
|
|
//bail
|
|
return;
|
|
}
|
|
else//it's a wholesale new record
|
|
{
|
|
//see if another record is already using
|
|
//this name...
|
|
q.Format("SELECT groups.* FROM groups "
|
|
"WHERE (((groups.a)=\"%s\"));",strName);
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())//group name already exists
|
|
{
|
|
AfxMessageBox("That group name is already in use!");
|
|
return;
|
|
|
|
}
|
|
|
|
rs->AddNewRecord();
|
|
rs->UpdateField("a",&strName);
|
|
rs->UpdateField("b",&strRights);
|
|
rs->UpdateField("d",&strReports);
|
|
if(!rs->SaveRecord())
|
|
CDialog::OnCancel();
|
|
|
|
//now get the autonumber id assigned to this record
|
|
q.Format("SELECT groups.* FROM groups WHERE (((groups.a)=\"%s\"));",strName);
|
|
rs->Query(q);
|
|
rs->FetchField("id",&lID);
|
|
strHash.Format("%u",lID);
|
|
//this is so after adding new group
|
|
//list centers on it
|
|
m_strSelectedGroup=strHash;
|
|
|
|
strHash=strHash+strName+strRights;
|
|
k->GZHash(&strHash);
|
|
//now save the hash
|
|
rs->UpdateField("c",&strHash);
|
|
if(!rs->SaveRecord())
|
|
{
|
|
AfxMessageBox("If you just received an error about creating a duplicate\r\n"
|
|
"You were probably trying to use the same group name twice.\r\n"
|
|
"Each group name must be unique");
|
|
//pretend user pressed cancel
|
|
m_bAddMode=true;
|
|
OnDelete();
|
|
}
|
|
|
|
//reset this bad boy
|
|
m_strGroupsReportsInitialValue=m_strGroupsReports;
|
|
//bob's your uncle
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//*********************************************
|
|
void CGroupsDlg::OnOk()
|
|
{}//do nothing
|
|
|
|
|
|
//****************************************
|
|
void CGroupsDlg::OnKillfocusGroupname()
|
|
{
|
|
if(!m_bAddMode)
|
|
Save(true);
|
|
}
|
|
|
|
//***********************************
|
|
bool CGroupsDlg::SaveField(CEdit *edControl,CString fldname,bool AllowEmpty)
|
|
{
|
|
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);
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
void CGroupsDlg::OnRButtonDblClk(UINT nFlags, CPoint point)
|
|
{
|
|
/*
|
|
return;
|
|
|
|
if(m_pApp->m_lusrID!=1) return;//only the manager!
|
|
CKD d;
|
|
d.DoModal();
|
|
// TODO: Add your message handler code here and/or call default
|
|
m_bMasterMode=!m_bMasterMode;
|
|
if(m_bMasterMode)
|
|
SetWindowText("User groups - Edit / Add.");
|
|
else
|
|
SetWindowText("User groups - Edit / Add");
|
|
//CDialog::OnRButtonDblClk(nFlags, point);
|
|
*/
|
|
}
|
|
|
|
//**********************************************
|
|
void CGroupsDlg::OnBtnremoverpt()
|
|
{
|
|
CString fname,vname;
|
|
int nFound=0;
|
|
m_lbReportsGroup.RebuildIndex();
|
|
int x=m_lbReportsGroup.SelectionCount();
|
|
if(x<1) return;
|
|
|
|
for(int y=0;y<x;y++)
|
|
{
|
|
fname=m_lbReportsGroup.GetSelectedItem(y);
|
|
//see if it's already in the list
|
|
nFound=m_strGroupsReports.Find(fname,0);
|
|
|
|
|
|
if(nFound!=-1)//not found
|
|
m_strGroupsReports.Delete(nFound,fname.GetLength());
|
|
|
|
|
|
}
|
|
|
|
//refresh display
|
|
DisplayReportLists();
|
|
}
|
|
|
|
|
|
//***************************************
|
|
void CGroupsDlg::OnBtnaddrpt()
|
|
{
|
|
CString fname;
|
|
//needed for some weird hacky reason
|
|
//that I never fixed
|
|
m_lbReportsPool.RebuildIndex();
|
|
int x=m_lbReportsPool.SelectionCount();
|
|
if(x<1) return;
|
|
|
|
for(int y=0;y<x;y++)
|
|
{
|
|
fname=m_lbReportsPool.GetSelectedItem(y);
|
|
|
|
//see if it's already in the list
|
|
if(m_strGroupsReports.Find(fname,0)==-1)//not found
|
|
m_strGroupsReports+=fname;
|
|
|
|
}
|
|
|
|
//refresh display
|
|
DisplayReportLists();
|
|
|
|
}
|
|
|
|
void CGroupsDlg::OnDblclkLbrptgroup()
|
|
{
|
|
OnBtnremoverpt();
|
|
}
|
|
|
|
void CGroupsDlg::OnDblclkLbrptpool()
|
|
{
|
|
OnBtnaddrpt();
|
|
}
|
|
|
|
|
|
//**************************************
|
|
//display all reports for this group
|
|
//display all available reports not in group
|
|
//safe to call from anywhere....:)
|
|
void CGroupsDlg::DisplayReportLists()
|
|
{
|
|
|
|
CString q,vname,fname;
|
|
bool GroupHasReports=true;
|
|
m_lbReportsPool.Clear();
|
|
m_lbReportsGroup.Clear();
|
|
//to avoid extra lb processing when adding strings
|
|
if(m_strGroupsReports.IsEmpty()) GroupHasReports=false;
|
|
|
|
lbrs->Query("SELECT rptsmaster.virtualname, rptsmaster.filename "
|
|
"FROM rptsmaster WHERE (((rptsmaster.x)=True)) ORDER BY rptsmaster.virtualname;");
|
|
|
|
ASSERT(!lbrs->IsEmpty());
|
|
if(lbrs->IsEmpty()) return;
|
|
|
|
lbrs->MoveFirst();
|
|
|
|
do
|
|
{
|
|
lbrs->FetchField("virtualname",&vname);
|
|
lbrs->FetchField("filename",&fname);
|
|
//see if it's in the group if so put in group list
|
|
if(!GroupHasReports)
|
|
{//just put into the pool list
|
|
m_lbReportsPool.AddRow(vname,fname);
|
|
}
|
|
else
|
|
{//see where it goes and put it in the right list
|
|
if(m_strGroupsReports.Find(fname,0)==-1)//not found
|
|
m_lbReportsPool.AddRow(vname,fname);//into the pool
|
|
else
|
|
m_lbReportsGroup.AddRow(vname,fname);//into the group
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}while(lbrs->MoveForward());
|
|
|
|
|
|
|
|
}
|
|
|
|
void CGroupsDlg::OnBtndone()
|
|
{
|
|
Save(true);
|
|
CDialog::OnOK();
|
|
}
|