From 9e409d6e1e2cb1d35cf26f3fd2bd9048c624280f Mon Sep 17 00:00:00 2001
From: LiFan <2308045698@qq.com>
Date: 星期五, 05 七月 2024 11:29:43 +0800
Subject: [PATCH] update AP

---
 jrj/project/business/AP/APBank.cpp                           |  603 ---
 jrj/project/business/AP/APNew3.warizd.cpp                    | 1100 ++++---
 jrj/project/business/AP/maint.ap.cpp                         |  772 +---
 jrj/project/business/VATNotify/list.vatnotify.cpp            |  811 ++---
 jrj/project/business/VATNotify/maint.papercard.vatnotify.cpp | 1261 +++++---
 jrj/project/business/VATNotify/simple.maint.vatnotify.cpp    | 1351 +++++---
 jrj/project/business/VATNotify/VATNotifyParse.cpp            |  616 ---
 jrj/project/business/VATNotify/update.vatnotify.cpp          |  818 ++---
 jrj/project/business/AP/Select.AP.cpp                        |  627 ---
 jrj/project/business/AP/list.ap.cpp                          |  946 +++---
 10 files changed, 3,907 insertions(+), 4,998 deletions(-)

diff --git a/jrj/project/business/AP/APBank.cpp b/jrj/project/business/AP/APBank.cpp
index 6c3d5bb..496b944 100644
--- a/jrj/project/business/AP/APBank.cpp
+++ b/jrj/project/business/AP/APBank.cpp
@@ -6,537 +6,126 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) APListBankMaint : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwtable	dw_base;
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+		xnode	m_agentNode;	//Agent Condition
+
+	public:
+		APListBankMaint(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static APListBankMaint* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			APListBankMaint* pWin = new APListBankMaint(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
+		{
+			//重置工具条
+			SetAgent();
+			return 1;
+		}
 
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"xmCancel")
+			{
+				CloseWindow();
+				return 1;
+			}
+			if (comdid == L"xmOK")
+			{
+				xaserverarg arg = GetArg();
+				dw_base.AcceptText();
+				arg.AddArg(L"PayedTerm", dw_base.GetItemString(1, L"PayedTerm"));
+				arg.AddArg(L"PayedBank", dw_base.GetItemString(1, L"PayedBank"));
+				arg.AddArg(L"PayedBankNo", dw_base.GetItemString(1, L"PayedBankNo"));
+				arg.AddArg(L"result", L"ok");
+				CloseWindow();
+				return 1;
+			}
+			return 0;
+		}
 
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
 
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&APListBankMaint::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&APListBankMaint::OnSetFocus);
+		}
+
+		/*
+		int  OnRetrieve()
+		{
+			xml x ;
+			
+			xaserverarg ;
+			
+			arg.AddArg(L"xxx",L"xxx");
+			if (getUrl(L"",arg.GetString(),x)!=1)
+			{
+				trace(x.text());
 				return -1;
-			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
+			}else
 			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
-			}
-			else
-			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
-			}
-		}
-		return 1;
-	}
-
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
-			}
-			else
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
+				//dw_list.Retrieve(x);
+				//dw_list.Redraw();
 			}
 			return 1;
 		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
+		*/
 
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
+		int onload()
+		{
+			dw_base = GetControl(L"dw_base");
+			dw_base.openUrl(L"/sale/view/AP/template/PayBank");
+
+			dw_base.SetColHeaderHeight(0);
+			dw_base.SetRowSelectorWidth(0);
+			dw_base.SetHScrollState(false);
+			dw_base.SetVScrollState(false);
+
+			OnAttachEvent();
+
 			return 1;
 		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
 
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
+		int onloaded()
+		{
+			SetAgent();
+
 			return 1;
 		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
-			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
-				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
-				}
-			}
-
-		}
-
-		return 1;
-	}
-
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
-
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
-
-};
\ No newline at end of file
+	};
diff --git a/jrj/project/business/AP/APNew3.warizd.cpp b/jrj/project/business/AP/APNew3.warizd.cpp
index 6c3d5bb..3858b6e 100644
--- a/jrj/project/business/AP/APNew3.warizd.cpp
+++ b/jrj/project/business/AP/APNew3.warizd.cpp
@@ -6,537 +6,661 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) APNewWarizd3 : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwgrid	dw_1;
+		xdwgrid	dw_2;
+		xdwgrid	dw_3;
+		xdwgrid	dw_4;
+		xdwgrid	dw_5;
+		xdwgrid	dw_6;
+		xdwgrid	dw_101;
+		xdwgrid	dw_102;
+		bool	    bstart;
+		xlayersheet m_layer;
+		xnode	m_agentNode;	//Agent Condition
+		xstring searchStr;
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+	public:
+		APNewWarizd3(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static APNewWarizd3* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			APNewWarizd3* pWin = new APNewWarizd3(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
+				{
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
+				}
 			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
+			return 1;
 		}
 
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
 
 
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
+		int OnDoubleClicked(TEvent* evt, LPARAM p)
 		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
+			dw_1.AcceptText();
+			dw_2.AcceptText();
 
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
+			HCURSOR hCursor = xutil::SetCursorWait();
+			int col = dw_1.GetColumn();
+			dw_1.ItemChangeTo(dw_1.GetRow(), L"PayAmount", dw_1.GetItemString(dw_1.GetRow(), L"Balance"));
+			dw_1.Redraw();
+			xutil::RestoreCursor(hCursor);
+			return 1;
+		}
+
+		int OnDoubleClickedOne(TEvent* evt, LPARAM p)
 		{
-			//alert(L"1");
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
 
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
+			double Amount = dw_3.GetItemDouble(hdr.row, L"Amount");
+			double PayedAmount = dw_3.GetItemDouble(hdr.row, L"PayedAmount");
 
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
+			if (colname == L"PrePayAmount" || colname == L"Amount")
 			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
+				double Amount1 = dw_3.GetItemDouble(hdr.row, L"Amount");
+				double PrePayAmount = dw_3.GetItemDouble(hdr.row, L"PrePayAmount");
+				dw_3.SetItemDouble(hdr.row, L"PayedAmount", (Amount - PrePayAmount).round(2));
 			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
+			return 1;
 		}
-		else
+
+
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
 		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
+			//重置工具条
+			//SetAgent();
+			return 1;
+		}
+
+		int ProcessBase(xdwgrid dw_obj)
+		{
+			xstring SupplierID;
+			for (int i = 1; i <= dw_obj.GetRowCount(); i++)
 			{
-				int i;
+				bool inserted = false;
+				SupplierID = dw_obj.GetItemString(i, L"SupplierID");
+				int row = 1;
+				/*for(row = 1; row <= dw_3.GetRowCount(); row++)
+				{
+					if( SupplierID ==  dw_3.GetItemString(row,L"SupplierID")) break;
+				}
+				if(row > dw_3.GetRowCount())
+				{*/
+				row = dw_3.InsertRow(0);
+				inserted = true;
+				/*}*/
+				if (inserted)
+				{
+					xstring sdate = win32::GetLocalDate();
+					dw_3.SetItemString(row, L"APDate", sdate);
+
+					dw_3.SetItemString(row, L"CreateDate", sdate);
+					dw_3.SetItemString(row, L"PayedDate", sdate);
+					xstring suserid = publiccode::GetUser().id;
+					xstring susername = publiccode::GetUser().name;
+					dw_3.SetItemString(row, L"CreatorID", suserid);
+					dw_3.SetItemDisplayString(row, L"CreatorID", susername);
+					dw_3.SetItemDouble(row, L"PayedAmount", dw_obj.GetItemDouble(i, L"PayedAmount"));
+					dw_3.SetItemDouble(row, L"PrePayAmount", dw_obj.GetItemDouble(i, L"PrePayAmount"));
+					dw_3.SetItemDouble(row, L"Amount", dw_obj.GetItemDouble(i, L"Amount"));
+
+					dw_3.SetItemString(row, L"APType", L"000"); /*货款*/
+					dw_3.SetItemString(row, L"SupplierID", dw_obj.GetItemString(i, L"SupplierID"));
+					dw_3.SetItemDisplayString(row, L"SupplierID", dw_obj.GetItemDisplayString(i, L"SupplierID"));
+					dw_3.SetItemString(row, L"APSupplierID", dw_obj.GetItemString(i, L"APSupplierID"));
+					dw_3.SetItemDisplayString(row, L"APSupplierID", dw_obj.GetItemDisplayString(i, L"APSupplierID"));
+					dw_3.SetItemDisplayString(row, L"SalespersonID", dw_obj.GetItemDisplayString(i, L"SalespersonID"));
+					dw_3.SetItemString(row, L"SalespersonID", dw_obj.GetItemString(i, L"SalespersonID"));
+					dw_3.SetItemString(row, L"OrgName", dw_obj.GetItemString(i, L"OrgName"));
+					dw_3.SetItemString(row, L"InvoiceNo", dw_obj.GetItemString(i, L"NInvoiceNo"));
+					xstring APID = publiccode::GetGuid();
+					dw_3.SetItemString(row, L"APID", APID);
+				}
+				else
+				{
+					double amt = 0.0;
+					amt = dw_3.GetItemDouble(row, L"PayedAmount");
+					amt += dw_obj.GetItemDouble(i, L"PayedAmount");
+					dw_3.SetItemDouble(row, L"PayedAmount", amt);
+
+					amt = dw_3.GetItemDouble(row, L"PrePayAmount");
+					amt += dw_obj.GetItemDouble(i, L"PrePayAmount");
+					dw_3.SetItemDouble(row, L"PrePayAmount", amt);
+
+					amt = dw_3.GetItemDouble(row, L"Amount");
+					amt += dw_obj.GetItemDouble(i, L"Amount");
+					dw_3.SetItemDouble(row, L"Amount", amt);
+				}
+				dw_obj.SetItemString(i, L"APID", dw_3.GetItemString(row, L"APID"));
+			}
+			dw_3.Redraw();
+
+			return 1;
+		}
+
+		int OnTabSelectedSheet(TEvent* evt, LPARAM p)
+		{
+			int index = m_layer.GetSheetIndex();
+			if (index == 1)
+			{
+				dw_1.AcceptText();
+
+				dw_4.Reset();
+				dw_3.Reset();
+				dw_6.Reset();
+
+				xml x ;
+				
+				x.loadXML(L"<data/>");
+
+				xml x1 ;
+				
+				dw_2.DwUpdateAllToEx(x1);
+				xstring SupplierID = L"";
+				int i = 0;
+				int row = 0;
+				for (i = 1; i <= dw_1.GetRowCount(); i++)
+				{
+					xstring Amount = dw_1.GetItemString(i, L"PayAmount");
+					xstring PrePayAmount = dw_1.GetItemString(i, L"PrePayAmount");
+					SupplierID = dw_1.GetItemString(i, L"VATSupplierID");
+					xstring VATInvoiceID = dw_1.GetItemString(i, L"VATInvoiceID");
+					if (Amount != L"" && Amount.toInt() != 0)
+					{
+						int row = dw_4.InsertRow(0);
+						dw_4.SetItemString(row, L"InvoiceNo", dw_1.GetItemString(i, L"InvoiceNo"));
+						dw_4.SetItemString(row, L"NInvoiceNo", dw_1.GetItemString(i, L"NInvoiceNo"));
+						dw_4.SetItemString(row, L"VATNo", dw_1.GetItemString(i, L"VATNo"));
+
+						dw_4.SetItemString(row, L"Amount", dw_1.GetItemString(i, L"PayAmount"));
+						dw_4.SetItemString(row, L"PrePayAmount", dw_1.GetItemString(i, L"PrePayAmount"));
+						dw_4.SetItemString(row, L"PayedAmount", dw_1.GetItemString(i, L"APAmount"));
+
+						dw_4.SetItemString(row, L"CurrencyCode", L"RMB");
+						dw_4.SetItemString(row, L"SupplierID", dw_1.GetItemString(i, L"SupplierID"));
+						dw_4.SetItemDisplayString(row, L"SupplierID", dw_1.GetItemDisplayString(i, L"SupplierID"));
+						dw_4.SetItemString(row, L"APSupplierID", dw_1.GetItemString(i, L"VATSupplierID"));
+						dw_4.SetItemDisplayString(row, L"APSupplierID", dw_1.GetItemDisplayString(i, L"VATSupplierID"));
+						dw_4.SetItemString(row, L"VATInvoiceID", VATInvoiceID);
+
+						dw_4.SetItemDisplayString(row, L"SalespersonID", dw_1.GetItemDisplayString(i, L"SalespersonID"));
+						dw_4.SetItemString(row, L"SalespersonID", dw_1.GetItemString(i, L"SalespersonID"));
+						dw_4.SetItemString(row, L"OrgName", dw_1.GetItemString(i, L"OrgName"));
+
+						xstring APLineID = publiccode::GetGuid();
+						dw_4.SetItemString(row, L"APLineID", APLineID);
+					}
+				}
+				ProcessBase(dw_4);
+				for (i = 1; i <= dw_6.GetRowCount(); i++)
+				{
+					SupplierID = dw_6.GetItemString(i, L"SupplierID");
+					for (row = 1; row <= dw_3.GetRowCount(); row++)
+					{
+						if (SupplierID == dw_3.GetItemString(row, L"SupplierID"))
+						{
+							dw_6.SetItemString(i, L"APID", dw_3.GetItemString(row, L"APID"));
+							break;
+						}
+					}
+				}
+
+				KXMLDOMNodeList nodes = x1.selectNodes(L"data/Item[DisAmountCurrent != '']");
+				int len = nodes.length();
 				for (i = 0; i < len; i++)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					KXMLDOMNode n = nodes.item(i);
+					x.documentElement().appendChild(n);
 				}
-				tv_1.ExpandItem(0);
+				dw_5.Retrieve(x);
+				dw_5.Redraw();
+				dw_5.SetReadOnly(true);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
+		int ResetDataForContinue()
+		{
+			dw_1.Reset();
+			dw_2.Reset();
+			dw_3.Reset();
+			dw_4.Reset();
+			dw_5.Reset();
+			dw_6.Reset();
 
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
+			return 1;
+		}
 
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
+		int OnSave(bool continueAdd)
+		{
+			dw_3.AcceptText();
+			dw_4.AcceptText();
 
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
+			xstring error;
+			xstring str;
+			xml x ;
+			xml x1 ;
+			xml x2 ;
+			xaserverarg arg;
+			xaserverarg arg1;
+			xaserverarg arg2;
+
+			dw_3.DwUpdateAllToEx(x);
+			arg.AddArg(L"content", x.xml());
+
+			if (xurl::get(L"/sale/data/AP/update", arg.GetString(), x) != 1)
+			{
+				error = x.text();
+				alert(L"err:" + error);
+				return 1;
+			}
+			str = x.documentElement().getAttribute(L"text");
+			if (str != L"true")
+			{
+				alert(L"保存失败1!");
+				return 1;
+			}
+
+			dw_4.DwUpdateAllToEx(x1);
+			arg1.AddArg(L"content", x1.xml());
+
+			if (xurl::get(L"/sale/data/AP/update", arg1.GetString(), x1) != 1)
+			{
+				error = x1.text();
+				alert(L"err:" + error);
+				return 1;
+			}
+			str = x1.documentElement().getAttribute(L"text");
+			if (str != L"true")
+			{
+				alert(L"保存失败2!");
+				return 1;
+			}
+
+			if (dw_6.GetRowCount() > 0)
+			{
+				dw_6.DwUpdateAllToEx(x2);
+				arg2.AddArg(L"content", x2.xml());
+
+				if (xurl::get(L"/sale/data/AP/update", arg2.GetString(), x2) != 1)
+				{
+					error = x2.text();
+					alert(L"err:" + error);
+					return 1;
+				}
+				str = x2.documentElement().getAttribute(L"text");
+				if (str != L"true")
+				{
+					alert(L"保存失败3!");
+					return 1;
+				}
+			}
+
+			dw_3.ResetUpdateStatus();
+			dw_4.ResetUpdateStatus();
+			dw_6.ResetUpdateStatus();
+
+			if (!continueAdd)
+			{
+				alert(L"保存成功!");
+				CloseWindow();
+			}
+			else
+			{
+				ResetDataForContinue();
+				m_layer.SelectSheet(0);
+			}
+
+			return 1;
+		}
+
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			int index;
+			if (comdid == L"xmPrev")
+			{
+				index = m_layer.GetSheetIndex();
+				index--;
+				m_layer.SelectSheet(index);
+			}
+			else if (comdid == L"xmNext")
+			{
+				index = m_layer.GetSheetIndex();
+				index++;
+				if (index == 1)
+				{
+					GetControl(L"sle_filter").SetText(L"");
+					xstring str = L"";
+					if (str != searchStr)
+					{
+						searchStr = str;
+						dw_1.Filter(L"VATSupplierID", searchStr);
+					}
+				}
+				m_layer.SelectSheet(index);
+				return 1;
+			}
+			else if (comdid == L"xmCancel")
+			{
+				CloseWindow();
+				return 1;
+			}
+			else if (comdid == L"xmOk")
+			{
+				return OnSave(false);
+			}
+			else if (comdid == L"xmOkEx")
+			{
+				return OnSave(true);
+			}
+			else if (comdid == L"xmFilter")  return OnFilter();
+			else if (comdid == L"xmQuery")
+			{
+
+				index = m_layer.GetSheetIndex();
+				index++;
+				OnRetrieve();
+
+				if (dw_1.GetRowCount() > 0)
+				{
+					OnPrepayRetrieve(1, bstart);
+					dw_2.Redraw();
+				}
+
+				return 1;
+			}
+			return 0;
+		}
+
+
+		int OnItemChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
+			int row = hdr.row;
+
+			if (colname == L"PayAmount")
+			{
+				double amt = dw_1.GetItemDouble(row, L"PayAmount");
+				dw_1.SetItemDouble(row, L"APAmount", amt);
+				dw_1.Redraw();
+			}
+			if (colname == L"APAmount")
+			{
+				double APAmount = dw_1.GetItemDouble(row, L"APAmount");
+				dw_1.SetItemDouble(row, L"PayAmount", APAmount);
+				dw_1.Redraw();
+			}
+			return 1;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+
+		int OnRowChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+
+			OnPrepayRetrieve(row, bstart);
+			xml x = ViewObject::RetrieveData(L"/sale/data/AP/list/invoice/supplier", L"InvoiceNo", dw_1.GetItemString(row, L"InvoiceNo"),
+				"SupplierID", dw_1.GetItemString(row, L"SupplierID"));
+			if (x) dw_101.Retrieve(x);
+
+			dw_2.Redraw();
+
+			return 1;
+		}
+
+		int OnItemAskStyle(TEvent* evt, LPARAM p)
+		{
+			int DMS_CSSSTYLE = 0x8;
+			DWASKSTYLENMHDR& hdr = *(DWASKSTYLENMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+			int col = hdr.col;
+			xstring colname = hdr.colname;
+
+			int rows = dw_1.GetRowCount();
+			if (row < 1 || row > rows)
+			{
+				return 1;
+			}
+
+			if (colname == L"NInvoiceNo")
+			{
+				xstring NInvoiceNo = dw_1.GetItemString(row, L"NInvoiceNo");
+				xstring InvoiceNo = dw_1.GetItemString(row, L"InvoiceNo");
+				if (NInvoiceNo != InvoiceNo)
+				{
+					hdr.mask = DMS_CSSSTYLE;
+					hdr.cssstyle = L"color:#ff0000";
+				}
+			}
+			return 1;
+		}
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&APNewWarizd3::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&APNewWarizd3::OnSetFocus);
+			AttachEvent(L"dw_1", L"DWV_DOUBLECLICKED", (FEvent)&APNewWarizd3::OnDoubleClicked);//行双击
+			AttachEvent(L"dw_1", L"DWV_ITEMCHANGED", (FEvent)&APNewWarizd3::OnItemChanged);
+			AttachEvent(L"tab_1", L"LYSN_SELECTEDSHEET", (FEvent)&APNewWarizd3::OnTabSelectedSheet);
+			AttachEvent(L"dw_1", L"DWV_ROWFOCUSCHANGED", (FEvent)&APNewWarizd3::OnRowChanged);
+			AttachEvent(L"dw_1", L"DWV_ASKSTYLE", (FEvent)&APNewWarizd3::OnItemAskStyle);
+			return 1;
+		}
+
+		int OnPrepayRetrieve(int row, bool start = false)
+		{
+			xstring supplier = dw_1.GetItemString(row, L"VATSupplierID");
+
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"SupplierID", supplier);
+			arg.AddArg(L"InvoiceNo", dw_1.GetItemString(row, L"InvoiceNo"));
+			if (getUrl(L"/sale/data/AP/prepaychecklistex", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
 				return -1;
 			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
+			else
 			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
+				dw_2.Retrieve(x);
+				dw_2.Redraw();
+			}
+			return 1;
+		}
+
+		int OnPrepayRetrieve0(int row, bool start = false)
+		{
+			xstring supplier = dw_1.GetItemString(row, L"VATSupplierID");
+			xstring VATInvoiceID = dw_1.GetItemString(row, L"VATInvoiceID");
+			xstring filterStr = supplier + L"||" + VATInvoiceID;
+			if (!start)
+			{
+				dw_2.Filter(L"FilterColumn", filterStr);
+				dw_2.Redraw();
+				if (dw_2.GetRowCount() > 0) return 1;
+			}
+
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"SupplierID", supplier);
+			if (getUrl(L"/sale/data/AP/prepaychecklist", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				return -1;
 			}
 			else
 			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
-			}
-		}
-		return 1;
-	}
-
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
-			}
-			else
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
-			}
-			return 1;
-		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
-
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
-		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
-			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
+				if (start)
 				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
