¶Ô±ÈÐÂÎļþ |
| | |
| | | #include <wobject/xstring.hpp> |
| | | #include <xcontrol/xtreeview.hpp> |
| | | #include <xcontrol/xdwgrid.hpp> |
| | | #include <wobject/xdouble.hpp> |
| | | #include <xcontrol/xlayersheet.hpp> |
| | | |
| | | #include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" |
| | | #include "viewobject/view.base.hpp" |
| | | |
| | | using xml = KXMLDOMDocument; |
| | | class __declspec(dllexport) SKUItem : public xframe |
| | | { |
| | | public: |
| | | xtreeview tv_1; |
| | | xdwgrid dw_list; |
| | | xstring m_type; |
| | | xstring CategoryID; |
| | | xnode m_agentNode; //Agent Condition |
| | | xstring m_agentCond; //Agent Node |
| | | xstring m_searchtxt; |
| | | public: |
| | | SKUItem(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {} |
| | | public: |
| | | static SKUItem* CreateInstance(void* implPtr, void* hWnd) |
| | | { |
| | | SKUItem* pWin = new SKUItem(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"[SKUItem.tree.xq]"; |
| | | xml x; |
| | | |
| | | xaserverarg arg; |
| | | |
| | | arg.AddArg(L"parentID", CategoryID); |
| | | arg.AddArg(L"query", L""); |
| | | if (xaserver::ExecXQuery(GetServerUrl(), query, arg.GetString(), x) != 1) |
| | | { |
| | | trace(x.text()); |
| | | return -1; |
| | | } |
| | | else |
| | | { |
| | | dw_list.openUrl(L"å
¶ä»è®¾ç½®.vface/template/other/SKUItem"); |
| | | dw_list.Retrieve(x); |
| | | dw_list.Redraw(); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | int OnTreeSelChanged(TEvent* evt, LPARAM p) |
| | | { |
| | | NMTREEVIEW& nmtv = *(NMTREEVIEW*)evt->notify.pnmh; |
| | | HTREEITEM sitem = nmtv.itemNew.hItem; |
| | | |
| | | HCURSOR hCursor = xutil::SetCursorWait(); |
| | | dw_list.AcceptText(); |
| | | xml z; |
| | | |
| | | z.loadXML(L"<root/>"); |
| | | dw_list.Retrieve(z); |
| | | dw_list.Redraw(); |
| | | dw_list.ResetUpdateStatus(); |
| | | |
| | | KXMLDOMElement ele = tv_1.GetItemData(sitem); |
| | | if (!ele.selectSingleNode(L"ID")) return 0; |
| | | CategoryID = ele.selectSingleNode(L"ID").text(); |
| | | //trace(CategoryID); |
| | | m_searchtxt = L""; |
| | | |
| | | OnReTrieve(); |
| | | xutil::RestoreCursor(hCursor); |
| | | return 1; |
| | | } |
| | | |
| | | int CreateSubTree(HTREEITEM pitem) |
| | | { |
| | | KXMLDOMElement sitemdata = tv_1.GetItemData(pitem); |
| | | xstring sHasChild = sitemdata.selectSingleNode(L"@HasChild").text();//sitemdata.getAttribute(L"HasChild"); |
| | | //trace(sHasChild); |
| | | xstring pid = sitemdata.selectSingleNode(L"ID").text(); |
| | | //trace(sHasChild+L"sdaga"+pid); |
| | | if (sHasChild == L"1") {//æ°æ®æåèç¹ |
| | | HTREEITEM citem = tv_1.GetChildItem(pitem); |
| | | //alert(xstring(citem)); |
| | | if (citem == 0) {//æ è§å¾æåèç¹ |
| | | xml x; |
| | | |
| | | xaserverarg arg; |
| | | |
| | | arg.AddArg(L"parentID", pid); |
| | | arg.AddArg(L"query", L""); |
| | | if (xaserver::ExecXQuery(GetServerUrl(), L"[SKUItem.tree.xq]", arg.GetString(), x) != 1) |
| | | { |
| | | trace(x.xml()); |
| | | return 0; |
| | | } |
| | | //trace(x.xml()); |
| | | var list = x.selectNodes(L"root/SKUItem"); |
| | | int i = 0, s = list.length; |
| | | KXMLDOMElement xitem; |
| | | KXMLDOMNode d; |
| | | for (i = 0; i < s; i++) { |
| | | xitem = list.item(s - i - 1); |
| | | //if(i==0)xitem.setAttribute(L"HasChild",L"1"); |
| | | xstring Name = xitem.selectSingleNode(L"ItemName").text(); |
| | | HTREEITEM kitem = tv_1.InsertItem(pitem, 0, Name, xitem, 15); |
| | | //int kitem=tv_1.InsertChildItem(tv_1.GetId(), pitem,Name,xitem,15); |
| | | xstring HasChild = xitem.selectSingleNode(L"@HasChild").text();//item.getAttribute(L"HasChild"); |
| | | //trace(HasChild, kitem); |
| | | if (HasChild == L"1") |
| | | tv_1.SetItemChild1(kitem, 1); |
| | | } |
| | | } |
| | | } |
| | | return 1; |
| | | } |
| | | int CreateRootTree() { |
| | | xstring id = L"00000000-0000-0000-0000-000000000000"; |
| | | xml x; |
| | | |
| | | x.loadXML(L"<SKUItem HasChild='1' ><ID>" + id + L"</ID></SKUItem>"); |
| | | HTREEITEM hroot = tv_1.InsertItem(L"产å项ç®åç±»", x.documentElement(), 17); |
| | | //trace(hroot); |
| | | CreateSubTree(hroot); |
| | | tv_1.ExpandItemEx(hroot); |
| | | CategoryID = id; |
| | | OnReTrieve(); |
| | | return 1; |
| | | } |
| | | int OnTreeExpanding(TEvent* evt, int p) |
| | | { |
| | | NMTREEVIEW& nmtv = *(NMTREEVIEW*)evt->notify.pnmh; |
| | | |
| | | HTREEITEM sitem = nmtv.itemNew.hItem; |
| | | CreateSubTree(sitem); |
| | | return 1; |
| | | } |
| | | int afterSave() { |
| | | HTREEITEM hitem = tv_1.GetSelectedItem(); |
| | | if (hitem == 0) |
| | | hitem = tv_1.GetRootItem(); |
| | | int rows = dw_list.GetRowCount(); |
| | | KXMLDOMElement ele = tv_1.GetItemData(hitem); |
| | | |
| | | HTREEITEM firstChild = tv_1.GetChildItem(hitem); |
| | | while (firstChild > 0) { |
| | | tv_1.DeleteItem(firstChild); |
| | | firstChild = tv_1.GetChildItem(hitem); |
| | | } |
| | | if (rows > 0) |
| | | { |
| | | tv_1.SetItemChild1(hitem, 1); |
| | | ele.setAttribute(L"HasChild", L"1"); |
| | | //trace(ele.xml); |
| | | tv_1.SetItemData(hitem, ele); |
| | | } |
| | | else |
| | | { |
| | | tv_1.SetItemChild1(hitem, 0); |
| | | ele.setAttribute(L"HasChild", L"0"); |
| | | //trace(ele.xml); |
| | | tv_1.SetItemData(hitem, ele); |
| | | } |
| | | CreateSubTree(hitem); |
| | | if (tv_1.GetRootItem() == hitem) |
| | | tv_1.ExpandItemEx(hitem); |
| | | |
| | | dw_list.ResetUpdateStatus(); |
| | | return 0; |
| | | } |
| | | int OnSave() |
| | | { |
| | | xml x; |
| | | |
| | | dw_list.AcceptText(); |
| | | dw_list.DwUpdateAllToEx(x); |
| | | trace(x.xml()); |
| | | xaserverarg arg; |
| | | |
| | | arg.AddArg(L"content", x.xml()); |
| | | arg.AddArg(L"dbmap", L"SKUItem.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_list.Redraw(); |
| | | afterSave(); |
| | | return 1; |
| | | } |
| | | int OnSetValue(int row) { |
| | | dw_list.SetItemString(row, L"PID", CategoryID); |
| | | dw_list.SetItemString(row, L"ID", publiccode::GetGuid()); |
| | | 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()); |
| | | 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); |
| | | return 1; |
| | | } |
| | | |
| | | int OnDeleteRow() |
| | | { |
| | | int row = dw_list.GetRow(); |
| | | if (row<0 || row>dw_list.GetRowCount()) return 0; |
| | | dw_list.DeleteRow(row); |
| | | 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(); |
| | | return 0; |
| | | } |
| | | |
| | | //å½ä»¤å¤çäºä»¶ |
| | | int OnXCommand(TEvent* evt, LPARAM param) |
| | | { |
| | | return OnCmdDispatch(evt->xcommand.pStrID); |
| | | } |
| | | |
| | | int OnAttachEvent() |
| | | { |
| | | //ç»å®å·¥å
·æ¡ç¹å»äºä»¶ |
| | | AttachEvent(L"WM_XCOMMAND", (FEvent)&SKUItem::OnXCommand); |
| | | //è·åç¦ç¹äºä»¶ï¼ç¨äºé置工å
·æ¡ |
| | | AttachEvent(L"WM_SETFOCUS", (FEvent)&SKUItem::OnSetFocus); |
| | | //è·å¾æ çéæ©äºä»¶ |
| | | AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&SKUItem::OnTreeSelChanged); |
| | | AttachEvent(L"tv_1", L"TVN_ITEMEXPANDING", (FEvent)&SKUItem::OnTreeExpanding); |
| | | return 1; |
| | | } |
| | | |
| | | int OnInitial() |
| | | { |
| | | SetAgent(); |
| | | OnAttachEvent(); |
| | | return 1; |
| | | } |
| | | |
| | | int onload() |
| | | { |
| | | m_type = L"all"; |
| | | tv_1 = new treeview; |
| | | tv_1.setNativePointer(GetControl(L"tv_1")); |
| | | dw_list = new xdwgrid; |
| | | dw_list.setNativePointer(GetControl(L"dw_list")); |
| | | dw_list.openUrl(L"å
¶ä»è®¾ç½®.vface/template/other/SKUItem"); |
| | | |
| | | OnInitial(); |
| | | CreateRootTree(); |
| | | |
| | | return 1; |
| | | } |
| | | }; |