#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());
|
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;
|
}
|
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) {
|
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 = GetControl(L"tv_1");
|
dw_list = GetControl(L"dw_list");
|
dw_list.openUrl(L"ÆäËûÉèÖÃ.vface/template/other/SKUItem");
|
|
OnInitial();
|
CreateRootTree();
|
|
return 1;
|
}
|
};
|