+					dw_2.Retrieve(x);
+					dw_2.Redraw();
+					bstart = false;
+				}
+				else
+				{
+					xml x1 ;
+					
+					dw_2.DwUpdateAllToEx(x1);
+					KXMLDOMElement docElement = x1.documentElement();
+					if (docElement)
+					{
+						KXMLDOMNodeList lst = x.selectNodes(L"data/Item");
+						int n = lst.length();
+						for (int i = 0; i < n; i++)
+						{
+							KXMLDOMElement e = lst.item(i);
+							docElement.appendChild(e);
+							KXMLDOMElement fe = x1.createElement(L"FilterColumn");
+							fe.text = filterStr;
+							e.appendChild(fe);
+							fe.Release();
+							e.Release();
+						}
+						docElement.Release();
+						lst.Release();
+						dw_2.Retrieve(x1);
+					}
+					else
+					{
+						dw_2.Retrieve(x);
+					}
+					dw_2.Filter(L"FilterColumn", filterStr);
+					dw_2.Redraw();
 				}
 			}
-
+			return 1;
 		}
 
-		return 1;
-	}
+		int  OnRetrieve()
+		{
+			HCURSOR  hCursor = xutil::SetCursorWait();
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"QueryTxt", GetControl(L"sle_search").GetText());
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
+			xcombobox cbx_type = GetControl(L"cbx_ship");
+			int h = xcombobox::GetCurSel(cbx_type.GetId());
+			if (h < 0) return 1;
+			xstring str = xcombobox::GetItemData(cbx_type.GetId());
+			arg.AddArg(L"ShipDays", str);
+			trace(str);
+			if (getUrl(L"/sale/data/AP/list101", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				xutil::RestoreCursor(hCursor);
+				return -1;
+			}
+			else
+			{
+				dw_1.Retrieve(x);
+				dw_1.Redraw();
+			}
+			bstart = true;
+			xutil::RestoreCursor(hCursor);
+			return 1;
+		}
 
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
+		int OnFilter()
+		{
+			xstring str = GetControl(L"sle_filter").GetText();
+			if (str != searchStr)
+			{
+				searchStr = str;
+				dw_1.Filter(L"*", searchStr);
 
-};
\ No newline at end of file
+				if (dw_1.GetRowCount() > 0)
+				{
+					OnPrepayRetrieve(1, bstart);
+					dw_2.Redraw();
+				}
+				return 1;
+			}
+			return 1;
+		}
+
+		int onload()
+		{
+			m_layer = GetControl(L"tab_1");
+			dw_1 = GetControl(L"dw_1");
+			dw_1.openUrl(L"/sale/view/AP/template/ImportList100");
+			dw_1.SetAskStyle(true);
+
+			dw_1.SetColumnState(L"VATNo", false);
+			dw_1.SetColumnState(L"APAmount", false);
+			dw_1.SetColumnState(L"PrePayAmount", false);
+			dw_1.SetColumnState(L"PrePayBalance", false);
+			dw_1.SetColumnState(L"VATDate", false);
+			dw_1.SetColumnState(L"InvoiceNo", false);
+			dw_1.SetColumnState(L"SupplierID", false);
+
+			dw_2 = GetControl(L"dw_2");
+			dw_2.openUrl(L"/sale/view/AP/template/ImportList2");
+			dw_2.SetColumnState(L"Balance", false);
+			dw_2.SetColumnState(L"DisAmountCurrent", false);
+			dw_2.SetColumnState(L"DisAmount", false);
+
+			dw_101 = GetControl(L"dw_101");
+			dw_101.openUrl(L"/sale/view/AP/template/AP/List1");
+			dw_102 = GetControl(L"dw_102");
+			dw_102.openUrl(L"/sale/view/AP/template/AP/List1");
+
+			dw_3 = GetControl(L"dw_3");
+			dw_3.openUrl(L"/sale/view/AP/template/ImportList3");
+			dw_4 = GetControl(L"dw_4");
+			dw_4.openUrl(L"/sale/view/AP/template/ImportList4");
+
+			dw_5 = GetControl(L"dw_5");
+			dw_5.openUrl(L"/sale/view/AP/template/ImportList5");
+			dw_6 = GetControl(L"dw_6");
+			dw_6.openUrl(L"/sale/view/AP/template/ImportList6");
+
+			OnAttachEvent();
+			searchStr = L"";
+			bstart = true;
+
+			return 1;
+		}
+
+		int onloaded()
+		{
+			return 1;
+		}
+	};
diff --git a/jrj/project/business/AP/Select.AP.cpp b/jrj/project/business/AP/Select.AP.cpp
index 6c3d5bb..5ed3e2f 100644
--- a/jrj/project/business/AP/Select.AP.cpp
+++ b/jrj/project/business/AP/Select.AP.cpp
@@ -6,537 +6,130 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) APSelectDlg : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwgrid	dw_list;
+		xcontrol query;
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+		xnode	m_agentNode;	//Agent Condition
+
+	public:
+		APSelectDlg(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static APSelectDlg* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			APSelectDlg* pWin = new APSelectDlg(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
+			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 param)
+		{
+			//重置工具条
+			SetAgent();
+			return 1;
+		}
+		int onOk()
+		{
+			xaserverarg arg = GetArg();
+			arg.AddArg(L"items", L"");
+			KXMLDOMElement ele = dw_list.GetRowElement(dw_list.GetRow());
+			arg.AddArg(L"items", L"<data>" + xstring(ele.xml()) + L"</data>");
+			CloseWindow();
+			return 1;
+		}
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"xmCancel")
+			{
+				CloseWindow();
+				return 1;
+			}
+			else if (comdid == L"xmQuery")
+			{
+				RetrieveData();
+				return 1;
+			}
+			else if (comdid == L"xmOk")
+			{
+				onOk();
+				return 1;
+			}
+			return 0;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&APSelectDlg::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&APSelectDlg::OnSetFocus);
+			AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&APSelectDlg::onOk);
+		}
+
+		int RetrieveData()
+		{
+			xstring keyword = query.GetText();
+			trace(keyword);
+			xml x = ViewObject::RetrieveData(L"/sale/data/PurchaseOrder/po/searchadvance", L"PONo", keyword);
+			if (x)
+				dw_list.Retrieve(x);
 			dw_list.Redraw();
 			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
-			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
-				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
-				}
-				tv_1.ExpandItem(0);
-			}
-		}
-
-		return 1;
-	}
-
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
-
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
-
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
-				return -1;
-			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
-			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
-			}
-			else
-			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
-			}
-		}
-		return 1;
-	}
-
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
-			}
-			else
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
-			}
 			return 1;
 		}
-		if (comdid == L"action:bill.Annex")
+
+		int onload()
 		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
-
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
-		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
+			dw_list = GetControl(L"dw_list");
+			dw_list.openUrl(L"/sale/view/PurchaseOrder/template/purchaseorder/POAdvance");
+			OnAttachEvent();
+			dw_list.SetColumnState(L"POID", false);
+			dw_list.SetColumnState(L"PartyID", false);
+			xaserverarg arg = GetArg();
+			xstring PONo;
+			if (arg)
 			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
-				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
-				}
+				PONo = arg.GetArgString(L"PONo");
 			}
-
+			query = GetControl(L"sle_search");
+			query.SetText(PONo);
+			RetrieveData();
+			return 1;
 		}
 
-		return 1;
-	}
+		int onloaded()
+		{
+			SetAgent();
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
-
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
-
-};
\ No newline at end of file
+			return 1;
+		}
+	};
diff --git a/jrj/project/business/AP/list.ap.cpp b/jrj/project/business/AP/list.ap.cpp
index 6c3d5bb..3d185f7 100644
--- a/jrj/project/business/AP/list.ap.cpp
+++ b/jrj/project/business/AP/list.ap.cpp
@@ -6,537 +6,509 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) ListAP : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xstring apType;
+		xstring DatePicker;
+		xstring DatePickerOne;
+		xdwgrid	dw_list;
+		xdwtable dw_arg;
+		xnode	m_agentNode;	//Agent Condition
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+	public:
+		ListAP(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static ListAP* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			ListAP* pWin = new ListAP(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
-
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
-
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
-
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
-				return -1;
-			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
 		{
-			xstring error = x.text();
-			trace(error);
+			//重置工具条
+			SetAgent();
+			return 1;
 		}
-		else
+
+		xstring GetPayType()
 		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
+			xcombobox cbx_type = GetControl(L"cbx_type");
+			int h = xcombobox::GetCurSel(cbx_type.GetId());
+			if (h < 0) return "";
+			return xcombobox::GetLBText(cbx_type.GetId(), h);
+		}
+
+		xstring GetEntityName(int pr)
+		{
+			return L"AP3";
+		}
+
+		xstring GetEntityIDName(int /*param*/ pr)
+		{
+			return L"APID";
+		}
+
+		xstring GetEntityID(int /*param*/ pr)
+		{
+			return dw_list.GetItemString(dw_list.GetRow(), L"APID");
+		}
+
+		int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
+		{
+			if (updateItem == L"del")
 			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
+				int DelRow = dw_list.GetRow();
+				dw_list.DeleteRow(DelRow);
+				return 1;
 			}
-			else
+			return 1;
+		}
+
+		int OnBank()
+		{
+			xaserverarg arg;
+			
+			OpenWindow(L"dev:xpage[APBank.vx]", arg);
+			if (arg.GetArgString(L"result") == L"ok")
 			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
+				int ll_row = dw_list.GetNextSelectRow(1);
+				dw_list.AcceptText();
+
+				while (ll_row > 0 && ll_row <= dw_list.GetRowCount())
+				{
+					dw_list.SetItemString(ll_row, L"PayedTerm", arg.GetArgString(L"PayedTerm"));
+					dw_list.SetItemString(ll_row, L"PayedBank", arg.GetArgString(L"PayedBank"));
+					dw_list.SetItemString(ll_row, L"PayedBankNo", arg.GetArgString(L"PayedBankNo"));
+					ll_row = dw_list.GetNextSelectRow(ll_row + 1);
+				}
+				dw_list.Redraw();
+				return 1;
 			}
+			else return 1;
 		}
-		return 1;
-	}
 
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
 		{
-
-			if (TypeWork.find(L"采购") >= 0)
+			if (comdid == L"xmBank") return OnBank();
+			if (comdid == L"xmSave") return OnSave();
+			if (comdid == L"xmAnalysis") return OnAnalysis();
+			if (comdid == L"xmRefresh" || comdid == L"xmSearch")
 			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
+				xstring payTypeOne = GetPayType();
+				if (payTypeOne == L"已付货款" || payTypeOne == L"待付货款")
+				{
+					return OnRetrieveEx(apType, DatePicker);
+				}
+				else if (payTypeOne == L"预付货款")
+				{
+					apType = L"001";
+					return OnRetrieveEx(apType, DatePicker);
+				}
+				else if (payTypeOne == L"预付货款(已冲)L")
+				{
+					apType = L"001";
+					return OnRetrieveEx1(apType, DatePickerOne);
+				}
+
 			}
-			else
+			if (comdid == L"xmAddRow")
 			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
+				xstring payType = GetPayType();
+				if (payType == L"已付货款" || payType == L"待付货款")
+					OpenWindow(L"dev:xpage[APNew3.warizd.vx]");
+				else if (payType == L"预付货款" || payType == L"预付货款(已冲)L")
+				{
+					xaserverarg arg1;
+					
+					arg1.AddArg(L"APType", apType);
+					
+					OpenWindow(L"dev:xpage[maint.ap.vx]", arg1);
+				}
+				return 1;
 			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
+			if (comdid == L"xmSaveAs")
 			{
 				dw_list.SaveAs(L"");
+				return 1;
+			}
+			if (comdid == L"xmModifyRow")
+			{
+
+				int row = dw_list.GetRow();
+				if (row < 1) return 1;
+				KXMLDOMElement ele = dw_list.GetRowElement(row);
+				xstring APID = ele.selectSingleNode(L"APID").text();
+				ele.Release();
+				xaserverarg arg;
+				
+				arg.AddArg(L"APID", APID);
+				arg.AddArg(L"APType", apType);
+				
+				OpenWindow(L"dev:xpage[maint.ap.vx]", pa);
+				return 1;
+			}
+			if (comdid.find(L"action:", 0) >= 0)
+			{
+				xstring payType1 = GetPayType();
+				if (payType1 == L"已付货款" || payType1 == L"预付货款") ProcessFlowAction(comdid, 1);
+			}
+			return 0;
+		}
+
+		int OnDoubleClicked(TEvent* evt, LPARAM p)
+		{
+			return OnCmdDispatch(L"xmModifyRow");
+		}
+
+		int OnCombboChanged(TEvent* evt, int lParam)
+		{
+			xstring id = L"";
+			xstring name = L"";
+			int h = xcombobox::GetCurSel(evt.hCtrl);
+			if (h > -1)
+			{
+				xstring txt = xcombobox::GetLBText(evt.hCtrl, h);
+				apType = L"---";
+				if (txt == L"已付货款")
+				{
+					dw_list.openUrl(L"/sale/view/AP/template/AP/list1");
+					apType = L"000";
+					OnRetrieveEx(apType, DatePicker);
+				}
+				else if (txt == L"待付货款")
+				{
+					dw_list.openUrl(L"/sale/view/AP/template/AP/list2");
+					OnRetrieveEx(apType, DatePicker);
+				}
+				else if (txt == L"预付货款")
+				{
+					dw_list.openUrl(L"/sale/view/AP/template/AP/list3");
+					apType = L"001";
+					OnRetrieveEx(apType, DatePicker);
+				}
+				else if (txt == L"预付货款(已冲)L")
+				{
+					dw_list.openUrl(L"/sale/view/AP/template/AP/list3");
+					apType = L"001";
+					OnRetrieveEx1(apType, DatePickerOne);
+				}
+
+				dw_list.SetColumnState(L"APID", false);
+
 			}
 			return 1;
 		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
 
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
 		}
-		if (comdid == L"action:bill.AnnexEx")
+
+		int OnItemChanged(TEvent* evt, LPARAM p)
 		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
+			//if(datareading) return 0;
+			HCURSOR HCursor = xutil::SetCursorWait();
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+			xstring col = hdr.colname;
+			xstring data = hdr.data;
+			xstring ETD = L"";
+			if (col == L"InvoiceNo")
 			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
+				if (dw_list.GetItemString(row, L"InvoiceNo") != L"")
 				{
+					xml x12 = ViewObject::RetrieveData(L"/sale/data/AP/GetInvoiceNoEx", L"InvoiceNo", dw_list.GetItemString(row, L"InvoiceNo"));
+					if (x12)
+					{
+						xstring COUNT = x12.text();
+						if (COUNT != L"")
+						{
+							alert(COUNT);
+							dw_list.SetItemString(row, L"InvoiceNo", L"");
+							dw_list.SetItemString(row, L"NotifyInvoiceNo", L"");
+							dw_list.SetItemString(row, L"GDNDate", L"");
+							dw_list.Redraw();
+							return 1;
+						}
+					}
 
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
+					xml x11 = ViewObject::RetrieveData(L"/sale/data/AP/GetInvoiceNo", L"InvoiceNo", dw_list.GetItemString(row, L"InvoiceNo"));
+					if (x11)
+					{
+						 ETD = x11.text();
+					}
+					dw_list.SetItemString(row, L"NotifyInvoiceNo", dw_list.GetItemString(row, L"InvoiceNo"));
+					dw_list.SetItemString(row, L"GDNDate", ETD);
+					dw_list.Redraw();
 
+					return 1;
+				}
+				else
+				{
+					dw_list.SetItemString(row, L"NotifyInvoiceNo", L"");
+					dw_list.SetItemString(row, L"GDNDate", L"");
+					dw_list.Redraw();
 				}
 			}
 
+			return 1;
 		}
 
