343 lines
7.7 KiB
C++
343 lines
7.7 KiB
C++
// ProbStatDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "sp.h"
|
|
#include "ProbStatDlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CProbStatDlg dialog
|
|
|
|
|
|
CProbStatDlg::CProbStatDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CProbStatDlg::IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CProbStatDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_pApp= (CSpApp*)AfxGetApp();
|
|
/*
|
|
rs=new GZRset("Problem status dialog");
|
|
rs->SetConnect(m_pApp->strConnectString);
|
|
*/
|
|
//Initialize recordset pointer
|
|
|
|
rs=m_pApp->rsPool->GetRS("CProbStatDlg");
|
|
m_bAddMode=false;
|
|
}
|
|
|
|
|
|
void CProbStatDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CProbStatDlg)
|
|
DDX_Control(pDX, IDC_BTNCOLOR, m_btnColor);
|
|
DDX_Control(pDX, IDC_LBLSAMPLE, m_lblSample);
|
|
DDX_Control(pDX, IDC_LBLSTATUSLIST, m_lblStatusList);
|
|
DDX_Control(pDX, IDC_EDSTATUSITEM, m_edStatusItem);
|
|
DDX_Control(pDX, IDC_CBSTATUSITEMLIST, m_cbStatusItemsList);
|
|
DDX_Control(pDX, IDC_BTNDONE, m_BtnDone);
|
|
DDX_Control(pDX, IDC_BTNDELETE, m_BtnDelete);
|
|
DDX_Control(pDX, IDC_BTNADD, m_BtnAdd);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CProbStatDlg, CDialog)
|
|
//{{AFX_MSG_MAP(CProbStatDlg)
|
|
ON_BN_CLICKED(IDC_BTNADD, OnBtnadd)
|
|
ON_BN_CLICKED(IDC_BTNDELETE, OnBtndelete)
|
|
ON_BN_CLICKED(IDC_BTNDONE, OnBtndone)
|
|
ON_CBN_CLOSEUP(IDC_CBSTATUSITEMLIST, OnCloseupCbstatusitemlist)
|
|
ON_BN_CLICKED(IDC_BTNCOLOR, OnBtncolor)
|
|
ON_EN_KILLFOCUS(IDC_EDSTATUSITEM, OnKillfocusEdstatusitem)
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CProbStatDlg message handlers
|
|
|
|
void CProbStatDlg::OnBtnadd()
|
|
{
|
|
CString q,text;
|
|
if(m_bAddMode)
|
|
{//save
|
|
m_edStatusItem.GetWindowText(text);
|
|
if(text.IsEmpty())
|
|
{
|
|
AfxMessageBox("You haven't entered any text, click on Cancel if don't want to add an item");
|
|
m_edStatusItem.SetFocus();
|
|
return;
|
|
}
|
|
q.Format("SELECT probstat.notes "
|
|
"FROM probstat WHERE (((probstat.notes)=\"%s\"));",text);
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())
|
|
{
|
|
AfxMessageBox("There is already an item with this name");
|
|
m_edStatusItem.SetFocus();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
q.Format("INSERT INTO probstat ( notes, red, green, blue ) "
|
|
"SELECT \"%s\", %u, %u, %u;",text,m_lRed,m_lGreen,m_lBlue);
|
|
rs->Ex(q);
|
|
rs->Close();
|
|
}
|
|
|
|
|
|
m_cbStatusItemsList.ShowWindow(TRUE);
|
|
m_lblStatusList.ShowWindow(TRUE);
|
|
m_btnColor.ShowWindow(TRUE);
|
|
m_lblSample.ShowWindow(TRUE);
|
|
m_BtnDelete.SetWindowText("Delete");
|
|
m_BtnAdd.SetWindowText("Add");
|
|
m_BtnDone.ShowWindow(TRUE);
|
|
m_edStatusItem.SetFocus();
|
|
FillList();
|
|
m_bAddMode=false;
|
|
|
|
|
|
}
|
|
else
|
|
{//go to add mode
|
|
m_edStatusItem.SetWindowText("");
|
|
m_btnColor.ShowWindow(FALSE);
|
|
m_lblSample.ShowWindow(FALSE);
|
|
m_cbStatusItemsList.ShowWindow(FALSE);
|
|
m_lblStatusList.ShowWindow(FALSE);
|
|
m_BtnDelete.SetWindowText("Cancel");
|
|
m_BtnAdd.SetWindowText("Save");
|
|
m_BtnDone.ShowWindow(FALSE);
|
|
m_edStatusItem.SetFocus();
|
|
m_bAddMode=true;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProbStatDlg::OnBtndelete()
|
|
{
|
|
CString q;
|
|
long count;
|
|
|
|
if(m_bAddMode)
|
|
{
|
|
|
|
m_cbStatusItemsList.ShowWindow(TRUE);
|
|
m_lblStatusList.ShowWindow(TRUE);
|
|
m_BtnDelete.SetWindowText("Delete");
|
|
m_BtnAdd.SetWindowText("Add");
|
|
m_BtnDone.ShowWindow(TRUE);
|
|
m_edStatusItem.SetFocus();
|
|
FillList();
|
|
m_bAddMode=false;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
if(m_cbStatusItemsList.GetCurrentRowID()=="1")
|
|
{
|
|
AfxMessageBox("You can't delete this item");
|
|
return;
|
|
}
|
|
q.Format("SELECT Count(probs.id) AS itemcount "
|
|
"FROM probs INNER JOIN probstat ON probs.status = probstat.id "
|
|
"GROUP BY probstat.id "
|
|
"HAVING (((probstat.id)=%s));",m_cbStatusItemsList.GetCurrentRowID());
|
|
//m_pApp->ShowStuff(q);
|
|
rs->Query(q);
|
|
|
|
if(!rs->IsEmpty())
|
|
{
|
|
rs->FetchField("itemcount",&count);
|
|
//v1.9.4.5 changed %s below to %u was causing a crash
|
|
q.Format("You can't delete this item.\r\n"
|
|
"It's in use on %u workorders in the system.",count);
|
|
AfxMessageBox(q);
|
|
return;
|
|
|
|
}
|
|
else
|
|
{
|
|
if(AfxMessageBox("Delete this status item?",MB_YESNO)==IDYES)
|
|
{
|
|
q.Format("DELETE probstat.id, probstat.* "
|
|
"FROM probstat WHERE (((probstat.id)=%s));",m_cbStatusItemsList.GetCurrentRowID());
|
|
rs->Ex(q);
|
|
|
|
FillList();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
void CProbStatDlg::OnBtndone()
|
|
{
|
|
// TODO: Add your control notification handler code here
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CProbStatDlg::OnOK()
|
|
{
|
|
// TODO: Add extra validation here
|
|
|
|
|
|
}
|
|
|
|
CProbStatDlg::~CProbStatDlg()
|
|
{
|
|
m_pApp->rsPool->ReleaseRS(&rs->m_nID);
|
|
}
|
|
|
|
void CProbStatDlg::FillList()
|
|
{
|
|
|
|
CString q,strData,strIndex;
|
|
long lData;
|
|
//FILL STATUS LIST
|
|
m_cbStatusItemsList.Clear();
|
|
rs->Query("SELECT probstat.id, probstat.notes FROM probstat ORDER BY probstat.id;");
|
|
|
|
if(!rs->IsEmpty())
|
|
{
|
|
do
|
|
{
|
|
rs->FetchField("notes",&strData);
|
|
rs->FetchField("id",&lData);
|
|
strIndex.Format("%u",lData);
|
|
m_cbStatusItemsList.AddRow(strData,strIndex);
|
|
}while(rs->MoveForward());
|
|
m_cbStatusItemsList.SetCurSel(0);
|
|
OnCloseupCbstatusitemlist();
|
|
}
|
|
|
|
}
|
|
|
|
BOOL CProbStatDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
m_lblSample.SetFontName("Arial");
|
|
m_lblSample.SetTextColor(RGB(0,0,0));
|
|
m_lblSample.SetBkColor(RGB(255,255,255));
|
|
m_lblSample.SetFontSize(22);
|
|
m_lblSample.SetFontBold(TRUE);
|
|
|
|
FillList();
|
|
// TODO: Add extra initialization here
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CProbStatDlg::OnCloseupCbstatusitemlist()
|
|
{
|
|
CString q;
|
|
m_edStatusItem.SetWindowText(m_cbStatusItemsList.GetCurrentRowText());
|
|
|
|
q.Format("SELECT probstat.* FROM probstat "
|
|
"WHERE (((probstat.id)=%s));",m_cbStatusItemsList.GetCurrentRowID());
|
|
rs->QueryReadOnly(q);
|
|
if(!rs->IsEmpty())
|
|
{
|
|
rs->FetchField("red",&m_lRed);
|
|
rs->FetchField("green",&m_lGreen);
|
|
rs->FetchField("blue",&m_lBlue);
|
|
|
|
}
|
|
else
|
|
{
|
|
m_lRed=0;
|
|
m_lGreen=0;
|
|
m_lBlue=0;
|
|
}
|
|
|
|
m_lblSample.SetTextColor(RGB(m_lRed,m_lGreen,m_lBlue));
|
|
|
|
|
|
//CString id;
|
|
//id=m_cbStatusItemsList.GetCurrentRowID();
|
|
|
|
|
|
}
|
|
|
|
|
|
//COLOR CHANGE?
|
|
void CProbStatDlg::OnBtncolor()
|
|
{
|
|
CString q;
|
|
|
|
CColorDialog dlg(RGB(255,0,0),CC_SOLIDCOLOR/*|CC_PREVENTFULLOPEN*/);
|
|
|
|
if (dlg.DoModal() == IDOK)
|
|
{
|
|
COLORREF color = dlg.GetColor();
|
|
|
|
m_lRed=GetRValue(color);
|
|
m_lGreen=GetGValue(color);
|
|
m_lBlue=GetBValue(color);
|
|
|
|
|
|
q.Format("UPDATE probstat SET probstat.red = %u, probstat.green = %u, probstat.blue = %u "
|
|
"WHERE (((probstat.id)=%s));",
|
|
m_lRed, m_lGreen, m_lBlue,
|
|
m_cbStatusItemsList.GetCurrentRowID());
|
|
|
|
rs->Ex(q);
|
|
|
|
m_lblSample.SetTextColor(RGB(m_lRed,m_lGreen,m_lBlue));
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void CProbStatDlg::OnKillfocusEdstatusitem()
|
|
{
|
|
CString text,q;
|
|
|
|
if(m_bAddMode || m_edStatusItem.GetModify()==FALSE) return;
|
|
m_edStatusItem.GetWindowText(text);
|
|
if(text.IsEmpty())
|
|
{
|
|
AfxMessageBox("You haven't entered any text, this field can not be blank");
|
|
m_edStatusItem.Undo();
|
|
m_edStatusItem.SetFocus();
|
|
return;
|
|
}
|
|
q.Format("SELECT probstat.notes "
|
|
"FROM probstat WHERE (((probstat.notes)=\"%s\"));",text);
|
|
rs->Query(q);
|
|
if(!rs->IsEmpty())
|
|
{
|
|
AfxMessageBox("There is already an item with this name");
|
|
m_edStatusItem.SetFocus();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
q.Format("UPDATE probstat SET probstat.notes = \"%s\" "
|
|
"WHERE (((probstat.id)=%s));", text, m_cbStatusItemsList.GetCurrentRowID());
|
|
|
|
rs->Ex(q);
|
|
rs->Close();
|
|
}
|
|
|
|
m_edStatusItem.SetModify(FALSE);
|
|
FillList();
|
|
|
|
}
|