// SnREdit.cpp : implementation file // #include "stdafx.h" #include "sp.h" #include "SnREdit.h" #include "NonClientsDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSnREdit dialog CSnREdit::CSnREdit(CWnd* pParent /*=NULL*/) : CDialog(CSnREdit::IDD, pParent) { //{{AFX_DATA_INIT(CSnREdit) //}}AFX_DATA_INIT m_pApp = (CSpApp*)AfxGetApp(); /* rs = new GZRset("Error: Ship/Receive rs."); rs->SetConnect(m_pApp->strConnectString); */ //Initialize recordset pointer rs=m_pApp->rsPool->GetRS("CSnREdit"); cfm = new CgzCurrencyFormatter; m_strSelectedSentTo="0"; m_strSelectedSentVia="0"; bModified=false; k=new GZK; k->GZSetUniqueKey(40); } CSnREdit::~CSnREdit() { m_pApp->rsPool->ReleaseRS(&rs->m_nID); delete cfm; delete k; } void CSnREdit::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSnREdit) DDX_Control(pDX, IDC_LBLWO, m_lblInfo); DDX_Control(pDX, IDC_LBLREPAIRCTRS, m_lblRepairCenters); DDX_Control(pDX, IDC_LBLMANUFACTURERS, m_lblManufacturers); DDX_Control(pDX, IDC_LBLSENTVIA, m_lblSentVia); DDX_Control(pDX, IDC_LBLETARECEIVED, m_lblEtaReceived); DDX_Control(pDX, IDC_EDWAYBILL, m_edWaybill); DDX_Control(pDX, IDC_EDRMA, m_edRMA); DDX_Control(pDX, IDC_EDNOTES, m_edNotes); DDX_Control(pDX, IDC_EDCOST, m_edCost); DDX_Control(pDX, IDC_EDCHARGE, m_edCharge); DDX_Control(pDX, IDC_DTSENT, m_dtSent); DDX_Control(pDX, IDC_DTRECETA, m_dtRecEta); DDX_Control(pDX, IDC_CKRECEIVED, m_ckReceived); DDX_Control(pDX, IDC_CBSENTVIA, m_cbSentVia); DDX_Control(pDX, IDC_CBSENTTO, m_cbSentTo); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSnREdit, CDialog) //{{AFX_MSG_MAP(CSnREdit) ON_EN_KILLFOCUS(IDC_EDCHARGE, OnKillfocusEdcharge) ON_EN_KILLFOCUS(IDC_EDCOST, OnKillfocusEdcost) ON_BN_CLICKED(IDC_CKRECEIVED, OnCkreceived) ON_BN_CLICKED(IDC_LBLMANUFACTURERS, OnLblmanufacturers) ON_BN_CLICKED(IDC_LBLREPAIRCTRS, OnLblrepairctrs) ON_BN_CLICKED(IDC_LBLSENTVIA, OnLblsentvia) ON_CBN_CLOSEUP(IDC_CBSENTTO, OnCloseupCbsentto) ON_CBN_CLOSEUP(IDC_CBSENTVIA, OnCloseupCbsentvia) ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DTRECETA, OnDatetimechangeDtreceta) ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DTSENT, OnDatetimechangeDtsent) ON_EN_KILLFOCUS(IDC_EDNOTES, OnKillfocusEdnotes) ON_EN_KILLFOCUS(IDC_EDRMA, OnKillfocusEdrma) ON_EN_KILLFOCUS(IDC_EDWAYBILL, OnKillfocusEdwaybill) ON_BN_CLICKED(IDC_BTNDONE, OnBtndone) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSnREdit message handlers BOOL CSnREdit::OnInitDialog() { CString q,strData; long lData; bool bData; COleCurrency crData; COleDateTime dtData; CDialog::OnInitDialog(); //"Hyperlink-o-size" labels m_lblManufacturers.SetTextColor(RGB(0,0,255)); m_lblManufacturers.SetFontUnderline(TRUE); m_lblManufacturers.SetLink(TRUE); m_lblManufacturers.SetLinkCursor(m_pApp->hcHand); m_lblManufacturers.SetLinkURL(""); m_lblRepairCenters.SetTextColor(RGB(0,0,255)); m_lblRepairCenters.SetFontUnderline(TRUE); m_lblRepairCenters.SetLink(TRUE); m_lblRepairCenters.SetLinkCursor(m_pApp->hcHand); m_lblRepairCenters.SetLinkURL(""); m_lblSentVia.SetTextColor(RGB(0,0,255)); m_lblSentVia.SetFontUnderline(TRUE); m_lblSentVia.SetLink(TRUE); m_lblSentVia.SetLinkCursor(m_pApp->hcHand); m_lblSentVia.SetLinkURL(""); //FILL PICKLISTS FillLists(); //ATTEMPT TO FILL FIELDS /* q.Format("SELECT subrepair.*, probs.wolink, users.first, users.last " "FROM (subrepair LEFT JOIN probs ON subrepair.link = probs.id) LEFT JOIN users ON subrepair.creator = users.id " "WHERE (((subrepair.id)=%s));",m_strSubRepairID); */ q.Format("SELECT subrepair.*, probs.wolink, users.first, users.last, [nonclients]![company_person] & \" \" & IIf(IsNull([unitmodels]![description]),[unitmodels]![model],[unitmodels]![description]) & \" \" & IIf(IsNull([sn]),\"\",\"sn:\" & [sn]) AS item " "FROM ((((subrepair LEFT JOIN probs ON subrepair.link = probs.id) LEFT JOIN users ON subrepair.creator = users.id) LEFT JOIN units ON probs.unit = units.id) LEFT JOIN unitmodels ON units.model = unitmodels.id) LEFT JOIN nonclients ON unitmodels.manufacturer = nonclients.id " "WHERE (((subrepair.id)=%s));",m_strSubRepairID); #ifdef _DEBUG m_pApp->ShowStuff(q); #endif rs->Query(q); m_lblEtaReceived.SetWindowText("Return E.T.A."); m_ckReceived.SetCheck(FALSE); if(rs->IsEmpty())//No record {//set to defaults m_cbSentTo.Select(m_strSelectedSentTo); m_cbSentVia.Select(m_strSelectedSentVia); m_dtSent.SetTime(COleDateTime::GetCurrentTime()); m_dtRecEta.SetTime(COleDateTime::GetCurrentTime()); m_edCharge.SetWindowText("$0.00"); m_edCost.SetWindowText("$0.00"); } else //there is a record { //fill the fields rs->FetchField("isback",&bData); if(bData) { m_lblEtaReceived.SetWindowText("Received back:"); m_ckReceived.SetCheck(TRUE); m_bInitiallyReceived=true; rs->FetchField("received",&dtData); m_dtRecEta.SetTime(dtData); } else { m_bInitiallyReceived=false; rs->FetchField("eta",&dtData); m_dtRecEta.SetTime(dtData); } rs->FetchField("where",&lData); m_cbSentTo.Select(lData); rs->FetchField("sentvia",&lData); m_cbSentVia.Select(lData); rs->FetchField("sent",&dtData); m_dtSent.SetTime(dtData); rs->FetchField("waybill",&strData); m_edWaybill.SetWindowText(strData); rs->FetchField("rma",&strData); m_edRMA.SetWindowText(strData); rs->FetchField("cost",&crData); m_edCost.SetWindowText(cfm->Format(crData)); rs->FetchField("charge",&crData); m_edCharge.SetWindowText(cfm->Format(crData)); rs->FetchField("notes",&strData); m_edNotes.SetWindowText(strData); rs->FetchField("wolink",&lData); strData.Format("Subrepair item from Workorder # %u",lData); m_strWorkorderID.Format("%u",lData); SetWindowText(strData); rs->FetchField("first",&strData); m_strOrderer=strData; rs->FetchField("last",&strData); m_strOrderer+=" " + strData; //for send mail function if required rs->FetchField("creator",&lData); m_strOrdererID.Format("%u",lData); rs->FetchField("item",&strData); m_lblInfo.SetWindowText(strData); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } //********************************* void CSnREdit::FillLists() { CString q,strData,strIndex; long lData; m_cbSentVia.Clear(); m_cbSentVia.AddRow(" < na/unknown >","0"); rs->Query("SELECT nonclients.company_person, nonclients.id " "FROM nonclients WHERE (((nonclients.type)=2));");//type 2 = couriers/shippers if(!rs->IsEmpty()) { rs->MoveFirst(); do { rs->FetchField("company_person",&strData); rs->FetchField("id",&lData); strIndex.Format("%u",lData); m_cbSentVia.AddRow(strData,strIndex); }while(rs->MoveForward()); } m_cbSentTo.Clear(); m_cbSentTo.AddRow(" < Not sent out >","0"); rs->Query("SELECT nonclients.company_person, nonclients.id " "FROM nonclients WHERE (((nonclients.type)=1)) OR (((nonclients.type)=3));");//type 1 = subcontractors repair centers 3=manufact if(!rs->IsEmpty()) { rs->MoveFirst(); do { rs->FetchField("company_person",&strData); rs->FetchField("id",&lData); strIndex.Format("%u",lData); m_cbSentTo.AddRow(strData,strIndex); }while(rs->MoveForward()); } m_cbSentTo.Select(m_strSelectedSentTo); m_cbSentVia.Select(m_strSelectedSentVia); } void CSnREdit::OnKillfocusEdcharge() { COleCurrency crData; CString str; if(m_edCharge.GetModify()) bModified=true; m_edCharge.GetWindowText(str); if(crData.ParseCurrency(str)!=TRUE) { AfxMessageBox("I could not interpret your entry in the charge field\r\n" "I can't save this field until a valid currency entry is made.\r\n" "If you want to leave it blank put a zero in it."); m_edCharge.SetFocus(); return; } m_edCharge.SetWindowText(cfm->Format(crData)); } void CSnREdit::OnKillfocusEdcost() { COleCurrency crData; CString str; if(m_edCost.GetModify()) bModified=true; m_edCost.GetWindowText(str); if(crData.ParseCurrency(str)!=TRUE) { AfxMessageBox("I could not interpret your entry in the cost field\r\n" "I can't save this field until a valid currency entry is made.\r\n" "If you want to leave it blank, put a zero in it."); m_edCost.SetFocus(); return; } m_edCost.SetWindowText(cfm->Format(crData)); } void CSnREdit::OnCkreceived() { if(m_ckReceived.GetCheck()==TRUE)//user has indicated receipt { m_lblEtaReceived.SetWindowText("Received back:"); m_dtRecEta.SetTime(COleDateTime::GetCurrentTime()); } else//user has indicated not received for some unknown reason { //probably just to try the patience of the programmer //and the resourcefulness of his error checking m_lblEtaReceived.SetWindowText("Return E.T.A."); m_dtRecEta.SetTime(COleDateTime::GetCurrentTime()); //bug avoidance:make sure when header saves this page //the dates are set correctly depending on user selection } bModified=true; } void CSnREdit::OnLblmanufacturers() { m_strSelectedSentTo=m_cbSentTo.GetCurrentRowID(); m_strSelectedSentVia=m_cbSentVia.GetCurrentRowID(); PopupNonClients(3); FillLists(); } void CSnREdit::OnLblrepairctrs() { m_strSelectedSentTo=m_cbSentTo.GetCurrentRowID(); m_strSelectedSentVia=m_cbSentVia.GetCurrentRowID(); PopupNonClients(1); FillLists(); } void CSnREdit::OnLblsentvia() { m_strSelectedSentVia=m_cbSentVia.GetCurrentRowID(); m_strSelectedSentTo=m_cbSentTo.GetCurrentRowID(); PopupNonClients(2); FillLists(); } void CSnREdit::PopupNonClients(long type) { CNonClientsDlg d; long ltype; ltype=type; d.SetType(<ype); d.DoModal(); } void CSnREdit::OnCloseupCbsentto() { bModified=true; } void CSnREdit::OnCloseupCbsentvia() { bModified=true; } void CSnREdit::OnDatetimechangeDtreceta(NMHDR* pNMHDR, LRESULT* pResult) { bModified=true; *pResult = 0; } void CSnREdit::OnDatetimechangeDtsent(NMHDR* pNMHDR, LRESULT* pResult) { bModified=true; COleDateTime dtData; m_dtSent.GetTime(dtData); m_dtRecEta.SetTime(dtData); *pResult = 0; } void CSnREdit::OnKillfocusEdnotes() { if(m_edNotes.GetModify()) bModified=true; } void CSnREdit::OnKillfocusEdrma() { if(m_edRMA.GetModify()) bModified=true; } void CSnREdit::OnKillfocusEdwaybill() { if(m_edWaybill.GetModify()) bModified=true; } void CSnREdit::OnBtndone() { CString profile,q,strData,msg,subj,unitdesc; COleDateTime dtData; COleCurrency crData; bool bReceived=false; long lData; if(bModified) { q.Format("SELECT subrepair.*, probs.wolink, users.first, users.last, [nonclients]![company_person] & \" \" & IIf(IsNull([unitmodels]![description]),[unitmodels]![model],[unitmodels]![description]) & \" \" & IIf(IsNull([sn]),\"\",\"sn:\" & [sn]) AS item " "FROM ((((subrepair LEFT JOIN probs ON subrepair.link = probs.id) LEFT JOIN users ON subrepair.creator = users.id) LEFT JOIN units ON probs.unit = units.id) LEFT JOIN unitmodels ON units.model = unitmodels.id) LEFT JOIN nonclients ON unitmodels.manufacturer = nonclients.id " "WHERE (((subrepair.id)=%s));",m_strSubRepairID); rs->Query(q); //save changes if modified strData= m_cbSentTo.GetCurrentRowID(); lData=atol(strData); rs->UpdateField("where",&lData); m_dtSent.GetTime(dtData); rs->UpdateField("sent",&dtData); bReceived=( m_ckReceived.GetCheck() ? true : false); rs->UpdateField("isback",&bReceived); m_dtRecEta.GetTime(dtData); if(bReceived) rs->UpdateField("received",&dtData); else rs->UpdateField("eta",&dtData); strData= m_cbSentVia.GetCurrentRowID(); lData=atol(strData); rs->UpdateField("sentvia",&lData); m_edWaybill.GetWindowText(strData); rs->UpdateField("waybill",&strData); m_edRMA.GetWindowText(strData); rs->UpdateField("rma",&strData); m_edNotes.GetWindowText(strData); rs->UpdateField("notes",&strData); m_edCost.GetWindowText(strData); crData.ParseCurrency(strData); rs->UpdateField("cost",&crData); m_edCharge.GetWindowText(strData); crData.ParseCurrency(strData); rs->UpdateField("charge",&crData); dtData=COleDateTime::GetCurrentTime(); rs->UpdateField("modifier",&m_pApp->m_lusrID); rs->UpdateField("modified",&dtData); rs->SaveRecord(); rs->SaveRecord(); } //bugbug breceived being used without initialization if(m_bInitiallyReceived==false && bReceived==true) { strData.Format("Should I notify the person who created \r\n" "this sub repair record:%s \r\n" "that this item is in?",m_strOrderer); if(AfxMessageBox(strData,MB_YESNO)==IDYES) { m_lblInfo.GetWindowText(unitdesc); subj.Format("WO#%s unit shipped out has returned",m_strWorkorderID); msg.Format("%s \r\nsent away for repair has been received back.",unitdesc); SendMail(msg,subj); } } //flush rs rs->Close(); //rs->Query("SELECT subrepair.* FROM subrepair WHERE (((subrepair.id)=0));"); CDialog::OnOK(); } void CSnREdit::SendMail(CString strMsg, CString strSubject) { CString q; long lData; COleDateTime dtData,dtData2,dtData3; bool bData; //encrypt the subject and message // k->GZEncrypt(&strMsg,false); k->GZEncrypt(&strSubject,false); //save the message //open the recordset without returning a record (no id=0) rs->Query("SELECT mail.* FROM mail;"); rs->AddNewRecord(); //******************************** // START SAVING FIELDS //******************************** //FROM rs->UpdateField("from",&m_pApp->m_lusrID); //DATE: dtData=COleDateTime::GetCurrentTime(); rs->UpdateField("date",&dtData); //POPUP - wont do anything now //but in future should cause instant message bData = true; rs->UpdateField("popup",&bData); //SUBJECT rs->UpdateField("subject",&strSubject); //MESSAGE rs->UpdateField("message",&strMsg); //DELIVERY DATE //get the date, remove on the date portion which //sets the time to 0:0:0 (midnight) dtData3=COleDateTime::GetCurrentTime(); dtData2.SetDate(dtData3.GetYear(),dtData3.GetMonth(),dtData3.GetDay()); rs->UpdateField("deliverydate",&dtData2); rs->SaveRecord(); //****************** DONE SAVING FIELDS ************* //*************************************************** //retrieve the id number q.Format("SELECT mail.* FROM mail " "WHERE (((mail.from)=%u) AND ((mail.date)=#%s#));" ,m_pApp->m_lusrID,dtData.Format(_T("%m/%d/%Y %H:%M:%S"))); rs->Query(q); //should work but.... ASSERT(!rs->IsEmpty()); rs->FetchField("id",&lData); //save the recipient record q.Format("INSERT INTO mailroute ( maillink, recipient, remind ) " "SELECT %u , %s , True;",lData,m_strOrdererID); rs->Ex(q); rs->Close(); }