-		return 1;
-	}
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&ListAP::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&ListAP::OnSetFocus);
+			AttachEvent(L"cbx_type", L"CBN_SELCHANGE", (FEvent)&ListAP::OnCombboChanged);//属性组切换list中列的数量变化
+			AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&ListAP::OnDoubleClicked);//行双击
+			AttachEvent(L"cbx_state", L"CBN_SELCHANGE", (FEvent)&ListAP::OnDatePicker);
+			AttachEvent(L"dw_list", L"DWV_ITEMCHANGED", (FEvent)&ListAP::OnItemChanged);
+		}
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
+		int OnDatePicker(TEvent* evt, int lParam)
+		{
+			xstring payTypeTwo = GetPayType();
+			if (payTypeTwo == L"已付货款" || payTypeTwo == L"待付货款")
+			{
+				int h = xcombobox::GetCurSel(evt.hCtrl);
+				if (h > -1)
+				{
+					xstring txt = xcombobox::GetLBText(evt.hCtrl, h);
+					if (txt == L"出运日期")
+					{
+						apType = L"000";
+						DatePicker = L"GDNDate";
+						OnRetrieveEx(apType, DatePicker);
+					}
+					else if (txt == L"请款日期")
+					{
+						apType = L"000";
+						DatePicker = L"APDate";
+						OnRetrieveEx(apType, DatePicker);
+					}
+					else if (txt == L"付款日期")
+					{
+						apType = L"000";
+						DatePicker = L"PayedDate";
+						OnRetrieveEx(apType, DatePicker);
+					}
+				}
+			}
+			else if (payTypeTwo == L"预付货款")
+			{
+				int h1 = xcombobox::GetCurSel(evt.hCtrl);
+				if (h1 > -1)
+				{
+					xstring txt1 = xcombobox::GetLBText(evt.hCtrl, h1);
+					if (txt1 == L"出运日期")
+					{
+						apType = L"001";
+						DatePicker = L"GDNDate";
+						OnRetrieveEx(apType, DatePicker);
+					}
+					else if (txt1 == L"请款日期")
+					{
+						apType = L"001";
+						DatePicker = L"APDate";
+						OnRetrieveEx(apType, DatePicker);
+					}
+					else if (txt1 == L"付款日期")
+					{
+						apType = L"001";
+						DatePicker = L"PayedDate";
+						OnRetrieveEx(apType, DatePicker);
+					}
+				}
+			}
+			else if (payTypeTwo == L"预付货款(已冲)L")
+			{
+				int h2 = xcombobox::GetCurSel(evt.hCtrl);
+				if (h2 > -1)
+				{
+					xstring txt2 = xcombobox::GetLBText(evt.hCtrl, h2);
+					if (txt2 == L"出运日期")
+					{
+						apType = L"001";
+						DatePickerOne = L"GDNDate";
+						OnRetrieveEx1(apType, DatePickerOne);
+					}
+					else if (txt2 == L"请款日期")
+					{
+						apType = L"001";
+						DatePickerOne = L"APDate";
+						OnRetrieveEx1(apType, DatePickerOne);
+					}
+					else if (txt2 == L"付款日期")
+					{
+						apType = L"001";
+						DatePickerOne = L"PayedDate";
+						OnRetrieveEx1(apType, DatePickerOne);
+					}
+				}
+			}
+			return 1;
+		}
 
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
+		int OnSave()
+		{
+			xml x ;
+			
+			dw_list.DwUpdateAllToEx(x);
+			xaserverarg arg;
+			
+			arg.AddArg(L"content", x.xml());
+			//trace(x.xml);
+			if (xurl::get(L"/sale/data/AP/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_list.ResetUpdateStatus();
+				alert(L"保存成功!");
+			}
+			else
+			{
+				alert(L"保存失败!");
+			}
+			return 1;
+		}
 
-};
\ No newline at end of file
+		int  OnRetrieveEx1(xstring APType, xstring DatePickerOne)
+		{
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"QueryTxt", GetControl(L"sle_search").GetText());
+			arg.AddArg(L"APType", APType);
+			arg.AddArg(L"QueryArg", GetQueryArg());
+			arg.AddArg(L"DatePicker", DatePickerOne);
+
+			trace(GetQueryArg());
+			if (getUrl(L"/sale/data/AP/list9", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				return -1;
+			}
+			else
+			{
+				dw_list.Retrieve(x);
+				dw_list.Redraw();
+				dw_list.SetReadOnly(true);
+				dw_list.SetSelectionMode(1);
+			}
+			return 1;
+		}
+
+		xstring GetQueryArg()
+		{
+			dw_arg.AcceptText();
+			xml x ;
+			
+			dw_arg.DwUpdateAllTo(x);
+
+			return x.xml();
+		}
+
+		int  OnRetrieveEx(xstring APType, xstring DatePicker)
+		{
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"QueryTxt", GetControl(L"sle_search").GetText());
+			arg.AddArg(L"APType", APType);
+			arg.AddArg(L"QueryArg", GetQueryArg());
+			arg.AddArg(L"DatePicker", DatePicker);
+
+			trace(GetQueryArg());
+			if (getUrl(L"/sale/data/AP/list", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				return -1;
+			}
+			else
+			{
+				//trace(L"xml=L"+x.xml);
+				dw_list.Retrieve(x);
+				dw_list.Redraw();
+				//dw_list.SetReadOnly(true);
+				dw_list.SetSelectionMode(1);
+			}
+			return 1;
+		}
+
+		int OnAnalysis()
+		{
+			HCURSOR hCursor = xutil::SetCursorWait();
+			xstring str = dw_list.DataAnalysis(L"");
+			xaserverarg arg;
+			
+			arg.AddArg(L"html", str);
+			int obj = cast(dw_list as int);
+			arg.AddArg(L"obj", obj.toString());
+			OpenWindow(L"dev:xpage[data.vanalysis.vx]", arg);
+			xutil::RestoreCursor(hCursor);
+			return 1;
+		}
+
+		int onload()
+		{
+			dw_list = GetControl(L"dw_list");
+			dw_list.openUrl(L"/sale/view/AP/template/AP/list1");
+			dw_list.SetColumnState(L"APID", false);
+			dw_list.SetColumnState(L"SupplierID", false);
+			dw_list.SetColumnState(L"VATNo", false);
+
+			dw_arg = GetControl(L"dw_arg");
+			dw_arg.openUrl(L"/sale/view/AR/template/queryarg");
+			dw_arg.SetColHeaderHeight(0);
+			dw_arg.SetRowSelectorWidth(0);
+			dw_arg.SetHScrollState(false);
+			dw_arg.SetVScrollState(false);
+			dw_arg.SetItemString(1, L"DateType", L"本月");
+
+			OnAttachEvent();
+			apType = L"000";
+			OnRetrieveEx(apType, DatePicker);
+
+			return 1;
+		}
+
+		int onloaded()
+		{
+			SetAgent();
+
+			return 1;
+		}
+	};
diff --git a/jrj/project/business/AP/maint.ap.cpp b/jrj/project/business/AP/maint.ap.cpp
index 6c3d5bb..02e4f58 100644
--- a/jrj/project/business/AP/maint.ap.cpp
+++ b/jrj/project/business/AP/maint.ap.cpp
@@ -6,537 +6,299 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) MaintAP : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
-
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+	public:
+		xstring APID;
+		xstring APType;
+		xdwtable dw_base;
+		xnode	m_agentNode;	//Agent Condition
+		int hObject = 0;
+	public:
+		MaintAP(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static MaintAP* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			MaintAP* pWin = new MaintAP(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
+		{
+			//重置工具条
+			SetAgent();
+			return 1;
+		}
+		int updateAdvance()
+		{
+			xstring AdvanceID = dw_base.GetItemString(1, L"AdvanceID");
+			xstring ChargeOffState = L"Y";
+			xstring ChargeOffDate = dw_base.GetItemString(1, L"APDate");
+			xstring PayedAmount = dw_base.GetItemString(1, L"PayedAmount");
+			xstring val = L"<data><PO><item guid='" + AdvanceID + L"' update.modify='1'>" +
+				"<ChargeOffState update.modify='1'>" + ChargeOffState + L"</ChargeOffState>" +
+				"<ChargeOffMoney update.modify='1'>" + PayedAmount + L"</ChargeOffMoney>" +
+				"<ChargeOffDate update.modify='1'>" + ChargeOffDate + L"</ChargeOffDate></item></PO></data>";
+			xaserverarg arg;
+			
+			arg.AddArg(L"content", val);
+			xml x ;
+			
+			if (xurl::get(L"/sale/data/PurchaseOrder/update/polistex", arg.GetString(), x) != 1)
+			{
+				xstring error = x.text();
+				//alert(error);
+				return 0;
+			}
+			return 1;
+		}
 
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
+		int OnSave()
+		{
+			xstring APNo = dw_base.GetItemString(1, L"APNo");
+			xml x ;
+			if (APNo == L"")
+			{
+				x = ViewObject::RetrieveData(L"/sale/data/AP/MakeAPNo");
+				APNo = x.text();
+				dw_base.SetItemString(1, L"APNo", APNo);
+			}
+			xstring AdvanceID = dw_base.GetItemString(1, L"AdvanceID");
+			xstring OrigSysID = dw_base.GetItemString(1, L"OrigSysID");
+			xstring APType1 = dw_base.GetItemString(1, L"APType");
+			if (APType1 != L"000")
+			{
+				if (AdvanceID == L"" && OrigSysID != L"") {
+					alert(L"请转入");
+					return 0;
+				}
+			}
 
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
+			
+			dw_base.AcceptText();
+			dw_base.DwUpdateAllTo(x);
+			xaserverarg arg;
+			
+			arg.AddArg(L"content", x.xml());
 
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
+			if (xurl::get(L"/sale/data/AP/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_base.ResetUpdateStatus();
+				updateAdvance();
+				alert(L"保存成功!");
+				SendMessage(hObject, 0x401, L"xmRefresh", 0);
+				CloseWindow();
+			}
+			else
+			{
+				alert(L"保存失败!");
+			}
+			return 1;
+		}
+
+		int OnItemChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
+			int row = hdr.row;
+			xstring dwname = L"dw_base";
+			xstring ETD = L"";
+
+			if (value == L"") return 1;
+			if (colname == L"SupplierID")
+			{
+				dw_base.SetItemString(1, L"APSupplierID", dw_base.GetItemString(1, L"SupplierID"));
+				dw_base.SetItemDisplayString(1, L"APSupplierID", dw_base.GetItemDisplayString(1, L"SupplierID"));
+			}
+			if (colname == L"Amount")
+			{
+				dw_base.SetItemString(1, L"PayedAmount", dw_base.GetItemString(1, L"Amount"));
+			}
+			if (colname == L"InvoiceNo")
+			{
+				dw_base.SetItemString(1, L"NotifyInvoiceNo", dw_base.GetItemString(1, L"InvoiceNo"));
+
+				xml x11 = ViewObject::RetrieveData(L"/sale/data/AP/GetInvoiceNo", L"InvoiceNo", dw_base.GetItemString(1, L"InvoiceNo"));
+				if (x11)
+				{
+					ETD = x11.text();
+				}
+				dw_base.SetItemString(1, L"GDNDate", ETD);
+			}
+
+			return 1;
+
+		}
+		int OnImport()
+		{
+			xaserverarg arg1;
+			
+			arg1.AddArg(L"PONo", dw_base.GetItemString(1, L"PONo"));
+			OpenWindow(L"dev:xpage[Select.AP.vx]", arg1);
+			xstring str = arg1.GetArgString(L"items");
+			if (str != L"")
+			{
+				xml x ;
+				
+				x.loadXML(str);
+				KXMLDOMNodeList items = x.selectNodes(L"data/item");
+				KXMLDOMNode t = items.item(0);
+				KXMLDOMNodeList items1 = x.selectNodes(L"data");
+				KXMLDOMNode t1 = items1.item(0);
+				if (t1.selectSingleNode(L"item/@guid"))dw_base.SetItemString(1, L"AdvanceID", t1.selectSingleNode(L"item/@guid").text());
+				if (t.selectSingleNode(L"PONo"))dw_base.SetItemString(1, L"PONo", t.selectSingleNode(L"PONo").text());
+				if (t.selectSingleNode(L"OrgName"))dw_base.SetItemString(1, L"OrgName", t.selectSingleNode(L"OrgName").text());
+				if (t.selectSingleNode(L"SalespersonID/@_displaystring"))dw_base.SetItemDisplayString(1, L"SalespersonID", t.selectSingleNode(L"SalespersonID/@_displaystring").text());
+				if (t.selectSingleNode(L"SalespersonID"))dw_base.SetItemString(1, L"SalespersonID", t.selectSingleNode(L"SalespersonID").text());
+				if (t.selectSingleNode(L"AdvancedMoney"))dw_base.SetItemString(1, L"Amount", t.selectSingleNode(L"AdvancedMoney").text());
+				if (t.selectSingleNode(L"AdvancedMoney"))dw_base.SetItemString(1, L"PayedAmount", t.selectSingleNode(L"AdvancedMoney").text());
+				if (t.selectSingleNode(L"PartyID"))dw_base.SetItemString(1, L"SupplierID", t.selectSingleNode(L"PartyID").text());
+				if (t.selectSingleNode(L"PartyID"))dw_base.SetItemString(1, L"APSupplierID", t.selectSingleNode(L"PartyID").text());
+				if (t.selectSingleNode(L"ShortName"))dw_base.SetItemDisplayString(1, L"APSupplierID", t.selectSingleNode(L"ShortName").text());
+				if (t.selectSingleNode(L"ShortName"))dw_base.SetItemDisplayString(1, L"SupplierID", t.selectSingleNode(L"ShortName").text());
+				if (t.selectSingleNode(L"SONo"))dw_base.SetItemString(1, L"SONO", t.selectSingleNode(L"SONo").text());
+
+				if (t.selectSingleNode(L"POAmount"))dw_base.SetItemString(1, L"POAmount", t.selectSingleNode(L"POAmount").text());
+			}
+			return 1;
+		}
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"xmImport")
+			{
+				OnImport();
+				return 1;
+			}
+			else if (comdid == L"xmClose")
+			{
+				CloseWindow();
+				return 1;
+			}
+			else if (comdid == L"xmSave")
+			{
+				return OnSave();
+			}
+			return 0;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&MaintAP::OnXCommand);
+			AttachEvent(L"dw_base", L"DWV_ITEMCHANGED", (FEvent)&MaintAP::OnItemChanged);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&MaintAP::OnSetFocus);
+		}
+
+		int  OnRetrieve()
+		{
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"EntityID", APID);
+			if (getUrl(L"/sale/data/AP/base", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
 				return -1;
 			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
+			else
 			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
+				dw_base.Retrieve(x);
+				dw_base.Redraw();
+			}
+			return 1;
+		}
+
+		int onload()
+		{
+			APID = L"";
+			APType = L"";
+			if (GetWinParam())
+			{
+				xaserverarg arg=GetArg();
+			
+				APID = arg.GetArgString(L"APID");
+				APType = arg.GetArgString(L"APType");
+			}
+			dw_base = GetControl(L"dw_base");
+			dw_base.openUrl(L"/sale/view/AP/template/Base1");
+			dw_base.SetColHeaderHeight(0);
+			dw_base.SetRowSelectorWidth(0);
+			dw_base.SetHScrollState(false);
+			dw_base.SetVScrollState(false);
+
+			OnAttachEvent();
+
+			if (APID != L"")
+			{
+				OnRetrieve();
 			}
 			else
 			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
+				xstring sdate = publiccode::GetCurrentDate();
+				dw_base.SetItemString(1, L"APDate", sdate);
+				dw_base.SetItemString(1, L"PayedDate", sdate);
+				dw_base.SetItemString(1, L"CreateDate", sdate);
+				xstring suserid = publiccode::GetUser().id;
+				xstring susername = publiccode::GetUser().name;
+				dw_base.SetItemString(1, L"CreatorID", suserid);
+				dw_base.SetItemDisplayString(1, L"CreatorID", susername);
+				dw_base.SetItemString(1, L"APType", L"001");
+				dw_base.SetItemDisplayString(1, L"APType", L"预付款");
+				dw_base.SetItemString(1, L"ApprovalStatus", L"6");
+
 			}
-		}
-		return 1;
-	}
-
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
+			for (int m = 1; m <= dw_base.GetColumnCount(); m++)
 			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
-			}
-			else
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
+				xstring col = dw_base.GetColumnName(m);
+				if (col == L"OrgName" || col == L"APNo")
+					dw_base.SetColumnProp(col, L"cellprotect", L"1");
 			}
 			return 1;
 		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
 
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
+		int onloaded()
+		{
+			SetAgent();
+
 			return 1;
 		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
-			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
-				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
-				}
-			}
-
-		}
-
-		return 1;
-	}
-
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
-
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
-
-};
\ No newline at end of file
+	};
diff --git a/jrj/project/business/VATNotify/VATNotifyParse.cpp b/jrj/project/business/VATNotify/VATNotifyParse.cpp
index 6c3d5bb..466f9f4 100644
--- a/jrj/project/business/VATNotify/VATNotifyParse.cpp
+++ b/jrj/project/business/VATNotify/VATNotifyParse.cpp
@@ -6,537 +6,127 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) VATNotifyParse : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwtable	dw_base;
+		xnode	m_agentNode;	//Agent Condition
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+	public:
+		VATNotifyParse(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static VATNotifyParse* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			VATNotifyParse* pWin = new VATNotifyParse(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
-			}
-		}
-
-		return 1;
-	}
-
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
-
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
-
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
-				return -1;
-			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
-			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
-			}
-			else
-			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
-			}
-		}
-		return 1;
-	}
-
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
-			}
-			else
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
 			}
 			return 1;
 		}
-		if (comdid == L"action:bill.Annex")
+
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
 		{
-			xaserverarg& arg = *new xaserverarg;
+			//重置工具条
+			//SetAgent();
+			return 1;
+		}
+
+		int OnOk()
+		{
+
+			xaserverarg arg = GetArg();
+			arg.AddArg(L"process", L"ok");
+			arg.AddArg(L"Quantity", dw_base.GetItemString(1, L"Quantity"));
+			arg.AddArg(L"CustQuantity", dw_base.GetItemString(1, L"CustQuantity"));
+			arg.AddArg(L"Amount", dw_base.GetItemString(1, L"Amount"));
+			CloseWindow();
+			return 1;
+		}
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"xmOk") return OnOk();
+			if (comdid == L"xmCancel")
+			{
+				CloseWindow();
+				return 1;
+			}
+			return 0;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+		
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&VATNotifyParse::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&VATNotifyParse::OnSetFocus);
+		}
+
+		/*
+		int  OnRetrieve()
+		{
+			xml x ;
+			
+			xaserverarg arg = new xaserverarg;
 			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
-
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
-		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
+			arg.AddArg(L"xxx",L"xxx");
+			if (getUrl(L"",arg.GetString(),x)!=1)
 			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
-				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
-				}
+				trace(x.text());
+				return -1;
+			}else
+			{
+				//dw_base.Retrieve(x);
+				//dw_base.Redraw();
 			}
+			return 1;
+		}
+		*/
 
+		int onload()
+		{
+			dw_base = GetControl(L"dw_base");
+			dw_base.openUrl(L"/sale/view/VATNotify/template/VATNotify/ParseNumber");
+
+			dw_base.SetColHeaderHeight(0);
+			dw_base.SetRowSelectorWidth(0);
+			dw_base.SetHScrollState(false);
+			dw_base.SetVScrollState(false);
+
+			OnAttachEvent();
+
+			return 1;
 		}
 
-		return 1;
-	}
+		int onloaded()
+		{
+			//SetAgent();			
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
-
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
-
-};
\ No newline at end of file
+			return 1;
+		}
+	};
diff --git a/jrj/project/business/VATNotify/list.vatnotify.cpp b/jrj/project/business/VATNotify/list.vatnotify.cpp
index 6c3d5bb..28986e4 100644
--- a/jrj/project/business/VATNotify/list.vatnotify.cpp
+++ b/jrj/project/business/VATNotify/list.vatnotify.cpp
@@ -6,537 +6,404 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) listvatnotifyWin : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwgrid	dw_list;
+		xdwpages dw_pages;
+		xdwtable dw_arg;
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+		xnode	m_agentNode;	//Agent Condition
+
+		int 	m_pageindex;
+		int	m_pagenumber;
+		xstring 	m_QueryTxt;
+		xstring DatePicker;
+
+	public:
+		listvatnotifyWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static listvatnotifyWin* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			listvatnotifyWin* pWin = new listvatnotifyWin(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
-
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
-
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
-
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
-				return -1;
-			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
 		{
-			xstring error = x.text();
-			trace(error);
+			//重置工具条
+			SetAgent();
+			return 1;
 		}
-		else
+
+		int OnDWClick(TEvent* evt, LPARAM p)
 		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring value = hdr.data;
+			xstring colname = hdr.colname;
+			int row = hdr.row;
+
+			if (row < 1) return 1;
+
+			xaserverarg arg;
+			if (colname == L"SONo")
 			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
+				xstring SONo = dw_list.GetItemString(row, colname);
+				;
+				
+				arg.AddArg(L"EntityNo", SONo);
+				arg.AddArg(L"ReadOnly", L"true");
+				OpenWindow(L"dev:xpage[base.maint.so.vx]", arg);
 			}
-			else
+			if (colname == L"InvoiceNo")
 			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
+				xstring InvoiceNo = dw_list.GetItemString(row, colname);
+				;
+				
+				arg.AddArg(L"EntityNo", InvoiceNo);
+				arg.AddArg(L"ReadOnly", L"true");
+				OpenWindow(L"dev:xpage[maintex.GDN3.vx]", arg);
 			}
+			return 1;
 		}
