From 6e93e717799723de98287f5a036ab34367bd08cd Mon Sep 17 00:00:00 2001
From: xj qian <qianxj15@sina.com>
Date: 星期五, 05 七月 2024 17:15:44 +0800
Subject: [PATCH] update some

---
 jrj/project/business/AR/ExchageFile.cpp |  504 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 504 insertions(+), 0 deletions(-)

diff --git a/jrj/project/business/AR/ExchageFile.cpp b/jrj/project/business/AR/ExchageFile.cpp
new file mode 100644
index 0000000..1516d05
--- /dev/null
+++ b/jrj/project/business/AR/ExchageFile.cpp
@@ -0,0 +1,504 @@
+#include <wobject/xstring.hpp>
+#include <xcontrol/xtreeview.hpp>
+#include <xcontrol/xdwgrid.hpp>
+
+#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
+#include "viewobject/view.base.hpp"
+
+using xml = KXMLDOMDocument;
+	class __declspec(dllexport) ExchangeFileView : public xframe
+	{
+	public:
+		xcell	dw_exchangefile;
+		xdwtable dw_arg;
+		xdwgrid dw_exch;
+		xstring filename;
+		xnode	m_agentNode;	//Agent Condition
+
+	public:
+		ExchangeFileView(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static ExchangeFileView* CreateInstance(void* implPtr, void* hWnd)
+		{
+			ExchangeFileView* pWin = new ExchangeFileView(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 OnCellClicked(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			//if(hdr.col ==1)hdr.idFrom = -1;
+			//if(hdr.col ==2)hdr.idFrom = -1;
+			if (hdr.row == 1)hdr.idFrom = -1;
+			return 2;
+		}
+
+		int OnValid()
+		{
+			int row = dw_exchangefile.GetValidRow();
+			int col = dw_exchangefile.GetValidCol();
+			for (int i = 2; i < row; i++)
+			{
+
+			}
+			return 1;
+		}
+
+		int OnCellItemChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			/*int currentrow;
+			int currentcol;
+			const xstring data;
+			int anchorrow;
+			int anchorcol;*/
+			if (hdr.currentcol == 1 && hdr.data != L"")
+			{
+				//dw_exchangefile.SetItemString(hdr.currentrow,hdr.currentcol, L"");
+			}
+			return 1;
+		}
+
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
+		{
+			//重置工具条
+			SetAgent();
+			return 1;
+		}
+
+		int OnDeleteRow()
+		{
+			dw_exch.DeleteRow(0);
+			return 1;
+		}
+
+		int OnInsertRow()
+		{
+			int row = dw_exch.InsertRow(0);
+			xstring sdate = publiccode::GetCurrentDate();
+			dw_exch.SetItemString(row, L"CreateDate", sdate);
+			dw_exch.SetItemString(row, L"SEDate", sdate);
+			dw_exch.SetItemString(row, L"CurrencyCode", L"USD");
+			xstring suserid = publiccode::GetUser().id;
+			xstring susername = publiccode::GetUser().name;
+			dw_exch.SetItemString(row, L"CreatorID", suserid);
+			dw_exch.SetItemDisplayString(row, L"CreatorID", susername);
+
+			if (row > 1)
+			{
+				xstring exchrate = dw_exch.GetItemString(row - 1, L"ExchRate");
+				if (exchrate != L"") dw_exch.SetItemString(row, L"ExchRate", exchrate);
+			}
+			return 1;
+		}
+
+
+		int OnTran()
+		{
+			//get head
+			xstring head = L"";
+			xstring val = L"";
+			int cols = dw_exchangefile.GetValidCol(1);
+			for (int col = 1; col <= cols; ++col)
+			{
+				val = dw_exchangefile.GetItemString(1, col);
+				val = val.trim();
+				if (val == L"")continue;
+				if (val.find(L"(L") >= 0) val = val.left(val.find(L"(L"));
+				if (val.find(L"(") >= 0) val = val.left(val.find(L"("));
+				if (val.find(L"[") >= 0) val = val.left(val.find(L"["));
+				if (val.find(L"【") >= 0) val = val.left(val.find(L"【"));
+				if (val.find(L"/") >= 0) val = val.left(val.find(L"/"));
+				if (val.find(L"\r") >= 0) val = val.left(val.find(L"\r"));
+				if (val.find(L"\n") >= 0) val = val.left(val.find(L"\n"));
+				if (head == L"") head = val; else head += L",L" + val;
+			}
+
+			xml x;
+			
+			xaserverarg arg ;
+			arg.setNativePointer(arg.CreateInstance());
+			arg.AddArg(L"head", head);
+			//alert(head);
+			if (getUrl(L"/sale/data/AR/match/bank", arg.GetString(), x) != 1)return 1;
+			KXMLDOMNode n = x.selectSingleNode(L"data/Bank");
+			if (!n)
+			{
+				alert(L"未匹配到合适的银行,请先配置数据转换信息");
+				return 1;
+			}
+
+			KXMLDOMNodeList items = n.selectNodes(L"Item");
+			int len = items.length();
+			IntegerArray indexs = IntegerArray::make();
+			StringArray columns = StringArray::make();
+			xstring bank = n.selectSingleNode(L"@name").text();
+			for (int i = 0; i < len; i++)
+			{
+				KXMLDOMElement e = items.item(i);
+				xstring str = e.getAttribute(L"index");
+				indexs.push_back(str.toInt());
+				columns.push_back(e.selectSingleNode(L"DataColumn").text());
+			}
+
+			if (MessageBox(GetHWND(), L"是否载入" + bank + L"结汇数据!", L"提示", 1) == 2)  return 1;
+
+			SwitchLayer(L"sheet2", L"frame");
+			//set bank account
+			xml xb = ViewObject::RetrieveData(L"/sale/data/AR/tran/bank/info", L"bank", bank);
+			if (xb)
+			{
+				KXMLDOMNode nt = xb.selectSingleNode(L"/data/Item/Account");
+				if (nt)
+				{
+					dw_arg.SetItemString(1, L"Bank", nt.text());
+					if (nt.selectSingleNode(L"@_displaystring"))
+						dw_arg.SetItemDisplayString(1, L"Bank", nt.selectSingleNode(L"@_displaystring").text());
+				}
+
+			}
+
+			//clear data
+			for (int m = dw_exch.GetRowCount(); m > 0; m--)	dw_exch.DeleteRow(m);
+
+
+			//读取客户转换信息
+			xml xc;
+			
+			if (getUrl(L"/sale/data/AR/tran/customer", L"", xc) != 1)
+			{
+				trace(xc.text());
+				return -1;
+			}
+
+			HCURSOR  hCursor = xutil::SetCursorWait();
+			KXMLDOMDocument xdoc = xc;
+
+			int rows = dw_exchangefile.GetValidRow();
+			for (int row = 2; row <= rows; ++row)
+			{
+				val = dw_exchangefile.GetItemString(row, indexs.item(0));
+				if (val.trim() == L"") continue;
+				int curRow = dw_exch.InsertRow(0);
+
+				//init
+				xstring sdate = publiccode::GetCurrentDate();
+				dw_exch.SetItemString(curRow, L"CreateDate", sdate);
+				dw_exch.SetItemString(curRow, L"SEDate", sdate);
+				xstring suserid = publiccode::GetUser().id;
+				xstring susername = publiccode::GetUser().name;
+				dw_exch.SetItemString(curRow, L"CreatorID", suserid);
+				dw_exch.SetItemDisplayString(curRow, L"CreatorID", susername);
+
+				for (int k = 0; k < indexs.length(); k++)
+				{
+					val = dw_exchangefile.GetItemString(row, indexs.item(k));
+					if (columns.item(k) == L"ExchRate")
+					{
+						double d = val.toDouble();
+						if (d > 100.0) d = d / 100.0;
+						dw_exch.SetItemDouble(curRow, L"ExchRate", d);
+					}
+					else if (columns.item(k) == L"CurrencyCode")
+					{
+						if (val == L"美元") val = L"USD";
+					}
+					else if (columns.item(k) == L"CustomerID")
+					{
+						if (xdoc)
+						{
+							KXMLDOMNode n1 = xdoc.selectSingleNode(L"/data/Item[contains(\"" + val + L"\",RawColumn)]");
+							if (n1)
+							{
+								//alert(n1.xml);
+								if (n1.selectSingleNode(L"DataColumn"))dw_exch.SetItemString(curRow, columns.item(k), n1.selectSingleNode(L"DataColumn").text());
+								if (n1.selectSingleNode(L"DataColumn/@_displaystring"))dw_exch.SetItemDisplayString(curRow, columns.item(k), n1.selectSingleNode(L"DataColumn/@_displaystring").text());
+							}
+						}
+					}
+					else
+						dw_exch.SetItemString(curRow, columns.item(k), val);
+				}
+			}
+			xutil::RestoreCursor(hCursor);
+			alert(L"转换完成!");
+
+			return 1;
+		}
+
+		int OnSaveData()
+		{
+			xstring exchRate = dw_arg.GetItemString(1, L"ExchRate");
+			xstring Bank = dw_arg.GetItemString(1, L"Bank");
+			if (Bank == L"")
+			{
+				alert(L"请输入结汇银行!");
+				return 1;
+			}
+			if (exchRate == L"")
+			{
+				alert(L"请输入汇率!");
+				return 1;
+			}
+			for (int row = 1; row <= dw_exch.GetRowCount(); row++)
+			{
+				if (dw_exch.GetItemString(row, L"ExchRate") == L"")
+				{
+					dw_exch.SetItemString(row, L"ExchRate", exchRate);
+				}
+				/*else
+				{
+
+				}*/
+				if (dw_exch.GetItemString(row, L"Bank") == L"")
+				{
+					dw_exch.SetItemString(row, L"Bank", Bank);
+					dw_exch.SetItemDisplayString(row, L"Bank", dw_arg.GetItemDisplayString(1, L"Bank"));
+				}
+			}
+			dw_exch.Redraw();
+
+			xml x;
+			
+			dw_exch.AcceptText();
+			dw_exch.DwUpdateAllToEx(x);
+			xaserverarg arg ;
+			
+			arg.AddArg(L"content", x.xml());
+
+
+
+
+			//trace(x.xml());
+			if (xurl::get(L"/sale/data/AR/update", arg.GetString(), x) != 1)
+			{
+				xstring error = x.text();
+				alert(L"err:" + error);
+				return 1;
+			}
+			xstring str = x.documentElement().getAttribute(L"text");
+			if (str == L"true")
+			{
+				dw_exch.ResetUpdateStatus();
+				alert(L"保存成功!");
+			}
+			else
+			{
+				alert(L"保存失败!");
+			}
+			return 1;
+		}
+
+		int OnSave(bool saveas = false)
+		{
+
+			xstring myurl = L"data/SettleExchange";
+			xstring sfilename = filename;
+			if (filename == L"" || saveas)
+			{
+				xaserverarg arg ;
+				arg.setNativePointer(arg.CreateInstance());
+				arg.AddArg(L"src", L"data/SettleExchange");
+				OpenWindow(L"dev:xpage[trade.document.saveas.vx]", cast(arg as int));
+				if (arg.GetArgString(L"result") == L"ok")
+				{
+					sfilename = arg.GetArgString(L"filename");
+				}
+				else
+					return 1;
+			}
+
+			xstring content = dw_exchangefile.GetData();
+
+			xstring sguid = publiccode::GetGuid();
+			xstring sname = sguid;
+			xstring str = sname.mid(0, 2);
+			str = str.toUpper();
+			xstring suri = L"attachment" + str;
+			int ret = xaserver::UploadData(suri, sguid + L".jpg", content);
+			if (ret < 0)
+			{
+				alert(L"上传文件出错!");
+				return 0;
+			}
+
+			xml x;
+			
+			xaserverarg args ;
+			args.setNativePointer(args.CreateInstance());
+			args.AddArg(L"myurl", myurl);
+			args.AddArg(L"name", sfilename);
+			args.AddArg(L"filepath", sname);
+			args.AddArg(L"fileext", L"xdoc");
+			args.AddArg(L"filesource", sfilename);
+
+
+
+			if (xurl::get(L"/sale/data/TDocument3/attachment/add", args.GetString(), x) != 1)
+			{
+				alert(L"保存出错了!");
+				return 0;
+			}
+			else
+			{
+				filename = sfilename;
+				SetWindowText(GetHWND(), L"结汇文件:" + filename);
+				alert(x.text());
+			}
+
+			return 1;
+		}
+
+		int SendCtrlCmd(xcontrol xc, xstring cmd)
+		{
+			SendMessage(xc.GetId(), 0x401, cmd, 0);
+			return 1;
+		}
+
+
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"xmFileOpen")
+			{
+				xaserverarg args ;
+				args.setNativePointer(args.CreateInstance());
+				args.AddArg(L"src", L"data/SettleExchange");
+				args.AddArg(L"process", L"path");
+				OpenWindow(L"dev:xpage[trade.document.selectdlg.vx]", cast(args as int));
+				if (args.GetArgString(L"result") == L"ok")
+				{
+					xstring u = args.GetArgString(L"src");
+					xml x;
+					
+					xaserver::LoadUrl(GetServerUrl(), u, L"", x);
+					dw_exchangefile.LoadTemplateEx(x.documentElement());
+					dw_exchangefile.Redraw();
+					filename = args.GetArgString(L"filename");
+					SetWindowText(GetHWND(), L"结汇文件:" + filename);
+				}
+				return 1;
+			}
+			else if (comdid == L"xmFileNew")
+			{
+				dw_exchangefile.openUrl(L"/sale/view/AR/template/file");
+				dw_exchangefile.Redraw();
+				filename = L"";
+				SetWindowText(GetHWND(), L"结汇文件:[new]");
+				return 1;
+			}
+			else if (comdid == L"xmFileSave")
+			{
+				return OnSave();
+			}
+			if (comdid == L"xmAddRow")
+			{
+				return OnInsertRow();
+			}
+			else if (comdid == L"xmDeleteRow")
+			{
+				return OnDeleteRow();
+			}
+			else if (comdid == L"xmSave")
+			{
+				return OnSaveData();
+			}
+			else if (comdid == L"xmFileSaveAs")
+			{
+				return OnSave(/*saveas*/true);
+			}
+			else if (comdid.left(3) == L"IK_")
+			{
+				xstring cmd = comdid.mid(3, comdid.length());
+				SendCtrlCmd(GetControl(L"dw_raw"), cmd);
+				return 1;
+			}
+			else if (comdid == L"xmTrans")
+			{
+				OpenWindow(L"dev:xpage[ExchangeColumnTran.vx]");
+				return 1;
+			}
+			else if (comdid == L"xmClient")
+			{
+				OpenWindow(L"dev:xpage[CustomerTran.AR.vx]");
+				return 1;
+			}
+			else if (comdid == L"xmBank")
+			{
+				OpenWindow(L"dev:xpage[ExchangeBankTran.vx]");
+				return 1;
+			}
+			else if (comdid == L"xmTran")
+			{
+				return OnTran();
+			}
+			return 0;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&ExchangeFileView::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&ExchangeFileView::OnSetFocus);
+			AttachEvent(L"dw_exchangefile", L"CELL_ITEMCHANGED", (FEvent)&ExchangeFileView::OnCellItemChanged);
+			AttachEvent(L"dw_exchangefile", L"DWV_CLICKED", (FEvent)&ExchangeFileView::OnCellClicked);
+			return 1;
+		}
+
+
+
+		int onload()
+		{
+			dw_arg = GetControl(L"dw_arg");
+			dw_arg.openUrl(L"/sale/view/AR/template/import/arg");
+			dw_arg.SetColHeaderHeight(0);
+			dw_arg.SetRowSelectorWidth(0);
+			dw_arg.SetHScrollState(false);
+			dw_arg.SetVScrollState(false);
+
+			dw_exchangefile = GetControl(L"dw_raw");
+			dw_exch = GetControl(L"dw_exch");
+			dw_exch.openUrl(L"/sale/view/AR/template/listex");
+			OnAttachEvent();
+
+
+			filename = L"";
+			return 1;
+		}
+
+		int onloaded()
+		{
+			SetAgent();
+			SetWindowText(GetHWND(), L"结汇文件:[new]");
+
+			return 1;
+		}
+	};

--
Gitblit v1.9.3