From 7a91c3a1ed37b0332d4ff0ebeae60bd6da3665c0 Mon Sep 17 00:00:00 2001 From: xj qian <qianxj15@sina.com> Date: 星期二, 16 七月 2024 18:28:58 +0800 Subject: [PATCH] Merge branch 'master' of http://116.62.18.175:6699/r/mis-prj --- jrj/project/business/BasicCode/QuickCode_Tree.cpp | 696 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 696 insertions(+), 0 deletions(-) diff --git a/jrj/project/business/BasicCode/QuickCode_Tree.cpp b/jrj/project/business/BasicCode/QuickCode_Tree.cpp new file mode 100644 index 0000000..b8b99b0 --- /dev/null +++ b/jrj/project/business/BasicCode/QuickCode_Tree.cpp @@ -0,0 +1,696 @@ +#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) QuickCode_Tree : public xwin +{ +public: + xdwgrid dw_list; + xtreeview tv_1; + xstring m_config; + xstring m_agent; + xstring m_id; + xstring m_dbmap; + xstring treexquery; + xstring c_type; + KXMLDOMDocument m_configDoc; + xstring kpstr; + xstring strtpl; + xstring m_QueryTxt; + xnode m_agentNode; +public: + QuickCode_Tree(void* implPtr, HWND hWnd) :xwin(implPtr, hWnd) {} +public: + static QuickCode_Tree* CreateInstance(void* implPtr, void* hWnd) + { + QuickCode_Tree* pWin = new QuickCode_Tree(implPtr, (HWND)hWnd); + return pWin; + } + int alert(xstring str) + { + TApp::alert(this, str); + //win::MessageBox(GetHWND(),str,L"提示:",0); + return 0; + } + 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 OnRetrieve() + { + dw_list.AcceptText(); + xml x; + + xaserverarg arg; + + arg.AddArg(L"id", m_id); + arg.AddArg(L"sType", c_type); + arg.AddArg(L"QueryTxt", m_QueryTxt); + //trace(arg.GetString()); + /*if (TDataSet::exec(m_config, L"query1", arg.GetString(),x) != 1) + { + trace(x.text()); + return -1; + }*/ + if (xurl::get(L"QuickCode/entity/listaddtree", arg.GetString(), x) != 1) + { + trace(x.text()); + return -1; + } + //trace(x.xml()); + if (x.xml() == L"") + { + xml xx; + xx.loadXML(L"<root/>"); + dw_list.Retrieve(xx); + dw_list.Redraw(); + } + else + { + dw_list.Retrieve(x); + dw_list.Redraw(); + } + + return 1; + } + int OnTreeSelChanged(TEvent* evt, LPARAM p) + { + NMTREEVIEW& nmtv = *(NMTREEVIEW*)evt->notify.pnmh; + HTREEITEM hItem = nmtv.itemNew.hItem; + + + HTREEITEM hitem = tv_1.GetSelectedItem(); + //c_type=dw_type.GetItemLabel(hitem); + //如果是跟节点 + HTREEITEM roothitem = tv_1.GetRootItem(); + if (hitem == roothitem) { + c_type = L""; + } + else + { + c_type = tv_1.GetItemLabel(hitem); + + } + OnRetrieve(); + return 1; + } + int adduomfolder() + { + xaserverarg arg; + + arg.AddArg(L"note", L"新增"); + arg.AddArg(L"m_id", m_id); + //win::OpenWindow(L"dev:xpage[AddUomGroup.vx]",arg); + openUrl(L"公共设置.vface/xpage/quickcode/AddGroup", arg); + xstring ok = arg.GetArgString(L"return"); + if (ok == L"ok") { + xstring GroupName = arg.GetArgString(L"GroupName"); + xml xx; + + xaserverarg args; + + args.AddArg(L"GroupName", GroupName); + args.AddArg(L"OldGroupName", L""); + args.AddArg(L"m_id", m_id); + /*if(TFile::exec(m_config,L"updateuomtype",args,xx)!=1) + { + trace(L"error:"+xx.xml()); + alert(L"保存出错!"); + return 0; + }*/ + if (xurl::get(L"QuickCode/pref/quickcode_tree.updateGroup", args.GetString(), xx) != 1) + { + trace(L"error:" + (xstring)xx.xml()); + alert(L"保存出错!"); + return 0; + } + else + { + xstring vv = xx.documentElement().text(); + xml x; + + x.loadXML(L"<row GroupName='" + GroupName + L"'/>"); + HTREEITEM root = tv_1.GetRootItem(); + if (vv == L"OK") + { + tv_1.InsertChildItem(root, GroupName, x.documentElement(), 15); + } + + } + } + return 1; + } + int modifyuomfolder() + { + + HTREEITEM h = tv_1.GetSelectedItem(); + if (!h) + { + alert(L"请选择需要修改的组名"); + return 0; + } + HTREEITEM roothitem = tv_1.GetRootItem(); + if (h == roothitem) + { + alert(L"不能修改根节点名称!"); + } + else + { + KXMLDOMElement e = tv_1.GetItemData(h); + trace(e.xml()); + //xstring OldGroupName= e.SelectSingleNode(L"@GroupName").text(); + xstring OldGroupName = tv_1.GetItemLabel(h); + xaserverarg arg; + + arg.AddArg(L"note", L"修改"); + arg.AddArg(L"m_id", m_id); + arg.AddArg(L"GroupName", OldGroupName); + OpenWindow(L"dev:xpage[AddUomGroup.vx]", arg); + xstring ok = arg.GetArgString(L"return"); + if (ok == L"ok") { + xstring NewGroupName = arg.GetArgString(L"GroupName"); + xml xx; + + xaserverarg args; + + args.AddArg(L"GroupName", NewGroupName); + args.AddArg(L"OldGroupName", OldGroupName); + args.AddArg(L"m_id", m_id); + /*if(TFile::exec(m_config,L"updateuomtype",args,xx)!=1) + { + trace(L"error:"+xx.xml()); + alert(L"保存出错!"); + return 0; + }*/ + if (xurl::get(L"QuickCode/pref/quickcode_tree.updateGroup", args.GetString(), xx) != 1) + { + trace(L"error:" + (xstring)xx.xml()); + alert(L"保存出错!"); + return 0; + } + else + { + trace(xx.xml()); + xstring vv = xx.documentElement().text(); + if (vv == L"OK") + { + tv_1.SetItemLabel(h, NewGroupName); + } + + } + } + } + return 1; + } + int deluomfolder() + { + + HTREEITEM hitem = tv_1.GetSelectedItem(); + if (!hitem) + { + alert(L"请选择需要删除的组名"); + return 0; + } + else + { + + int s = dw_list.GetRowCount(); + if (s > 0) + { + alert(L"该分组下面存在数据,不能删除!"); + return 0; + } + HTREEITEM roothitem = tv_1.GetRootItem(); + if (hitem == roothitem) + { + alert(L"不能删除根节点!"); + } + else + { + //缺少判断删除的条件 + xstring GroupName = tv_1.GetItemLabel(hitem); + if (MessageBox(GetHWND(), L"确定删除组名:" + GroupName + L" 吗?", L"提示", 1) == 1) + { + xml xx; + + xaserverarg arg; + + arg.AddArg(L"GroupName", GroupName); + arg.AddArg(L"m_id", m_id); + trace(GroupName); + trace(m_id); + /*if (xaserver::ExecXAction(GetServerUrl(),L"[delete.type.FND_UOM.xa]",arg.GetString()) == 1) + { + tv_1.DeleteItem(wid,hitem); + //OnTreeSelChanged(); + }*/ + if (xurl::get(L"QuickCode/pref/quickcode_tree.deleteGroup", arg.GetString(), xx) == 1) + { + tv_1.DeleteItem(hitem); + } + else + alert(L"删除失败!"); + } + } + } + return 1; + } + xdwgrid getDW() + { + return dw_list; + } + int GridSearch() + { + xml x; + + xaserver::LoadUrl(L"", L"dev:vface[公共设置.vface]", L"", x); + //trace(x.xml()); + //trace(strtpl); + xstring aa = strtpl; + var doc = x; + var n = doc.selectSingleNode(L"//resource[@url='" + aa + L"']/@src"); + //trace(n.text()); + + xaserverarg arg; + + arg.AddArg(L"sheet", n.text()); + arg.AddArg(L"search", list::m_QueryTxt); + openUrl(L"view.dlg.vface/xpage/grid/column/search", arg); + xstring ok = arg.GetArgString(L"return"); + if (ok == L"ok") { + xstring txt = arg.GetArgString(L"search"); + if (txt != L"") { + m_QueryTxt = txt; + //trace(txt); + OnRetrieve(); + } + } + return 0; + } + int OnCmdDispatch(xstring comdid) + { + HCURSOR hCursor = xutil::SetCursorWait(); + xdwgrid dw = getDW(); + if (comdid == L"save") { + dw_list.AcceptText(); + xml x; + + xaserverarg arg; + + dw_list.DwUpdateAllToEx(x); + KXMLDOMElement e = x.documentElement(); + e.setAttribute(L"id", m_id); + //arg.AddArg(L"id",m_id); + //trace(m_id); + //trace(m_dbmap); + if (m_id == L"开票银行") + { + xml kp; + + kp.loadXML(L"<root></root>"); + KXMLDOMElement ele = kp.documentElement(); + var list = e.selectNodes(L"item[@update.modify='1' or @update.delete='1' ]"); + int j; + int k = list.length; + for (j = 0; j < k; j++) + { + KXMLDOMElement ele1 = list.item(j); + ele.appendChild(ele1); + } + kpstr = ele.xml(); + trace(ele.xml()); + } + if (m_id == L"开票银行") + { + arg.AddArg(L"content", kpstr); + } + else + { + arg.AddArg(L"content", e.xml()); + } + arg.AddArg(L"dbmap", m_dbmap); + /*if(TFile::exec(m_config,L"save",arg,x)!=1) + { + trace(L"error:"+x.xml()); + alert(L"保存出错!"); + return 0; + }*/ + trace(m_dbmap + L"\r\n" + e.xml()); + if (xurl::get(L"QuickCode/pref/quickcode.save", arg.GetString(), x) != 1) + { + xstring error = x.text(); + trace(error); + } + //trace(arg.GetString()); + if (x.selectSingleNode(L"error")) + { + alert(L"保存出错2!"); + return 0; + } + dw_list.ResetUpdateStatus(); + alert(L"保存成功!"); + } + else if (comdid == L"add") { + dw.InsertRow(0); + int rows = dw.GetRowCount(); + dw.SetItemString(rows, L"GroupName", c_type); + dw.SetItemString(rows, L"BankName", c_type); + } + else if (comdid == L"insert") { + int row = dw.GetRow(); + if (row<1 || row>dw.GetRowCount()) return 0; + dw.InsertRow(row); + + dw.SetItemString(row, L"GroupName", c_type); + } + else if (comdid == L"delet") { + dw_list.AcceptText(); + int row2 = dw.GetRow(); + if (row2<1 || row2>dw.GetRowCount()) return 0; + dw.DeleteRow(row2); + } + else if (comdid == L"adduomfolder") + adduomfolder(); + else if (comdid == L"modifyuomfolder") + modifyuomfolder(); + else if (comdid == L"deluomfolder") + deluomfolder(); + else if (comdid == L"search") + GridSearch(); + xutil::RestoreCursor(hCursor); + return 0; + } + int OnXCommand(TEvent* evt, LPARAM param) + { + return OnCmdDispatch(evt->xcommand.pStrID); + } + int OnSetFocus(TEvent* evt, LPARAM p) + { + SetAgent(); + tv_1 = new treeview; + tv_1.setNativePointer(GetControl(L"tv_1")); + + HTREEITEM root = tv_1.GetRootItem(); + tv_1.ExpandItem(root); + return 1; + } + int OnDoubleClicked(TEvent* evt, LPARAM p) + { + DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh; + int row = hdr.row; + if (row<1 || row > dw_list.GetRowCount()) return 0; + + xaserverarg arg; + + //xstring str = hdr.data; + xstring colname = hdr.colname; + xstring str = dw_list.GetItemString(row, colname); + arg.AddArg(L"value", str); + openUrl(L"/sale/view/view.dlg/xpage/memo/edit", arg); + xstring comdid = arg.GetArgString(L"comdid"); + if (comdid == L"xmOK") + { + xstring value = arg.GetArgString(L"value"); + dw_list.SetItemString(row, colname, value); + dw_list.Redraw(); + } + + return 1; + } + int ItemOutput() + { + xstring d = xaserver::GetCurrentDate(); + d = d.left(10) + L""; + dw_list.SaveAs(d); + return 1; + } + int OnSelectAllRow() + { + int rows = dw_list.GetRowCount(); + if (rows < 1) return -1; + dw_list.SelectRow(1, rows, true); + dw_list.Redraw(); + return 1; + } + int OnRowCopy() + { + int rows = dw_list.GetRowCount(); + if (rows < 1) return -1; + int cols = dw_list.GetColumnCount(); + xstring str = L""; + int row = dw_list.GetNextSelectRow(1); + int i; + while (row > 0) + { + xstring tmp1 = L""; + for (i = 1; i < cols; i++) + { + int w = dw_list.GetColumnWidth(i); + if (w < 5) continue; + xstring tmp; + if (dw_list.GetItemDisplayString(row, i + 1)) + tmp = dw_list.GetItemDisplayString(row, i + 1); + else + tmp = dw_list.GetItemString(row, i + 1); + tmp1 += tmp + L"\t"; + } + str += tmp1 + L"\r\n"; + row = dw_list.GetNextSelectRow(row + 1); + } + dw_list.SetDataToClip(str); + return 1; + } + int OnColCopy(xstring col) + { + int rows = dw_list.GetRowCount(); + if (rows < 1) return -1; + xstring str = L""; + int row = dw_list.GetNextSelectRow(1); + while (row > 0) + { + xstring tmp; + if (dw_list.GetItemDisplayString(row, col)) + tmp = dw_list.GetItemDisplayString(row, col); + else + tmp = dw_list.GetItemString(row, col); + str += tmp + L"\r\n"; + row = dw_list.GetNextSelectRow(row + 1); + } + dw_list.SetDataToClip(str); + + return 1; + } + int OnRClick(TEvent* evt, LPARAM p) + { + DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh; + int row = hdr.row; + + int m = win::CreatePopupMenu(); + int MF_STRING = 0x00000000; + int MF_DISABLED = 0x00000002; + int TPM_RIGHTBUTTON = 0x0002; + int TPM_RETURNCMD = 0x0100; + int MF_CHECKED = 0x8; + int MF_SEPARATOR = 0x0800; + win::AppendMenu(m, MF_STRING, 1, L"复制行"); + win::AppendMenu(m, MF_STRING, 101, L"复制列"); + win::AppendMenu(m, MF_SEPARATOR, -1, L""); + win::AppendMenu(m, MF_STRING, 2, L"全选"); + win::AppendMenu(m, MF_SEPARATOR, -1, L""); + win::AppendMenu(m, MF_STRING, 4, L"导出到Excel"); + win::AppendMenu(m, MF_SEPARATOR, -1, L""); + win::AppendMenu(m, MF_STRING, 6, L"显示列设置"); + xrect xr; + xpoint pt; + win::GetCursorPos(pt); + int ret = win::TrackPopupMenu(m, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, GetHWND(), xr); + + //trace(ret); + HCURSOR hCursor = xutil::SetCursorWait(); + if (ret == 1) { OnRowCopy(); } + else if (ret == 101) { + xstring colname = hdr.colname; + if (colname != L"") + OnColCopy(colname); + } + else if (ret == 2) { OnSelectAllRow(); } + else if (ret == 4) { ItemOutput(); } + else if (ret == 6) {} + xutil::RestoreCursor(hCursor); + + return 1; + } + int OnAttachEvent() + { + //获取焦点事件,用于重置工具条 + AttachEvent(L"WM_SETFOCUS", (FEvent)&QuickCode_Tree::OnSetFocus); + //绑定工具条点击事件 + AttachEvent(L"WM_XCOMMAND", (FEvent)&QuickCode_Tree::OnXCommand); + //获得树的选择事件 + AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&QuickCode_Tree::OnTreeSelChanged); + AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&QuickCode_Tree::OnDoubleClicked);//行双击 + AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&QuickCode_Tree::OnRClick);//鼠标右键 + return 1; + } + + + xstring jxParam(xstring p, xstring n) + { + if (p != L"") + { + p += L"&"; + int i = 1; + while (p.find(L"=L", 0) > 0) + { + xstring name = p.mid(0, p.find(L"=L", 0)); + xstring value = p.mid(p.find(L"=L", 0) + 1, p.find(L"&", 0) - p.find(L"=L", 0) - 1); + if (name == n) return L"" + value; + i += 1; + p = p.mid(p.find(L"&", 0) + 1, p.length()); + } + } + return L""; + } + int getURLParam() + { + if (GetWinParam()) + { + xpage xp = new xpage; + xp.setNativePointer(GetXPage()); + xstring aurl = xp.GetWkUrl(); + xaserverarg arg; + if (aurl && aurl.find(L"native=true", 0) > 0) + { + int p = GetParam(); + arg; + arg.setNativePointer(p); + } + else + { + arg = GetParam(); + } + xstring config = arg.GetArgString(L"config"); + xml x; + + if (config == L"") + { + xstring configXml = arg.GetArgString(L"configxml"); + x.loadXML(configXml); + } + else + { + getUrl(config, L"", x); + } + m_configDoc = x; + + } + + return 1; + } + int loaded() + { + getURLParam(); + KXMLDOMDocument ee = m_configDoc; + xstring id = m_id; + var n = ee.selectSingleNode(L"//list/dwview[@type='dwgrid'][@id='" + id + L"']"); + if (n) + { + KXMLDOMElement e = n; + //trace(e.xml); + xstring vface = m_configDoc.selectSingleNode(L"//vface[1]").text(); + xstring dwname = L"";//e.selectsingleNode(L"@name").text(); + xstring tpl = L"";//e.selectsingleNode(L"@url").text(); + xstring dbmap = L""; + xstring strtreexquery = L""; + if (e.selectSingleNode(L"@name")) dwname = e.selectSingleNode(L"@name").text(); + if (e.selectSingleNode(L"@url")) tpl = e.selectSingleNode(L"@url").text(); + if (e.selectSingleNode(L"@dbmap")) dbmap = e.selectSingleNode(L"@dbmap").text(); + if (e.selectSingleNode(L"@treexquery")) strtreexquery = e.selectSingleNode(L"@treexquery").text(); + m_dbmap = dbmap; + treexquery = strtreexquery; + //trace(vface +L"/"+ tpl); + //trace(selectmode); + dw_list = new xdwgrid; + dw_list.setNativePointer(GetControl(dwname)); + dw_list.openUrl(vface + L"/" + tpl); + strtpl = tpl; + trace(tpl); + + } + } + int onload() + { + + SetArg(); + m_config = L"QuickCode.config"; + m_agent = L""; + dw_list = new xdwtable; + dw_list.setNativePointer(GetControl(L"dw_list")); + if (GetWinParam()) + { + xaserverarg arg = GetArg(); + //trace(arg.GetString()); + xstring id = arg.GetArgString(L"id"); + if (id == L"") return 0; + m_id = id; + loaded(); + + /*xstring tpl = arg.GetArgString(L"tpl"); + if(tpl == L"") + tpl = L"QuickCode.tpl/QuickCode"; + dw_list.SetDataObject(GetServerUrl(),L"dev:sheet["+tpl+L"]"); + //dw_list.SetColHeaderHeight(0); + //dw_list.SetRowSelectorWidth(0); + xstring dbmap = arg.GetArgString(L"dbmap"); + if(dbmap == L"") + dbmap = L"QuickCode.dbmap"; + m_dbmap = dbmap; + xstring txquery=arg.GetArgString(L"treexquery"); + treexquery=txquery; + xstring title = arg.GetArgString(L"title"); + if(title != L"") + win::SetWindowText(GetHWND(),title);*/ + OnRetrieve(); + } + SetAgent(); + xstring aa = treexquery; + xstring xfNodeAgentArea2 = L"treeagent"; + xnode tnode = new xnode; + tnode.setNativePointer(GetAgentNode(xfNodeAgentArea2)); + xstring stree = L"<vbox><xtree name='tv_1' imagelist='0'>"; + stree += L"<treeitem src='xquery:[" + aa + L"]' xcaption='@GroupName' xroot='/root' xpath='row' xchildpath='row' image='15' loop='yes' xdata='.'/>"; + stree += L"</xtree></vbox>"; + SetAgentNode(tnode, stree); + + tv_1 = new treeview; + tv_1.setNativePointer(GetControl(L"tv_1")); + + HTREEITEM root = tv_1.GetRootItem(); + tv_1.ExpandItem( root); + OnAttachEvent(); + + return 1; + } +}; \ No newline at end of file -- Gitblit v1.9.3