-		return 1;
-	}
 
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
+		int OnPrint()
 		{
+			xaserverarg arg;
+			
+			arg.AddArg(L"EntityName", L"VATNotify");
+			arg.AddArg(L"EntityID", L"", L"");
+			xstring InvoiceNo = dw_list.GetItemString(dw_list.GetRow(), L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_list.GetItemString(dw_list.GetRow(), L"InvoiceNo");
 
-			if (TypeWork.find(L"采购") >= 0)
+			xstring NInvoiceNoEx = dw_list.GetItemString(dw_list.GetRow(), L"NInvoiceNo");
+			xstring InvoiceNoEx = dw_list.GetItemString(dw_list.GetRow(), L"InvoiceNo");
+			if (NInvoiceNoEx != InvoiceNoEx)
 			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
+				NInvoiceNoEx = InvoiceNoEx;
 			}
-			else
+			xstring SupplierID = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
+			arg.AddArg(L"EntityNo", InvoiceNo, L"");
+			arg.AddArg(L"EntityNoEx", NInvoiceNoEx, L"");
+			arg.AddArg(L"SupplierID", SupplierID);
+			arg.AddArg(L"VATNotifyID", L"");
+			trace(InvoiceNo + L"==1" + NInvoiceNoEx + L"==2" + SupplierID + L"==3" + dw_list.GetGuid(dw_list.GetRow()));
+			
+			openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", arg);
+			return 1;
+		}
+
+		int OnPrintItem()
+		{
+			xaserverarg arg;
+			
+			arg.AddArg(L"EntityName", L"VATNotify");
+			arg.AddArg(L"EntityID", L"", L"");
+			xstring InvoiceNo = dw_list.GetItemString(dw_list.GetRow(), L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_list.GetItemString(dw_list.GetRow(), L"InvoiceNo");
+
+			xstring NInvoiceNoEx = dw_list.GetItemString(dw_list.GetRow(), L"NInvoiceNo");
+			xstring InvoiceNoEx = dw_list.GetItemString(dw_list.GetRow(), L"InvoiceNo");
+			if (NInvoiceNoEx != InvoiceNoEx)
 			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
+				NInvoiceNoEx = InvoiceNoEx;
 			}
+			xstring SupplierID = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
+			arg.AddArg(L"EntityNo", InvoiceNo, L"");
+			arg.AddArg(L"EntityNoEx", NInvoiceNoEx, L"");
+			arg.AddArg(L"SupplierID", SupplierID);
+			arg.AddArg(L"VATNotifyID", dw_list.GetGuid(dw_list.GetRow()));
+			trace(L"=====L" + InvoiceNo + L"=====L" + SupplierID + L"=====L" + dw_list.GetGuid(dw_list.GetRow()));
+			
+			openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", p);
+			return 1;
 		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
 
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
+		int OnOpen() {
+			int row = dw_list.GetRow();
+			if (row < 1) return 0;
+			KXMLDOMElement ele = dw_list.GetRowElement(row);
+			xstring entityid = ele.selectSingleNode(L"InvoiceNo").text();
+			xaserverarg arg;
+			
+			arg.AddArg(L"invoiceno", entityid);
+			
+			OpenWindow(L"dev:xpage[simple.maint.vatnotify.vx]", arg);
+			return 1;
 		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
+
+		int OnPapercardOpen() {
+			int row = dw_list.GetRow();
+			if (row < 1) return 0;
+			KXMLDOMElement ele = dw_list.GetRowElement(row);
+			xstring entityid = ele.selectSingleNode(L"InvoiceNo").text();
+			xstring classifyID = ele.selectSingleNode(L"ClassifyID").text();
+			xstring supplierID = ele.selectSingleNode(L"SupplierID").text();
+			xstring cname = ele.selectSingleNode(L"CName").text();
+
+			xaserverarg arg;
+			
+			arg.AddArg(L"invoiceno", entityid);
+			arg.AddArg(L"ClassifyID", classifyID);
+			arg.AddArg(L"SupplierID", supplierID);
+			arg.AddArg(L"CName", cname);
+			
+			OpenWindow(L"dev:xpage[maint.papercard.vatnotify.vx]", p);
+			return 1;
 		}
-#endif 
-		return 0;
-	}
 
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
+		int OnModify() {
+			int row = dw_list.GetRow();
+			if (row < 1) return 0;
+			KXMLDOMElement ele = dw_list.GetRowElement(row);
+			xstring entityid = ele.selectSingleNode(L"InvoiceNo").text();
+			xaserverarg arg;
+			
+			arg.AddArg(L"invoiceno", entityid);
+			
+			OpenWindow(L"dev:xpage[update.vatnotify.vx]", arg);
+			return 1;
+		}
 
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
+		int Onfinish() {
+
+			return 1;
+		}
+
+		int OnDeleteRow()
 		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
+			if (dw_list.GetRow() < 1) return 1;
+			int row = dw_list.GetRow();
+			xstring InvoiceNo = dw_list.GetItemString(row, L"InvoiceNo");
+			int res = MessageBox(GetHWND(), L"是否确认删除" + InvoiceNo + L"的开票通知?", L"提示", 4);
+			if (res == 6)
 			{
-				alert(L"处理成功");
-				OnRetrieve();
+				xml x = ViewObject::RetrieveData(L"/sale/data/VATNotify/entity/delete", L"invoiceno", InvoiceNo);
+				if (!x)
+				{
+					alert(L"删除错误");
+					return 1;
+				}
+				//dw_list.DeleteRow(row);
+				alert(x.text());
+				OnRetrieve(DatePicker);
 			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
 
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
+			return 1;
 		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
+
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
 		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
+			if (comdid == L"xm:import") {
+				OpenWindow(L"dev:xpage[import.vatnotify.vx]", 0);
+			}
+			if (comdid == L"action:bill.open") {
+				OnOpen();
+			}
+			else if (comdid == L"xm:notify") {
+				OnOpen();
+			}
+			else if (comdid == L"xm:papercardnotify") {
+				OnPapercardOpen();
+			}
+			else if (comdid == L"xm:modify") {
+				OnModify();
+			}
+			else if (comdid == L"xm:finish") {
+				Onfinish();
+			}
+			else if (comdid == L"xm:ratecalc") {
+
+			}
+			else if (comdid == L"find")
+			{
+				m_QueryTxt = GetControl(L"txt").GetText();
+				return OnRetrieve(DatePicker);
+			}
+			else if (comdid == L"xmRefresh")
+			{
+				return OnRetrieve(DatePicker);
+			}
+			else if (comdid == L"xmDeleteRow")
+			{
+				return OnDeleteRow();
+			}
+			else if (comdid == L"xmPrint") {
+				return OnPrint();
+			}
+			else if (comdid == L"xmPrintItem") {
+				return OnPrintItem();
+			}
+			else if (comdid == L"xmSaveAs")
 			{
 				dw_list.SaveAs(L"");
+				return 1;
 			}
-			return 1;
+			return 0;
 		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
 
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
 		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
 
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&listvatnotifyWin::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&listvatnotifyWin::OnSetFocus);
+			AttachEvent(L"dw_list", L"DWV_CLICKED", (FEvent)&listvatnotifyWin::OnDWClick);
+			AttachEvent(L"cbx_state", L"CBN_SELCHANGE", (FEvent)&listvatnotifyWin::OnDatePicker);
 		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
 
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
+		int OnDatePicker(TEvent* evt, int lParam)
 		{
-			xstring s = publiccode::GetUser().id;
+			
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
 
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
+			int h = xcombobox::GetCurSel(evt.hCtrl);
+			if (h > -1)
 			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
+				xstring txt = xcombobox::GetLBText(evt.hCtrl, h);
+				if (txt == L"通知日期")
 				{
 
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
+					DatePicker = L"NotifyDate";
+					OnRetrieve(DatePicker);
+				}
+				else if (txt == L"出运日期")
+				{
 
+					DatePicker = L"ETD";
+					OnRetrieve(DatePicker);
 				}
 			}
-
+			return 1;
 		}
 
-		return 1;
-	}
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
+		xstring GetQueryArg()
+		{
+			dw_arg.AcceptText();
+			xml x ;
+			
+			dw_arg.DwUpdateAllTo(x);
+			return x.xml();
+		}
 
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
+		int  OnRetrieve(xstring DatePicker)
+		{
+			HCURSOR  hCursor = xutil::SetCursorWait();
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"pageindex", xstring(m_pageindex));
+			arg.AddArg(L"pagenumber", xstring(m_pagenumber));
+			arg.AddArg(L"QueryTxt", m_QueryTxt);
+			arg.AddArg(L"QueryArg", GetQueryArg());
+			arg.AddArg(L"DatePicker", DatePicker);
+			if (getUrl(L"/sale/data/VATNotify/entity/listOne", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				xutil::RestoreCursor(hCursor);
+				return -1;
+			}
+			else
+			{
+				//trace(x.xml);
+				KXMLDOMElement ele = x.documentElement();
+				if (dw_pages.ptr_native_)
+				{
+					if (ele.selectSingleNode(L"@TotalPage"))
+					{
+						xstring s = ele.selectSingleNode(L"@TotalPage").text(); //总数量				
+						dw_pages.SetMaxPage(s.toInt());
+					}
+				}
+				dw_list.Retrieve(x);
+				dw_list.Redraw();
+				dw_list.SetReadOnly(true);
+			}
+			xutil::RestoreCursor(hCursor);
+			return 1;
+		}
 
