예제 #1
0
        private bool SaveChanges()
        {
            int selectedID = -1;

            //Required to get back to current customer when entering a new customer.
            if (m_CurrentCustomer.HasValue == false)
            {
                m_CurrentCustomer = m_Customer.GetNewCustomerID();
            }
            else
            {
                selectedID = customerSearchGridView.FocusedRowHandle;
            }

            try
            {
                if (m_Customer.UpdateCustomer(m_CurrentCustomer.Value, nameTextEdit.Text, contactTextEdit.Text, Convert.ToString(phoneTextEdit.EditValue), emailTextEdit.Text, Convert.ToString(faxTextEdit.EditValue), noteMemoEdit.Text, Convert.ToString(addressTextEdit.EditValue), Convert.ToString(cityTextEdit.EditValue), Convert.ToString(stateTextEdit.EditValue), Convert.ToString(postalTextEdit.EditValue), inactiveCheckEdit.Checked, Convert.ToString(lpnPrefixTextEdit.EditValue), Utilities.ChangeType <int?>(firstLPNNumberTextEdit.EditValue), Utilities.ChangeType <int?>(lastLPNNumberTextEdit.EditValue), Convert.ToString(beforeItemCodetextEdit.EditValue), Convert.ToString(beforeLotCodetextEdit.EditValue), Convert.ToString(beforeQtyCodetextEdit.EditValue), Convert.ToString(endCodeTextEdit.EditValue), Convert.ToString(plantCodeTextEdit.EditValue), Convert.ToString(expirationDateFormatComboBox.EditValue), Utilities.ChangeType <int?>(lotCodeFormatLookUpEdit.EditValue), m_CustomersSession) != true)
                {
                    MessageBox.Show("The customer was not updated succesfully.", "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                foreach (CustomerShifts customerShift in customerShiftsXpCollection)
                {
                    if (customerShift.Customer == null || customerShift.Customer.CustomerID == -1)
                    {
                        customerShift.Customer = m_CustomersSession.GetObjectByKey <Customers>(m_CurrentCustomer.Value);
                    }
                    customerShift.Save();
                }

                foreach (CustomerPlants customerPlant in customerPlantsXpCollection)
                {
                    if (customerPlant.Customer == null || customerPlant.Customer.CustomerID == -1)
                    {
                        customerPlant.Customer = m_CustomersSession.GetObjectByKey <Customers>(m_CurrentCustomer.Value);
                    }
                    customerPlant.Save();
                }

                BindCustomerSearch();
                BindCustomersControls(m_CurrentCustomer.Value);
                if (selectedID != -1)
                {
                    customerSearchGridView.FocusedRowHandle = selectedID;
                }
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Error Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }