// DlgTasks.cpp : implementation file // #include "stdafx.h" #include "sp.h" #include "DlgTasks.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDlgTasks dialog CDlgTasks::CDlgTasks(CWnd* pParent /*=NULL*/) : CDialog(CDlgTasks::IDD, pParent) { //{{AFX_DATA_INIT(CDlgTasks) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_bAddMode=false; m_pApp= (CSpApp*)AfxGetApp(); /* rs=new GZRset("Error: Tasks dialog"); rs->SetConnect(m_pApp->strConnectString); */ //Initialize recordset pointer rs=m_pApp->rsPool->GetRS("CDlgTasks"); m_pstrReturnValue=NULL; m_strSelectedTask.Empty(); } CDlgTasks::~CDlgTasks() { m_pApp->rsPool->ReleaseRS(&rs->m_nID); } void CDlgTasks::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDlgTasks) DDX_Control(pDX, IDC_LBLTASKS, m_lblTasks); DDX_Control(pDX, IDC_CKACTIVE, m_ckActive); DDX_Control(pDX, IDC_EDMINUTES, m_edMinutes); DDX_Control(pDX, IDC_EDDETAILS, m_edDetails); DDX_Control(pDX, IDC_EDDESCRIPTION, m_edDescription); DDX_Control(pDX, IDC_CBTASKS, m_cbTasks); 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(CDlgTasks, CDialog) //{{AFX_MSG_MAP(CDlgTasks) ON_BN_CLICKED(IDC_BTNADD, OnBtnadd) ON_BN_CLICKED(IDC_BTNDELETE, OnBtndelete) ON_BN_CLICKED(IDC_BTNDONE, OnBtndone) ON_CBN_CLOSEUP(IDC_CBTASKS, OnCloseupCbtasks) ON_EN_KILLFOCUS(IDC_EDDESCRIPTION, OnKillfocusEddescription) ON_EN_KILLFOCUS(IDC_EDDETAILS, OnKillfocusEddetails) ON_EN_KILLFOCUS(IDC_EDMINUTES, OnKillfocusEdminutes) ON_BN_CLICKED(IDC_CKACTIVE, OnCkactive) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDlgTasks message handlers BOOL CDlgTasks::OnInitDialog() { CDialog::OnInitDialog(); Security(); // TODO: Add extra initialization here FillList(); if(m_bReadOnly) { m_btnAdd.ShowWindow(FALSE); m_btnDelete.ShowWindow(FALSE); m_edDescription.SetReadOnly(TRUE); m_edDetails.SetReadOnly(TRUE); m_ckActive.EnableWindow(FALSE); m_edMinutes.SetReadOnly(TRUE); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } //***************************************** void CDlgTasks::OnBtnadd() { CString strData; bool bData; long lData; if(!m_bAddMode) { //go add mode DisableAll(false); m_bAddMode=true; m_btnDelete.SetWindowText("CANCEL"); m_btnAdd.SetWindowText("SAVE"); m_btnDone.ShowWindow(FALSE); m_lblTasks.ShowWindow(FALSE); m_cbTasks.ShowWindow(FALSE); ClearFields(); return; } else {//SAVE Record m_edDescription.GetWindowText(strData); if(strData.IsEmpty()) { AfxMessageBox("You must enter a task description"); return; } if(!rs->AddNewRecord()) return; //SAVE DESCRIPTION rs->UpdateField("description",&strData); //ACTIVE bData=(m_ckActive.GetCheck() ? true : false); rs->UpdateField("active",&bData); //DETAILS m_edDetails.GetWindowText(strData); rs->UpdateField("details",&strData); //Minutes m_edMinutes.GetWindowText(strData); lData=atol(strData); rs->UpdateField("minutes",&lData); //ATTEMPT TO SAVE if(!rs->SaveRecord()) return; m_bAddMode=false; m_lblTasks.ShowWindow(TRUE); m_cbTasks.ShowWindow(TRUE); m_btnDelete.SetWindowText("Delete"); m_btnAdd.SetWindowText("Add"); m_btnDone.ShowWindow(TRUE); FillList(); m_edDescription.GetWindowText(strData); m_cbTasks.SelectString(-1,strData); OnCloseupCbtasks(); return; } } //******************************************* void CDlgTasks::OnBtndelete() { CString q; if(m_bAddMode) { m_bAddMode=false; m_lblTasks.ShowWindow(TRUE); m_cbTasks.ShowWindow(TRUE); m_btnDelete.SetWindowText("Delete"); m_btnAdd.SetWindowText("Add"); m_btnDone.ShowWindow(TRUE); FillList(); return; } //DELETE..... //check if unused and deletable //IN PMPARTS??? q.Format("SELECT probs.taskid FROM probs " "WHERE (((probs.taskid)=%s));",m_strSelectedTask); rs->Query(q); if(!rs->IsEmpty()) { AfxMessageBox("DATA INTEGRITY PROTECTION:\r\n" "This task appears in one or more workorders\r\n" "and cannot be deleted at this time."); return; } if(AfxMessageBox("Permanently delete part?",MB_YESNO)==IDYES) { q.Format("DELETE tasks.*, tasks.id " "FROM tasks WHERE (((tasks.id)=%s));",m_strSelectedTask); rs->Ex(q); m_strSelectedTask=""; FillList(); } } //****************************************** void CDlgTasks::OnBtndone() { if(m_pstrReturnValue!=NULL) *m_pstrReturnValue=m_strSelectedTask; CDialog::OnOK(); } void CDlgTasks::OnCloseupCbtasks() { //FILL FIELDS CString strData,q; bool bData; long lData; strData=m_cbTasks.GetCurrentRowID(); q.Format("SELECT tasks.* FROM tasks " "WHERE (((tasks.id)=%s));",m_cbTasks.GetCurrentRowID()); rs->Query(q); if(rs->IsEmpty()) { return; } //DESCRIPTION rs->FetchField("description",&strData); m_edDescription.SetWindowText(strData); //DETAILS rs->FetchField("details",&strData); m_edDetails.SetWindowText(strData); //ACTIVE rs->FetchField("active",&bData); m_ckActive.SetCheck(bData ? TRUE : FALSE); //MINUTES rs->FetchField("minutes",&lData); strData.Format("%u",lData); m_edMinutes.SetWindowText(strData); m_strSelectedTask=m_cbTasks.GetCurrentRowID(); } void CDlgTasks::OnKillfocusEddescription() { SaveField(&m_edDescription,"description",false); } void CDlgTasks::OnKillfocusEddetails() { SaveField(&m_edDetails,"details",true); } void CDlgTasks::OnKillfocusEdminutes() { if(m_bAddMode) return; long lData; CString strData; m_edMinutes.GetWindowText(strData); lData=atol(strData); rs->UpdateField("minutes",&lData); } //************************************************************ //SAVE EDIT CONTROL FIELD //************************************************************ bool CDlgTasks::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(); return true; } //************************************************************ //SAVE CheckBox CONTROL FIELD //************************************************************ bool CDlgTasks::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(); return true; } //********************************** void CDlgTasks::FillList() { CString strData; CString strIndex; long lData; m_cbTasks.Clear(); rs->Query("SELECT tasks.* FROM tasks " "ORDER BY tasks.description;"); if(rs->IsEmpty()) { DisableAll(true); return; } rs->MoveFirst(); do { rs->FetchField("description",&strData); rs->FetchField("id",&lData); strIndex.Format("%u",lData); m_cbTasks.AddRow(strData,strIndex); }while(rs->MoveForward()); //pretend user has selected so that other fields get filled in if(m_strSelectedTask.IsEmpty()) //first time in { m_cbTasks.SetCurSel(0); m_strSelectedTask=m_cbTasks.GetCurrentRowID(); } else//something valid was selected before so stick with it m_cbTasks.Select(m_strSelectedTask); OnCloseupCbtasks(); } //******************************* void CDlgTasks::ClearFields() { m_edDetails.SetWindowText(""); m_edDescription.SetWindowText(""); m_edMinutes.SetWindowText("0"); m_ckActive.SetCheck(TRUE); } void CDlgTasks::OnCkactive() { SaveField(&m_ckActive,"active"); } void CDlgTasks::DisableAll(bool disable) { BOOL e = disable ? FALSE : TRUE; m_btnDelete.EnableWindow(e); m_cbTasks.EnableWindow(e); m_ckActive.EnableWindow(e); m_edDescription.EnableWindow(e); m_edMinutes.EnableWindow(e); m_edDetails.EnableWindow(e); } void CDlgTasks::Security() { int x=m_pApp->Allowed(RTASKS,true); m_bReadOnly=false; if(x==2)//read only m_bReadOnly=true; if(x==0) { m_pApp->SecurityWarning(); CDialog::OnCancel(); } }