-};
\ No newline at end of file
+		int OnChangePages(TEvent* evt, LPARAM p)
+		{
+			PAGENMHDR& h = *(PAGENMHDR*)evt->notify.pnmh;
+			int c = h.cur;
+			HCURSOR hCursor = xutil::SetCursorWait();
+			m_pageindex = c;
+			OnRetrieve(DatePicker);
+			xutil::RestoreCursor(hCursor);
+			return 1;
+		}
+
+		int OnDoubleClicked(TEvent* evt, LPARAM p)
+		{
+			HCURSOR hCursor = xutil::SetCursorWait();
+			OnCmdDispatch(L"action:bill.open");
+			xutil::RestoreCursor(hCursor);
+			return 1;
+		}
+
+		int onload()
+		{
+			dw_list = GetControl(L"dw_list");
+			dw_list.openUrl(L"/sale/view/VATNotify/template/VATNotify/list");
+			dw_arg = GetControl(L"dw_arg");
+			dw_arg.openUrl(L"/sale/view/AR/template/queryarg");
+			dw_arg.SetColHeaderHeight(0);
+			dw_arg.SetRowSelectorWidth(0);
+			dw_arg.SetHScrollState(false);
+			dw_arg.SetVScrollState(false);
+			dw_arg.SetItemString(1, L"DateType", L"本月");
+			//dw_arg.SetItemString(1,L"DateType",L"");
+			AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listvatnotifyWin::OnDoubleClicked);//行双击
+			dw_pages = GetControl(L"pages");
+			AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listvatnotifyWin::OnChangePages);
+
+
+			OnAttachEvent();
+
+			return 1;
+		}
+
+		int onloaded()
+		{
+			SetAgent();
+
+			m_pageindex = 1;
+			m_pagenumber = 10000;
+			m_QueryTxt = L"";
+
+			//OnRetrieve();
+
+			return 1;
+		}
+	};
diff --git a/jrj/project/business/VATNotify/maint.papercard.vatnotify.cpp b/jrj/project/business/VATNotify/maint.papercard.vatnotify.cpp
index 6c3d5bb..d942af0 100644
--- a/jrj/project/business/VATNotify/maint.papercard.vatnotify.cpp
+++ b/jrj/project/business/VATNotify/maint.papercard.vatnotify.cpp
@@ -6,537 +6,786 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) maintpapercardvatnotifyWin : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwtable	dw_profit;
+		xdwtable	dw_arg;
+		xdwgrid		dw_item;
+		xdwgrid		dw_fob;
+		xstring		InvNo;
+		xstring		CurInvNo;
+		xnode	m_agentNode;	//Agent Condition
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+	public:
+		maintpapercardvatnotifyWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static maintpapercardvatnotifyWin* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			maintpapercardvatnotifyWin* pWin = new maintpapercardvatnotifyWin(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
+		{
+			//重置工具条
+			SetAgent();
+			return 1;
+		}
 
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
+		int OnPrint()
+		{
+			xaserverarg arg;
+			
+			arg.AddArg(L"EntityName", L"VATNotify", L"");
+			arg.AddArg(L"EntityID", L"", L"");
+			arg.AddArg(L"EntityNo", dw_item.GetItemString(1, L"InvoiceNo"), L"");
+			
+			openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", p);
+			return 1;
+		}
 
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
+		int OnPrintItem()
+		{
+			xaserverarg arg;
+			
+			arg.AddArg(L"EntityName", L"VATNotify", L"");
+			arg.AddArg(L"EntityID", L"", L"");
+			arg.AddArg(L"EntityNo", dw_item.GetItemString(1, L"InvoiceNo"), L"");
+			
+			openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", p);
+			return 1;
+		}
 
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
+
+
+		int onebill()
+		{
+			if (!GetWinParam()) return 1;
+
+			int ll_row = dw_item.GetNextSelectRow(1);
+			if (ll_row < 1) return 1;
+
+			int MB_OKCANCEL = 1;
+			int IDOK = 1;
+			int ret = MessageBox(GetHWND(), L"确认开票吗?", L"提示", MB_OKCANCEL);
+			if (ret != IDOK) return 1;
+			dw_item.AcceptText();
+
+			xaserverarg arg;
+			
+			int pArg = GetArg();
+			
+
+			xstring ls_dtlno = arg.GetArgString(L"invoiceno");
+			RetrieveFob(ls_dtlno);
+			RetrieveProfit(ls_dtlno);
+			while (ll_row > 0 && ll_row <= dw_item.GetRowCount())
+			{
+				dw_item.SetItemString(ll_row, L"NInvoiceNo", ls_dtlno);
+				xstring sdate = publiccode::GetCurrentDate();
+
+				dw_item.SetItemDisplayString(ll_row, L"NClassifyID", arg.GetArgString(L"CName"));
+				dw_item.SetItemString(ll_row, L"NClassifyID", arg.GetArgString(L"ClassifyID"));
+
+				int ll_find = FobLookup(arg.GetArgString(L"ClassifyID"));
+				xstring qtyUnit1 = dw_fob.GetItemString(ll_find, L"CQtyUnit");
+				dw_item.SetItemString(ll_row, L"CQtyUnit", qtyUnit1);
+				dw_item.SetItemString(ll_row, L"VATRefundRate", dw_fob.GetItemString(ll_find, L"VATRefundRate"));
+
+				dw_item.SetItemString(ll_row, L"NotifyDate", sdate);
+				dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L"Amount"));
+				ll_row = dw_item.GetNextSelectRow(ll_row + 1);
+			}
+			dw_item.Redraw();
+			return 1;
+		}
+
+		int onebillno() {
+			/*
+			int ll_row = dw_item.GetNextSelectRow(1);
+			if(ll_row < 1) return 1;
+
+			int MB_OKCANCEL = 1;
+			int IDOK  = 1;
+			int ret = win32::MessageBox(GetHWND(),L"确认不予开票吗?",L"提示",MB_OKCANCEL);
+			if(ret !=IDOK) return 1;
+			dw_item.AcceptText();
+
+			while(ll_row > 0 && ll_row <= dw_item.GetRowCount())
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row,L"InvoiceNo");
+				dw_item.SetItemString(ll_row,L"NInvoiceNo",L"");
+				dw_item.SetItemString(ll_row,L"NAmount",L"");
+				dw_item.SetItemString(ll_row,L"NotifyDate",L"");
+				dw_item.SetItemString(ll_row,L"NClassifyID",L"");
+				dw_item.SetItemString(ll_row,L"NName",L"");
+				dw_item.ItemChangeTo(ll_row,L"NAmount",dw_item.GetItemString(ll_row,L""));
+				dw_item.ItemChangeTo(ll_row,L"NQuantity",dw_item.GetItemString(ll_row,L""));
+				ll_row =  dw_item.GetNextSelectRow(ll_row + 1);
+			}
+			dw_item.Redraw();
+			*/
+
+			int ll_row = dw_item.GetNextSelectRow(1);
+			if (ll_row < 1) return 1;
+
+			int MB_OKCANCEL = 1;
+			int IDOK = 1;
+			int ret = MessageBox(GetHWND(), L"确认不予开票吗?", L"提示", MB_OKCANCEL);
+			if (ret != IDOK) return 1;
+			dw_item.AcceptText();
+
+			while (ll_row > 0 && ll_row <= dw_item.GetRowCount())
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L""));
+				dw_item.ItemChangeTo(ll_row, L"NQuantity", dw_item.GetItemString(ll_row, L""));
+				dw_item.SetItemString(ll_row, L"NotifyDate", L"");
+				dw_item.SetItemString(ll_row, L"NClassifyID", L"");
+				dw_item.SetItemString(ll_row, L"NName", L"");
+				dw_item.SetItemDisplayString(ll_row, L"NClassifyID", L"");
+				dw_item.SetItemString(ll_row, L"NInvoiceNo", L"");
+				ll_row = dw_item.GetNextSelectRow(ll_row + 1);
+			}
+			dw_item.Redraw();
+
+			return 1;
+		}
+
+		int CalcRate()
+		{
+			for (int row = 1; row <= dw_fob.GetRowCount(); row++)
+			{
+				xstring InvoiceNo = dw_fob.GetItemString(row, L"InvoiceNo");
+				xstring ClassifyID = dw_fob.GetItemString(row, L"ClassifyID");
+				double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
+				double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
+				double fobAmt = dw_fob.GetItemDouble(row, L"FobAmt");
+				double rate = sumAmt / fobAmt;
+				double LimitAmt = fobAmt * rate;
+				dw_fob.SetItemDouble(row, L"Rate", rate);
+				dw_fob.SetItemDouble(row, L"LimitAmt", LimitAmt);
+				dw_fob.SetItemDouble(row, L"RestAmt", LimitAmt - sumAmt);
+			}
+			RecalcProfitData();
+			dw_fob.Redraw();
+
+			return 1;
+		}
+
+		int onimport() {
+			//OpenWindow(L"dev:xpage[import.vatnotify.vx]",0);
+			return 1;
+		}
+
+		int OnFobItemChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
+			int row = hdr.row;
+
+			if (colname == L"Rate" || colname == L"FobAmt")
+			{
+				xstring InvoiceNo = dw_fob.GetItemString(row, L"InvoiceNo");
+				xstring ClassifyID = dw_fob.GetItemString(row, L"ClassifyID");
+				double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
+				double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
+				double fobAmt = dw_fob.GetItemDouble(row, L"FobAmt");
+				double rate = dw_fob.GetItemDouble(row, L"Rate");
+				double LimitAmt = fobAmt * rate;
+				dw_fob.SetItemDouble(row, L"LimitAmt", LimitAmt);
+				dw_fob.SetItemDouble(row, L"RestAmt", LimitAmt - sumAmt);
+				dw_fob.Redraw();
+				RecalcProfitData();
+				return 1;
+			}
+
+			return 1;
+		}
+
+		int OnArgChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
+			int row = hdr.row;
+			xstring SupplierID = dw_arg.GetItemString(1, L"SupplierID");
+			if (SupplierID != L"")
+			{
+				if (GetWinParam())
+				{
+					xaserverarg arg;
+					
+					int pArg = GetArg();
+					
+					arg.AddArg(L"SupplierID", SupplierID);
+					OnRetrieve();
+				}
+			}
+
+			return 1;
+		}
+
+		int OnItemChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
+			int row = hdr.row;
+			xstring ClassifyID = dw_item.GetItemString(row, L"NClassifyID");
+			if (ClassifyID == L"") ClassifyID = dw_item.GetItemString(row, L"ClassifyID");
+			xstring InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
+			int ll_find = FobLookup(ClassifyID);
+			if (colname == L"NAmount")
+			{
+				if (ll_find > 0)
+				{
+					xstring qtyUnit = dw_fob.GetItemString(ll_find, L"CQtyUnit");
+					double limitAmt = dw_fob.GetItemDouble(ll_find, L"LimitAmt");
+					double CQuantity = dw_fob.GetItemDouble(ll_find, L"CQuantity");
+					double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
+					double amt = dw_item.GetItemDouble(row, L"NAmount");
+					double qty = CQuantity * amt / limitAmt;
+					if (qtyUnit.trim() != L"千克")
+					{
+						int d = xstring(qty).toInt();
+						xstring s = xstring(d);
+						qty = s.toDouble();
+					}
+					double restAmt = limitAmt - sumAmt;
+					dw_fob.SetItemDouble(ll_find, L"RestAmt", restAmt);
+					dw_item.ItemChangeTo(row, L"NQuantity", xstring(qty));
+					dw_item.Redraw();
+					dw_fob.Redraw();
+				}
+				return 1;
+			}
+			else if (colname == L"NQuantity")
+			{
+				if (ll_find > 0)
+				{
+					double CQuantity1 = dw_fob.GetItemDouble(ll_find, L"CQuantity");
+					double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
+					double restQuantity = CQuantity1 - sumQty;
+					dw_fob.SetItemDouble(ll_find, L"RestQty", restQuantity);
+					dw_fob.Redraw();
+				}
+				return 1;
+			}
+			else if (colname == L"NInvoiceNo")
+			{
+				row = dw_item.GetRow();
+				InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+				if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
+				RetrieveFob(InvoiceNo);
+				RetrieveProfit(InvoiceNo);
+				return 1;
+			}
+			else if (colname == L"NClassifyID")
+			{
+				xstring NQuantity = dw_item.GetItemString(row, L"NQuantity");
+				if (NQuantity != L"") dw_item.ItemChangeTo(row, L"NQuantity", NQuantity);
+				xstring NAmount = dw_item.GetItemString(row, L"NAmount");
+				if (NAmount != L"") dw_item.ItemChangeTo(row, L"NAmount", NAmount);
+				xstring sdate = publiccode::GetCurrentDate();
+				dw_item.SetItemString(row, L"NotifyDate", sdate);
+
+				xstring qtyUnit1 = dw_fob.GetItemString(ll_find, L"CQtyUnit");
+				dw_item.SetItemString(row, L"CQtyUnit", qtyUnit1);
+				dw_item.SetItemString(row, L"VATRefundRate", dw_fob.GetItemString(ll_find, L"VATRefundRate"));
+				dw_item.Redraw();
+				return 1;
+			}
+			return 1;
+		}
+
+		double GetSumAmountExcept(xstring InvoiceNo, xstring ClassifyID, xstring InvoiceNoExcept)
+		{
+			xml x ;
+			
+			xaserverarg arg = ViewObject::MakeArg();
+			arg.AddArg(L"ClassifyID", ClassifyID);
+			arg.AddArg(L"InvoiceNo", InvoiceNo);
+			arg.AddArg(L"InvoiceExcept", InvoiceNoExcept);
+
+			if (xurl::get(L"/sale/data/VATNotify/entity/suminfo", arg.GetString(), x) != 1)
+			{
+				xstring error = x.text();
+				alert(L"err:" + error);
+				return 0.0;
+			}
+			KXMLDOMNode n = x.selectSingleNode(L"data/Item/amt");
+			if (!n) return 0.0;
+			xstring str = n.text();
+			return str.toDouble();
+		}
+
+		double GetSumQuantityExcept(xstring InvoiceNo, xstring ClassifyID, xstring InvoiceNoExcept)
+		{
+			xml x ;
+			
+			xaserverarg arg = ViewObject::MakeArg();
+			arg.AddArg(L"ClassifyID", ClassifyID);
+			arg.AddArg(L"InvoiceNo", InvoiceNo);
+			arg.AddArg(L"InvoiceExcept", InvoiceNoExcept);
+
+			if (xurl::get(L"/sale/data/VATNotify/entity/suminfo", arg.GetString(), x) != 1)
+			{
+				xstring error = x.text();
+				alert(L"err:" + error);
+				return 0.0;
+			}
+			KXMLDOMNode n = x.selectSingleNode(L"data/Item/qty");
+			if (!n) return 0.0;
+			xstring str = n.text();
+			return str.toDouble();
+		}
+
+		double GetSumAmount(xstring InvoiceNo, xstring ClassifyID)
+		{
+			double amt = 0;
+			xstring InvoiceNoExcept = dw_item.GetItemString(1, L"InvoiceNo");
+			if (InvoiceNoExcept != L"") amt = GetSumAmountExcept(InvoiceNo, ClassifyID, InvoiceNoExcept);
+
+			for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"NInvoiceNo");
+				if (ls_dtlno == L"") ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				if (InvoiceNo == ls_dtlno)
+				{
+					xstring classifyID = dw_item.GetItemString(ll_row, L"NClassifyID");
+					if (classifyID == L"")  classifyID = dw_item.GetItemString(ll_row, L"ClassifyID");
+					if (classifyID == ClassifyID)
+						amt += dw_item.GetItemDouble(ll_row, L"NAmount");
+				}
+			}
+			return amt;
+		}
+
+		double GetSumQuantity(xstring InvoiceNo, xstring ClassifyID)
+		{
+			double qty = 0;
+			xstring InvoiceNoExcept = dw_item.GetItemString(1, L"InvoiceNo");
+			if (InvoiceNoExcept != L"") qty = GetSumQuantityExcept(InvoiceNo, ClassifyID, InvoiceNoExcept);
+
+			for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"NInvoiceNo");
+				if (ls_dtlno == L"") ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				if (InvoiceNo == ls_dtlno)
+				{
+					xstring classifyID = dw_item.GetItemString(ll_row, L"NClassifyID");
+					if (classifyID == L"")  classifyID = dw_item.GetItemString(ll_row, L"ClassifyID");
+					if (classifyID == ClassifyID)
+						qty += dw_item.GetItemDouble(ll_row, L"NQuantity");
+				}
+			}
+			return qty;
+		}
+
+		int RecalcProfitData()
+		{
+			double fobAmt = GetSumFobAmt();
+			double limitAmt = GetSumLimitAmount();
+			double RefundAmt = GetSumRefund();
+			double goodsAmt = limitAmt - RefundAmt;
+			double freight = dw_profit.GetItemDouble(1, L"Freight");
+			double comm = dw_profit.GetItemDouble(1, L"Comm");
+			double 	netAmount = fobAmt - freight - comm;
+			double exchCost = (limitAmt - RefundAmt) / fobAmt;
+			dw_profit.SetItemDouble(1, L"NetAmount", netAmount);
+			dw_profit.SetItemDouble(1, L"SaleAmount", fobAmt);
+			dw_profit.SetItemDouble(1, L"SaleCost", goodsAmt);
+			dw_profit.SetItemDouble(1, L"Drawback", RefundAmt);
+			dw_profit.SetItemDouble(1, L"ExchCost", exchCost);
+			dw_profit.Redraw();
+			return 1;
+		}
+
+		double GetSumLimitAmount()
+		{
+			double amt = 0;
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				amt += dw_fob.GetItemDouble(ll_row, L"LimitAmt");
+			}
+			return amt;
+		}
+
+		double GetSumRefund()
+		{
+			double amt = 0;
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				double rate = dw_fob.GetItemDouble(ll_row, L"VATRate");
+				double refundRate = dw_fob.GetItemDouble(ll_row, L"VATRefundRate");
+				double d = dw_fob.GetItemDouble(ll_row, L"LimitAmt");
+				double val = d / (100.0 + rate) * refundRate;
+				amt += val;
+			}
+			return amt;
+		}
+
+		double GetSumFobAmt()
+		{
+			double amt = 0;
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				amt += dw_fob.GetItemDouble(ll_row, L"FobAmt");
+			}
+			return amt;
+		}
+
+		int FobLookup(xstring ClassifyID)
+		{
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				if (dw_fob.GetItemString(ll_row, L"ClassifyID") == ClassifyID) return ll_row;
+			}
+			return -1;
+		}
+
+		int addother() {
+			return 1;
+		}
+		int deleteother() {
+			return 1;
+		}
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"save") {
+				return OnSave();
+			}
+			else if (comdid == L"onebill") {
+				return onebill();
+			}
+			else if (comdid == L"onebillno") {
+				return onebillno();
+			}
+			else if (comdid == L"xmPrint") {
+				return OnPrint();
+			}
+			else if (comdid == L"xmPrintItem") {
+				return OnPrintItem();
+			}
+			else if (comdid == L"xmCalcRate") {
+				return CalcRate();
+			}
+			return 0;
+		}
+
+		int OnRowChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+
+			xstring InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
+			if (InvoiceNo != CurInvNo)
+			{
+				CurInvNo = InvoiceNo;
+				RetrieveFob(InvoiceNo);
+				RetrieveProfit(InvoiceNo);
+				RecalcProfitData();
+			}
+
+			return 1;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+
+		int OnSave()
+		{
+			xml x ;
+			
+			dw_item.AcceptText();
+			dw_item.DwUpdateAllToEx(x);
+
+			xml x0 = ViewObject::MakeXml();
+			x0.loadXML(L"<root/>");
+
+			KXMLDOMNodeList t = x.selectNodes(L"root/item[@update.modify]");
+			KXMLDOMElement e1 = x0.documentElement();
+			int len = t.length();
+			for (int i = 0; i < len; i++)
+			{
+				e1.appendChild(t.item(i));
+			}
+			xaserverarg arg = ViewObject::MakeArg();
+			arg.AddArg(L"content", x0.xml());
+
+			//trace(x.xml);
+			//return 1;
+			if (xurl::get(L"/sale/data/VATNotify/base/update", arg.GetString(), x0) != 1)
+			{
+				xstring error = x0.text();
+				alert(L"err:" + error);
+				return 1;
+			}
+			xstring str = x0.documentElement().getAttribute(L"text");
+			if (str == L"true")
+			{
+				dw_item.ResetUpdateStatus();
+				alert(L"保存成功!");
+			}
+			else
+			{
+				alert(L"保存失败1!");
+				return 1;
+			}
+
+			dw_fob.AcceptText();
+			xml x1 ;
+			
+			dw_fob.DwUpdateAllToEx(x1);
+			arg.AddArg(L"content", x1.xml());
+			if (xurl::get(L"/sale/data/VATNotify/fob/update", arg.GetString(), x1) != 1)
+			{
+				xstring error1 = x1.text();
+				alert(L"err:" + error1);
+				return 1;
+			}
+			str = x1.documentElement().getAttribute(L"text");
+			if (str == L"true")
+			{
+				dw_fob.ResetUpdateStatus();
+				alert(L"保存成功!");
+			}
+			else
+			{
+				alert(L"保存失败2!");
+				return 1;
+			}
+			return 1;
+		}
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&maintpapercardvatnotifyWin::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&maintpapercardvatnotifyWin::OnSetFocus);
+			AttachEvent(L"dw_item", L"DWV_ITEMCHANGED", (FEvent)&maintpapercardvatnotifyWin::OnItemChanged);
+			AttachEvent(L"dw_arg", L"DWV_ITEMCHANGED", (FEvent)&maintpapercardvatnotifyWin::OnArgChanged);
+			AttachEvent(L"dw_fob", L"DWV_ITEMCHANGED", (FEvent)&maintpapercardvatnotifyWin::OnFobItemChanged);
+			AttachEvent(L"dw_item", L"DWV_ROWFOCUSCHANGED", (FEvent)&maintpapercardvatnotifyWin::OnRowChanged);
+			AttachEvent(L"dw_item", L"DWV_ASKDATA", (FEvent)&maintpapercardvatnotifyWin::OnAskDataItem);
+		}
+
+		int RetrieveFob(xstring InvoiceNo, bool start = false)
+		{
+			if (!start)
+			{
+				dw_fob.Filter(L"InvoiceNo", InvoiceNo);
+				dw_fob.Redraw();
+				if (dw_fob.GetRowCount() > 0) return 1;
+			}
+
+			//start = true;
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"invoiceno", InvoiceNo);
+			if (getUrl(L"/sale/data/VATNotify/entity/fob", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
 				return -1;
 			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
-			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
-			}
 			else
 			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
-			}
-		}
-		return 1;
-	}
-
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
-			}
-			else
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
-			}
-			return 1;
-		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
-
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
-		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
-			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
+				//trace(x.xml);
+				if (start)
 				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
+					dw_fob.Retrieve(x);
+					dw_fob.Redraw();
+				}
+				else
+				{
+					xml x1 ;
+					
+					dw_fob.DwUpdateAllToEx(x1);
+					KXMLDOMElement docElement = x1.documentElement();
+					if (docElement)
+					{
+						KXMLDOMNodeList lst = x.selectNodes(L"data/Item");
+						int n = lst.length();
+						for (int i = 0; i < n; i++)
+						{
+							KXMLDOMElement e = lst.item(i);
+							docElement.appendChild(e);
+							e.Release();
+						}
+						docElement.Release();
+						lst.Release();
+						dw_fob.Retrieve(x1);
+					}
+					else
+					{
+						dw_fob.Retrieve(x);
+					}
+					dw_fob.Filter(L"InvoiceNo", InvoiceNo);
+					dw_fob.Redraw();
 				}
 			}
-
+			return 1;
 		}
 
