// KBEditorsView.cpp : implementation of the CKBEditorsView class // #include "stdafx.h" #include "KBEditors.h" #include "KBEditorsDoc.h" #include "KBEditorsView.h" #include "MetaKBDlg.h" #include "CptSheet.h" #include "TableDlg.h" #include "RuleSheet.h" #include "InferenceDlg.h" #include "ServiceDlg.h" #include "kbdbdlg.h" #include "GenDlg.h" #include "xmlrpc.h" #include "DesignDocument.h" #include "FunSheet.h" //{{AFX_INCLUDES() #include "webbrowser2.h" //}}AFX_INCLUDES #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CKBEditorsView IMPLEMENT_DYNCREATE(CKBEditorsView, CFormView) BEGIN_MESSAGE_MAP(CKBEditorsView, CFormView) //{{AFX_MSG_MAP(CKBEditorsView) ON_COMMAND(ID_CONCEPT, OnConcept) ON_COMMAND(ID_BUTTON32774, OnRule) ON_COMMAND(ID_Inference, OnInference) ON_COMMAND(ID_BUTTON32777, OnValidation) ON_COMMAND(ID_BUTTON32791, OnFunction) ON_COMMAND(ID_GenerateDoc, OnGenerateDoc) ON_COMMAND(ID_TableEd, OnTableEdit) ON_COMMAND(ID_Service, OnService) ON_COMMAND(ID_META_KB, OnCreateMetaKB) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CKBEditorsView construction/destruction CKBEditorsView::CKBEditorsView() : CFormView(CKBEditorsView::IDD) { //{{AFX_DATA_INIT(CKBEditorsView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // TODO: add construction code here } CKBEditorsView::~CKBEditorsView() { } void CKBEditorsView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CKBEditorsView) //}}AFX_DATA_MAP } void CKBEditorsView::OnInitialUpdate() { CFormView::OnInitialUpdate(); //GetDocument()->RPC = new CXMLRPC("http://193.227.5.59/OntoServerSameh/rpc.asp"); // GetParentFrame()->RecalcLayout(); // ResizeParentToFit(); } ///////////////////////////////////////////////////////////////////////////// // CKBEditorsView printing BOOL CKBEditorsView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CKBEditorsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CKBEditorsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void CKBEditorsView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/) { // TODO: add customized printing code here } ///////////////////////////////////////////////////////////////////////////// // CKBEditorsView diagnostics #ifdef _DEBUG void CKBEditorsView::AssertValid() const { CFormView::AssertValid(); } void CKBEditorsView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CKBEditorsDoc* CKBEditorsView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CKBEditorsDoc))); return (CKBEditorsDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CKBEditorsView message handlers void CKBEditorsView::OnConcept() { CCptSheet* m_CCptSheet = new CCptSheet("Concept Editor",this,0); m_CCptSheet->SeeDoc( GetDocument()); if (m_CCptSheet->CptDlgExist){ m_CCptSheet->Create(this); m_CCptSheet->CptDlgExist = FALSE; } // delete m_CCptSheet; } void CKBEditorsView::OnRule() { CRuleSheet* m_RuleSheet = new CRuleSheet("Rule Editor",this,0); m_RuleSheet->SeeDoc( GetDocument()); if (m_RuleSheet->RuleDlgExist) { m_RuleSheet->Create(this); m_RuleSheet->RuleDlgExist = FALSE; } } void CKBEditorsView::OnService() { /*CServiceDlg sDlg; sDlg.SeeDoc( GetDocument()); sDlg.DoModal(); */ if(GetDocument()->AppName.IsEmpty()){ AfxMessageBox("Open Knowledge Base First"); return; } if(FAILED(::CoInitialize(NULL))) return; CKBDBDlg dbDlg; dbDlg.SeeDoc( GetDocument()); dbDlg.DoModal(); /* CDBHandle ss; if(FAILED(::CoInitialize(NULL))) return; CStringArray KeyNames; CStringArray KeyVal; CStringArray KeyType; KeyNames.Add("EmployeeID"); KeyVal.Add("1"); KeyType.Add("Integer"); CString dd = ss.GetDBValue("C:\\Program Files\\Microsoft Office\\Office\\Samples\\Northwind.mdb","Employees","BirthDate",KeyNames,KeyVal,KeyType); AfxMessageBox(dd); */ /* CStringArray tt; ss.GetTables(tt); for(int i=0;iRemoveSpace(strCond); x=strCond.Find("@"); CString strConc; while(x>=0) { int pos=x+1; CString strCpt; CString strProp; while(strCond[pos] !='.') { strCpt = strCpt + strCond[pos++]; } pos++; while(pos < strCond.GetLength() && strCond[pos] != '=' && strCond[pos] !='>' && strCond[pos] !='+' && strCond[pos] !='-' && strCond[pos] !='<' && strCond[pos] !=' ' &&strCond[pos] !='*' &&strCond[pos] !='/' && strCond[pos] !='&' && strCond[pos] !='|' && strCond[pos] !='!' && strCond[pos] !=')' ) { strProp = strProp + strCond[pos++]; } strConc = "@"+strCpt + "."+ strProp; if (!GetDocument()->m_CptList.Lookup(strCpt,GetDocument()->Cpt)) { Return = FALSE; Out = Out + strCpt + " Is Not Found
"; } if (!GetDocument()->Cpt->m_PropList.Lookup(strProp,GetDocument()->Prop)) { Return = FALSE; Out = Out + "Property " + strProp + " Is Not Found in Concept " + strCpt + "
" ; } if (GetDocument()->Prop->Type == "real" || GetDocument()->Prop->Type == "integer" || GetDocument()->Prop->Type == "date") strCond.Replace(strConc,"0"); else strCond.Replace(strConc,"\"X\""); x=strCond.Find("@"); if (x==0)break; } strCond = Rule->ReplaceNow(strCond); strCond = Rule->ValidateDateFun(strCond); strCond = Rule->ReplaceAbsDate(strCond); BOOL r = Rule->CEval(strCond); delete Rule; if (r && !Return) { Out = Out + "Syntax Error
" ; } return !r; } BOOL CKBEditorsView::ValidateAction(CString strAction,CString & Out) { BOOL Return = TRUE; if (strAction.IsEmpty()) return TRUE; strAction.TrimRight();strAction.TrimLeft(); char LastCh = strAction[strAction.GetLength()-1]; if (LastCh !=';') { Out = Out + "Semicolon Missed
"; Return = FALSE; } strAction.Delete(strAction.GetLength()-1,1); strAction.Replace(";","&&"); strAction.Replace("=","=="); if(strAction.Find("=") == -1) { Out = Out + "Double Equal Used in Action
"; Return = FALSE; } return (ValidateCondition(strAction,Out)&& Return); } void CKBEditorsView::OnValidation() { CString str; // CFileDialog cfdlg(FALSE,"*.html","*.html",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"HTML Files (*.html)"); // cfdlg.DoModal(); str = "validation.htm"; //cfdlg.GetPathName(); CStdioFile OutFile(str,CFile::modeCreate | CFile::modeWrite ); // Ontology str = "Knowledge Validation"; OutFile.WriteString(str); str = "

Knowledge Validation

"; OutFile.WriteString(str); BOOL OneError = FALSE; POSITION pos = GetDocument()->m_ClusterList.GetStartPosition(); while (pos !=NULL) { GetDocument()->m_ClusterList.GetNextAssoc(pos,str,GetDocument()->Cluster); POSITION pos1 = GetDocument()->Cluster->RuleList.GetStartPosition(); BOOL written = FALSE; while (pos1 !=NULL) { CString str1; CString Out,Out1; GetDocument()->Cluster->RuleList.GetNextAssoc(pos1,str1,GetDocument()->Rule); if (!ValidateCondition(GetDocument()->Rule->GetCondition(),Out)) { if (!written) { OutFile.WriteString("

Cluster " + str+"

"); } OutFile.WriteString("

Condition of " + str1+"

"); OutFile.WriteString("

" + Out+"

"); OneError = TRUE; written = TRUE; } if (!ValidateAction(GetDocument()->Rule->GetAction(),Out1)) { if (!written) { OutFile.WriteString("

Cluster " + str+"

"); } OutFile.WriteString("

Action of " + str1+"

"); OutFile.WriteString("

" + Out1+"

"); written = TRUE; OneError = TRUE; } } } OutFile.WriteString("

Concept Validations

"); pos = GetDocument()->m_CptList.GetStartPosition(); while (pos !=NULL) { CConcept * Cpt; GetDocument()->m_CptList.GetNextAssoc(pos,str,Cpt); if (str != Cpt->NameL) { OutFile.WriteString(str + " != " + Cpt->NameL + "
"); OneError = TRUE; } } str = ""; OutFile.WriteString(str); OutFile.Close(); /* if (!OneError) { str = "validation1.htm"; CStdioFile OutFile1(str,CFile::modeCreate | CFile::modeWrite ); str = "Knowledge Validation"; OutFile1.WriteString(str); str = "

Knowledge is Correct

"; OutFile1.WriteString(str); OutFile1.Close(); ShellExecute(GetSafeHwnd(),"open","validation1.htm",NULL,NULL,SW_SHOW); }else */ ShellExecute(GetSafeHwnd(),"open","validation.htm",NULL,NULL,SW_SHOW); } void CKBEditorsView::OnGenerateDoc() { CDesignDocument dd; dd.SeeDoc(GetDocument()); dd.DoModal(); } void CKBEditorsView::OnTableEdit() { CTableDlg Table; Table.SeeDoc(GetDocument()); Table.DoModal(); } /* void CKBEditorsView::OnCoordinator() { CCoordinator cco(this,GetDocument()); CGenDLG Gdlg; Gdlg.SeeDoc(this,GetDocument()); Gdlg.DoModal(); // CGenDLG* pDialog; //pDialog = new CGenDLG(); //BOOL ret = pDialog->Create(IDD_GoBs,NULL); //pDialog->SeeDoc(this,GetDocument()); //pDialog->ShowWindow(SW_SHOW); if(Gdlg.DiagnosisRequired == TRUE){ //cco.Start(); // if((int)ShellExecute(GetSafeHwnd(),"open","DiagCuptex.exe",NULL,NULL,SW_SHOW)>32)return; ShellExecute(GetSafeHwnd(),"open","DiagCuptex.exe",NULL,NULL,SW_SHOW); } // Gdlg.SeeDoc(this,GetDocument()); // Gdlg.DoModal(); } */ void CKBEditorsView::OnCreateMetaKB() { CMetaKBdlg dlg; dlg.SeeDoc(GetDocument()); dlg.DoModal(); } void CKBEditorsView::OnFunction() { CFunSheet m_CFunSheet("Function Editor"); m_CFunSheet.SeeDoc (GetDocument ()); m_CFunSheet.DoModal(); }