xj qian
2024-06-28 69ca48293b089073a494c36faafaee3f0c83e7a4
jrj/project/business/SO/Apply.SOItem.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,297 @@
#include <wobject/xstring.hpp>
#include <xcontrol/xtreeview.hpp>
#include <xcontrol/xdwgrid.hpp>
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
using xml = KXMLDOMDocument;
   class __declspec(dllexport) ApplySOItem : public xframe
   {
   public:
      ApplySOItem(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
   public:
      static ApplySOItem* CreateInstance(void* implPtr, void* hWnd)
      {
         ApplySOItem* pWin = new ApplySOItem(implPtr, (HWND)hWnd);
         return pWin;
      }
   public:
      xdwgrid   dw_list;
      xnode   m_agentNode;   //Agent Condition
      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 ProcessUsedArg(xaserverarg arg)
      {
         xstring EntityIDList = L"";
         int ll_row = dw_list.GetNextSelectRow(1);
         while (ll_row > 0 && ll_row <= dw_list.GetRowCount())
         {
            xstring id = dw_list.GetGuid(ll_row);
            if (EntityIDList == L"") EntityIDList = id; else EntityIDList += L",L" + id;
            ll_row = dw_list.GetNextSelectRow(ll_row + 1);
         }
         if (EntityIDList != L"") arg.AddArg(L"EntityID", EntityIDList);
         //alert(EntityIDList);
         return 1;
      }
      xstring GetEntityName(int pr)
      {
         return L"SaleItem3";
      }
      xstring GetEntityID(int pr)
      {
         int row = dw_list.GetRow();
         xstring id = dw_list.GetGuid(row);
         return id;
      }
      int ViewUpdate(int pr, xstring updateItem, xaserverarg  arg)
      {
         if (updateItem == L"del")
         {
            int DelRow = dw_list.GetRow();
            dw_list.DeleteRow(DelRow);
            return 1;
         }
         else if (updateItem == L"setstate")
         {
            int row = dw_list.GetRow();
            if (row < 1) return 1;
            if (arg.GetArgString(L"billstatus") != L"")
            {
               xstring billstatus = arg.GetArgString(L"billstatus");
               xstring statusName = GetBillStatusName(billstatus);
               dw_list.SetItemString(row, L"ChkState", billstatus);
               dw_list.SetItemDisplayString(row, L"ChkState", statusName);
            }
            dw_list.Redraw();
         }
         return 1;
      }
      //焦点激活处理函数
      int OnSetFocus(TEvent* evt, LPARAM p)
      {
         //重置工具条
         SetAgent();
         return 1;
      }
      /*
      int OnApply()
      {
         int row =  dw_list.GetNextSelectRow(1);
         if(row < 1) return 1;
         while (row>0)
         {
            dw_list.SetItemString(row,L"ChkState",L"2");
            row =  dw_list.GetNextSelectRow(row + 1);
         }
         if(OnSave()==1)
         {
            xaserverarg arg = new xaserverarg;
            arg.setNativePointer(arg.CreateInstance());
            xml x = new xml;
            x.setNativePointer(x.CreateInstance());
            arg.AddArg(L"FlowID",L"1A83D53D-DD12-4FDB-A274-FA8D5982AB53");
            arg.AddArg(L"Category",L"PurchesItem3");
            arg.AddArg(L"Reciever",L"admin");
            arg.AddArg(L"Status",L"业务审核");
            xaserverarg parg = GetParam();
            xstring SONo = parg.GetArgString(L"SONo");
            row =  dw_list.GetNextSelectRow(1);
            while (row>0)
            {
               arg.AddArg(L"EntityID",dw_list.GetGuid(row));
               arg.AddArg(L"EntityNo",dw_list.GetItemString(row,L"GoodsNo"));
               arg.AddArg(L"Subject",L"请核准订单"+SONo+L"采购数据,货号为"+dw_list.GetItemString(row,L"GoodsNo"));
               if(url::get(L"/sale/data/PurchaseOrder/task/add", arg.GetString(),x)!=1)
               {
                  xstring error = x.GetXmlDoc().text;
                  alert(error);
                  return -1;
               }else
               {
                  trace(x.GetXml());
               }
               row =  dw_list.GetNextSelectRow(row + 1);
            }
            alert(L"提交成功");
         }
         return 1;
      }
      */
      int OnAskGoodsNo()
      {
         int rowCount = dw_list.GetRowCount();
         xstring skunos = L"";
         xstring GoodsNo1 = dw_list.GetItemString(dw_list.GetRow(), L"GoodsNo");
         xstring GoodsNo2 = GoodsNo1.mid(0, 1);
         xstring GoodsNo3 = GoodsNo1.mid(1, 1);
         xstring GoodsNo4 = GoodsNo1.mid(2, 1);
         for (int i = 1; i <= rowCount; i++)
         {
            if (dw_list.GetItemString(i, L"SKUNo") != L"" && dw_list.GetItemString(i, L"GoodsNo") == L"" || GoodsNo1.find(L"N") >= 0
               || GoodsNo1.find(L"n") >= 0 || GoodsNo4.isNumber() == false && GoodsNo2.isNumber() == true && GoodsNo3.isNumber() == true)
            {
               if (skunos == L"")
                  skunos = dw_list.GetItemString(i, L"SKUNo");
               else
                  skunos += L",L" + dw_list.GetItemString(i, L"SKUNo");
            }
         }
         xaserverarg arg ;
         arg.AddArg(L"SKUNoList", skunos);
         OpenWindow(L"dev:xpage[Product.FetchNo.vx]", arg);
         return 1;
      }
      //命令发布函数
      int OnCmdDispatch(xstring comdid)
      {
         if (comdid == L"xmCancel")
         {
            CloseWindow();
            return 1;
         }
         else if (comdid == L"xmAskGoodsNo")
         {
            OnAskGoodsNo();
         }
         //else if(comdid==L"xmApply") return OnApply();
         else if (comdid.find(L"action:", 0) >= 0)
         {
            xstring GoodsNo = dw_list.GetItemString(dw_list.GetRow(), L"GoodsNo");
            xstring GoodsNo2 = GoodsNo.mid(0, 2);
            xstring GoodsNo4 = GoodsNo.mid(2, 1);
            if (GoodsNo == L"")
            {
               alert(L"公司货号未指定");
               return 0;
            }
            if (GoodsNo.find(L"N") >= 0 || GoodsNo.find(L"n") >= 0) {
               alert(L"公司货号带有N");
               return 0;
            }
            if (GoodsNo4 >= L"A" && GoodsNo4 <= L"z" && GoodsNo2 >= L"22" && GoodsNo2 <= L"99")
            {
               alert(L"公司货号为新品货号");
               return 0;
            }
            xstring CType = dw_list.GetItemString(dw_list.GetRow(), L"CType");
            if (CType == L"")
            {
               alert(L"客户合同附件未上传!");
               return 0;
            }
            int ret = ProcessFlowAction(comdid, 1);
            return ret;
         }
         return 0;
      }
      //命令处理事件
      int OnXCommand(TEvent* evt, LPARAM p)
      {
         return OnCmdDispatch(evt->xcommand.pStrID);
      }
      int OnAttachEvent()
      {
         //绑定工具条点击事件
         AttachEvent(L"WM_XCOMMAND", (FEvent)&ApplySOItem::OnXCommand);
         //获取焦点事件,用于重置工具条
         //AttachEvent(L"WM_SETFOCUS",OnSetFocus);
         return 1;
      }
      int  OnRetrieve()
      {
         xml x;
         xaserverarg arg=GetArg();
         arg.AddArg(L"id", arg.GetArgString(L"EntityNo"));
         if (getUrl(L"/sale/data/SaleOrder/maint/item", arg.GetString(), x) != 1)
         {
            //trace(x.GetXmlDoc().text);
            return -1;
         }
         else
         {
            dw_list.Retrieve(x);
            dw_list.Redraw();
         }
         dw_list.SetReadOnly(true);
         dw_list.SetSelectionMode(3);
         return 1;
      }
      int onload()
      {
         dw_list = GetControl(L"dw_list");
         dw_list.openUrl(L"/sale/view/SaleOrder/template/item");
         dw_list.SetReadOnly(true);
         dw_list.SetColumnState(L"EnquiryPriceListID", false);
         dw_list.SetColumnState(L"ItemID", false);
         dw_list.SetColumnState(L"LineType", false);
         dw_list.SetColumnState(L"Assortment", false);
         dw_list.SetColumnState(L"ClassifyID", false);
         dw_list.SetColumnState(L"UnitFreight", false);
         dw_list.SetColumnState(L"CName", false);
         dw_list.SetColumnState(L"QuoteLineID", false);
         dw_list.SetColumnState(L"POSupplierID", false);
         dw_list.SetColumnState(L"Submitter", false);
         dw_list.SetColumnState(L"ScheduleShipDate", false);
         OnAttachEvent();
         SetArg();
         OnRetrieve();
         return 1;
      }
      int onloaded()
      {
         //SetAgent();
         return 1;
      }
   };