-		return 1;
-	}
+		int RetrieveProfit(xstring InvoiceNo)
+		{
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"invoiceno", InvoiceNo);
+			if (getUrl(L"/sale/data/VATNotify/entity/profit", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				return -1;
+			}
+			else
+			{
+				dw_profit.Retrieve(x);
+				dw_profit.Redraw();
+			}
+			return 1;
+		}
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
+		int  OnRetrieve()
+		{
+			xml x ;
+			
+			xaserverarg arg;
+			
 
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
+			if (GetWinParam())
+			{
+				int pArg = GetArg();
+			
+			}
+			else
+				return 1;
+			if (getUrl(L"/sale/data/VATNotify/entity/papercard", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				return -1;
+			}
+			else
+			{
+				dw_item.Retrieve(x);
+				dw_item.Redraw();
+				dw_item.SetSelectionMode(3);
+			}
+			if (dw_item.GetRowCount() > 0)
+			{
+				//xstring InvoiceNo = dw_item.GetItemString(1,L"NInvoiceNo");
+				//if(InvoiceNo==L"") InvoiceNo = dw_item.GetItemString(1,L"InvoiceNo");
+				xstring InvoiceNo = arg.GetArgString(L"invoiceno");
+				CurInvNo = InvoiceNo;
+				RetrieveFob(InvoiceNo);
+				RetrieveProfit(InvoiceNo);
+				RecalcProfitData();
+			}
 
-};
\ No newline at end of file
+			return 1;
+		}
+
+		//base AskData
+		int OnAskDataItem(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+			xstring x = hdr.colname;
+			if (x == L"userInvoiceNo") //下拉
+			{
+				xstring sInvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+				hdr.data = sInvoiceNo;
+			}
+
+			return 1;
+		}
+
+		int onload()
+		{
+			dw_item = GetControl(L"dw_item");
+			dw_item.openUrl(L"/sale/view/VATNotify/template/VATNotify/item");
+			dw_item.SetColumnState(L"CName", false);
+			dw_item.SetColumnState(L"CreatorID", false);
+			dw_item.SetColumnState(L"CreateDate", false);
+			dw_item.SetColumnState(L"VATRate", false);
+			dw_item.SetColumnState(L"VATRefundRate", false);
+			dw_item.SetColumnState(L"IsFinish", false);
+			dw_item.SetColumnState(L"Type", false);
+
+			dw_fob = GetControl(L"dw_fob");
+			dw_fob.openUrl(L"/sale/view/VATNotify/template/VATNotify/fob");
+			dw_profit = GetControl(L"dw_profit");
+			dw_profit.openUrl(L"/sale/view/VATNotify/template/VATNotify/profit");
+			dw_profit.SetColHeaderHeight(0);
+			dw_profit.SetRowSelectorWidth(0);
+			dw_profit.SetHScrollState(false);
+			dw_profit.SetVScrollState(false);
+
+			InvNo = L"";
+			CurInvNo = L"";
+			xaserverarg arg;
+			
+
+			if (GetWinParam())
+			{
+				int pArg = GetArg();
+				
+				InvNo = arg.GetArgString(L"invoiceno");
+				SetWindowText(GetHWND(), InvNo);
+			}
+			CurInvNo = InvNo;
+
+			dw_arg = GetControl(L"dw_arg");
+			dw_arg.openUrl(L"/sale/view/VATNotify/template/VATNotify/PaperCardArg");
+			dw_arg.SetColHeaderHeight(0);
+			dw_arg.SetRowSelectorWidth(0);
+			dw_arg.SetHScrollState(false);
+			dw_arg.SetVScrollState(false);
+
+			OnRetrieve();
+			OnAttachEvent();
+
+			return 1;
+		}
+
+		int onloaded()
+		{
+			SetAgent();
+
+			return 1;
+		}
+	};
diff --git a/jrj/project/business/VATNotify/simple.maint.vatnotify.cpp b/jrj/project/business/VATNotify/simple.maint.vatnotify.cpp
index 6c3d5bb..f60c9b4 100644
--- a/jrj/project/business/VATNotify/simple.maint.vatnotify.cpp
+++ b/jrj/project/business/VATNotify/simple.maint.vatnotify.cpp
@@ -6,537 +6,876 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) simplemaintvatnotifyWin : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwtable	dw_profit;
+		xdwgrid		dw_item;
+		xdwgrid		dw_fob;
+		xstring		InvNo;
+		xstring		CurInvNo;
+		xnode	m_agentNode;	//Agent Condition
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+	public:
+		simplemaintvatnotifyWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static simplemaintvatnotifyWin* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			simplemaintvatnotifyWin* pWin = new simplemaintvatnotifyWin(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
+		xstring  GetEntityData(int pr)
+		{
+			xml x ;
+			dw_item.AcceptText();
+			dw_item.DwUpdateAllToEx(x);
+			return x.xml();
+		}
 
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
+		{
+			//重置工具条
+			SetAgent();
+			return 1;
+		}
 
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
+		int OnPrint()
+		{
+			xaserverarg arg;
+			
+			arg.AddArg(L"EntityName", L"VATNotify");
+			arg.AddArg(L"EntityID", L"", L"");
+			xstring InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"InvoiceNo");
+			xstring SupplierID = dw_item.GetItemString(dw_item.GetRow(), L"SupplierID");
+			arg.AddArg(L"EntityNo", InvoiceNo, L"");
+			arg.AddArg(L"SupplierID", SupplierID);
+			arg.AddArg(L"VATNotifyID", L"");
+			
+			openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", arg);
+			return 1;
+		}
 
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
+		int OnPrintItem()
+		{
+			xaserverarg arg;
+			
+			arg.AddArg(L"EntityName", L"VATNotify", L"");
+			arg.AddArg(L"EntityID", L"", L"");
+			xstring InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(dw_item.GetRow(), L"InvoiceNo");
+			xstring SupplierID = dw_item.GetItemString(dw_item.GetRow(), L"SupplierID");
+			arg.AddArg(L"EntityNo", InvoiceNo, L"");
+			arg.AddArg(L"SupplierID", SupplierID);
+			arg.AddArg(L"VATNotifyID", dw_item.GetGuid(dw_item.GetRow()));
+			trace(InvoiceNo + L"====L" + dw_item.GetGuid(dw_item.GetRow()));
+			
+			openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", p);
+			return 1;
+		}
+
+		int allbill() {
+			int MB_OKCANCEL = 1;
+			int IDOK = 1;
+			int ret =MessageBox(GetHWND(), L"全数开票?", L"提示", MB_OKCANCEL);
+			if (ret != IDOK) return 1;
+			dw_item.AcceptText();
+			for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				dw_item.SetItemString(ll_row, L"NInvoiceNo", ls_dtlno);
+				dw_item.SetItemString(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L"Amount"));
+				xstring sdate = publiccode::GetCurrentDate();
+				dw_item.SetItemString(ll_row, L"NotifyDate", sdate);
+				dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L"Amount"));
+			}
+			dw_item.Redraw();
+			return 1;
+		}
+
+		int allbillno() {
+			int MB_OKCANCEL = 1;
+			int IDOK = 1;
+			int ret =MessageBox(GetHWND(), L"全数不开票?", L"提示", MB_OKCANCEL);
+			if (ret != IDOK) return 1;
+			dw_item.AcceptText();
+			for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L""));
+				dw_item.ItemChangeTo(ll_row, L"NQuantity", dw_item.GetItemString(ll_row, L""));
+				dw_item.SetItemString(ll_row, L"NQtyUnit", L"");
+				dw_item.SetItemString(ll_row, L"NotifyDate", L"");
+				dw_item.SetItemString(ll_row, L"NClassifyID", L"");
+				dw_item.SetItemDisplayString(ll_row, L"NClassifyID", L"");
+				dw_item.SetItemString(ll_row, L"NName", L"");
+				dw_item.SetItemString(ll_row, L"NInvoiceNo", L"");
+			}
+			dw_item.Redraw();
+			return 1;
+		}
+
+		int onebill()
+		{
+			int ll_row = dw_item.GetNextSelectRow(1);
+			if (ll_row < 1) return 1;
+
+			int MB_OKCANCEL = 1;
+			int IDOK = 1;
+			int ret =MessageBox(GetHWND(), L"确认开票吗?", L"提示", MB_OKCANCEL);
+			if (ret != IDOK) return 1;
+			dw_item.AcceptText();
+
+			while (ll_row > 0 && ll_row <= dw_item.GetRowCount())
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				dw_item.SetItemString(ll_row, L"NInvoiceNo", ls_dtlno);
+				//dw_item.SetItemString(ll_row,L"NAmount",dw_item.GetItemString(ll_row,L"Amount"));
+				xstring sdate = publiccode::GetCurrentDate();
+				dw_item.SetItemString(ll_row, L"NotifyDate", sdate);
+				dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L"Amount"));
+				ll_row = dw_item.GetNextSelectRow(ll_row + 1);
+			}
+
+			dw_item.Redraw();
+			return 1;
+		}
+
+		int onebillno() {
+			int ll_row = dw_item.GetNextSelectRow(1);
+			if (ll_row < 1) return 1;
+
+			int MB_OKCANCEL = 1;
+			int IDOK = 1;
+			int ret = MessageBox(GetHWND(), L"确认不予开票吗?", L"提示", MB_OKCANCEL);
+			if (ret != IDOK) return 1;
+			dw_item.AcceptText();
+
+			while (ll_row > 0 && ll_row <= dw_item.GetRowCount())
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				dw_item.ItemChangeTo(ll_row, L"NAmount", dw_item.GetItemString(ll_row, L""));
+				dw_item.ItemChangeTo(ll_row, L"NQuantity", dw_item.GetItemString(ll_row, L""));
+				dw_item.SetItemString(ll_row, L"NotifyDate", L"");
+				dw_item.SetItemString(ll_row, L"NClassifyID", L"");
+				dw_item.SetItemDisplayString(ll_row, L"NClassifyID", L"");
+				dw_item.SetItemString(ll_row, L"NQtyUnit", L"");
+				dw_item.SetItemString(ll_row, L"NName", L"");
+				dw_item.SetItemString(ll_row, L"NInvoiceNo", L"");
+				ll_row = dw_item.GetNextSelectRow(ll_row + 1);
+			}
+			dw_item.Redraw();
+			return 1;
+		}
+
+		int CalcRate()
+		{
+			for (int row = 1; row <= dw_fob.GetRowCount(); row++)
+			{
+				xstring InvoiceNo = dw_fob.GetItemString(row, L"InvoiceNo");
+				xstring ClassifyID = dw_fob.GetItemString(row, L"ClassifyID");
+				double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
+				double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
+				double fobAmt = dw_fob.GetItemDouble(row, L"FobAmt");
+				double rate = sumAmt / fobAmt;
+				double LimitAmt = fobAmt * rate;
+				dw_fob.SetItemDouble(row, L"Rate", rate);
+				dw_fob.SetItemDouble(row, L"LimitAmt", LimitAmt);
+				dw_fob.SetItemDouble(row, L"RestAmt", LimitAmt - sumAmt);
+			}
+			RecalcProfitData();
+			dw_fob.Redraw();
+
+			return 1;
+		}
+
+		int onimport() {
+			//OpenWindow(L"dev:xpage[import.vatnotify.vx]",0);
+			return 1;
+		}
+
+		int OnFobItemChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
+			int row = hdr.row;
+
+			if (colname == L"Rate" || colname == L"FobAmt")
+			{
+				xstring InvoiceNo = dw_fob.GetItemString(row, L"InvoiceNo");
+				xstring ClassifyID = dw_fob.GetItemString(row, L"ClassifyID");
+				double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
+				double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
+				double fobAmt = dw_fob.GetItemDouble(row, L"FobAmt");
+				double rate = dw_fob.GetItemDouble(row, L"Rate");
+				double LimitAmt = fobAmt * rate;
+				dw_fob.SetItemDouble(row, L"LimitAmt", LimitAmt);
+				dw_fob.SetItemDouble(row, L"RestAmt", LimitAmt - sumAmt);
+				dw_fob.Redraw();
+				RecalcProfitData();
+				return 1;
+			}
+
+			return 1;
+		}
+
+		int OnItemChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			xstring colname = hdr.colname;
+			xstring value = hdr.data;
+			int row = hdr.row;
+			xstring ClassifyID = dw_item.GetItemString(row, L"NClassifyID");
+			if (ClassifyID == L"") ClassifyID = dw_item.GetItemString(row, L"ClassifyID");
+			xstring InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
+			int ll_find = FobLookup(ClassifyID);
+
+			//trace(L"\r\n"+ ll_find.toString()+L":"+ ClassifyID);
+
+			if (colname == L"NAmount")
+			{
+				if (ll_find > 0)
+				{
+					//xstring qtyUnit = dw_fob.GetItemString(ll_find,L"CQtyUnit");
+					xstring qtyUnit = dw_fob.GetItemString(ll_find, L"QtyUnit");
+					double limitAmt = dw_fob.GetItemDouble(ll_find, L"LimitAmt");
+					double CQuantity = dw_fob.GetItemDouble(ll_find, L"CQuantity");
+					double sumAmt = GetSumAmount(InvoiceNo, ClassifyID);
+					double amt = dw_item.GetItemDouble(row, L"NAmount");
+					//double qty = CQuantity * amt /limitAmt;
+					double qty = dw_item.GetItemDouble(row, L"Quantity");
+					if (qtyUnit.trim() != L"千克")
+					{
+						int d = xstring(qty).toInt();
+						xstring s = xstring(d);
+						qty = s.toDouble();
+					}
+					else
+					{
+						dw_item.SetItemDouble(row, L"NQuantity", qty);
+						xstring sqty = dw_item.GetItemString(row, L"NQuantity");
+						qty = sqty.toDouble();
+					}
+					double restAmt = limitAmt - sumAmt;
+					dw_fob.SetItemDouble(ll_find, L"RestAmt", restAmt);
+					dw_item.ItemChangeTo(row, L"NQuantity", xstring(qty));
+					dw_fob.Redraw();
+				}
+				return 1;
+			}
+			else if (colname == L"NQuantity")
+			{
+				if (ll_find > 0)
+				{
+					double CQuantity1 = dw_fob.GetItemDouble(ll_find, L"CQuantity");
+					double sumQty = GetSumQuantity(InvoiceNo, ClassifyID);
+					double restQuantity = CQuantity1 - sumQty;
+					dw_fob.SetItemDouble(ll_find, L"RestQty", restQuantity);
+
+					xstring qtyUnit2 = dw_fob.GetItemString(ll_find, L"QtyUnit");
+					dw_item.SetItemString(row, L"NQtyUnit", qtyUnit2);
+
+					dw_fob.Redraw();
+				}
+				return 1;
+			}
+			else if (colname == L"NInvoiceNo")
+			{
+				row = dw_item.GetRow();
+				InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+				if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
+				RetrieveFob(InvoiceNo);
+				RetrieveProfit(InvoiceNo);
+				return 1;
+			}
+			else if (colname == L"NClassifyID")
+			{
+				xstring NQuantity = dw_item.GetItemString(dw_item.GetRow(), L"NQuantity");
+				if (NQuantity != L"") dw_item.ItemChangeTo(dw_item.GetRow(), L"NQuantity", NQuantity);
+				xstring NAmount = dw_item.GetItemString(dw_item.GetRow(), L"NAmount");
+				if (NAmount != L"") dw_item.ItemChangeTo(dw_item.GetRow(), L"NAmount", NAmount);
+				xstring sdate = publiccode::GetCurrentDate();
+				dw_item.SetItemString(dw_item.GetRow(), L"NotifyDate", sdate);
+
+				//xstring qtyUnit1 = dw_fob.GetItemString(ll_find,L"CQtyUnit");
+				xstring qtyUnit1 = dw_fob.GetItemString(ll_find, L"QtyUnit");
+				dw_item.SetItemString(dw_item.GetRow(), L"NQtyUnit", qtyUnit1);
+				dw_item.SetItemString(dw_item.GetRow(), L"VATRefundRate", dw_fob.GetItemString(ll_find, L"VATRefundRate"));
+				dw_item.Redraw();
+
+				return 1;
+			}
+			/*
+					if dwo.name='notifycname' then
+			if trim(data)='' then
+				this.setItem(row,'notifycustid','')
+			else
+				//cwd
+				if pos(data,'"') > 0 then
+					ll_find = dw_3.find(L"cname='"+data+L"'",0,dw_3.rowCount())
+				else
+					ll_find = dw_3.find('cname=L"'+data+'"',0,dw_3.rowCount())
+				end if
+				//end
+		//		ll_find = dw_3.find('cname=L"'+data+'"',0,dw_3.rowCount())
+				if ll_find > 0 then
+					this.setItem(row,'notifycustid',dw_3.getItemString(ll_find,'custid'))
+					this.setItem(row,'custunit',dw_3.getItemString(ll_find,'custunit'))
+
+					decimal ld_rate
+					ls_custid = dw_3.getItemString(ll_find,'custid')
+					select retax into :ld_rate from code_t_custom where code_s = :ls_custid;
+					this.setitem(row,'retax',ld_rate)
+				end if
+			end if
+			if not isnull(this.getItemDecimal(row,'notifybuyamt')) then
+				dwoex = this.object.notifybuyamt
+				this.event itemchanged(row,dwoex,xstring(this.getItemDecimal(row,'notifybuyamt')))
+			end if
+			if not isnull(this.getItemDecimal(row,'notifycustqty')) then
+				dwoex = this.object.notifycustqty
+				this.event itemchanged(row,dwoex,xstring(this.getItemDecimal(row,'notifycustqty')))
+			end if
+			dw_1.setitem( dw_1.getrow(), 'notifydate',today())
+			*/
+			return 1;
+		}
+
+		double GetSumAmountExcept(xstring InvoiceNo, xstring ClassifyID, xstring InvoiceNoExcept)
+		{
+			xml x ;
+			
+			xaserverarg arg = ViewObject::MakeArg();
+			arg.AddArg(L"ClassifyID", ClassifyID);
+			arg.AddArg(L"InvoiceNo", InvoiceNo);
+			arg.AddArg(L"InvoiceExcept", InvoiceNoExcept);
+
+			if (xurl::get(L"/sale/data/VATNotify/entity/suminfo", arg.GetString(), x) != 1)
+			{
+				xstring error = x.text();
+				alert(L"err:" + error);
+				return 0.0;
+			}
+			KXMLDOMNode n = x.selectSingleNode(L"data/Item/amt");
+			if (!n) return 0.0;
+			xstring str = n.text();
+			return str.toDouble();
+		}
+
+		double GetSumQuantityExcept(xstring InvoiceNo, xstring ClassifyID, xstring InvoiceNoExcept)
+		{
+			xml x ;
+			
+			xaserverarg arg = ViewObject::MakeArg();
+			arg.AddArg(L"ClassifyID", ClassifyID);
+			arg.AddArg(L"InvoiceNo", InvoiceNo);
+			arg.AddArg(L"InvoiceExcept", InvoiceNoExcept);
+
+			if (xurl::get(L"/sale/data/VATNotify/entity/suminfo", arg.GetString(), x) != 1)
+			{
+				xstring error = x.text();
+				alert(L"err:" + error);
+				return 0.0;
+			}
+			KXMLDOMNode n = x.selectSingleNode(L"data/Item/qty");
+			if (!n) return 0.0;
+			xstring str = n.text();
+			return str.toDouble();
+		}
+
+		double GetSumAmount(xstring InvoiceNo, xstring ClassifyID)
+		{
+			double amt = 0;
+			xstring InvoiceNoExcept = dw_item.GetItemString(1, L"InvoiceNo");
+			if (InvoiceNoExcept != L"") amt = GetSumAmountExcept(InvoiceNo, ClassifyID, InvoiceNoExcept);
+
+			for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"NInvoiceNo");
+				if (ls_dtlno == L"") ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				if (InvoiceNo == ls_dtlno)
+				{
+					xstring classifyID = dw_item.GetItemString(ll_row, L"NClassifyID");
+					if (classifyID == L"")  classifyID = dw_item.GetItemString(ll_row, L"ClassifyID");
+					if (classifyID == ClassifyID)
+						amt += dw_item.GetItemDouble(ll_row, L"NAmount");
+				}
+			}
+			return amt;
+		}
+
+		int RecalcProfitData()
+		{
+			double fobAmt = GetSumFobAmt();
+			double limitAmt = GetSumLimitAmount();
+			double RefundAmt = GetSumRefund();
+			double goodsAmt = limitAmt - RefundAmt;
+			double freight = dw_profit.GetItemDouble(1, L"Freight");
+			double comm = dw_profit.GetItemDouble(1, L"Comm");
+			double 	netAmount = fobAmt - freight - comm;
+			double exchCost = (limitAmt - RefundAmt) / fobAmt;
+			dw_profit.SetItemDouble(1, L"NetAmount", netAmount);
+			dw_profit.SetItemDouble(1, L"SaleAmount", fobAmt);
+			dw_profit.SetItemDouble(1, L"SaleCost", goodsAmt);
+			dw_profit.SetItemDouble(1, L"Drawback", RefundAmt);
+			dw_profit.SetItemDouble(1, L"ExchCost", exchCost);
+			dw_profit.Redraw();
+			return 1;
+		}
+		double GetSumLimitAmount()
+		{
+			double amt = 0;
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				amt += dw_fob.GetItemDouble(ll_row, L"LimitAmt");
+			}
+			return amt;
+		}
+		double GetSumRefund()
+		{
+			double amt = 0;
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				double rate = dw_fob.GetItemDouble(ll_row, L"VATRate");
+				double refundRate = dw_fob.GetItemDouble(ll_row, L"VATRefundRate");
+				double d = dw_fob.GetItemDouble(ll_row, L"LimitAmt");
+				double val = d / (100.0 + rate) * refundRate;
+				amt += val;
+			}
+			return amt;
+		}
+		double GetSumFobAmt()
+		{
+			double amt = 0;
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				amt += dw_fob.GetItemDouble(ll_row, L"FobAmt");
+			}
+			return amt;
+		}
+
+		double GetSumQuantity(xstring InvoiceNo, xstring ClassifyID)
+		{
+			double qty = 0;
+			xstring InvoiceNoExcept = dw_item.GetItemString(1, L"InvoiceNo");
+			if (InvoiceNoExcept != L"") qty = GetSumQuantityExcept(InvoiceNo, ClassifyID, InvoiceNoExcept);
+
+			for (int ll_row = 1; ll_row <= dw_item.GetRowCount(); ll_row++)
+			{
+				xstring ls_dtlno = dw_item.GetItemString(ll_row, L"NInvoiceNo");
+				if (ls_dtlno == L"") ls_dtlno = dw_item.GetItemString(ll_row, L"InvoiceNo");
+				if (InvoiceNo == ls_dtlno)
+				{
+					xstring classifyID = dw_item.GetItemString(ll_row, L"NClassifyID");
+					if (classifyID == L"")  classifyID = dw_item.GetItemString(ll_row, L"ClassifyID");
+					if (classifyID == ClassifyID)
+					{
+						qty += dw_item.GetItemDouble(ll_row, L"NQuantity");
+					}
+				}
+			}
+			return qty;
+		}
+
+		int FobLookup(xstring ClassifyID)
+		{
+			for (int ll_row = 1; ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				if (dw_fob.GetItemString(ll_row, L"ClassifyID") == ClassifyID) return ll_row;
+			}
+			return -1;
+		}
+
+		int addother() {
+			return 1;
+		}
+		int deleteother() {
+			return 1;
+		}
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"save") {
+				return OnSave();
+			}
+			else if (comdid == L"xmParse")
+				return OnParse();
+			else if (comdid == L"allbill") {
+				return allbill();
+			}
+			else if (comdid == L"allbillno") {
+				return allbillno();
+			}
+			else if (comdid == L"onebill") {
+				return onebill();
+			}
+			else if (comdid == L"onebillno") {
+				return onebillno();
+			}
+			else if (comdid == L"import") {
+				return onimport();
+			}
+			else if (comdid == L"addother") {
+				return addother();
+			}
+			else if (comdid == L"deleteother") {
+				return deleteother();
+			}
+			else if (comdid == L"xmPrint") {
+				return OnPrint();
+			}
+			else if (comdid == L"xmPrintItem") {
+				return OnPrintItem();
+			}
+			else if (comdid == L"xmCalcRate") {
+				return CalcRate();
+			}
+			return 0;
+		}
+
+		int OnRowChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+
+			xstring InvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+			if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(row, L"InvoiceNo");
+			if (InvoiceNo != CurInvNo)
+			{
+				CurInvNo = InvoiceNo;
+				RetrieveFob(InvoiceNo);
+				RetrieveProfit(InvoiceNo);
+				RecalcProfitData();
+			}
+
+			return 1;
+		}
+
+		int OnParse()
+		{
+			xaserverarg arg;
+			
+			OpenWindow(L"dev:xpage[VATNotifyParse.vx]", arg);
+			if (arg.GetArgString(L"process") == L"ok")
+			{
+				int row = dw_item.GetRow();
+				int row1 = dw_item.InsertRow(0);
+				dw_item.SetItemString(row1, L"SupplierID", dw_item.GetItemString(row, L"SupplierID"));
+				dw_item.SetItemDisplayString(row1, L"SupplierID", dw_item.GetItemDisplayString(row, L"SupplierID"));
+				dw_item.SetItemString(row1, L"Amount", arg.GetArgString(L"Amount"));
+				dw_item.SetItemString(row1, L"Quantity", arg.GetArgString(L"Quantity"));
+				dw_item.SetItemString(row1, L"CQuantity", arg.GetArgString(L"CustQuantity"));
+				dw_item.SetItemString(row1, L"ClassifyID", dw_item.GetItemString(row, L"ClassifyID"));
+				dw_item.SetItemDisplayString(row1, L"ClassifyID", dw_item.GetItemDisplayString(row, L"ClassifyID"));
+			}
+			return 1;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+
+		int OnSave()
+		{
+			xml x ;
+			
+			dw_item.AcceptText();
+			dw_item.DwUpdateAllToEx(x);
+			xaserverarg arg = ViewObject::MakeArg();
+			arg.AddArg(L"content", x.xml());
+
+
+
+			//trace(x.xml);
+			//return 1;
+			if (xurl::get(L"/sale/data/VATNotify/base/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_item.ResetUpdateStatus();
+			}
+			else
+			{
+				alert(L"保存失败1!");
+				return 1;
+			}
+
+			dw_fob.AcceptText();
+			xml x1 ;
+			
+			dw_fob.DwUpdateAllToEx(x1);
+			arg.AddArg(L"content", x1.xml());
+			int MB_OKCANCEL = 1;
+			int IDOK = 1;
+
+			/*
+			for(int ll_row=1;	ll_row <= dw_fob.GetRowCount(); ll_row++)
+			{
+				xstring RestQty = dw_fob.GetItemString(ll_row,L"RestQty");
+				//xstring ClassifyID=dw_fob.GetItemString(ll_row,L"CName");
+				if(RestQty !=L"0.00" ){
+					//xstring qty =RestQty;
+					int ret = win32::MessageBox(GetHWND(),L" 存在结存数量不为0的物品,确认保存吗?",L"提示",MB_OKCANCEL);
+					if(ret !=IDOK) return 1;
+				}
+			}
+			*/
+
+
+			//return 0;
+			if (xurl::get(L"/sale/data/VATNotify/fob/update", arg.GetString(), x1) != 1)
+			{
+				xstring error1 = x1.text();
+				alert(L"err:" + error1);
+				return 1;
+			}
+			str = x1.documentElement().getAttribute(L"text");
+			if (str == L"true")
+			{
+				dw_fob.ResetUpdateStatus();
+				alert(L"保存成功!");
+			}
+			else
+			{
+				alert(L"保存失败2!");
+				return 1;
+			}
+			return 1;
+		}
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&simplemaintvatnotifyWin::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&simplemaintvatnotifyWin::OnSetFocus);
+			AttachEvent(L"dw_item", L"DWV_ITEMCHANGED", (FEvent)&simplemaintvatnotifyWin::OnItemChanged);
+			AttachEvent(L"dw_fob", L"DWV_ITEMCHANGED", (FEvent)&simplemaintvatnotifyWin::OnFobItemChanged);
+			AttachEvent(L"dw_item", L"DWV_ROWFOCUSCHANGED", (FEvent)&simplemaintvatnotifyWin::OnRowChanged);
+			AttachEvent(L"dw_item", L"DWV_ASKDATA", (FEvent)&simplemaintvatnotifyWin::OnAskDataItem);
+			AttachCloseWindow();
+		}
+
+		int RetrieveFob(xstring InvoiceNo, bool start = false)
+		{
+			if (!start)
+			{
+				dw_fob.Filter(L"InvoiceNo", InvoiceNo);
+				dw_fob.Redraw();
+				if (dw_fob.GetRowCount() > 0) return 1;
+			}
+
+			//start = true;
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"invoiceno", InvoiceNo);
+			if (getUrl(L"/sale/data/VATNotify/entity/fob", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
 				return -1;
 			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
-			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
-			}
 			else
 			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
-			}
-		}
-		return 1;
-	}
-
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
-			}
-			else
-			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
-			}
-			return 1;
-		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
-
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
-		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
-			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
+				//trace(x.xml);
+				if (start)
 				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
