xj qian
2024-07-16 7a91c3a1ed37b0332d4ff0ebeae60bd6da3665c0
jrj/project/business/BasicCode/ColorCardNew.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,416 @@
#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) ColorCardNew : public listwin
{
public:
   xdwgrid   dw_list;
   xdwgrid   dw_detail;
   bool    ismodify;
   xnode   m_agentNode;
   xstring   m_agentCond;
public:
   ColorCardNew(void* implPtr, HWND hWnd) :listwin(implPtr, hWnd) {}
public:
   static ColorCardNew* CreateInstance(void* implPtr, void* hWnd)
   {
      ColorCardNew* pWin = new ColorCardNew(implPtr, (HWND)hWnd);
      return pWin;
   }
   int SetAgent()
   {
      xstring xfNodeAgentArea  = L"agentarea";
      xnode anode = GetAgentNode(xfNodeAgentArea);
      KXMLDOMElement xframeElement =  GetElement();
      KXMLDOMNode agent = xframeElement.selectSingleNode(L"agent/"+xfNodeAgentArea+L"[1]/*");
      if(agent)
         SetAgentNode(anode, agent.xml());
      return 1;
   }
   //焦点激活处理函数
   int OnSetFocus(TEvent* evt, LPARAM param)
   {
      SetAgent();
      //重置工具条
      return 1;
   }
   int ProcessFlowAction(xstring guid,xstring comdid)
   {
      //int pr = pr1;
      //xstring action = comdid;//.mid(comdid.find(L"action:",0)+7,9999);
      /*if(action == L"bill.delete" || action == L"bill.deleteEx")
      {
         if (MessageBox(GetHWND(),L"是否确定删除记录!",L"提示1",1) == 2)
            return 1;
      }*/
      xaserverarg arg0 ;
      arg0.setNativePointer(arg0.CreateInstance());
      //arg0.AddArg(L"Action", action,L"xs:xstring");
      arg0.AddArg(L"EntityName", L"ColorCard",L"xs:xstring");
      arg0.AddArg(L"EntityIDName", L"ColorCardID",L"xs:xstring");
      arg0.AddArg(L"EntityID", guid,L"xs:xstring");
      arg0.AddArg(L"FunctionCode", comdid,L"xs:xstring");
      xml x = new xml;
      if(xurl::get(L"/sale/data/Role.config/sys/sql/action", arg0.GetString(), x) != 1)
      {
         //ismodify=false;
         //dw_list.SetReadOnly(ismodify);
         return -1;
      }
      xstring kk=x.xml();
      if(kk.find(L"<root/>",0)>=0)
      {
         //ismodify=true;
         //dw_list.SetReadOnly(ismodify);
         return 1;
      }
      return -1;
   }
   int ModifyProcessAction(xstring guid,xstring comdid)
   {
      if(ProcessFlowAction(guid,comdid)>0)
      {
         ismodify=true;
         dw_list.SetReadOnly(ismodify);
         return -1;
      }
      else
      {
         ismodify=false;
         dw_list.SetReadOnly(ismodify);
         return -1;
      }
   }
   int DeleteProcessAction(xstring guid,xstring comdid)
   {
      if(ProcessFlowAction(guid,comdid)>0)
      {
         return -1; //没有权限
      }
      else
      {
         return 1; //有权限
      }
   }
   //根据ColorCardID加载Detail数据
   int  OnRetrieveDetail(xstring ColorCardID)
   {
      xml x;
      xaserverarg arg;
      arg.AddArg(L"ColorCardID",ColorCardID);
      if (xurl::get(L"ColorCard/entity/list1",arg.GetString(),x) != 1)
      {
         trace(x.text());
         return -1;
      }
      dw_detail.Retrieve(x);
      dw_detail.Redraw();
      dw_detail.SetReadOnly(ismodify);
      return 1;
   }
   int OnPreSave()
   {
      if (dw_list)
      {
         xstring colorCardCName;
         xstring colorCardName;
         xstring orgID;
         int i;
         int row = dw_list.GetRowCount();
         for (i=1; i<=row;i++)
         {
            colorCardCName=dw_list.GetItemString(i,L"ColorCardCName")+L"";
            colorCardName=dw_list.GetItemString(i,L"ColorCardName")+L"";
            orgID=dw_list.GetItemString(i,L"OrgID")+L"";
            if (colorCardCName==L"" || !colorCardCName)
            {
               alert(L"第"+xstring(i)+L"行色卡名称中文为空");
               return -1;
            }
            if (colorCardName==L"" || !colorCardName)
            {
               alert(L"第"+ xstring(i) +L"行色卡名称为空");
               return -1;
            }
            if (orgID==L"" || !orgID)
            {
               alert(L"第"+ xstring(i) +L"行关联组织为空");
               return -1;
            }
         }
      }
      return 1 ;
   }
   //保存
   int OnSave()
   {
      dw_list.AcceptText();
      dw_detail.AcceptText();
      int rec;
      rec = OnPreSave();
      if (rec == -1)
         return -1;
      xml x= new xml;
      dw_list.DwUpdateAllToEx(x);
      xaserverarg arg;
      KXMLDOMElement e=  x.selectSingleNode(L"root");
      arg.AddArg(L"content",e.xml());
      arg.AddArg(L"dbmap",L"ColorCard.dbmap");
      if (xurl::get(L"ColorCard/pref/colorcard.save",arg.GetString(),x) != 1)
      {
         trace(L"error:"+(xstring)x.xml());
         alert(L"保存失败!");
         return 0;
      }
      else
      {
         alert(L"保存成功!");
         dw_list.ResetUpdateStatus();
      }
      dw_list.Redraw();
   }
   //新增
   int OnAdd()
   {
      dw_list.AcceptText();
      int nrow=dw_list.InsertRow(0);
      dw_list.ShowRowTo(nrow);
      xstring tempguid = publiccode::GetGuid();
      dw_list.SetItemString(nrow,L"ColorCardID",tempguid);
      OnRetrieveDetail(tempguid);
      return 1;
   }
   //插入
   int OnInsert()
   {
      dw_list.AcceptText();
      int row = dw_list.GetRow();
      if(row<1) return 0;
      int nrow=dw_list.InsertRow(row);
      xstring tempguid = publiccode::GetGuid();
      dw_list.SetItemString(nrow,L"ColorCardID",tempguid);
      OnRetrieveDetail(tempguid);
   }
   //删除
   int OnDelete()
   {
      dw_list.AcceptText();
      int row = dw_list.GetRow();
      if(row<1) return 0;
      xstring id=dw_list.GetItemString(row,L"ColorCardID");
      if(DeleteProcessAction(id,L"DeleteColorCard")<0)
      {
         alert(L"您没有权限删除该数据");
         return -1;
      }
      if(id !=L"")
      {
         xml x;
         xaserverarg arg;
         arg.setNativePointer(arg.CreateInstance());
         arg.AddArg(L"ColorCardID", id);
         if(xurl::get(L"ColorCard/pref/beforedelete",arg.GetString(),x)!=1)
         {
            trace(L"error:"+(xstring)x.xml());
            alert(L"删除出错!");
            return 0;
         }
         KXMLDOMElement e= x.documentElement();
         if(e.selectSingleNode(L"error"))
         {
            alert(e.selectSingleNode(L"error").text());
            return 0;
         }
      }
      dw_list.DeleteRow(row);
   }
   int OnAddRowDetail()
   {
      dw_detail.AcceptText();
      int nrow=dw_detail.InsertRow(0);
      xstring tempguid = publiccode::GetGuid();
      dw_detail.SetItemString(dw_detail.GetRow(),L"ColorCardID",dw_list.GetItemString(dw_list.GetRow(),L"ColorCardID"));
      dw_detail.SetItemString(dw_detail.GetRow(),L"ColorID",tempguid);
      //OnRetrieveDetail(tempguid);
      dw_detail.ShowRowTo(nrow);
      return 1;
   }
   int OnInsertRowDetail()
   {
      dw_detail.AcceptText();
      int row = dw_detail.GetRow();
      if(row<1) return 0;
      int nrow=dw_detail.InsertRow(row);
      xstring tempguid = publiccode::GetGuid();
      dw_detail.SetItemString(dw_detail.GetRow(),L"ColorCardID",dw_list.GetItemString(dw_list.GetRow(),L"ColorCardID"));
      dw_detail.SetItemString(dw_detail.GetRow(),L"ColorID",tempguid);
      return 1;
   }
   int OnDelRowDetail()
   {
      int row = dw_detail.GetRow();
      int rowz = dw_list.GetRow();
      if(row<1)return 0;
      dw_detail.DeleteRow(row);
      KXMLDOMElement ez= dw_list.GetRowElement(rowz);
      xml xz;
      dw_detail.DwUpdateAllToEx(xz);
      if (ez.selectSingleNode(L"root"))
         ez.removeChild(ez.selectSingleNode(L"root"));
      ez.appendChild(xz.documentElement());
      return 1;
   }
   //命令发布函数
   int OnCmdDispatch(xstring comdid)
   {
      if(comdid==L"save") OnSave();
      else if(comdid==L"add") OnAdd();
      else if(comdid==L"insert") OnInsert();
      else if(comdid==L"del") OnDelete();
      else if(comdid==L"addrowDetail") OnAddRowDetail();
      else if(comdid==L"insertrowDetail") OnInsertRowDetail();
      else if(comdid==L"deleterowDetail") OnDelRowDetail();
      return 1;
   }
   //命令处理事件
   int OnXCommand(TEvent* evt, LPARAM param)
   {
      return OnCmdDispatch(evt->xcommand.pStrID);
   }
   //行改变事件
   int OnListRowChanged(TEvent* evt, int p)
   {
      dw_detail.AcceptText();
      DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
      int row = hdr.row;
      dw_list.Redraw();
      KXMLDOMElement e = dw_list.GetRowElement(row);
      xstring ColorCardID = e.selectSingleNode(L"ColorCardID").text();
      OnRetrieveDetail(ColorCardID);
      return 1;
   }
   int OnDetailChanged(TEvent* evt, int p)
   {
      int row = dw_list.GetRow();
      KXMLDOMElement e= dw_list.GetRowElement(row);
      xml x;
      dw_detail.DwUpdateAllToEx(x);
      if (e.selectSingleNode(L"root"))
         e.removeChild(e.selectSingleNode(L"root"));
      e.appendChild(x.documentElement());
      return 0;
   }
   int OnDwListClick(TEvent* evt, int p)
   {
      DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
      int row = hdr.row;
      dw_list.Redraw();
      KXMLDOMElement e = dw_list.GetRowElement(row);
      xstring ColorCardID = e.selectSingleNode(L"ColorCardID").text();
      ModifyProcessAction(ColorCardID,L"ModifyColorCard");
      return 1;
   }
   int OnAttachEvent()
   {
      //绑定工具条点击事件
      AttachEvent(L"WM_XCOMMAND", (FEvent)&ColorCardNew::OnXCommand);
      //获取焦点事件,用于重置工具条
      AttachEvent(L"WM_SETFOCUS", (FEvent)&ColorCardNew::OnSetFocus);
      //行改变事件
      AttachEvent(L"dw_list",L"DWV_ROWFOCUSCHANGED", (FEvent)&ColorCardNew::OnListRowChanged);
      AttachEvent(L"dw_detail",L"DWV_ITEMCHANGED", (FEvent)&ColorCardNew::OnDetailChanged);
      //AttachEvent(L"dw_list",L"DWV_ITEMCHANGED",OnDetailChanged);
      AttachEvent(L"dw_list",L"DWV_CLICKED", (FEvent)&ColorCardNew::OnDwListClick);
      return 1;
   }
   int  OnRetrieve(xstring str)
   {
      xml x;
      xaserverarg arg;
      arg.AddArg(L"id",str);
      if (xurl::get(L"ColorCard/entity/list",arg.GetString(),x) != 1)
      {
         trace(x.text());
         return -1;
      }
      //doc=x;
      dw_list.Retrieve(x);
      dw_list.Redraw();
      return 1;
   }
   int OnInitial()
   {
      SetAgent();
      OnAttachEvent();
      return 1;
   }
   int onload()
   {
      dw_list = GetControl(L"dw_list");
      dw_list.openUrl(L"产品设置.vface/template/ColorCard/list");
      dw_detail = GetControl(L"dw_detail");
      dw_detail.openUrl(L"产品设置.vface/template/ColorCard/listex");
      OnInitial();
      OnRetrieve(L"FND_ColorCard");
      return 1;
   }
};