#include #include #include #include #include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" #include "viewobject/view.base.hpp" using xml = KXMLDOMDocument; class __declspec(dllexport) APNewWarizd3 : public xframe { 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; public: APNewWarizd3(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {} public: static APNewWarizd3* CreateInstance(void* implPtr, void* hWnd) { APNewWarizd3* pWin = new APNewWarizd3(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 OnDoubleClicked(TEvent* evt, LPARAM p) { dw_1.AcceptText(); dw_2.AcceptText(); 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) { DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh; xstring colname = hdr.colname; xstring value = hdr.data; double Amount = dw_3.GetItemDouble(hdr.row, L"Amount"); double PayedAmount = dw_3.GetItemDouble(hdr.row, L"PayedAmount"); if (colname == L"PrePayAmount" || colname == L"Amount") { 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", xdouble(Amount - PrePayAmount).round(2)); } return 1; } //½¹µã¼¤»î´¦Àíº¯Êý int OnSetFocus(TEvent* evt, LPARAM param) { //ÖØÖù¤¾ßÌõ //SetAgent(); return 1; } int ProcessBase(xdwgrid dw_obj) { xstring SupplierID; for (int i = 1; i <= dw_obj.GetRowCount(); 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 = publiccode::GetCurrentDate(); 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""); 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++) { KXMLDOMNode n = nodes.item(i); x.documentElement().appendChild(n); } dw_5.Retrieve(x); dw_5.Redraw(); dw_5.SetReadOnly(true); } return 1; } int ResetDataForContinue() { dw_1.Reset(); dw_2.Reset(); dw_3.Reset(); dw_4.Reset(); dw_5.Reset(); dw_6.Reset(); return 1; } int OnSave(bool continueAdd) { dw_3.AcceptText(); dw_4.AcceptText(); 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; } else { 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 { if (start) { 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; } int OnRetrieve() { HCURSOR hCursor = xutil::SetCursorWait(); xml x ; xaserverarg arg; arg.AddArg(L"QueryTxt", GetControl(L"sle_search").GetText()); xcombobox cbx_type = GetControl(L"cbx_ship"); int h = xcombobox::GetCurSel(cbx_type.GetHWND()); if (h < 0) return 1; xstring str = xcombobox::GetItemData(cbx_type.GetHWND()); 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; } int OnFilter() { xstring str = GetControl(L"sle_filter").GetText(); if (str != searchStr) { searchStr = str; dw_1.Filter(L"*", searchStr); 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; } };