+					dw_fob.Retrieve(x);
+					dw_fob.Redraw();
+				}
+				else
+				{
+					xml x1 ;
+					
+					dw_fob.DwUpdateAllToEx(x1);
+					KXMLDOMElement docElement = x1.documentElement();
+					if (docElement)
+					{
+						KXMLDOMNodeList lst = x.selectNodes(L"data/Item");
+						int n = lst.length();
+						for (int i = 0; i < n; i++)
+						{
+							KXMLDOMElement e = lst.item(i);
+							docElement.appendChild(e);
+							e.Release();
+						}
+						docElement.Release();
+						lst.Release();
+						dw_fob.Retrieve(x1);
+					}
+					else
+					{
+						dw_fob.Retrieve(x);
+					}
+					dw_fob.Filter(L"InvoiceNo", InvoiceNo);
+					dw_fob.Redraw();
 				}
 			}
-
+			return 1;
 		}
 
-		return 1;
-	}
+		int RetrieveProfit(xstring InvoiceNo)
+		{
+			xml x ;
+			
+			xaserverarg arg;
+			
+			arg.AddArg(L"invoiceno", InvoiceNo);
+			if (getUrl(L"/sale/data/VATNotify/entity/profit", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				return -1;
+			}
+			else
+			{
+				dw_profit.Retrieve(x);
+				dw_profit.Redraw();
+			}
+			return 1;
+		}
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
+		int  OnRetrieve()
+		{
+			HCURSOR  hCursor = xutil::SetCursorWait();
 
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
 
-};
\ No newline at end of file
+			xml x ;
+			
+			xaserverarg arg;
+			
+
+			if (GetWinParam())
+			{
+				int pArg = GetArg();
+				
+			}
+			else
+			{
+				xutil::RestoreCursor(hCursor);
+				return 1;
+			}
+			if (getUrl(L"/sale/data/VATNotify/entity/base", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				xutil::RestoreCursor(hCursor);
+				return -1;
+			}
+			else
+			{
+				dw_item.Retrieve(x);
+				dw_item.Redraw();
+				dw_item.SetSelectionMode(1);
+			}
+			if (dw_item.GetRowCount() > 0)
+			{
+				xstring InvoiceNo = dw_item.GetItemString(1, L"NInvoiceNo");
+				if (InvoiceNo == L"") InvoiceNo = dw_item.GetItemString(1, L"InvoiceNo");
+				CurInvNo = InvoiceNo;
+				RetrieveFob(InvoiceNo);
+				RetrieveProfit(InvoiceNo);
+				RecalcProfitData();
+			}
+
+			xutil::RestoreCursor(hCursor);
+			return 1;
+		}
+
+		//base AskData
+		int OnAskDataItem(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+			xstring x = hdr.colname;
+			if (x == L"userInvoiceNo") //下拉
+			{
+				xstring sInvoiceNo = dw_item.GetItemString(row, L"NInvoiceNo");
+				hdr.data = sInvoiceNo;
+			}
+
+			return 1;
+		}
+
+		int onload()
+		{
+			dw_item = GetControl(L"dw_item");
+			dw_item.openUrl(L"/sale/view/VATNotify/template/VATNotify/item");
+			dw_item.SetColumnState(L"InvoiceNo", false);
+			dw_item.SetColumnState(L"CName", false);
+			//dw_item.SetColumnState(L"CreatorID",false);
+			//dw_item.SetColumnState(L"CreateDate",false);
+			dw_item.SetColumnState(L"VATRate", false);
+			dw_item.SetColumnState(L"VATRefundRate", false);
+			dw_item.SetColumnState(L"IsFinish", false);
+			dw_item.SetColumnState(L"Type", false);
+			dw_item.SetColumnState(L"QtyUnitName", false);
+			dw_item.SetColumnState(L"QtyUnit", false);
+			dw_item.SetColumnState(L"CQtyUnit", false);
+
+			dw_fob = GetControl(L"dw_fob");
+			dw_fob.openUrl(L"/sale/view/VATNotify/template/VATNotify/fob");
+			dw_profit = GetControl(L"dw_profit");
+			dw_profit.openUrl(L"/sale/view/VATNotify/template/VATNotify/profit");
+			dw_profit.SetColHeaderHeight(0);
+			dw_profit.SetRowSelectorWidth(0);
+			dw_profit.SetHScrollState(false);
+			dw_profit.SetVScrollState(false);
+
+			InvNo = L"";
+			CurInvNo = L"";
+			xaserverarg arg;
+			
+
+			if (GetWinParam())
+			{
+				int pArg = GetArg();
+				
+				InvNo = arg.GetArgString(L"invoiceno");
+				SetWindowText(GetHWND(), InvNo);
+			}
+			CurInvNo = InvNo;
+
+			OnRetrieve();
+			OnAttachEvent();
+
+			return 1;
+		}
+
+		int onloaded()
+		{
+			SetAgent();
+
+			return 1;
+		}
+	};
diff --git a/jrj/project/business/VATNotify/update.vatnotify.cpp b/jrj/project/business/VATNotify/update.vatnotify.cpp
index 6c3d5bb..c7d5e60 100644
--- a/jrj/project/business/VATNotify/update.vatnotify.cpp
+++ b/jrj/project/business/VATNotify/update.vatnotify.cpp
@@ -6,537 +6,361 @@
 #include "viewobject/view.base.hpp"
 
 using xml = KXMLDOMDocument;
