// ServiceDlg.cpp : implementation file // #include "stdafx.h" #include "KBEditors.h" #include "KBEditorsDoc.h" #include "ServiceDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CServiceDlg dialog CServiceDlg::CServiceDlg(CWnd* pParent /*=NULL*/) : CDialog(CServiceDlg::IDD, pParent) { //{{AFX_DATA_INIT(CServiceDlg) //}}AFX_DATA_INIT } void CServiceDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CServiceDlg) DDX_Control(pDX, IDC_ServiceName, m_ServiceName); DDX_Control(pDX, IDC_OutProp, m_ProOutput); DDX_Control(pDX, IDC_OutCpt, m_CptOutput); DDX_Control(pDX, IDC_TriggerName, m_TriggerName); DDX_Control(pDX, IDC_TriggerType, m_TriggerType); DDX_Control(pDX, IDC_VAL, m_ValCompo); DDX_Control(pDX, IDC_OP, m_OpCompo); DDX_Control(pDX, IDC_PROP, m_PropCompo); DDX_Control(pDX, IDC_CPT, m_CptCompo); DDX_Control(pDX, IDC_MSFLEXGRID1, m_ConditionFlex); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CServiceDlg, CDialog) //{{AFX_MSG_MAP(CServiceDlg) ON_CBN_SELCHANGE(IDC_CPT, OnSelchangeCpt) ON_CBN_SELCHANGE(IDC_PROP, OnSelchangeProp) ON_CBN_SELCHANGE(IDC_OP, OnSelchangeOp) ON_CBN_SELCHANGE(IDC_OutCpt, OnSelchangeOutCpt) ON_CBN_SELCHANGE(IDC_TriggerType, OnSelchangeTriggerType) ON_CBN_SELCHANGE(IDC_ServiceName, OnSelchangeServiceName) ON_BN_CLICKED(IDC_ADDCONDITION, OnAddcondition) ON_BN_CLICKED(IDC_DELCONDITION, OnDelcondition) ON_BN_CLICKED(IDC_ADDSERVICE, OnAddservice) ON_BN_CLICKED(IDC_DELSERVICE, OnDelservice) ON_BN_CLICKED(IDC_NEWSERVICE, OnNewservice) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CServiceDlg message handlers void CServiceDlg::ClearGrid() { CString ss; for(int i = m_ConditionFlex.GetRows();i >2;i--){ m_ConditionFlex.RemoveItem(i); m_ConditionFlex.Refresh(); } ss.Empty(); m_ConditionFlex.SetTextMatrix(1,0,(LPCTSTR) ss); m_ConditionFlex.SetTextMatrix(1,1,(LPCTSTR) ss); m_ConditionFlex.SetTextMatrix(1,2,(LPCTSTR) ss); m_ConditionFlex.SetTextMatrix(1,3,(LPCTSTR) ss); } BOOL CServiceDlg::OnInitDialog() { CDialog::OnInitDialog(); CenterWindow(GetDesktopWindow()); FillCptCompo(); FillOutputCompo(); if(m_Doc->m_ServiceList.GetCount() <=0) return TRUE; CString TriggerCond = FillServiceListCptPropTriggerNameType(); DecomposeTriggerCondition(TriggerCond); // FillMatrixCptPropOpVal(strCpt,strProp,strOp,strVal); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } CString CServiceDlg::FillServiceListCptPropTriggerNameType() { CString strSer, ssCpt,ssProp; POSITION posSer = m_Doc->m_ServiceList.GetStartPosition(); CService * Service; while (posSer !=NULL) { m_Doc->m_ServiceList.GetNextAssoc(posSer,strSer,Service); m_ServiceName.AddString(strSer); } m_ServiceName.SelectString(-1,Service->ServiceName); DecomposeCptProp(Service->Output,ssCpt,ssProp); m_ProOutput.AddString(ssProp); m_ProOutput.SelectString(-1,ssProp); m_CptOutput.AddString(ssCpt); m_CptOutput.SelectString(-1,ssCpt); m_TriggerName.AddString(Service->Input); m_TriggerName.SelectString(-1,Service->Input); m_TriggerType.AddString(Service->InputType); m_TriggerType.SelectString(-1,Service->InputType); return Service->TriggerCondition; } void CServiceDlg::FillCptCompo() { CString str ; POSITION pos = m_Doc->m_CptList.GetStartPosition(); while (pos !=NULL) { m_Doc->m_CptList.GetNextAssoc(pos,str,m_Doc->Cpt); if (m_Doc->Cpt->m_PropList.GetCount() > 0) { m_CptCompo.AddString(m_Doc->Cpt->NameL); } } } void CServiceDlg::FillOutputCompo() { CString str1 ; POSITION pos1 = m_Doc->m_CptList.GetStartPosition(); while (pos1 !=NULL) { m_Doc->m_CptList.GetNextAssoc(pos1,str1,m_Doc->Cpt); if (m_Doc->Cpt->m_PropList.GetCount() > 0) { m_CptOutput.AddString(m_Doc->Cpt->NameL); } } } void CServiceDlg::DecomposeTriggerCondition(CString str) { for(int pos = 0;pos' || str[pos] =='<')) strOp = strOp + str[pos++]; while(pos < str.GetLength() && str[pos] != '|'){ if(str[pos] == '|')pos++; strVal = strVal + str[pos++]; } FillMatrixCptPropOpVal(strCpt,strProp,strOp,strVal); } } void CServiceDlg:: FillMatrixCptPropOpVal(CString strCpt,CString strProp,CString strOp,CString strVal) { m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,0,(LPCTSTR) strCpt); m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,1,(LPCTSTR) strProp); m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,2,(LPCTSTR) strOp); m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,3,(LPCTSTR) strVal); m_ConditionFlex.SetRows(m_ConditionFlex.GetRows()+1); } void CServiceDlg::SeeDoc(CKBEditorsDoc*Doc) { m_Doc = Doc; } void CServiceDlg::OnSelchangeCpt() { int Sel = m_CptCompo.GetCurSel(); if (Sel < 0 ) return; CString str; m_CptCompo.GetLBText(Sel,str); m_Doc->m_CptList.Lookup(str,m_Doc->Cpt); m_PropCompo.ResetContent(); POSITION pos = m_Doc->Cpt->m_PropList.GetStartPosition(); while (pos !=NULL) { CString str1; m_Doc->Cpt->m_PropList.GetNextAssoc(pos,str1,m_Doc->Prop); m_PropCompo.AddString(str1); } m_PropCompo.SetCurSel(0); m_OpCompo.SetCurSel(0); OnSelchangeProp(); m_ValCompo.SetCurSel(0); } void CServiceDlg::OnSelchangeProp() { int SelCpt = m_CptCompo.GetCurSel(); if (SelCpt < 0 ) return; CString strCpt; m_CptCompo.GetLBText(SelCpt,strCpt); m_Doc->m_CptList.Lookup(strCpt,m_Doc->Cpt); int SelProp = m_PropCompo.GetCurSel(); if (SelProp < 0 ) return; CString strProp; m_PropCompo.GetLBText(SelProp,strProp); m_Doc->Cpt->m_PropList.Lookup(strProp,m_Doc->Prop); m_ValCompo.ResetContent(); POSITION pos11 = m_Doc->Prop->m_LegalValueList.GetStartPosition(); while (pos11 !=NULL) { CString str11; CString str; m_Doc->Prop->m_LegalValueList.GetNextAssoc(pos11,str,str11); m_ValCompo.AddString(str); } m_OpCompo.SetCurSel(0); m_ValCompo.SetCurSel(0); } void CServiceDlg::OnSelchangeOp() { // TODO: Add your control notification handler code here } void CServiceDlg::OnSelchangeOutCpt() { int Sel = m_CptOutput.GetCurSel(); if (Sel < 0 ) return; CString str; m_CptOutput.GetLBText(Sel,str); m_Doc->m_CptList.Lookup(str,m_Doc->Cpt); m_ProOutput.ResetContent(); POSITION pos = m_Doc->Cpt->m_PropList.GetStartPosition(); while (pos !=NULL) { CString str1; m_Doc->Cpt->m_PropList.GetNextAssoc(pos,str1,m_Doc->Prop); m_ProOutput.AddString(str1); } m_ProOutput.SetCurSel(0); } void CServiceDlg::OnSelchangeTriggerType() { int Sel = m_TriggerType.GetCurSel(); if (Sel < 0 ) return; POSITION posCluster,posInference,posFunction,posTable; switch(Sel) { case 0: //Cluster m_TriggerName.ResetContent(); posCluster =m_Doc->m_ClusterList.GetStartPosition(); while (posCluster) { CCluster * Cluster; CString str ; m_Doc->m_ClusterList.GetNextAssoc(posCluster,str,Cluster); m_TriggerName.AddString(str); } break; case 1: //Function m_TriggerName.ResetContent(); break; case 2: //Inference posInference =m_Doc->m_InferenceList.GetStartPosition(); while (posInference) { CInference * Inference; CString str ; m_Doc->m_InferenceList.GetNextAssoc(posInference,str,Inference); m_TriggerName.AddString(str); } break; case 3: //Table m_TriggerName.ResetContent(); break; } } void CServiceDlg::OnSelchangeServiceName() { CString strSerName; CService* Service; int ss = m_ServiceName.GetCurSel(); if(ss<0) return; m_ServiceName.GetLBText(ss,strSerName); m_Doc->m_ServiceList.Lookup(strSerName,Service); CString ssCpt,ssProp; DecomposeCptProp(Service->Output,ssCpt,ssProp); m_ProOutput.SelectString(-1,ssProp); m_CptOutput.SelectString(-1,ssCpt); m_TriggerName.SelectString(-1,Service->Input); m_TriggerType.SelectString(-1,Service->InputType); ClearGrid(); DecomposeTriggerCondition(Service->TriggerCondition); } void CServiceDlg::OnAddcondition() { CString strCpt; CString strProp; CString strVal; CString strOp; if(m_CptCompo.GetCurSel()<0) return; if(m_PropCompo.GetCurSel()<0) return; if(m_ValCompo.GetCurSel()<0) return; if(m_OpCompo. GetCurSel()<0) return; m_CptCompo.GetLBText( m_CptCompo.GetCurSel(),strCpt); m_PropCompo.GetLBText(m_PropCompo.GetCurSel(),strProp); m_ValCompo.GetLBText( m_ValCompo.GetCurSel(),strVal); m_OpCompo.GetLBText( m_OpCompo.GetCurSel(),strOp); CRule R; CString strType = R.GetType(strCpt,strProp,&m_Doc->m_CptList); if(strType == "nominal" || strType == "Multi-Value"|| strType == "string") strVal = "\"" + strVal + "\""; m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,0,(LPCTSTR) strCpt); m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,1,(LPCTSTR) strProp); m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,2,(LPCTSTR) strOp); m_ConditionFlex.SetTextMatrix(m_ConditionFlex.GetRows()-1,3,(LPCTSTR) strVal); m_ConditionFlex.SetRows(m_ConditionFlex.GetRows()+1); } void CServiceDlg::OnDelcondition() { if(m_ConditionFlex.GetRows()<=2) return; int R = m_ConditionFlex.GetRow(); CString strCpt = m_ConditionFlex.GetTextMatrix(R,0); CString strProp = m_ConditionFlex.GetTextMatrix(R,1); CString strOp = m_ConditionFlex.GetTextMatrix(R,2); CString strVal = m_ConditionFlex.GetTextMatrix(R,3); if(strCpt.IsEmpty()) return; if(strProp.IsEmpty()) return; if(strOp.IsEmpty()) return; if(strVal.IsEmpty()) return; m_ConditionFlex.RemoveItem(R); } void CServiceDlg::OnAddservice() { CString strCpt; CString strProp; CString strVal; CString strOp; CString strServiceName; CString strTriggerCond; CString strInput; CString strInputType; CString strOutput; m_ServiceName.GetWindowText(strServiceName); if(strServiceName.IsEmpty()){ AfxMessageBox("Service Name Must be not empty"); return; } m_ServiceName.AddString(strServiceName); m_ServiceName.SelectString(-1,strServiceName); if(m_TriggerName.GetCurSel()<0){ AfxMessageBox("Trigger Name Must be not empty"); return; } if(m_TriggerType.GetCurSel()<0){ AfxMessageBox("Trigger Type Must be not empty"); return; } if(m_CptOutput.GetCurSel()<0){ AfxMessageBox("Output Concept Name Must be not empty"); return; } if(m_ProOutput.GetCurSel()<0){ AfxMessageBox("Output Property Name Must be not empty"); return; } if(m_ConditionFlex.GetRows()<=2){ CString strCpt = m_ConditionFlex.GetTextMatrix(0,0); if(strCpt.IsEmpty()){ AfxMessageBox("Condition Name Must be not empty"); return; } } strTriggerCond = GetTriggerCondition(); m_ServiceName.GetLBText( m_ServiceName.GetCurSel(),strServiceName); m_TriggerName.GetLBText( m_TriggerName.GetCurSel(),strInput); m_TriggerType.GetLBText( m_TriggerType.GetCurSel(),strInputType); CString o1,o2; m_CptOutput.GetLBText(m_CptOutput.GetCurSel(),o1); m_ProOutput.GetLBText(m_ProOutput.GetCurSel(),o2); strOutput = "@" + o1+"." + o2; CService* Ser = new CService; Ser->TriggerCondition = strTriggerCond; Ser->ServiceName = strServiceName; Ser->Input = strInput; Ser->InputType = strInputType; Ser->Output = strOutput; m_Doc->m_ServiceList.SetAt(strServiceName,Ser); AfxMessageBox("Service added Successfully"); m_Doc->OnSaveDocument(m_Doc->AppName); } void CServiceDlg::OnDelservice() { if(m_Doc->m_ServiceList.GetCount() <=0) return; int Sel = m_ServiceName.GetCurSel(); if (Sel < 0 ) return; CString str1; m_ServiceName.GetLBText(Sel,str1); m_ServiceName.DeleteString(Sel); CService * Ser; m_Doc->m_ServiceList.Lookup(str1,Ser); delete Ser; m_Doc->m_ServiceList.RemoveKey(str1); m_TriggerName.ResetContent(); // m_ServiceName.SetCurSel(0); // OnSelchangeServiceName(); OnNewservice(); AfxMessageBox("Service Deleted Successfully"); m_Doc->OnSaveDocument(m_Doc->AppName); } CString CServiceDlg::GetTriggerCondition() { CString temp; for (int i = 1 ;i