LiFan
2025-04-29 6c8c9ddaeb2bc6245a374c9354296bcfc2d96c06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
ÿþ#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 <xcontrol/ximageview.hpp>
 
#include "vbusiness/vframe/listwin.vframe.vbusiness.hpp"
#include "viewobject/view.base.hpp"
 
 
using xml = KXMLDOMDocument; 
    class __declspec(dllexport) ItemCustomerPictureView :  public xframe
    {
    public:
        ItemCustomerPictureView(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {}
    public:
        static ItemCustomerPictureView* CreateInstance(void* implPtr, void* hWnd)
        {
            return  new ItemCustomerPictureView(implPtr, (HWND)hWnd);
        }
    public:
        xdwgrid    dw_list;
        xdwtable dw_arg;
        xnode    m_agentNode;    //Agent Condition
        KXMLDOMElement imageElement;
    
        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;
        }
 
        //&q¹pÀo;mYtýQpe
        int OnSetFocus(TEvent* evt, LPARAM param)
        {
            //͑nå]wQag
            SetAgent();
            return 1;
        }
 
 
        //}TäNÑS^ýQpe
        int OnCmdDispatch(xstring comdid)
        {
            if(comdid==L"xmAddImage")
            {
                return OnAddImage();
            }
            else if(comdid==L"xmDeleteImage")
            {
                return OnDeleteImage();
            }
            else if(comdid==L"xmQuery")
            {
                return OnRetrieve();
            }
            return 0;
        }
        
        //}TäNYt‹NöN
        int OnXCommand(TEvent* evt, LPARAM param)
        {
            return OnCmdDispatch(evt->xcommand.pStrID);
        }
        
        int OnImgDBClicked(TEvent* evt, int p)
        {
            IMGNNMHDR& nmtv = *(IMGNNMHDR*)evt->notify.pnmh;
            xstring src = nmtv.path;    
            xaserverarg arg ;
            
            arg.AddArg(L"src",src);    
            
            int h = openUrl(L"/sale/view/ProductLibrary/xpage/bigpictureview", arg);    
            return 1;
        }    
        
        int OnAttachEvent()
        {
            //Ñ~š[å]wQag¹pûQ‹NöN
            AttachEvent(L"WM_XCOMMAND", (FEvent)&ItemCustomerPictureView::OnXCommand);
            //·ƒÖS&q¹p‹NöN ÿ(uŽN͑nå]wQag
            AttachEvent(L"WM_SETFOCUS", (FEvent)&ItemCustomerPictureView::OnSetFocus);
            AttachEvent(L"dw_list",L"DWV_ROWFOCUSCHANGED", (FEvent)&ItemCustomerPictureView::OnRowChanged);
            AttachEvent(L"im1",L"IMG_LDBCLICK", (FEvent)&ItemCustomerPictureView::OnImgDBClicked);
            return 1;
 
        }
        
        xstring Up(xstring name)
        {
            xstring str = name.mid(0,2);
            str = str.toUpper();
            return xaserver::UploadFile(L"product"+str, name+L".jpg", GetHWND(),L"",false);        
        }
        
        int OnAddImage(){
            int row =  dw_list.GetNextSelectRow(1);
            if(row < 1) row = dw_list.GetRow();
            if(row < 1 || row > dw_list.GetRowCount()) return 0;
            
            xstring skuid = dw_list.GetItemString(row,L"SKUID");
            //xstring SKUNo = dw_list.GetItemDisplayString(row,L"SKUID");
            xstring SKUNo = dw_list.GetItemString(row,L"No");
            //alert(SKUNo);
            xstring CustomerID = dw_list.GetItemString(row,L"CustomerID");
            xstring CustomerItemNo = dw_list.GetItemString(row,L"CustomerItemNo");
            xstring id = ViewObject::GetGuid();
            xstring ret1 = Up(id);
            if(ret1  == L"-1") return -1;
            if(ret1  == L"0")
            {
                alert(L"
N OþVGr1Y%");
                return -1;
            }
            xstring originfile = ret1; 
            xstring ext = originfile.right(7);
            if(ext.find(L".")>=0)
                ext = ext.mid(ext.find(L".")+1,9999);
            else
                ext = L"jpg";
 
            // þVGr T ReQpenc“^
            xml x ;
            
            x.loadXML(L"<Item update.new='1' update.modify='1' guid='" + id + L"'>" +
                L"<ProductPictureID>" + id + L"</ProductPictureID>" +
                L"<OriginFile>" + originfile + L"</OriginFile>" +
                L"<FileExt>" + ext + L"</FileExt>" +
                L"<SKUID>" + skuid + L"</SKUID>" +
                L"<CustomerItemNo>" + CustomerItemNo + L"</CustomerItemNo>" +
                L"<CustomerID>" + CustomerID + L"</CustomerID>" +
                L"<Name>[" + SKUNo.trim() + L"]</Name>" +
                L"<FileName>" + id + L".jpg</FileName>" +
                L"</Item>"
            );
            
            xaserverarg arg ;
            
            arg.AddArg(L"content",x.xml());
            //alert(x.xml());
            if(xurl::get(L"/sale/data/ProductLibrary/image/update", arg.GetString(),x)!=1)
            {
                alert(x.text());
                return -1;
            }
            dw_list.SetItemString(row,L"pic",L"*");
            dw_list.Redraw();
            //7R°eN NLub— ÿ>f:yþVGr
            OnShowImageEx(dw_list.GetItemString(dw_list.GetRow(),L"GDNLineID"));
            return 1;
        }
        
        int OnDeleteImage()
        {
            int row =  dw_list.GetNextSelectRow(1);
            if(row < 1) row = dw_list.GetRow();
            if(row < 1 || row > dw_list.GetRowCount()) return 0;
            
            ximageview im = GetControl(L"im1");
            int index = im.GetSelectIndex();
            int count = im.GetImageCount();
            
            if(count < 1) return 1;
            
            KXMLDOMNodeList images = imageElement.selectNodes(L"image");
            int length = images.length();
            if(length < index) return 1;
            
            int MB_OKCANCEL = 0x00000001;
            int IDOK = 1;
            if(MessageBox(GetHWND(),L"nx¤‹ Rd–S_MRþVGr?",L"Ðc:y", MB_OKCANCEL)!=IDOK) return 1;
            
            xstring id = images.item(index).selectSingleNode(L"@guid").text();
            
            xml x ;
            
            xaserverarg arg ;
            
            xstring str = L"<Item update.modify='1' update.delete='1' guid='"+id+L"'/>";
            arg.AddArg(L"content",str);
            if(xurl::get(L"/sale/data/ProductLibrary/image/update", arg.GetString(),x)!=1)
            {
                alert(x.text());
                return -1;
            }
            if(count==1) 
            {
                dw_list.SetItemString(row,L"pic",L"");
                dw_list.Redraw();
            }
            
            xstring skuid = dw_list.GetItemString(row,L"SKUID");
            xstring SKUNo = dw_list.GetItemDisplayString(row,L"SKUID");
            xstring CustomerItemNo = dw_list.GetItemString(row,L"CustomerItemNo");
            OnShowImageEx(dw_list.GetItemString(dw_list.GetRow(),L"GDNLineID"));
 
            return 1;
        }
        
        int OnShowImageEx(xstring GDNLineID)
        {
            ximageview im = GetControl(L"im1");
            im.Reset();
            
            int i=0;
            KXMLDOMElement xitem ;
            xstring picname; 
            xstring goodno; 
            
            xml x;
            xaserverarg arg;
            arg.AddArg(L"GDNLineID",GDNLineID);
            KXMLDOMNodeList  nlist = 0;
            /*arg.AddArg(L"ShipImage",L"0");
            xaserver::ExecXQuery(GetServerUrl(),L"[GNDItem.PictureList.xq]",arg.GetString(),x);
            nlist = x.selectNodes(L"ImageList/image");
            for(i=0;i<nlist.length();i++)
            {
                xitem = nlist.item(i);
                picname = xitem.selectSingleNode(L"PicPath").text(); 
                im.AddImages(picname, L"7hÁTþVGr");
            }*/
            arg.AddArg(L"ShipImage",L"1");
            xaserver::ExecXQuery(GetServerUrl(),L"[GNDItem.PictureList.xq]",arg.GetString(),x);
            imageElement = x.documentElement();
            nlist = x.selectNodes(L"ImageList/image");
            for(i=0;i<nlist.length();i++)
            {
                xitem = nlist.item(i);
                picname = xitem.selectSingleNode(L"PicPath").text(); 
                im.AddImages(picname, L"[úQ'þVGr]");
            }
            im.Redraw();
            return 1;
        }
        
        int OnShowImage(xstring skuid, xstring customerItemNo)
        {
            ximageview im = GetControl(L"im1");
            im.Reset();
            
            xml xp;
            
            xaserverarg arg_pic;
                
            
            arg_pic.AddArg(L"SKUID",skuid);
            arg_pic.AddArg(L"CustomerID",dw_list.GetItemString(dw_list.GetRow(),L"CustomerID"));
            arg_pic.AddArg(L"CustomerItemNo",customerItemNo);
            
            alert(arg_pic.GetString());
            
            if(xurl::get(L"/sale/data/ProductLibrary3/pref/picture/customer/imagelistSKU",arg_pic.GetString(),xp)!=1)
            {
                trace(L"error:" + (xstring)xp.xml());
            }else
            {
                imageElement = xp.documentElement();
                KXMLDOMNodeList  nlistp=  xp.selectNodes(L"ImageList/image");
                int lenp = nlistp.length();
                for(int ip=0;ip<lenp;ip++)
                {
                    KXMLDOMElement xitem = nlistp.item(ip);
                    xstring picname = xitem.selectSingleNode(L"PicPath").text(); 
                    xstring goodno = xitem.selectSingleNode(L"GoodsNo").text();     
                    if(picname == L"/business/products/Thumbs//")
                        picname = L"/business/products/Thumbs/00/00000000-0000-0000-0000-000000000000.jpg";
                    im.AddImages(picname, L"");
                }
                im.Redraw();
            }
            return 1;
        }
 
        int ShowRowImage(int row)
        {
            xstring id = dw_list.GetItemString(row,L"SKUID");
            xstring CustomerItemNo = dw_list.GetItemString(row,L"CustomerItemNo");
            OnShowImageEx(dw_list.GetItemString(row,L"GDNLineID"));
            return 1;
        }
                    
        int OnRowChanged(TEvent* evt, int p)
        {
            DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh;
            int row = hdr.row;
                    
            return ShowRowImage(row);
        }
        
        int  OnRetrieve()
        {
            xml x ;
            
            xaserverarg arg ;
                
            
            dw_arg.AcceptText();
            dw_arg.DwUpdateAllTo(x);
            arg.AddArg(L"query",x.xml());
            trace(x.xml());
            if (getUrl(L"/sale/data/ProductLibrary3/customeritem/list",arg.GetString(),x)!=1)
            {
                trace(x.text());
                return -1;
            }else    
            {
                dw_list.Retrieve(x);
                dw_list.Redraw();
            }
            if(dw_list.GetRowCount() > 0) 
                OnShowImageEx(dw_list.GetItemString(1,L"GDNLineID"));
            return 1;
        }
        
        int onload()
        {
            dw_list = GetControl(L"dw_list");
            dw_list.SetDataObject(GetServerUrl(),L"dev:sheet[ProductLibrary.tpl/GoodsCustomerList]");
            dw_arg= GetControl(L"dw_arg");
            dw_arg.openUrl(L"/sale/view/ProductLibrary/template/ItemCustomerArg");
            dw_arg.SetColHeaderHeight(0);
            dw_arg.SetRowSelectorWidth(0);
            dw_arg.SetHScrollState(false);
            dw_arg.SetVScrollState(false);
            
            dw_list.SetColumnState(L"UnitPrice",false);
            dw_list.SetColumnState(L"CurrencyCode",false);
            //dw_list.SetColumnState(L"CustomerID",false);
            dw_list.SetColumnState(L"SKUID",false);
            dw_list.SetColumnState(L"GDNLineID",false);
            
            //imageElement = 0;
            
            OnAttachEvent();    
            
            return 1;
        }
        
        int onloaded()
        {
            SetAgent();
            OnRetrieve();
            
            return 1;
        }        
    };