#include #include #include #include #include #include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" #include "viewobject/view.base.hpp" using xml = KXMLDOMDocument; class __declspec(dllexport) SKUTemplate : public xframe { public: xdwgrid dw_list; xdwtable dw_maint; xdwtable dw_category; int rowno; xnode m_agentNode; public: SKUTemplate(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {} public: static SKUTemplate* CreateInstance(void* implPtr, void* hWnd) { SKUTemplate* pWin = new SKUTemplate(implPtr, (HWND)hWnd); return pWin; } int SetAgent() { xstring xfNodeAgentArea = L"agentarea"; xnode anode = GetAgentNode(xfNodeAgentArea); if (m_agentNode) { SetAgentNode(anode, m_agentNode); } else { KXMLDOMElement xframeElement = GetElement(); KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*"); if (agent) { xstring s = agent.xml(); m_agentNode = SetAgentNode(anode, s); } } return 1; } int OnSetFocus(TEvent* evt, LPARAM p) { SetAgent(); return 1; } int OnReTrieve() { xstring query = L"[SKUTemplate.list.xq]"; xml x; xaserverarg arg; if (xaserver::ExecXQuery(GetServerUrl(), query, arg.GetString(), x) != 1) { trace(x.text()); return -1; } else { dw_list.Retrieve(x); dw_list.Redraw(); } return 1; } int OnRowChanged(TEvent* evt, LPARAM p) { DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh; int ll_row = hdr.row; rowno = ll_row; xstring TemplateContent = dw_list.GetItemString(ll_row, L"TemplateContent"); xstring Category = dw_list.GetItemString(ll_row, L"Category"); if (TemplateContent == L"") { dw_maint.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateContent"); dw_maint.SetColHeaderHeight(0); dw_maint.SetRowSelectorWidth(0); } if (Category == L"") { dw_category.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateCategory"); dw_category.SetColHeaderHeight(0); dw_category.SetRowSelectorWidth(0); } xml x; x.loadXML(TemplateContent); xml x1; x1.loadXML(Category); dw_maint.Retrieve(x); dw_maint.Redraw(); dw_category.Retrieve(x1); dw_category.Redraw(); return 1; } int OnSave() { dw_list.AcceptText(); dw_maint.AcceptText(); dw_category.AcceptText(); xml x; dw_list.DwUpdateAllToEx(x); trace(x.xml()); xaserverarg arg; arg.AddArg(L"content", x.xml()); arg.AddArg(L"dbmap", L"SKUTemplate.dbmap"); if (xaserver::ExecXAction(GetServerUrl(), L"[onSave.xa]", arg.GetString(), x) != 1) { trace(x.documentElement().text()); alert(L"±£´æÊ§°Ü"); } else { alert(L"±£´æ³É¹¦"); } dw_list.ResetUpdateStatus(); dw_maint.ResetUpdateStatus(); dw_category.ResetUpdateStatus(); dw_list.Redraw(); dw_maint.Redraw(); dw_category.Redraw(); return 1; } int OnSetValue(int row) { dw_list.SetItemString(row, L"TemplateID", publiccode::GetGuid()); return 1; } int RemoveAttribute(xml x, xstring nodename)//¸ù¾ÝÃû³ÆÉ¾³ýÊôÐÔ½Úµã { KXMLDOMElement e; auto list = x.getElementsByTagName(L"" + nodename + L""); if (list) { int nlen = list.length(); int i; for (i = 0; i < nlen; i++) { e = list.item(i); //trace(e.xml); e.removeAttribute(L"update.new"); e.removeAttribute(L"update.modify"); e.removeAttribute(L"update.delete"); e.removeAttribute(L"guid"); e.removeAttribute(L"update.origin"); e.removeAttribute(L"isnull"); //trace(e.xml); } } return 1; } int setMaint() { xml x; dw_maint.DwUpdateAllTo(x); int row = dw_list.GetRow(); trace(x.xml()); RemoveAttribute(x, L"TemplateContent"); RemoveAttribute(x, L"Item"); RemoveAttribute(x, L"ItemName"); RemoveAttribute(x, L"Remark"); RemoveAttribute(x, L"SeqNo"); //trace(x.xml()); dw_list.SetItemString(row, L"TemplateContent", x.xml()); dw_list.Redraw(); return 1; } int setItemCategory() { xml x; dw_category.DwUpdateAllTo(x); int row = dw_list.GetRow(); //trace(row); dw_list.SetItemString(row, L"Category", x.xml()); return 1; } int OnAddRow() { int row = dw_list.InsertRow(0); int rows = dw_list.GetRowCount(); OnSetValue(rows); dw_list.SetRow(dw_list.GetRowCount()); //trace(row.toString()); dw_maint.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateContent"); dw_maint.SetColHeaderHeight(0); dw_maint.SetRowSelectorWidth(0); dw_category.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateCategory"); dw_category.SetColHeaderHeight(0); dw_category.SetRowSelectorWidth(0); return 1; } int OnInsertRow() { int row = dw_list.GetRow(); if (row<0 || row>dw_list.GetRowCount()) return 0; dw_list.InsertRow(row); OnSetValue(row); dw_list.SetRow(row); dw_maint.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateContent"); dw_maint.SetColHeaderHeight(0); dw_maint.SetRowSelectorWidth(0); dw_category.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateCategory"); dw_category.SetColHeaderHeight(0); dw_category.SetRowSelectorWidth(0); return 1; } int OnChangeRowNo(int row) { xdwtable dw = new xdwtable; dw.setNativePointer(dw_maint.FindDwTable(L"Item", 0)); int i; for (i = row; i <= dw.GetRowCount(); i++) dw.SetItemString(i, L"SeqNo", xstring(i)); return 1; } int OnDeleteRow() { int row = dw_list.GetRow(); if (row<0 || row>dw_list.GetRowCount()) return 0; dw_list.DeleteRow(row); dw_maint.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateContent"); dw_maint.SetColHeaderHeight(0); dw_maint.SetRowSelectorWidth(0); dw_category.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateCategory"); dw_category.SetColHeaderHeight(0); dw_category.SetRowSelectorWidth(0); return 1; } int RemoveChild(xml x, xstring nodename)//¸ù¾ÝÃû³ÆÉ¾³ý½Úµã { KXMLDOMElement e; auto list = x.selectNodes(L"//Item[@update.delete='1']"); if (list) { int nlen = list.length(); int i; for (i = 0; i < nlen; i++) { e = list.item(i); //trace(e.xml); e.parentNode().removeChild(e); //trace(e.xml); } } return 1; } int setMaint_removeChild() { xml x; dw_maint.DwUpdateAllTo(x); int row = dw_list.GetRow(); //trace(x.xml()); RemoveChild(x, L"Item"); RemoveAttribute(x, L"TemplateContent"); RemoveAttribute(x, L"Item"); RemoveAttribute(x, L"ItemName"); RemoveAttribute(x, L"Remark"); RemoveAttribute(x, L"SeqNo"); //trace(x.xml()); dw_list.SetItemString(row, L"TemplateContent", x.xml()); dw_list.Redraw(); return 1; } int setItemCategory_removeChild() { xml x; dw_category.DwUpdateAllTo(x); int row = dw_list.GetRow(); RemoveChild(x, L"Item"); //trace(row); dw_list.SetItemString(row, L"Category", x.xml()); dw_list.Redraw(); return 1; } int del(xdwtable dw_1) { xdwtable dw = new xdwtable; dw.setNativePointer(dw_1.GetCurTable()); int row = dw.GetRow(); if (row < 1 || row > dw.GetRowCount()) return -1; dw.DeleteRow(row); //trace(dw.GetDwName()); if (dw_1.GetDwName() == L"TemplateContent") { OnChangeRowNo(row); if (dw.GetRowCount() == 1 && dw.GetItemString(1, L"ItemName") == L"") { dw_list.SetItemString(rowno, L"TemplateContent", L""); dw_list.Redraw(); } else { setMaint_removeChild(); } } if (dw_1.GetDwName() == L"Categorys") { //trace(dw.GetRowCount()); if (dw.GetRowCount() == 1 && dw.GetItemString(1, L"CategoryID") == L"") { dw_list.SetItemString(rowno, L"Category", L""); dw_list.Redraw(); } else { setItemCategory_removeChild(); } } return 1; } int SKUItem() { xaserverarg arg; arg.SetParam(L"dw_maint", &dw_maint); openUrl(L"ÆäËûÉèÖÃ.vface/xpage/SKUItem/select", arg); return 1; } int SKUItemcategory() { xaserverarg arg; arg.SetParam(L"dw_category", &dw_category); openUrl(L"ÆäËûÉèÖÃ.vface/xpage/SKUItemcategory/select", arg); return 1; } int SKUItemModify() { openUrl(L"ÆäËûÉèÖÃ.vface/xpage/SKUItem/list"); return 1; } //ÃüÁî·¢²¼º¯Êý int OnCmdDispatch(xstring comdid) { if (comdid == L"save") OnSave(); else if (comdid == L"AddRow") OnAddRow(); else if (comdid == L"InsertRow") OnInsertRow(); else if (comdid == L"DeleteRow") OnDeleteRow(); else if (comdid == L"SKUItem") SKUItem(); else if (comdid == L"SKUItemcategory") SKUItemcategory(); else if (comdid == L"del_1") del(dw_maint); else if (comdid == L"del_2") del(dw_category); else if (comdid == L"SKUItemModify") SKUItemModify(); return 0; } //ÃüÁî´¦Àíʼþ int OnXCommand(TEvent* evt, LPARAM param) { return OnCmdDispatch(evt->xcommand.pStrID); } int OnMaintChanged(TEvent* evt, LPARAM p) { //trace(L"hello"); setMaint(); return 1; } int OnCategoryChanged(TEvent* evt, LPARAM p) { setItemCategory(); return 1; } int OnAttachEvent() { //°ó¶¨¹¤¾ßÌõµã»÷ʼþ AttachEvent(L"WM_XCOMMAND", (FEvent)&SKUTemplate::OnXCommand); //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ AttachEvent(L"WM_SETFOCUS", (FEvent)&SKUTemplate::OnSetFocus); AttachEvent(L"dw_maint", L"DWV_ITEMCHANGED", (FEvent)&SKUTemplate::OnMaintChanged); AttachEvent(L"dw_category", L"DWV_ITEMCHANGED", (FEvent)&SKUTemplate::OnCategoryChanged); AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&SKUTemplate::OnRowChanged); return 1; } int OnInitial() { SetAgent(); OnAttachEvent(); return 1; } int onload() { dw_list = new xdwgrid; dw_list.setNativePointer(GetControl(L"dw_list")); dw_list.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/SKUTemplate"); dw_maint = new xdwtable; dw_maint.setNativePointer(GetControl(L"dw_maint")); dw_maint.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateContent"); dw_maint.SetColHeaderHeight(0); dw_maint.SetRowSelectorWidth(0); dw_category = new xdwtable; dw_category.setNativePointer(GetControl(L"dw_category")); dw_category.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/TemplateCategory"); dw_category.SetColHeaderHeight(0); dw_category.SetRowSelectorWidth(0); dw_category.SetReadOnly(true); OnInitial(); OnReTrieve(); xdwtable dw = new xdwtable; dw.setNativePointer(dw_category.FindDwTable(L"Item", 0)); //trace(dw.GetRowCount()); return 1; } };