Subversion Repositories SmartDukaan

Rev

Rev 2119 | Rev 2138 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2119 Rev 2126
Line 72... Line 72...
72
        Button addButton = new Button("Add");
72
        Button addButton = new Button("Add");
73
        headerVendorM.setWidget(0, TABLE_INDEX_ITEM_KEY + 1, addButton);
73
        headerVendorM.setWidget(0, TABLE_INDEX_ITEM_KEY + 1, addButton);
74
        addButton.addClickHandler(new ClickHandler() {
74
        addButton.addClickHandler(new ClickHandler() {
75
            @Override
75
            @Override
76
            public void onClick(ClickEvent event) {
76
            public void onClick(ClickEvent event) {
77
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog();
77
                VendorMappingDialog vendorMappingDialog = new VendorMappingDialog(productGroup.getText().trim(), brand.getText().trim(), 
-
 
78
                        modelNumber.getText().trim(), color.getText().trim());
78
                vendorMappingDialog.updateButton.setText("Add");
79
                vendorMappingDialog.updateButton.setText("Add");
79
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
80
                vendorMappingDialog.setVendorMappingUpdateListener(new VendorMappingDialog.VendorMappingUpdateListener() {
80
                    @Override
81
                    @Override
81
                    public boolean onUpdate(String key, long vendorId) {
82
                    public boolean onUpdate(String key, long vendorId) {
82
                        final int row = vendorTableM.getRowCount();
83
                        final int row = vendorTableM.getRowCount();
Line 172... Line 173...
172
     * On add button click a new item instance is created and all the information from UI fields is dumped in this item instance.
173
     * On add button click a new item instance is created and all the information from UI fields is dumped in this item instance.
173
     * This item instance is then passed to service implementation.
174
     * This item instance is then passed to service implementation.
174
     */
175
     */
175
    void addItem(ClickEvent event) {
176
    void addItem(ClickEvent event) {
176
        //TODO: validate UI fields
177
        //TODO: validate UI fields
177
        
-
 
178
        catalogService.checkSimilarItem(productGroup.getText().trim(), brand.getText().trim(),
178
        catalogService.checkSimilarItem(productGroup.getText().trim(), brand.getText().trim(),
179
                modelNumber.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
179
                modelNumber.getText().trim(), color.getText().trim(), new AsyncCallback<Long>() {
180
            @Override
180
            @Override
181
            public void onFailure(Throwable caught) {
181
            public void onFailure(Throwable caught) {
182
                GWT.log("Error checking similar item");
182
                GWT.log("Error checking similar item");
Line 192... Line 192...
192
                addNewItem();
192
                addNewItem();
193
            }
193
            }
194
        });
194
        });
195
    }
195
    }
196
    
196
    
197
    void addNewItem() {
197
    private void addNewItem() {
198
        Item item = new Item();
198
        Item item = new Item();
199
        
199
        
200
        item.setProductGroup(productGroup.getText().trim());
200
        item.setProductGroup(productGroup.getText().trim());
201
        item.setVendorCategory(vendorCategory.getItemText(vendorCategory.getSelectedIndex()));
201
        item.setVendorCategory(vendorCategory.getItemText(vendorCategory.getSelectedIndex()));
202
        
202
        
Line 204... Line 204...
204
        item.setModelNumber(modelNumber.getText().trim());
204
        item.setModelNumber(modelNumber.getText().trim());
205
        item.setModelName(modelName.getText().trim());
205
        item.setModelName(modelName.getText().trim());
206
        item.setColor(color.getText().trim());
206
        item.setColor(color.getText().trim());
207
        item.setComments(comments.getText().trim());
207
        item.setComments(comments.getText().trim());
208
        try {
208
        try {
-
 
209
            if(!mrp.getText().trim().isEmpty()) {
209
            double mrpValue = Double.parseDouble(mrp.getText().trim());
210
                double mrpValue = Double.parseDouble(mrp.getText().trim());
210
            if(mrpValue < 0) {
211
                if(mrpValue <= 0) {
211
                throw new NumberFormatException("Negative value of MRP");
212
                    throw new NumberFormatException("Negative value of MRP");
-
 
213
                }
-
 
214
                item.setMrp(mrpValue);
-
 
215
            } else {
-
 
216
                item.setMrp(-1);
212
            }
217
            }
213
            item.setMrp(mrpValue);
-
 
214
        } catch(NumberFormatException ex) {
218
        } catch(NumberFormatException ex) {
215
            Window.alert("Invalid MRP format");
219
            Window.alert("Invalid MRP format/value. Value shoule be greater than zero");
216
            return;
220
            return;
217
        }
221
        }
218
        try {
222
        try {
-
 
223
            if(!sellingPrice.getText().trim().isEmpty()) {
219
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
224
            double spValue = Double.parseDouble(sellingPrice.getText().trim());
220
            if(spValue < 0) {
225
            if(spValue <= 0) {
221
                throw new NumberFormatException("Negative value of Selling price");
226
                throw new NumberFormatException("Negative value of Selling price");
222
            }
227
            }
223
            item.setSellingPrice(spValue);
228
            item.setSellingPrice(spValue);
-
 
229
            } else {
-
 
230
                item.setSellingPrice(-1);
-
 
231
            }
224
        } catch(NumberFormatException ex) {
232
        } catch(NumberFormatException ex) {
225
            Window.alert("Invalid Selling Price format");
233
            Window.alert("Invalid Selling Price format/value. Value shoule be greater than zero");
226
            return;
234
            return;
227
        }
235
        }
228
        try {
236
        try {
229
            if(!weight.getText().trim().equals("")) {
237
            if(!weight.getText().trim().isEmpty()) {
230
                double wtValue = Double.parseDouble(weight.getText().trim());
238
                double wtValue = Double.parseDouble(weight.getText().trim());
231
                if(wtValue < 0) {
239
                if(wtValue <= 0) {
232
                    throw new NumberFormatException("Negative value of Weight");
240
                    throw new NumberFormatException("Negative value of Weight");
233
                }
241
                }
234
                item.setWeight(wtValue);
242
                item.setWeight(wtValue);
-
 
243
            } else {
-
 
244
                item.setWeight(-1);
235
            }
245
            }
236
        } catch(NumberFormatException ex) {
246
        } catch(NumberFormatException ex) {
237
            Window.alert("Invalid weight format");
247
            Window.alert("Invalid weight format/value. Value shoule be greater than zero");
238
            return;
248
            return;
239
        }
249
        }
240
        try {
250
        try {
241
            if(!startDate.getTextBox().getText().trim().equals("")) {
251
            if(!startDate.getTextBox().getText().trim().equals("")) {
242
                item.setStartDate(startDate.getValue().getTime());
252
                item.setStartDate(startDate.getValue().getTime());
243
            }
253
            }
244
        } catch(Exception ex) {
254
        } catch(Exception ex) {
245
            Window.alert("Invalid start date format");
255
            Window.alert("Invalid start date format");
246
            return;
256
            return;
247
        }
257
        }
248
        try {
-
 
249
            if(!retireDate.getTextBox().getText().trim().equals("")) {
-
 
250
                item.setRetireDate(retireDate.getValue().getTime());
-
 
251
            }
-
 
252
        } catch(Exception ex) {
-
 
253
            Window.alert("Invalid retire date format");
-
 
254
            return;
-
 
255
        }
-
 
256
        item.setBestDealsText(bestDealText.getText().trim());
258
        item.setBestDealsText(bestDealText.getText().trim());
257
        try {
259
        try {
258
            if(!bestDealValue.getText().trim().equals("")) {
260
            if(!bestDealValue.getText().trim().equals("")) {
259
                double bdValue = Double.parseDouble(bestDealValue.getText().trim());
261
                double bdValue = Double.parseDouble(bestDealValue.getText().trim());
260
                if(bdValue < 0) {
262
                if(bdValue < 0) {
261
                    throw new NumberFormatException("Negative value of BestDealValue");
263
                    throw new NumberFormatException("Negative value of BestDealValue");
262
                }
264
                }
263
                item.setBestDealsValue(bdValue);
265
                item.setBestDealsValue(bdValue);
-
 
266
            } else {
-
 
267
                item.setBestDealsValue(-1);
264
            }
268
            }
265
        } catch(NumberFormatException ex) {
269
        } catch(NumberFormatException ex) {
266
            Window.alert("Invalid best deal value format");
270
            Window.alert("Invalid best deal value format");
267
            return;
271
            return;
268
        }
272
        }
Line 271... Line 275...
271
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
275
                long bsrValue = Long.parseLong(bestSellingRank.getText().trim());
272
                if(bsrValue < 0) {
276
                if(bsrValue < 0) {
273
                    throw new NumberFormatException("Negative value of Best Selling Rank");
277
                    throw new NumberFormatException("Negative value of Best Selling Rank");
274
                }
278
                }
275
                item.setBestSellingRank(bsrValue);
279
                item.setBestSellingRank(bsrValue);
-
 
280
            } else {
-
 
281
                item.setBestSellingRank(-1);
276
            }
282
            }
277
            
283
            
278
        } catch(NumberFormatException ex) {
284
        } catch(NumberFormatException ex) {
279
            Window.alert("Invalid best selling rank format");
285
            Window.alert("Invalid best selling rank format");
280
            return;
286
            return;