/* * This method will add/update a supplier * @author nazmul hasan on 5th january 2016 */ private void OnAdd() { if (!ValidateSupplier()) { MessageBox.Show(ErrorMessage); return; } ProfileInfo profileInfo = new ProfileInfo(); profileInfo.setId(SupplierInfoNJ.ProfileInfoNJ.Id); profileInfo.setFirstName(SupplierInfoNJ.ProfileInfoNJ.FirstName); profileInfo.setLastName(SupplierInfoNJ.ProfileInfoNJ.LastName); profileInfo.setEmail(SupplierInfoNJ.ProfileInfoNJ.Email); profileInfo.setPhone(SupplierInfoNJ.ProfileInfoNJ.Phone); profileInfo.setFax(SupplierInfoNJ.ProfileInfoNJ.Fax); profileInfo.setWebsite(SupplierInfoNJ.ProfileInfoNJ.Website); SupplierInfo supplierInfo = new SupplierInfo(); supplierInfo.setProfileInfo(profileInfo); SupplierManager supplierManager = new SupplierManager(); SupplierInfoNJ supplierInfoNJ = new SupplierInfoNJ(); supplierInfoNJ.ProfileInfoNJ.Id = SupplierInfoNJ.ProfileInfoNJ.Id; supplierInfoNJ.ProfileInfoNJ.FirstName = SupplierInfoNJ.ProfileInfoNJ.FirstName; supplierInfoNJ.ProfileInfoNJ.LastName = SupplierInfoNJ.ProfileInfoNJ.LastName; supplierInfoNJ.ProfileInfoNJ.Email = SupplierInfoNJ.ProfileInfoNJ.Email; supplierInfoNJ.ProfileInfoNJ.Phone = SupplierInfoNJ.ProfileInfoNJ.Phone; supplierInfoNJ.ProfileInfoNJ.Fax = SupplierInfoNJ.ProfileInfoNJ.Fax; supplierInfoNJ.ProfileInfoNJ.Website = SupplierInfoNJ.ProfileInfoNJ.Website; supplierInfoNJ.Remarks = supplierInfo.getRemarks(); ResultEvent resultEvent = new ResultEvent(); if (SupplierInfoNJ.ProfileInfoNJ.Id > 0) { resultEvent = supplierManager.updateSupplier(supplierInfo); } else { resultEvent = supplierManager.createSupplier(supplierInfo); } if (resultEvent.getResponseCode() == Responses.RESPONSE_CODE_SUCCESS) { if (SupplierInfoNJ.ProfileInfoNJ.Id > 0) { for (int counter = 0; counter < SupplierList.Count; counter++) { SupplierInfoNJ tempSupplierInfoNJ = SupplierList.ElementAt(counter); if (tempSupplierInfoNJ.ProfileInfoNJ.Id == SupplierInfoNJ.ProfileInfoNJ.Id) { SupplierList.RemoveAt(counter); SupplierList.Insert(counter, supplierInfoNJ); } } } else { SupplierInfo responseSupplierInfo = (SupplierInfo)resultEvent.getResult(); SupplierInfoNJ.ProfileInfoNJ.Id = responseSupplierInfo.getProfileInfo().getId(); supplierInfoNJ.ProfileInfoNJ.Id = SupplierInfoNJ.ProfileInfoNJ.Id; if (SupplierList.Count == 0) { SupplierList.Add(supplierInfoNJ); } else { SupplierList.Insert(0, supplierInfoNJ); } } } MessageBox.Show(resultEvent.getMessage()); //resetting supplier info fields OnReset(); }