#include <wobject/xstring.hpp> 
 | 
#include <xcontrol/xtreeview.hpp> 
 | 
#include <xcontrol/xdwgrid.hpp> 
 | 
#include <wobject/xdouble.hpp> 
 | 
#include <xcontrol/xlayersheet.hpp> 
 | 
#include <xcontrol/xcell.hpp> 
 | 
  
 | 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" 
 | 
#include "vbusiness/vframe/maint.vframe.vbusiness.hpp" 
 | 
#include "viewobject/view.base.hpp" 
 | 
  
 | 
using xml = KXMLDOMDocument; 
 | 
class __declspec(dllexport) TestingCompanyMaint : public maint 
 | 
{ 
 | 
public: 
 | 
    KXMLDOMDocument m_configDoc; 
 | 
    xstring m_userid; 
 | 
    xstring m_username; 
 | 
    xstring ContactID; 
 | 
    xdwtable dw_base; 
 | 
    xcell dw_cell; 
 | 
    xstring m_EntityID = L""; 
 | 
public: 
 | 
    TestingCompanyMaint(void* implPtr, HWND hWnd) :maint(implPtr, hWnd) {} 
 | 
public: 
 | 
    static TestingCompanyMaint* CreateInstance(void* implPtr, void* hWnd) 
 | 
    { 
 | 
        TestingCompanyMaint* pWin = new TestingCompanyMaint(implPtr, (HWND)hWnd); 
 | 
        return pWin; 
 | 
    } 
 | 
  
 | 
    int setCellReadOnly() 
 | 
    { 
 | 
        dw_base = new xdwtable; 
 | 
        dw_base.setNativePointer(GetControl(L"dw_base")); 
 | 
        dw_cell = new xcell; 
 | 
        dw_cell.setNativePointer(dw_base.QueryItem(L"ixcell")); 
 | 
        xstring strnew = L"<cellprop celltype='' cellformatex='' cellformat='' cellprotectex='' cellprotect='±£»¤' cellvisibleex='' cellvisible='' cellvalid='' cellinitial=''/>"; 
 | 
        dw_cell.SetCellProps(2, 2, strnew); 
 | 
        return 0; 
 | 
    } 
 | 
    int OnSetFocus(TEvent* evt, LPARAM p) 
 | 
    { 
 | 
        SetAgent(L"maint"); 
 | 
        return 1; 
 | 
    } 
 | 
    xstring GetGuid() 
 | 
    { 
 | 
        return publiccode::GetGuid(); 
 | 
    } 
 | 
    int OnClear() { 
 | 
        //alert(m_EntityID); 
 | 
        if (m_EntityID == L"") { 
 | 
         
 | 
            m_userid = publiccode::GetUser().personid; 
 | 
            m_username = publiccode::GetUser().name; 
 | 
            /*dw_base = new xdwtable; 
 | 
            dw_base.setNativePointer(GetControl(L"dw_base"));*/ 
 | 
            dw_base = GetControl(L"dw_base"); 
 | 
            dw_base.SetItemString(1, L"PartyID", GetGuid()); 
 | 
            dw_base.SetItemString(1, L"PStatus", L"1"); 
 | 
            dw_base.SetItemDisplayString(1, L"PStatus", L"ÓÐЧ"); 
 | 
            dw_base.SetItemString(1, L"CreatorID", m_userid); 
 | 
            dw_base.SetItemString(1, L"PADStatus", L"1"); 
 | 
            dw_base.SetItemString(1, L"Type", L"20"); 
 | 
            dw_base.SetItemString(1, L"AddressID", GetGuid()); 
 | 
            dw_base.SetItemString(1, L"PADIdentifyAddressFlag", L"Y"); 
 | 
            dw_base.SetItemString(1, L"PrimaryFlag", L"Y"); 
 | 
            dw_base.SetItemString(1, L"EnterName", m_userid); 
 | 
            dw_base.SetItemDisplayString(1, L"EnterName", m_username); 
 | 
            dw_base.SetItemString(1, L"CreateDate", publiccode::GetCurrentDate()); 
 | 
             
 | 
            return 0; 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            setCellReadOnly(); 
 | 
        } 
 | 
        return 0; 
 | 
    } 
 | 
  
 | 
    int OnAddrow() 
 | 
    { 
 | 
        dw_base = new xdwtable; 
 | 
        dw_base.setNativePointer(GetControl(L"dw_base")); 
 | 
        xdwtable dw = new xdwtable; 
 | 
        dw.setNativePointer(dw_base.GetCurTable()); 
 | 
        xstring dw_n = dw.GetDwName(); 
 | 
        if (dw_n == L"item") 
 | 
        { 
 | 
            dw.InsertRow(0); 
 | 
            int rows = dw.GetRowCount(); 
 | 
            dw.SetRow(rows); 
 | 
        } 
 | 
        return 1; 
 | 
    } 
 | 
    int OnInsertRow() 
 | 
    { 
 | 
        dw_base = new xdwtable; 
 | 
        dw_base.setNativePointer(GetControl(L"dw_base")); 
 | 
        xdwtable dw = new xdwtable; 
 | 
        dw.setNativePointer(dw_base.GetCurTable()); 
 | 
        xstring dw_n = dw.GetDwName(); 
 | 
        if (dw_n == L"item") 
 | 
        { 
 | 
            int row = dw.GetRow(); 
 | 
            if (row < 1) return 0; 
 | 
            dw.InsertRow(row); 
 | 
            dw.SetRow(row); 
 | 
        } 
 | 
        return 1; 
 | 
    } 
 | 
  
 | 
    int OnDeleteRow() 
 | 
    { 
 | 
        dw_base = new xdwtable; 
 | 
        dw_base.setNativePointer(GetControl(L"dw_base")); 
 | 
        xdwtable dw = new xdwtable; 
 | 
        dw.setNativePointer(dw_base.GetCurTable()); 
 | 
        xstring dw_n = dw.GetDwName(); 
 | 
        if (dw_n == L"item") 
 | 
        { 
 | 
            int row = dw.GetRow(); 
 | 
            if (row < 1) return 0; 
 | 
            /*xstring del = dw.GetItemString(row,8); 
 | 
            if(del!=L"") 
 | 
            { 
 | 
                if(m_dels==L"") 
 | 
                { 
 | 
                    m_dels=del; 
 | 
                } 
 | 
                else 
 | 
                { 
 | 
                    xstring temp=m_dels; 
 | 
                    m_dels=del + L"|" + temp; 
 | 
                //+= L"|"+del; 
 | 
                } 
 | 
  
 | 
            }*/ 
 | 
            dw.DeleteRow(row); 
 | 
            dw.SetRow(row - 1); 
 | 
        } 
 | 
        return 1; 
 | 
    } 
 | 
    xstring getGoodsNo() 
 | 
    { 
 | 
        xml x; 
 | 
  
 | 
        xaserverarg arg; 
 | 
  
 | 
        if (getUrl(L"/sale/data/LogisticsCode/pref/shipcompany/PartyNo", arg.GetString(), x) != 1) 
 | 
        { 
 | 
            trace(x.xml()); 
 | 
            return L""; 
 | 
        } 
 | 
        KXMLDOMElement e = x.documentElement(); 
 | 
        if (e) 
 | 
        { 
 | 
            xstring code = e.text(); 
 | 
            trace(code); 
 | 
            return L"P" + code; 
 | 
        } 
 | 
        return L"P1000"; 
 | 
    } 
 | 
    int OnPreSave() 
 | 
    { 
 | 
        dw_base.AcceptText(); 
 | 
        dw_base = new xdwtable; 
 | 
        dw_base.setNativePointer(GetControl(L"dw_base")); 
 | 
        xstring ShipNo = dw_base.GetItemString(1, L"ShipNo"); 
 | 
        if (ShipNo == L"") 
 | 
        { 
 | 
            dw_base.SetItemString(1, L"ShipNo", getGoodsNo()); 
 | 
        } 
 | 
        xdwtable dwcon = new xdwtable; 
 | 
        dwcon.setNativePointer(dw_base.FindDwTable(L"item", 0)); 
 | 
        int i; 
 | 
        for (i = 1; i <= dwcon.GetRowCount(); i++) 
 | 
        { 
 | 
            xstring aTemp; 
 | 
            xstring aName = dwcon.GetItemString(i, L"ContacterName"); 
 | 
            trace(aName); 
 | 
            if (aName == L"" ) 
 | 
            { 
 | 
                aTemp = dwcon.GetItemString(i, L"Mobile") + dwcon.GetItemString(i, L"TEL") + dwcon.GetItemString(i, L"Fax") + dwcon.GetItemString(i, L"Email") + dwcon.GetItemString(i, L"PCRemark"); 
 | 
                //alert(aTemp); 
 | 
                if (aTemp == L"") 
 | 
                { 
 | 
                    alert(L"ÁªÏµÈËÃû³Æ±ØÌ"); 
 | 
                    return -1; 
 | 
                } 
 | 
            } 
 | 
            else { 
 | 
                xstring ContactID = dwcon.GetItemString(i, L"ContactID"); 
 | 
                if (ContactID == L"" ) 
 | 
                { 
 | 
                    dwcon.SetItemString(i, L"ContactID", GetGuid()); 
 | 
                    dwcon.SetItemString(i, L"PCStatus", L"1"); 
 | 
                    dw_base.SetItemString(1, L"PrimaryContactID", dwcon.GetItemString(1, L"ContactID")); 
 | 
                } 
 | 
  
 | 
  
 | 
  
 | 
            } 
 | 
        } 
 | 
        return 1; 
 | 
    } 
 | 
    int OnSave() 
 | 
    { 
 | 
  
 | 
        dw_base = new xdwtable; 
 | 
        dw_base.setNativePointer(GetControl(L"dw_base")); 
 | 
        xstring SName = dw_base.GetItemString(1, L"Name"); 
 | 
        if (SName == L"") { 
 | 
            alert(L"ÇëÊäÈë´¬¹«Ë¾Ãû³Æ£¡"); 
 | 
            return -1; 
 | 
        } 
 | 
        int rec = OnPreSave(); 
 | 
        if (rec == -1)    return -1; 
 | 
        xml x; 
 | 
  
 | 
        dw_base.DwUpdateAllTo(x); 
 | 
        trace(x.xml()); 
 | 
        xaserverarg arg; 
 | 
  
 | 
        arg.AddArg(L"content", x.xml()); 
 | 
        arg.AddArg(L"dbmap", L"Shipcompany.dbmap"); 
 | 
        //arg.AddArg(L"m_dels",m_dels);     
 | 
  
 | 
        if (getUrl(L"/sale/data/LogisticsCode/entity/shipcompany/save", arg.GetString(), x) != 1) 
 | 
        { 
 | 
            trace(L"error:" +(xstring)x.xml()); 
 | 
            alert(L"±£´æÊ§°Ü!"); 
 | 
            return 0; 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            trace(x.xml()); 
 | 
            if (x.selectSingleNode(L"error")) 
 | 
            { 
 | 
                alert(L"±£´æ³ö´í2!"); 
 | 
                return 0; 
 | 
            } 
 | 
            alert(L"±£´æ³É¹¦!"); 
 | 
            dw_base.ResetUpdateStatus(); 
 | 
            setCellReadOnly(); 
 | 
        } 
 | 
        dw_base.Redraw(); 
 | 
        //m_dels=L"";                 
 | 
        return 0; 
 | 
    } 
 | 
    int OnCmdDispatch(xstring comdid) 
 | 
    { 
 | 
        trace(comdid); 
 | 
        if (comdid.find(L"action:bill.row.add", 0) >= 0) { 
 | 
            OnAddrow(); 
 | 
        } 
 | 
        else if (comdid.find(L"bill.row.insert", 0) >= 0) { 
 | 
            OnInsertRow(); 
 | 
        } 
 | 
        else if (comdid.find(L"bill.row.delete", 0) >= 0) { 
 | 
            OnDeleteRow(); 
 | 
        } 
 | 
        else if (comdid.find(L"bill.save", 0) >= 0) { 
 | 
            //trace(1); 
 | 
            dw_base.AcceptText(); 
 | 
            OnSave(); 
 | 
        } 
 | 
        return 0; 
 | 
    } 
 | 
  
 | 
    int OnXCommand(TEvent* evt, LPARAM param) 
 | 
    { 
 | 
        return OnCmdDispatch(evt->xcommand.pStrID); 
 | 
    } 
 | 
    int OnCellChanged(TEvent* evt, LPARAM p) 
 | 
    { 
 | 
         
 | 
        dw_base = new xdwtable; 
 | 
        dw_base.setNativePointer(GetControl(L"dw_base")); 
 | 
        DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh; 
 | 
        xstring colname = hdr.colname; 
 | 
        //trace(colname); 
 | 
        if (colname == L"ShipNo") 
 | 
        { 
 | 
            xstring cspec = dw_base.GetItemString(1, 1); 
 | 
            trace(cspec); 
 | 
            xstring SpecRule = L"^\\d*$"; 
 | 
            xaserverarg args; 
 | 
  
 | 
            args.AddArg(L"CSpec", cspec); 
 | 
            args.AddArg(L"SpecRule", SpecRule); 
 | 
            xml  x; 
 | 
  
 | 
            getUrl(L"/sale/data/LogisticsCode/pref/forwarderno/check", args.GetString(), x); 
 | 
            if (x.selectSingleNode(L"root/spec")) 
 | 
            { 
 | 
                alert(L"ÇëÊäÈëÊý×Ö£¡"); 
 | 
                return 0; 
 | 
            } 
 | 
  
 | 
        } 
 | 
        return 1; 
 | 
    } 
 | 
    int OnAttachEvent() 
 | 
    { 
 | 
        AttachEvent(L"WM_XCOMMAND", (FEvent)&TestingCompanyMaint::OnXCommand); 
 | 
        AttachEvent(L"WM_SETFOCUS", (FEvent)&TestingCompanyMaint::OnSetFocus); 
 | 
        AttachEvent(L"dw_base", L"DWV_ITEMCHANGED", (FEvent)&TestingCompanyMaint::OnCellChanged); 
 | 
        return 1; 
 | 
    } 
 | 
  
 | 
    int onload() 
 | 
    { 
 | 
        SetArg(); 
 | 
        OnAttachEvent(); 
 | 
        //if(!m_configDoc) return -1; 
 | 
  
 | 
        maint::onload(); 
 | 
  
 | 
        OnClear(); 
 | 
        return 1; 
 | 
    } 
 | 
  
 | 
    int onloaded() 
 | 
    { 
 | 
        return maint::onloaded(); 
 | 
    } 
 | 
  
 | 
}; 
 |