ÿþ#include <wobject/xstring.hpp> #include <xcontrol/xtreeview.hpp> #include <xcontrol/xdwgrid.hpp> #include <wobject/xdouble.hpp> #include <xcontrol/xlayersheet.hpp> #include <xcontrol/xdatetimepick.hpp> #include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" #include "viewobject/view.base.hpp" using xml = KXMLDOMDocument; class __declspec(dllexport) APExpenseMaintWin : public xframe { public: xdwgrid dw_item; xdwtable dw_base; xstring tabname; xstring APID; xstring payType; xnode m_agentNode; //Agent Condition public: APExpenseMaintWin(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {} public: static APExpenseMaintWin* CreateInstance(void* implPtr, void* hWnd) { APExpenseMaintWin* pWin = new APExpenseMaintWin(implPtr, (HWND)hWnd); return pWin; } int SetAgent() { xstring xfNodeAgentArea = L"agentarea"; xnode anode = GetAgentNode(xfNodeAgentArea); if(m_agentNode) { SetAgentNode (anode,m_agentNode); } else { KXMLDOMElement xframeElement = GetElement(); KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/"+xfNodeAgentArea+L"[1]/*"); if(agent) { xstring s = agent.xml(); m_agentNode = SetAgentNode (anode,s); } } return 1; } int SetAgentEx() { SetAgent(); SwitchLayer(L"agent_"+tabname,L"agentareaframe"); return 1; } //&q¹pÀo;mYtýQpe int OnSetFocus(TEvent* evt, LPARAM param) { //͑nå]wQag SetAgentEx(); return 1; } int OnSave() { xstring APNo = dw_base.GetItemString(1, L"APNo"); xml x1; if (APNo == L"") { x1 = ViewObject::RetrieveData(L"/sale/data/AP/MakeAPNoEx"); APNo = x1.text(); dw_base.SetItemString(1, L"APNo", APNo); } xml x ; xaserverarg arg ; dw_base.AcceptText(); dw_item.AcceptText(); dw_item.DwUpdateAllToEx(x); dw_base.DwUpdateAllTo(x); arg.AddArg(L"content",x.xml()); trace(x.xml()); //return 1; //if(xurl::get(L"/sale/data/AP/Expense/update", arg.GetString(),x)!=1) 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(); alert(L"ÝOX[bŸR!"); }else { dw_base.SetItemString(1, L"APNo", L""); alert(L"ÝOX[1Y%!"); } return 1; } int AddItems(xml x) { KXMLDOMNodeList items = x.selectNodes(L"data/Item"); int len = items.length(); int row = 0; xstring ShipAgentID=L""; xstring ShipAgentName=L""; xstring sdate = publiccode::GetCurrentDate(); xstring SupplierBank=L""; xstring SupplierBankNo=L""; for(int i=0;i<len;i++) { row = dw_item.InsertRow(0); KXMLDOMNode t = items.item(i); if(t.selectSingleNode(L"ShipAgentID")) ShipAgentID = t.selectSingleNode(L"ShipAgentID").text(); if(t.selectSingleNode(L"ShipAgentID/@_displaystring")) ShipAgentName = t.selectSingleNode(L"ShipAgentID/@_displaystring").text(); if(t.selectSingleNode(L"SupplierBank")) SupplierBank = t.selectSingleNode(L"SupplierBank").text(); if(t.selectSingleNode(L"SupplierBankNo")) SupplierBankNo = t.selectSingleNode(L"SupplierBankNo").text(); if(t.selectSingleNode(L"Amount"))dw_item.SetItemString(row,L"RequestAmount",t.selectSingleNode(L"Amount").text()); if(t.selectSingleNode(L"Amount"))dw_item.SetItemString(row,L"Amount",t.selectSingleNode(L"Amount").text()); dw_item.SetItemString(row,L"CurrencyCode",L"RMB"); dw_item.SetItemString(row,L"ExchRate",L"1"); if (t.selectSingleNode(L"Emp"))dw_item.SetItemDisplayString(row, L"SalespersonID", t.selectSingleNode(L"Emp").text()); if (t.selectSingleNode(L"SalespersonID"))dw_item.SetItemString(row, L"SalespersonID", t.selectSingleNode(L"SalespersonID").text()); if(t.selectSingleNode(L"Dept"))dw_item.SetItemString(row,L"OrgName",t.selectSingleNode(L"Dept").text()); if(t.selectSingleNode(L"InvoiceNo"))dw_item.SetItemString(row,L"InvoiceNo",t.selectSingleNode(L"InvoiceNo").text()); if (t.selectSingleNode(L"FreightExpenseID"))dw_item.SetItemString(row, L"PreAPID", t.selectSingleNode(L"FreightExpenseID").text()); dw_item.SetItemString(row,L"APType",L"003"); dw_item.SetItemDisplayString(row,L"APType",L"ЏBg9"); xstring month = sdate.left(7); if(row >1)month = dw_item.GetItemString(row - 1,L"ExpMonth"); dw_item.SetItemString(row,L"ExpMonth",month); } if(dw_base.GetItemString(1,L"SalespersonID")==L"") { xstring suserid = publiccode::GetUser().id; xstring susername = publiccode::GetUser().name; dw_base.SetItemString(1,L"SalespersonID",suserid); dw_base.SetItemDisplayString(1,L"SalespersonID",susername); } double amt = 0.0; double amtttl = 0.0; for(int k=1; k<=dw_item.GetRowCount();k++) { amt = dw_item.GetItemDouble(k,L"Amount"); amtttl += amt; } dw_base.ItemChangeTo(1,L"Amount",xstring(amtttl)); if(dw_base.GetItemString(1,L"SupplierID")==L"") { dw_base.SetItemDisplayString(1,L"SupplierID",ShipAgentName); dw_base.ItemChangeTo(1,L"SupplierID",ShipAgentID); } if(dw_base.GetItemString(1,L"APDate")==L"") { dw_base.SetItemString(1,L"APDate",sdate); } if(dw_base.GetItemString(1,L"SupplierBank")==L"") { dw_base.SetItemString(1,L"SupplierBank",SupplierBank); dw_base.SetItemString(1,L"SupplierBankNo",SupplierBankNo); } if(dw_base.GetItemString(1,L"APType")==L"") { dw_base.SetItemString(1,L"APType",L"003"); dw_base.SetItemDisplayString(1,L"APType",L"ЏBg9"); } 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"; if(value != L"") { KXMLDOMNodeList nlist = GetElement().selectNodes(L"//*[@name='"+dwname+L"']/trans[@for='"+colname+L"']"); ViewObject::TransData(nlist, dw_base, hdr.row, colname, value); } 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")); } return 1; } int TEAddItem(xml x) { KXMLDOMNodeList items = x.selectNodes(L"data/Item"); int len = items.length(); int row = 0; xstring ShipAgentID = L""; xstring ShipAgentName = L""; xstring sdate = publiccode::GetCurrentDate(); xstring SupplierBank = L""; xstring SupplierBankNo = L""; xstring OrgName = L""; for (int i = 0; i < len; i++) { row = dw_item.InsertRow(0); KXMLDOMNode t = items.item(i); if (t.selectSingleNode(L"TestPartyID")) ShipAgentID = t.selectSingleNode(L"TestPartyID").text(); if (t.selectSingleNode(L"TestPartyID/@_displaystring")) ShipAgentName = t.selectSingleNode(L"TestPartyID/@_displaystring").text(); if (t.selectSingleNode(L"SupplierBank")) SupplierBank = t.selectSingleNode(L"SupplierBank").text(); if (t.selectSingleNode(L"SupplierBankNo")) SupplierBankNo = t.selectSingleNode(L"SupplierBankNo").text(); if (t.selectSingleNode(L"OrgName")) OrgName = t.selectSingleNode(L"OrgName").text(); if (t.selectSingleNode(L"TestAmount"))dw_item.SetItemString(row, L"RequestAmount", t.selectSingleNode(L"TestAmount").text()); if (t.selectSingleNode(L"TestAmount"))dw_item.SetItemString(row, L"Amount", t.selectSingleNode(L"TestAmount").text()); dw_item.SetItemString(row, L"CurrencyCode", L"RMB"); dw_item.SetItemString(row, L"ExchRate", L"1"); if (t.selectSingleNode(L"SalesPersonID/@_displaystring"))dw_item.SetItemDisplayString(row, L"SalespersonID", t.selectSingleNode(L"SalesPersonID/@_displaystring").text()); if (t.selectSingleNode(L"SalesPersonID"))dw_item.SetItemString(row, L"SalespersonID", t.selectSingleNode(L"SalesPersonID").text()); if (t.selectSingleNode(L"OrgName"))dw_item.SetItemString(row, L"OrgName", t.selectSingleNode(L"OrgName").text()); if (t.selectSingleNode(L"InvoiceNo"))dw_item.SetItemString(row, L"InvoiceNo", t.selectSingleNode(L"InvoiceNo").text()); if (t.selectSingleNode(L"TestExpensID"))dw_item.SetItemString(row, L"PreAPID", t.selectSingleNode(L"TestExpensID").text()); dw_item.SetItemString(row, L"APType", L"021"); dw_item.SetItemDisplayString(row, L"APType", L"KmՋ9"); xstring month = sdate.left(7); if (row > 1)month = dw_item.GetItemString(row - 1, L"ExpMonth"); dw_item.SetItemString(row, L"ExpMonth", month); } if (dw_base.GetItemString(1, L"SalespersonID") == L"") { xstring suserid = publiccode::GetUser().id; xstring susername = publiccode::GetUser().name; dw_base.SetItemString(1, L"SalespersonID", suserid); dw_base.SetItemDisplayString(1, L"SalespersonID", susername); } double amt = 0.0; double amtttl = 0.0; for (int k = 1; k <= dw_item.GetRowCount(); k++) { amt = dw_item.GetItemDouble(k, L"Amount"); amtttl += amt; } dw_base.ItemChangeTo(1, L"Amount", xstring(amtttl)); if (dw_base.GetItemString(1, L"SupplierID") == L"") { dw_base.SetItemDisplayString(1, L"SupplierID", ShipAgentName); dw_base.ItemChangeTo(1, L"SupplierID", ShipAgentID); } if (dw_base.GetItemString(1, L"APDate") == L"") { dw_base.SetItemString(1, L"APDate", sdate); } if (dw_base.GetItemString(1, L"OrgName") == L"") { dw_base.SetItemString(1, L"OrgName", OrgName); } if (dw_base.GetItemString(1, L"SupplierBank") == L"") { dw_base.SetItemString(1, L"SupplierBank", SupplierBank); dw_base.SetItemString(1, L"SupplierBankNo", SupplierBankNo); } if (dw_base.GetItemString(1, L"APType") == L"") { dw_base.SetItemString(1, L"APType", L"021"); dw_base.SetItemDisplayString(1, L"APType", L"KmՋ9"); } return 1; } int OnImport() { xaserverarg arg; if (payType == L"ЏBg9") OpenWindow(L"dev:xpage[FreightExpenseImport.vx]", arg); if (payType == L"KmՋ9") OpenWindow(L"dev:xpage[TestExpenseImport.vx]", arg); //alert(arg.GetArgString(L"items")); xstring str = arg.GetArgString(L"items"); //alert(str); if(str !=L"") { xml x ; x.loadXML(str); if (payType == L"ЏBg9")AddItems(x); if (payType == L"KmՋ9")TEAddItem(x); } return 1; } //}TäNÑS^ýQpe int OnCmdDispatch(xstring comdid) { if(comdid==L"tab_base") { tabname = L"base"; SetAgentEx(); return 1; } else if(comdid==L"tab_item") { tabname = L"item"; SetAgentEx(); return 1; } else if(comdid==L"xmClose") { CloseWindow(); return 1; } else if(comdid==L"xmSaveEx") { return OnSave(); } else if (comdid == L"xmDeleteItem") { dw_item.DeleteRow(dw_item.GetRow()); double amt = 0.0; double amtttl = 0.0; for (int k = 1; k <= dw_item.GetRowCount(); k++) { amt = dw_item.GetItemDouble(k, L"Amount"); amtttl += amt; } dw_base.ItemChangeTo(1, L"Amount", xstring(amtttl)); return 1; } else if(comdid==L"xmImport") return OnImport(); return 0; } //}TäNYt‹NöN int OnXCommand(TEvent* evt, LPARAM param) { return OnCmdDispatch(evt->xcommand.pStrID); } int OnAttachEvent() { //Ñ~š[å]wQag¹pûQ‹NöN AttachEvent(L"WM_XCOMMAND", (FEvent)&APExpenseMaintWin::OnXCommand); //·ƒÖS&q¹p‹NöN ÿ(uŽN͑nå]wQag AttachEvent(L"WM_SETFOCUS", (FEvent)&APExpenseMaintWin::OnSetFocus); AttachEvent(L"dw_base",L"DWV_ITEMCHANGED", (FEvent)&APExpenseMaintWin::OnItemChanged); return 1; } int OnRetrieve() { xml x ; xaserverarg arg ; arg.AddArg(L"EntityID",APID); if (getUrl(L"/sale/data/AP/expense",arg.GetString(),x)!=1) { trace(x.text()); return -1; }else { dw_base.Retrieve(x); dw_item.Retrieve(x); dw_base.Redraw(); } return 1; } int onload() { SetArg(); 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); dw_item = GetControl(L"dw_item"); dw_item.openUrl(L"/sale/view/AP/template/AP/item"); dw_item.SetColumnState(L"PreAPID", false); tabname =L"base"; OnAttachEvent(); APID = L""; payType = L"ЏBg9"; if (GetWinParam()) { xaserverarg arg = GetArg(); APID = arg.GetArgString(L"APID"); payType = arg.GetArgString(L"payType"); } if(APID !=L"") { OnRetrieve(); }else { 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"ApprovalStatus",L"6"); } return 1; } int onloaded() { SetAgent(); return 1; } };