|  |  | 
 |  |  | use "win.vl" | 
 |  |  | use "dev:vm[xdwgrid.vm]" | 
 |  |  | use "dev:vm[xdwtable.vm]" | 
 |  |  | use "pref.vl" | 
 |  |  | use "dev:vm[xml.vm]" | 
 |  |  | use "dev:vm[xaserverarg.vm]" | 
 |  |  | use "dev:vm[xaserver.vm]" | 
 |  |  | use "dev:vm[xutil.vm]" | 
 |  |  | use "frame.vl" | 
 |  |  | use "treeview.vm" | 
 |  |  | use "file.vl" | 
 |  |  | //unit vclient.vobject tpp | 
 |  |  | unit vbusiness.xpage | 
 |  |  | [ | 
 |  |  |    SKUItem is extend frame; | 
 |  |  |    about SKUItem | 
 |  |  |    [ | 
 |  |  |       field: | 
 |  |  |       [ | 
 |  |  |          treeview__      tv_1; | 
 |  |  |          xdwgrid__   dw_list; | 
 |  |  |          string    m_type; | 
 |  |  |          string CategoryID; | 
 |  |  |          xnode__   m_agentNode;   //Agent Condition | 
 |  |  |          string   m_agentCond;   //Agent Node | 
 |  |  |          string m_searchtxt;			 | 
 |  |  |       ] | 
 |  |  | 		 | 
 |  |  |       method: | 
 |  |  |       [ | 
 |  |  |          int SetAgent() | 
 |  |  | #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) | 
 |  |  |          { | 
 |  |  |             string xfNodeAgentArea  = "agentarea"; | 
 |  |  |             xnode__ anode = new xnode__; | 
 |  |  |             anode.setNativePointer(GetAgentNode(xfNodeAgentArea)); | 
 |  |  |             var xframeElement =  GetElement(); | 
 |  |  |             var agent = xframeElement.selectSingleNode("agent/"+xfNodeAgentArea+"[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) | 
 |  |  |             { | 
 |  |  |                string s = agent.xml; | 
 |  |  |                SetAgentNodeContent (anode,s); | 
 |  |  |                trace(x.xml()); | 
 |  |  |                return 0; | 
 |  |  |             } | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  |  | 
 |  |  |          //焦点激活处理函数 | 
 |  |  |          int OnSetFocus(ref TEvent evt,int param) | 
 |  |  |          { | 
 |  |  |             SetAgent(); | 
 |  |  |  | 
 |  |  |             //重置工具条 | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  |  | 
 |  |  |          int  OnReTrieve() | 
 |  |  |          { | 
 |  |  |             string query="[SKUItem.tree.xq]";				 | 
 |  |  |             xml__ x = new xml__; | 
 |  |  |             x.setNativePointer(x.CreateInstance()); | 
 |  |  |             xaserverarg__ arg = new xaserverarg__; | 
 |  |  |             arg.setNativePointer(arg.CreateInstance()); | 
 |  |  |             arg.AddArg("parentID",CategoryID); | 
 |  |  |             arg.AddArg("query",""); | 
 |  |  |             if (xaserver__::ExecXQuery(GetServerUrl(),query,arg.GetString(),x)!=1) | 
 |  |  |             { | 
 |  |  |                trace(x.GetXmlDoc().text); | 
 |  |  |                return -1; | 
 |  |  |             }else	 | 
 |  |  |             { | 
 |  |  |                dw_list.openUrl("其他设置.vface/template/other/SKUItem");	 | 
 |  |  |                dw_list.Retrieve(x); | 
 |  |  |                dw_list.Redraw(); | 
 |  |  |             //trace(x.xml()); | 
 |  |  |             auto 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; | 
 |  |  |          } | 
 |  |  |       } | 
 |  |  |       return 1; | 
 |  |  |    } | 
 |  |  |    int CreateRootTree() { | 
 |  |  |       xstring id = L"00000000-0000-0000-0000-000000000000"; | 
 |  |  |       xml x; | 
 |  |  |  | 
 |  |  |          int OnTreeSelChanged(ref TNotifyEvent evt,int p){ | 
 |  |  |             ref NMTREEVIEW nmtv = evt.pnmh; | 
 |  |  |             int sitem = nmtv.itemNew.hItem; | 
 |  |  |       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; | 
 |  |  |  | 
 |  |  |             int hCursor = xutil__::SetCursorWait(); | 
 |  |  |             dw_list.AcceptText(); | 
 |  |  |             xml__ z= new xml__; | 
 |  |  |             z.setNativePointer(xml__::CreateInstance());		 | 
 |  |  |             z.LoadXml("<root/>"); | 
 |  |  |             dw_list.Retrieve(z); | 
 |  |  |             dw_list.Redraw(); | 
 |  |  |             dw_list.ResetUpdateStatus(); | 
 |  |  | 				 | 
 |  |  |             msxml::IXMLDOMElement ele=treeview__::GetItemData(tv_1.GetId(), sitem); | 
 |  |  |             if(!ele.selectSingleNode("ID")) return 0; | 
 |  |  |             CategoryID = ele.selectSingleNode("ID").text; | 
 |  |  |             //trace(CategoryID); | 
 |  |  |             m_searchtxt = ""; | 
 |  |  |       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); | 
 |  |  |  | 
 |  |  |             OnReTrieve(); | 
 |  |  |             xutil__::RestoreCursor(hCursor); | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  |       HTREEITEM firstChild = tv_1.GetChildItem(hitem); | 
 |  |  |       while (firstChild) { | 
 |  |  |          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); | 
 |  |  |  | 
 |  |  |          int CreateSubTree(int pitem){ | 
 |  |  |             msxml::IXMLDOMElement sitemdata=treeview__::GetItemData(tv_1.GetId(), pitem); | 
 |  |  |             string sHasChild=sitemdata.selectSingleNode("@HasChild").text;//sitemdata.getAttribute("HasChild");	 | 
 |  |  |             //trace(sHasChild); | 
 |  |  |             string pid=sitemdata.selectSingleNode("ID").text; | 
 |  |  |             //trace(sHasChild+"sdaga"+pid); | 
 |  |  |             if(sHasChild=="1"){//数据有子节点		 | 
 |  |  |                int citem=treeview__::GetChildItem(tv_1.GetId(), pitem); | 
 |  |  |                //alert(string(citem)); | 
 |  |  |                if (citem==0){//树视图有子节点 | 
 |  |  |                   xml__ x=new xml__; | 
 |  |  |                   x.setNativePointer(xml__::CreateInstance()); | 
 |  |  |                   xaserverarg__ arg=new xaserverarg__; | 
 |  |  |                   arg.setNativePointer(arg.CreateInstance());	 | 
 |  |  |                   arg.AddArg("parentID",pid); | 
 |  |  |                   arg.AddArg("query",""); | 
 |  |  |                   if(xaserver__::ExecXQuery(GetServerUrl(),"[SKUItem.tree.xq]",arg.GetString(),x)!=1) | 
 |  |  |                   { | 
 |  |  |                      trace(x.GetXml()); | 
 |  |  |                      return 0; | 
 |  |  |                   } | 
 |  |  |                   //trace(x.GetXml()); | 
 |  |  |                   var list=x.GetXmlDoc().selectNodes("root/SKUItem"); | 
 |  |  |                   int i=0,s=list.length; | 
 |  |  |                   msxml::IXMLDOMElement xitem; | 
 |  |  |                   msxml::IXMLDOMNode d; | 
 |  |  |                   for (i=0;i<s;i++){ | 
 |  |  |                      xitem= list.item(s - i - 1); | 
 |  |  |                      //if(i==0)xitem.setAttribute("HasChild","1"); | 
 |  |  |                      string Name=xitem.selectSingleNode("ItemName").text; | 
 |  |  |                      int kitem=treeview__::InsertItem(tv_1.GetId(), pitem,0,Name,xitem,15);	 | 
 |  |  |                      //int kitem=treeview__::InsertChildItem(tv_1.GetId(), pitem,Name,xitem,15);	 | 
 |  |  |                      string HasChild=xitem.selectSingleNode("@HasChild").text;//item.getAttribute("HasChild");	 | 
 |  |  |                      //trace(HasChild, kitem); | 
 |  |  |                      if (HasChild=="1") | 
 |  |  |                         treeview__::SetItemChild1(tv_1.GetId(), kitem,1); | 
 |  |  |                   } | 
 |  |  |                } | 
 |  |  |             } | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  |          int CreateRootTree(){ | 
 |  |  |             string id="00000000-0000-0000-0000-000000000000"; | 
 |  |  |             xml__ x=new xml__; | 
 |  |  |             x.setNativePointer(xml__::CreateInstance()); | 
 |  |  |             x.LoadXml("<SKUItem HasChild='1' ><ID>"+id+"</ID></SKUItem>"); | 
 |  |  |             int hroot=treeview__::InsertItem(tv_1.GetId(), "产品项目分类", x.GetXmlDoc().documentElement, 17); | 
 |  |  |             //trace(hroot); | 
 |  |  |             CreateSubTree(hroot); | 
 |  |  |             treeview__::ExpandItemEx(tv_1.GetId(), hroot); | 
 |  |  |             CategoryID = id; | 
 |  |  |             OnReTrieve(); | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  |          int OnTreeExpanding(ref TNotifyEvent evt,int p)   { | 
 |  |  |             ref NMTREEVIEW nmtv = evt.pnmh; | 
 |  |  |             int sitem = nmtv.itemNew.hItem; | 
 |  |  |             CreateSubTree(sitem); | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  |          int afterSave(){ | 
 |  |  |             int hitem = treeview__::GetSelectedItem(tv_1.GetId()); | 
 |  |  |             if(hitem == 0) | 
 |  |  |                hitem = treeview__::GetRootItem(tv_1.GetId()); | 
 |  |  |             int rows = dw_list.GetRowCount(); | 
 |  |  |             msxml::IXMLDOMElement ele = treeview__::GetItemData(tv_1.GetId() ,hitem); | 
 |  |  |       dw_list.ResetUpdateStatus(); | 
 |  |  |       return 0; | 
 |  |  |    } | 
 |  |  |    int OnSave() | 
 |  |  |    { | 
 |  |  |       xml x; | 
 |  |  |  | 
 |  |  |             int firstChild = treeview__::GetChildItem(tv_1.GetId() ,hitem); | 
 |  |  |             while (firstChild>0){ | 
 |  |  |                treeview__::DeleteItem(tv_1.GetId() ,firstChild); | 
 |  |  |                firstChild = treeview__::GetChildItem(tv_1.GetId() ,hitem); | 
 |  |  |             } | 
 |  |  |             if(rows>0) | 
 |  |  |             { | 
 |  |  |                treeview__::SetItemChild1(tv_1.GetId() ,hitem,1); | 
 |  |  |                ele.setAttribute("HasChild","1"); | 
 |  |  |                //trace(ele.xml); | 
 |  |  |                treeview__::SetItemData(tv_1.GetId() ,hitem,ele); | 
 |  |  |             } | 
 |  |  |             else | 
 |  |  |             { | 
 |  |  |                treeview__::SetItemChild1(tv_1.GetId() ,hitem,0); | 
 |  |  |                ele.setAttribute("HasChild","0"); | 
 |  |  |                //trace(ele.xml); | 
 |  |  |                treeview__::SetItemData(tv_1.GetId() ,hitem,ele); | 
 |  |  |             } | 
 |  |  |             CreateSubTree(hitem); | 
 |  |  |             if(treeview__::GetRootItem(tv_1.GetId()) == hitem) | 
 |  |  |                treeview__::ExpandItemEx(tv_1.GetId() ,hitem); | 
 |  |  |       dw_list.AcceptText(); | 
 |  |  |       dw_list.DwUpdateAllToEx(x); | 
 |  |  |       trace(x.xml()); | 
 |  |  |       xaserverarg arg; | 
 |  |  |  | 
 |  |  |             dw_list.ResetUpdateStatus(); | 
 |  |  |             return 0; | 
 |  |  |          }			 | 
 |  |  |          int OnSave() | 
 |  |  |          { | 
 |  |  |             xml__ x=new xml__; | 
 |  |  |             x.setNativePointer(x.CreateInstance()); | 
 |  |  |             dw_list.AcceptText(); | 
 |  |  |             dw_list.DwUpdateAllToEx(x.GetXmlDoc()); | 
 |  |  |             trace(x.GetXml());				 | 
 |  |  |             xaserverarg__ arg = new xaserverarg__; | 
 |  |  |             arg.setNativePointer(arg.CreateInstance()); | 
 |  |  |             arg.AddArg("content", x.GetXml()); | 
 |  |  |             arg.AddArg("dbmap", "SKUItem.dbmap");		 | 
 |  |  |             if(xaserver__::ExecXAction(this.GetServerUrl(),"[onSave.xa]",arg.GetString(),x)!=1) | 
 |  |  |             { | 
 |  |  |                trace(x.GetXmlDoc().documentElement.text); | 
 |  |  |                alert("保存失败"); | 
 |  |  |             }else{ | 
 |  |  |                alert("保存成功"); | 
 |  |  |             } | 
 |  |  |             dw_list.ResetUpdateStatus(); | 
 |  |  |             dw_list.Redraw(); | 
 |  |  |             afterSave(); | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  |          int OnSetValue( int row){ | 
 |  |  |             dw_list.SetItemString(row,"PID",CategoryID); | 
 |  |  |             dw_list.SetItemString(row,"ID",TApp::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; | 
 |  |  |          } | 
 |  |  |       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 OnDeleteRow() | 
 |  |  |          {			 | 
 |  |  |             int row = dw_list.GetRow(); | 
 |  |  |             if(row<0 || row>dw_list.GetRowCount()) return 0;			 | 
 |  |  |             dw_list.DeleteRow(row); | 
 |  |  |             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 OnCmdDispatch(string comdid) | 
 |  |  |          { | 
 |  |  |             if (comdid =="Save")  OnSave(); | 
 |  |  |             else if (comdid =="AddRow") OnAddRow(); | 
 |  |  |             else if (comdid =="InsertRow") OnInsertRow(); | 
 |  |  |             else if (comdid =="DeleteRow") OnDeleteRow(); | 
 |  |  |             return 0; | 
 |  |  |          } | 
 |  |  | 			 | 
 |  |  |          //命令处理事件 | 
 |  |  |          int OnXCommand(ref TXCommandEvent evt,int param) | 
 |  |  |          { | 
 |  |  |             return OnCmdDispatch(evt.pStrID); | 
 |  |  |          } | 
 |  |  | 			 | 
 |  |  |          int OnAttachEvent() | 
 |  |  |          { | 
 |  |  |             //绑定工具条点击事件 | 
 |  |  |             AttachEvent("WM_XCOMMAND",OnXCommand); | 
 |  |  |             //获取焦点事件,用于重置工具条 | 
 |  |  |             AttachEvent("WM_SETFOCUS",OnSetFocus); | 
 |  |  |             //获得树的选择事件 | 
 |  |  |             AttachEvent("tv_1", "TVN_SELCHANGED",OnTreeSelChanged); | 
 |  |  |             AttachEvent("tv_1", "TVN_ITEMEXPANDING",OnTreeExpanding);				 | 
 |  |  |          } | 
 |  |  | 			 | 
 |  |  |          int OnInitial() | 
 |  |  |          { | 
 |  |  |             SetAgent(); | 
 |  |  |             OnAttachEvent();				 | 
 |  |  |             return 1; | 
 |  |  |          } | 
 |  |  | 			 | 
 |  |  |          int onload() | 
 |  |  |          { | 
 |  |  |             m_type = "all"; | 
 |  |  |             tv_1 =  new treeview__; | 
 |  |  |             tv_1.setNativePointer(this.GetControl("tv_1"));					 | 
 |  |  |             dw_list =  new xdwgrid__; | 
 |  |  |             dw_list.setNativePointer(this.GetControl("dw_list"));						 | 
 |  |  |             dw_list.openUrl("其他设置.vface/template/other/SKUItem");	 | 
 |  |  |    int OnDeleteRow() | 
 |  |  |    { | 
 |  |  |       int row = dw_list.GetRow(); | 
 |  |  |       if (row<0 || row>dw_list.GetRowCount()) return 0; | 
 |  |  |       dw_list.DeleteRow(row); | 
 |  |  |       return 1; | 
 |  |  |    } | 
 |  |  |  | 
 |  |  |             OnInitial(); | 
 |  |  |             CreateRootTree(); | 
 |  |  | 				 | 
 |  |  |             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 = GetControl(L"tv_1"); | 
 |  |  |       dw_list = GetControl(L"dw_list"); | 
 |  |  |       dw_list.openUrl(L"其他设置.vface/template/other/SKUItem"); | 
 |  |  |  | 
 |  |  |       OnInitial(); | 
 |  |  |       CreateRootTree(); | 
 |  |  |  | 
 |  |  |       return 1; | 
 |  |  |    } | 
 |  |  | }; |