-class __declspec(dllexport) listSupplierv3 : public listwin
-{
-public:
-	xdwgrid dw_goods;
-	xtreeview tv_1;
-	xcombobox ddlb_1;
-	int	changeddlb;
-	xstring TypeWork;
-	xstring GoodsUrl;
-	xstring m_sType; //type
-	xstring m_sTypeTxt; //选中树的data
-	//	xstring m_searchtxt;
-	int PIndex;
-	xnode	m_agentNode;	//Agent Condition
-	xstring	m_agentCond;	//Agent Node
-
-public:
-	listSupplierv3(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
-public:
-	static listSupplierv3* CreateInstance(void* implPtr, void* hWnd)
+	class __declspec(dllexport) UpdateVatNotifyWin : public xframe
 	{
-		listSupplierv3* pWin = new listSupplierv3(implPtr, (HWND)hWnd);
-		return pWin;
-	}
-	int OnRetrieve()
-	{
-		xml x;
+	public:
+		xdwgrid	dw_list;
+		xdwgrid	dw_item;
+		xdwgrid	dw_goods;
+		xnode	m_agentNode;	//Agent Condition
 
-		xaserverarg arg;
-		arg.AddArg(L"pageindex", xstring(PIndex)); //第几页
-		arg.AddArg(L"pagenumber", xstring(listwin::m_pageNumber)); //每页数量
-		arg.AddArg(L"QueryTxt", listwin::m_QueryTxt);
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		//alert(L"xxxx");
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
+	public:
+		UpdateVatNotifyWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
+	public:
+		static UpdateVatNotifyWin* CreateInstance(void* implPtr, void* hWnd)
 		{
-			return -1;
+			UpdateVatNotifyWin* pWin = new UpdateVatNotifyWin(implPtr, (HWND)hWnd);
+			return pWin;
 		}
-		else
+		int SetAgent()
 		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			xstring xfNodeAgentArea = L"agentarea";
+			xnode anode = GetAgentNode(xfNodeAgentArea);
+			if (m_agentNode)
 			{
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
+				SetAgentNode(anode, m_agentNode);
 			}
-			//alert(x.GetXml());
-			dw_list.Retrieve(x);
-			dw_list.Redraw();
-			dw_list.SetReadOnly(true);
-		}
-		return 1;
-	}
-
-	int SetEntityData(xaserverarg arg)
-	{
-		xstring strQueryTxt = arg.GetArgString(L"QueryTxt");
-		xml x;
-
-		arg.AddArg(L"sType", m_sType);
-		arg.AddArg(L"sTypeTxt", m_sTypeTxt);
-		trace(arg.GetString());
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/list", arg.GetString(), x) != 1)
-		{
-			alert(x.text());
-
-			return -1;
-		}
-		else
-		{
-			KXMLDOMElement e = x.documentElement();
-			if (listwin::dw_pages && e.selectSingleNode(L"@TotalPage"))
+			else
 			{
-
-				xstring s = e.selectSingleNode(L"@TotalPage").text(); //总数量				
-				listwin::dw_pages.SetMaxPage(s.toInt());
-			}
-			//trace(x.GetXml());
-			listwin::dw_list.Retrieve(x);
-			listwin::dw_list.Redraw();
-			listwin::dw_list.SetReadOnly(true);
-		}
-
-		return 1;
-	}
-
-	int OnChangePages(TEvent* evt, LPARAM p)
-	{
-		PAGENMHDR* h = (PAGENMHDR*)evt->notify.pnmh;
-		int c = h->cur;
-
-
-		HCURSOR hCursor = xutil::SetCursorWait();
-		OnRetrieve();
-		PIndex = c;
-		xutil::RestoreCursor(hCursor);
-		return 1;
-
-
-	}
-
-	int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
-	{
-		if (updateItem == L"refresh")
-		{
-			//trace(L"sd");
-			xdwpages zz = GetControl(L"pages");
-			int h = zz.SetCurPage(1);
-			//trace(h);
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	//树选择
-	int OnTreeSelChanged(TEvent evt, LPARAM p)
-	{
-		if (changeddlb != 1)
-		{
-			//alert(L"1");
-
-			HTREEITEM h = tv_1.GetSelectedItem();
-			KXMLDOMElement& e = *(KXMLDOMElement*)tv_1.GetItemData(h);
-
-			xstring t = e.selectSingleNode(L"@type").text();
-			m_sType = t + L"";
-			xstring txt = e.selectSingleNode(L"@code").text();
-			if (txt == L"")
-				txt = e.selectSingleNode(L"@name").text();
-			m_sTypeTxt = txt + L"";
-
-			//alert(m_sTypeTxt);
-
-			PIndex = 1;
-			OnRetrieve();
-		}
-		return 1;
-	}
-
-	int createSubTree(HTREEITEM h, KXMLDOMElement ele)
-	{
-		KXMLDOMNodeList nlist = ele.selectNodes(L"item");
-		int i;
-		int s = nlist.length();
-		if (s > 0)
-			for (i = 0; i < s; i++)
-			{
-
-				KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-				xstring name = e->selectSingleNode(L"@name").text();
-				HTREEITEM hw = tv_1.InsertChildItem(h, name, (LPARAM)e, 15);
-				createSubTree(hw, *e);
-			}
-		return 1;
-	}
-
-	int OnCreateTree(xstring sType)
-	{
-
-		while (tv_1.GetRootItem())
-			tv_1.DeleteItem(tv_1.GetRootItem());
-
-		xml x;
-
-		xaserverarg arg;
-
-		arg.AddArg(L"sType", sType);
-		//Tree.pref.supplier.xq
-		//getUrl(GetEntityName(1)+L"/entity/list",arg.GetString(),x);
-		//if (xaserver::ExecXQuery(GetServerUrl(),L"[Tree.pref.supplier.xq]",arg.GetString(),x)!=1)
-		if (getUrl(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/pref/list/tree", arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			KXMLDOMNodeList nlist = x.selectNodes(L"root/item");
-			int len = nlist.length();
-			if (len > 0)
-			{
-				int i;
-				for (i = 0; i < len; i++)
+				KXMLDOMElement xframeElement = GetElement();
+				KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea + L"[1]/*");
+				if (agent)
 				{
-
-					KXMLDOMElement* e = new KXMLDOMElement(nlist.item(i));
-					xstring name = e->selectSingleNode(L"@name").text();
-					HTREEITEM hw = tv_1.InsertChildItem(0, name, (LPARAM)e, 15);
-
-					createSubTree(hw, *e);
-					tv_1.ExpandItem(hw);
+					xstring s = agent.xml();
+					m_agentNode = SetAgentNode(anode, s);
 				}
-				tv_1.ExpandItem(0);
 			}
+			return 1;
 		}
 
-		return 1;
-	}
+		//焦点激活处理函数
+		int OnSetFocus(TEvent* evt, LPARAM param)
+		{
+			//重置工具条
+			//SetAgent();
+			return 1;
+		}
 
-	//xcombobox下拉
-	int OnSelectDdlb(TEvent evt, LPARAM p)
-	{
-		changeddlb = 1;
+		int OnSave()
+		{
+			xml x ;
+			
+			dw_list.AcceptText();
+			dw_list.DwUpdateAllToEx(x);
+			xaserverarg arg = ViewObject::MakeArg();
+			arg.AddArg(L"content", x.xml());
 
-		int CB_GETCURSEL = 0x0147;
-		int nIndex = SendMessageW(ddlb_1.GetHWND(), CB_GETCURSEL, 0, 0);
-		KXMLDOMElement e = ddlb_1.GetElement();//GetitemData(wid,nIndex);//ddlb_1.GetElement();
-		KXMLDOMElement e2 = e.selectSingleNode(L"item[" + xstring((nIndex + 1)) + L"]");
-		xstring text = e2.selectSingleNode(L"@element").text();
-		OnCreateTree(text);
-		changeddlb = 0;
-		return 1;
-	}
+			trace(x.xml());
+			//return 1;
+			if (xurl::get(L"/sale/data/VATNotify/base/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_list.ResetUpdateStatus();
+				alert(L"保存成功!");
+			}
+			else
+			{
+				alert(L"保存失败!");
+			}
+			return 1;
+		}
 
-	int OnDeleteRow()
-	{
-		int row = listwin::dw_list.GetNextSelectRow(1);
-		if (row < 1) {
-			row = listwin::dw_list.GetRow();
-			if (row < 1) {
-				//win::MessageBox(GetHWND(),L"请选中要删除的行!",L"提示",0);
+		//命令发布函数
+		int OnCmdDispatch(xstring comdid)
+		{
+			if (comdid == L"xmReplaceRow")
+			{
+				return OnReplaceRow();
+			}
+			if (comdid == L"xmReplaceSupplier")
+			{
+				return OnReplaceSupplier();
+			}
+			else if (comdid == L"xmAddRow")
+			{
+				return OnAddRow();
+			}
+			else if (comdid == L"xmSave")
+			{
+				return OnSave();
+			}
+			else if (comdid == L"xmDeleteRow")
+			{
+				return OnDeleteRow();
+			}
+			if (comdid == L"xmClose")
+			{
+				CloseWindow();
+				return 1;
+			}
+			return 0;
+		}
+
+		int OnDeleteRow()
+		{
+			if (dw_list.GetRowCount() == dw_item.GetRowCount())
+			{
+				int res = MessageBox(GetHWND(), L"你可以用替换完成相应的操作,还继续删除吗?", L"提示", 4);
+				if (res != 6) return 1;
+			}
+			else
+			{
+				int res1 = MessageBox(GetHWND(), L"确认删除对应的行?", L"提示", 4);
+				if (res1 != 6) return 1;
+			}
+			dw_list.DeleteRow(0);
+			dw_list.Redraw();
+			return 1;
+		}
+
+		int OnAddRow()
+		{
+			if (dw_item.GetRow() < 1) return 1;
+			int ll_row1 = dw_item.GetRow();
+			dw_list.InsertRow(0);
+			int ll_row = dw_list.GetRowCount();
+
+			KXMLDOMElement e = dw_item.GetRowElement(ll_row1);
+			dw_list.SetItemString(ll_row, L"SupplierID", dw_item.GetItemString(ll_row1, L"SupplierID"));
+			dw_list.SetItemDisplayString(ll_row, L"SupplierID", dw_item.GetItemDisplayString(ll_row1, L"SupplierID"));
+			dw_list.SetItemString(ll_row, L"CQuantity", dw_item.GetItemString(ll_row1, L"CustQuantity"));
+			dw_list.SetItemString(ll_row, L"Amount", dw_item.GetItemString(ll_row1, L"Amount"));
+			dw_list.SetItemString(ll_row, L"ClassifyID", dw_item.GetItemString(ll_row1, L"ClassifyID"));
+			dw_list.SetItemDisplayString(ll_row, L"ClassifyID", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
+			dw_list.SetItemString(ll_row, L"CName", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
+			if (e.selectSingleNode(L"Quantity")) dw_list.SetItemString(ll_row, L"Quantity", e.selectSingleNode(L"Quantity").text());
+			if (e.selectSingleNode(L"CreatorID"))	dw_list.SetItemString(ll_row, L"CreatorID", e.selectSingleNode(L"CreatorID").text());
+			if (e.selectSingleNode(L"CreateDate"))	dw_list.SetItemString(ll_row, L"CreateDate", e.selectSingleNode(L"CreateDate").text());
+			if (e.selectSingleNode(L"ModifierID"))	dw_list.SetItemString(ll_row, L"ModifierID", e.selectSingleNode(L"ModifierID").text());
+			if (e.selectSingleNode(L"ModifyDate"))	dw_list.SetItemString(ll_row, L"ModifyDate", e.selectSingleNode(L"ModifyDate").text());
+			if (e.selectSingleNode(L"VATRate"))	dw_list.SetItemString(ll_row, L"VATRate", e.selectSingleNode(L"VATRate").text());
+			if (e.selectSingleNode(L"VATRefundRate"))	dw_list.SetItemString(ll_row, L"VATRefundRate", e.selectSingleNode(L"VATRefundRate").text());
+			if (e.selectSingleNode(L"CustomUOM"))	dw_list.SetItemString(ll_row, L"CQtyUnit", e.selectSingleNode(L"CustomUOM").text());
+			if (e.selectSingleNode(L"IsFinish"))	dw_list.SetItemString(ll_row, L"IsFinish", e.selectSingleNode(L"IsFinish").text());
+			if (e.selectSingleNode(L"Type"))	dw_list.SetItemString(ll_row, L"Type", e.selectSingleNode(L"Type").text());
+			if (e.selectSingleNode(L"InvoiceNo"))	dw_list.SetItemString(ll_row, L"InvoiceNo", e.selectSingleNode(L"InvoiceNo").text());
+			dw_list.Redraw();
+			dw_item.SetItemString(ll_row1, L"Relation", xstring(ll_row));
+			dw_item.Redraw();
+			return 1;
+		}
+
+		int OnReplaceSupplier()
+		{
+			int ll_row = dw_list.GetRow();
+			int ll_row1 = dw_item.GetRow();
+
+			if (ll_row < 1 || ll_row1 < 1)
+			{
+				alert(L"没有操作!");
+				return 1;
+			}
+			xstring SupplierID1 = dw_item.GetItemString(ll_row1, L"SupplierID");
+			dw_list.SetItemString(ll_row, L"SupplierID", SupplierID1);
+			dw_list.SetItemDisplayString(ll_row, L"SupplierID", dw_item.GetItemDisplayString(ll_row1, L"SupplierID"));
+			dw_list.Redraw();
+			return 1;
+		}
+
+		int OnReplaceRow()
+		{
+			int ll_row = dw_list.GetRow();
+			int ll_row1 = dw_item.GetRow();
+			if (ll_row < 1 || ll_row1 < 1)
+			{
+				alert(L"没有操作!");
+				return 1;
+			}
+
+			bool updateSupplier = false;
+			bool updatePrice = false;
+			bool updateClassifyID = false;
+			xstring SupplierID = dw_list.GetItemString(ll_row, L"SupplierID");
+			xstring CQuantity = dw_list.GetItemString(ll_row, L"CQuantity");
+			xstring Amount = dw_list.GetItemString(ll_row, L"Amount");
+			xstring ClassifyID = dw_list.GetItemString(ll_row, L"ClassifyID");
+
+			xstring SupplierID1 = dw_item.GetItemString(ll_row1, L"SupplierID");
+			xstring CQuantity1 = dw_item.GetItemString(ll_row1, L"CustQuantity");
+			xstring Amount1 = dw_item.GetItemString(ll_row1, L"Amount");
+			xstring ClassifyID1 = dw_item.GetItemString(ll_row1, L"ClassifyID");
+
+			if (SupplierID != SupplierID1) updateSupplier = true;
+			if (CQuantity != CQuantity1) updatePrice = true;
+			if (Amount != Amount1) updatePrice = true;
+			if (ClassifyID != ClassifyID1) updateClassifyID = true;
+
+			if (updateSupplier && updatePrice && updateClassifyID)
+			{
+				int res = MessageBox(GetHWND(), L"上下数据报关品名、价格、工厂全不一致,是否要强制替换?", L"提示", 4);
+				if (res != 6) return 1;
+			}
+			if (updateSupplier)
+			{
+				dw_list.SetItemString(ll_row, L"SupplierID", SupplierID1);
+				dw_list.SetItemDisplayString(ll_row, L"SupplierID", dw_item.GetItemDisplayString(ll_row1, L"SupplierID"));
+			}
+			if (updatePrice)
+			{
+				dw_list.SetItemString(ll_row, L"CQuantity", CQuantity1);
+				dw_list.SetItemString(ll_row, L"Amount", Amount1);
+			}
+			if (updateClassifyID)
+			{
+				dw_list.SetItemString(ll_row, L"ClassifyID", ClassifyID);
+				dw_list.SetItemDisplayString(ll_row, L"ClassifyID", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
+				dw_list.SetItemString(ll_row, L"CName", dw_item.GetItemDisplayString(ll_row1, L"ClassifyID"));
+			}
+			dw_list.Redraw();
+			dw_item.SetItemString(ll_row1, L"Relation",xstring(ll_row));
+			dw_item.Redraw();
+			return 1;
+		}
+
+		//命令处理事件
+		int OnXCommand(TEvent* evt, LPARAM param)
+		{
+			return OnCmdDispatch(evt->xcommand.pStrID);
+		}
+
+		int OnAttachEvent()
+		{
+			//绑定工具条点击事件
+			AttachEvent(L"WM_XCOMMAND", (FEvent)&UpdateVatNotifyWin::OnXCommand);
+			//获取焦点事件,用于重置工具条
+			AttachEvent(L"WM_SETFOCUS", (FEvent)&UpdateVatNotifyWin::OnSetFocus);
+			AttachEvent(L"dw_item", L"DWV_ROWFOCUSCHANGED", (FEvent)&UpdateVatNotifyWin::OnRowChanged);
+
+		}
+
+		int RetrieveCustomSource(xstring classifyID, xstring supplierID)
+		{
+			xml x ;
+			
+			xaserverarg arg ;
+			
+			if (GetWinParam())
+			{
+				int pArg = GetArg();
+				
+			}
+			else
+				arg.AddArg(L"invoiceno", L"15HDLD0720");
+
+			arg.AddArg(L"ClassifyID", classifyID);
+			arg.AddArg(L"SupplierID", supplierID);
+			if (getUrl(L"/sale/data/VATNotify/pref/CustomSource", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
 				return -1;
 			}
-		}
-
-		KXMLDOMElement e = listwin::dw_list.GetRowElement(row);
-		//xstring sguid = e.SelectSingleNode(L"@guid").text;
-		//xstring sName = e.selectSingleNode(L"Name").text+L"";
-		xstring sguid = dw_list.GetItemString(dw_list.GetRow(), L"SupplierID");
-		xstring sName = dw_list.GetItemString(dw_list.GetRow(), L"Name");
-		int  MB_YESNO = 0x00000004;
-		int  IDYES = 6;
-		if (MessageBoxW(GetHWND(), L"确认要删除供应商 " + sName + L" 的信息吗?", L"提示", MB_YESNO) != IDYES) return 1;
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"guid", sguid);
-		arg.AddArg(L"EntityID", sguid);
-		//	trace(sguid);
-		if (xurl::post(GetServerUrl(), L"/sale/data/" + GetEntityName(1) + L"/entity/delete", arg.GetString(), x) != 1)
-		{
-			xstring error = x.text();
-			trace(error);
-		}
-		else
-		{
-			KXMLDOMElement msg = x.selectNodes(L"process").item(0);
-			xstring success = msg.selectSingleNode(L"@finished").text();
-			if (success == L"0")
+			else
 			{
-				alert(msg.selectSingleNode(L"@errInfo").text());
+				dw_goods.Retrieve(x);
+				dw_goods.Redraw();
+			}
+		}
+
+		int OnRowChanged(TEvent* evt, LPARAM p)
+		{
+			DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
+			int row = hdr.row;
+
+			if (row < 1) return 1;
+			KXMLDOMElement e = dw_item.GetRowElement(row);
+			xstring classifyID = e.selectSingleNode(L"ClassifyID").text();
+			xstring supplierID = e.selectSingleNode(L"SupplierID").text();
+			e.Release();
+			RetrieveCustomSource(classifyID, supplierID);
+
+			return 1;
+		}
+
+		int  OnRetrieve()
+		{
+			xml x ;
+			
+			xaserverarg arg;
+			
+			if (GetWinParam())
+			{
+				int pArg = GetArg();
+				
+			}
+			else
+				arg.AddArg(L"invoiceno", L"15HDLD0720");
+			if (getUrl(L"/sale/data/VATNotify/entity/base/miss", arg.GetString(), x) != 1)
+			{
+				trace(x.text());
+				//return -1;
 			}
 			else
 			{
-				MessageBoxW(GetHWND(), L"删除成功!", L"提示", 0);
-				listwin::dw_list.DeleteRow(row);
+				//alert(x.xml);
+				dw_list.Retrieve(x);
+				dw_list.Redraw();
 			}
-		}
-		return 1;
-	}
 
-	int OnRowChangedEx(TEvent* evt, LPARAM p)
-	{
-		DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
-		int row = hdr.row;
-		//if(row < 1 or row > dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = listwin::dw_list.GetRowElement(row);
-		xstring entity = ele.selectSingleNode(L"SupplierID").text();
-		xml x;
-
-		xaserverarg arg;
-		arg.setNativePointer(arg.CreateInstance());
-		arg.AddArg(L"EntityID", entity);
-
-
-		xstring no1 = publiccode::GetUser().no;
-		if (no1 != L"00201")
-		{
-
-			if (TypeWork.find(L"采购") >= 0)
+			if (getUrl(L"/sale/data/VATNotify/pref/GdnInvoice", arg.GetString(), x) != 1)
 			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritemEx";
+				trace(x.text());
+				return -1;
 			}
 			else
 			{
-				GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-			}
-		}
-		else
-		{
-			GoodsUrl = L"/sale/data/SupplierV3/entity/supplieritem";
-		}
-		if (getUrl(GetServerUrl(), GoodsUrl, arg.GetString(), x) != 1)
-		{
-			trace(x.text());
-			return -1;
-		}
-		else
-		{
-			dw_goods.Retrieve(x);
-			dw_goods.Redraw();
-			dw_goods.SetReadOnly(true);
-		}
-		SetAgent(L"list", entity);
-		return 1;
-	}
-
-	int GridSearch()
-	{
-		//alert(L"你好");
-#if 0
-
-		xstring m_config = L"view.Supplier.v3.config";
-		xdwgrid dw = listwin::dw_list;
-		xaserverarg& arg = *new xaserverarg;
-		arg.setNativePointer(arg.CreateInstance());
-		xstring str = TFile::node(m_config, L"config", L"search");
-		if (str != L"") {
-			arg.AddArg(L"sheet", str);
-		}
-		else
-			arg.AddArg(L"sheet", L"dev:sheet[Supplier.v3.tpl/list]");
-		arg.AddArg(L"search", listwin::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"") {
-				listwin::m_QueryTxt = txt;
-				//trace(txt);
-				OnRetrieve();
-			}
-		}
-#endif 
-		return 0;
-	}
-
-	int OnSelectAllRow()
-	{
-		int rows = listwin::dw_list.GetRowCount();
-		if (rows < 1) return -1;
-		listwin::dw_list.SelectRow(1, rows, true);
-		listwin::dw_list.Redraw();
-		return 1;
-	}
-
-	int OnRClick(TEvent evt, LPARAM p)
-	{
-		return 1;
-	}
-	int OnLogOff()
-	{
-		return 1;
-	}
-	int OnChecked()
-	{
-		xstring partyno = dw_list.GetItemString(dw_list.GetRow(), L"PartyNo");
-		if (partyno.find(L"N") < 0)
-		{
-			alert(L"已经是正式供应商");
-			return 0;
-		}
-		xstring entityid = GetEntityID(dw_list.GetRow());
-		int MB_OKCANCEL = 1;
-		int IDOK = 1;
-		int ret = MessageBoxW(GetHWND(), L"是否转成正式供应商?", L"提示", MB_OKCANCEL);
-		if (ret == IDOK)
-		{
-			xml x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/updateno", L"entityid", entityid);
-
-			if (xstring(x.xml()).find(L"success") > 0)
-			{
-				alert(L"处理成功");
-				OnRetrieve();
-			}
-		}
-		return 1;
-	}
-	int PreOnCmdDispatch(xstring comdid)
-	{
-		//alert(comdid);
-
-		if (comdid.find(L"action:LogOff", 0) >= 0) return OnLogOff();
-		if (comdid.find(L"action:bill.delete", 0) >= 0)
-		{
-			OnDeleteRow();
-			return 0;
-		}
-		if (comdid == L"action:search1") return GridSearch();
-		if (comdid == L"action:bill.refresh")
-		{
-			return OnRetrieve();
-		}
-		if (comdid == L"action:bill.xmSaveAs")
-		{
-			xstring  userno = publiccode::GetUser().no;
-			if (userno == L"00701" || userno == L"00601" || userno == L"admin")
-			{
-				dw_list.SaveAs(L"");
-			}
-			return 1;
-		}
-		if (comdid == L"action:bill.Annex")
-		{
-			xaserverarg& arg = *new xaserverarg;
-			arg.setNativePointer(arg.CreateInstance());
-			arg.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			arg.AddArg(L"ApplyStatus", dw_list.GetItemString(dw_list.GetRow(), L"ApplyStatus"));
-
-			OpenWindow(L"dev:xpage[maint.Document.Supplier.v3.vx]", (LPARAM)&arg);
-			return 1;
-		}
-		if (comdid == L"action:bill.AnnexEx")
-		{
-			xaserverarg& arg4 = *new xaserverarg;
-			arg4.setNativePointer(arg4.CreateInstance());
-			arg4.AddArg(L"entityid", dw_list.GetItemString(dw_list.GetRow(), L"SupplierID"));
-			//arg4.AddArg(L"ApplyStatus",dw_list.GetItemString(dw_list.GetRow(),L"ApplyStatus"));
-
-			//OpenWindow(L"dev:xpage[maint.Document.Customer.v3.vx]", p4);
-			OpenWindow(L"dev:xpage[maint.Document.SupplierSD.v3.vx]", (LPARAM)&arg4);
-			return 1;
-		}
-		if (comdid == L"action:bill.checked")
-			return OnChecked();
-		//	if(comdid==L"action:bill.import") return OnImport();
-		//	if(comdid.find(L"action:",0)>=0) return ProcessFlowAction(comdid,1);					
-			//if(comdid==L"search") return GridSearch(L"view.dlg.vface/xpage/grid/column/edit");
-			//if(comdid==L"showall") 	return ShowAll();	
-
-		return 1;
-	}
-
-
-	int PostOnAttachEvent()
-	{
-		//获得树的选择事件
-		AttachEvent(L"tv_1", L"TVN_SELCHANGED", (FEvent)&listSupplierv3::OnTreeSelChanged);
-		AttachEvent(L"cbx_1", L"CBN_SELCHANGE", (FEvent)&listSupplierv3::OnSelectDdlb);
-		AttachEvent(L"pages", L"PAGE_CLICK", (FEvent)&listSupplierv3::OnChangePages);
-		AttachEvent(L"dw_list", L"DWV_RCLICKED", (FEvent)&listSupplierv3::OnRClick);//鼠标右键		
-		//AttachEvent(L"dw_list", L"DWV_DOUBLECLICKED", (FEvent)&listSupplierv3::OnDoubleClicked);
-
-		return 1;
-	}
-
-	int onload()
-	{
-		PIndex = 1;
-		listwin::m_QueryTxt = L""; //查询条件
-		m_sType = L""; //type
-		m_sTypeTxt = L""; //选中树的data
-
-		listwin::onload();
-
-		tv_1 = GetControl(L"tv_1");
-		ddlb_1 = GetControl(L"cbx_1");
-
-		changeddlb = 0;
-		OnCreateTree(L"GoodsCates");
-		dw_list.SetColumnState(L"SupplierID", false);
-		dw_list.SetColumnState(L"userNo", false);
-		dw_list.SetColumnState(L"YearEstablished", false);
-		dw_list.SetColumnState(L"LegalPerson", false);
-		dw_list.SetColumnState(L"ThirdPartyReport", false);
-		dw_list.SetColumnState(L"bAddress", false);
-		dw_list.SetColumnState(L"PayType", false);
-		dw_list.SetColumnState(L"PicPath", false);
-		dw_list.SetColumnState(L"SDID", false);
-		dw_list.SetColumnState(L"AdvantageProduct", false);
-		//dw_list.SetColumnState(L"ApplyStatus",false);
-
-		dw_goods = GetControl(L"dw_goods");
-		dw_goods.openUrl(GetServerUrl(), L"/sale/view/SupplierV3/template/supplier/supplieritem");
-
-		if (publiccode::GetUser().name != L"admin")
-		{
-			xstring s = publiccode::GetUser().id;
-
-			xml supplier_x = ViewObject::RetrieveData(GetServerUrl(), L"/sale/data/SupplierV3/entity/FindBySaleType", L"id", s);
-			if (supplier_x)
-			{
-				TypeWork = supplier_x.text();
-
-				if (TypeWork.find(L"采购") >= 0)
+				dw_item.Retrieve(x);
+				dw_item.Redraw();
+				dw_item.SetReadOnly(true);
+				if (dw_item.GetRowCount() > 0)
 				{
-
-					dw_list.SetColumnState(L"DateEx", false);
-					dw_list.SetColumnState(L"DateExS", false);
-					dw_list.SetColumnState(L"Name", false);
-					dw_list.SetColumnState(L"ProvinceCode", false);
-					dw_list.SetColumnState(L"City", false);
-					dw_list.SetColumnState(L"District", false);
-					dw_list.SetColumnState(L"Address", false);
-					dw_list.SetColumnState(L"CName", false);
-					dw_list.SetColumnState(L"TEL", false);
-					dw_list.SetColumnState(L"Mob", false);
-					dw_list.SetColumnState(L"AreaCode", false);
-					dw_list.SetColumnState(L"Fax", false);
-					dw_goods.SetColumnState(L"Price", false);
-					dw_goods.SetColumnState(L"PackRMBPrice", false);
-					dw_goods.SetColumnState(L"PartRMBPrice", false);
-					dw_goods.SetColumnState(L"PaperRMBPrice", false);
-					dw_goods.SetColumnState(L"ETD", false);
-					dw_goods.SetColumnState(L"InvoiceNo", false);
-
+					KXMLDOMElement e = dw_item.GetRowElement(1);
+					xstring classifyID = e.selectSingleNode(L"ClassifyID").text();
+					xstring supplierID = e.selectSingleNode(L"SupplierID").text();
+					e.Release();
+					trace(L"!" + classifyID + L" " + supplierID);
+					RetrieveCustomSource(classifyID, supplierID);
 				}
 			}
 
+			return 1;
 		}
 
-		return 1;
-	}
+		int onload()
+		{
+			dw_list = GetControl(L"dw_list");
+			dw_list.openUrl(L"/sale/view/VATNotify/template/VATNotify/item");
+			dw_item = GetControl(L"dw_item");
+			dw_item.openUrl(L"/sale/view/VATNotify/template/VATNotify/DItem");
+			dw_goods = GetControl(L"dw_goods");
+			dw_goods.openUrl(L"/sale/view/VATNotify/template/VATNotify/DItem1");
 
-	int onloaded()
-	{
-		AttachEvent(L"dw_list", L"DWV_ROWFOCUSCHANGED", (FEvent)&listSupplierv3::OnRowChangedEx);
 
-		listwin::onloaded();
-		xstring EntityID;
-		int row = dw_list.GetRow();
-		if (row<0 || row>dw_list.GetRowCount()) return 1;
-		KXMLDOMElement ele = dw_list.GetRowElement(row);
-		xstring id = listwin::m_configDoc.selectSingleNode(L"//entity/EntityID[1]").text();
-		if (ele.selectSingleNode(id))
-			EntityID = ele.selectSingleNode(id).text();
-		listwin::SetAgent(L"list", EntityID);
-		return 1;
-	}
+			OnRetrieve();
+			OnAttachEvent();
 
-};
\ No newline at end of file
+			return 1;
+		}
+
+		int onloaded()
+		{
+			//SetAgent();			
+
+			return 1;
+		}
+	};

--
Gitblit v1.9.3