Esempio n. 1
0
        public static void AddNewCustomer(Dictionary <string, MyTextBox> newCustomerTextboxes, DateTime birthDate,
                                          RichTextBox comments_richTextbox, BindingNavigator bindingNavigatorCustomers, NewCustomer newCustomerForm)
        {
            if (!ValidateFields(newCustomerTextboxes, true))
            {
                return;
            }

            // Refresh the Binding Navigator if customer was added succesfully
            try
            {
                int last_page = bindingNavigatorCustomers.BindingSource.Count;

                NewCustomerDAO.AddNewCustomer(newCustomerTextboxes, birthDate, comments_richTextbox);

                foreach (KeyValuePair <string, Label> entry in App.GetCustomerLabels())
                {
                    entry.Value.DataBindings.Clear();
                }

                db.BindCustomerData(App.GetCustomerLabels(), App.getCommentsRichTextbox(), bindingNavigatorCustomers);

                bindingNavigatorCustomers.BindingSource.Position = last_page;

                // Added!
                newCustomerForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }
Esempio n. 2
0
        public static bool ValidateFields(Dictionary <string, MyTextBox> newCustomerTextboxes, bool checkAfm)
        {
            // Check for AFM input
            string afm = newCustomerTextboxes["AFM"].Text.Trim();

            if (!Int32.TryParse(afm, out int n))
            {
                ViewMessages.NonIntegerAfm();
                return(false);
            }

            if (afm.Length != 9)
            {
                ViewMessages.InvalidAfm();
                return(false);
            }

            if (checkAfm)
            {
                if (NewCustomerDAO.afmExists(afm))
                {
                    ViewMessages.AfmExists();
                    return(false);
                }
            }



            //Validate Last Name
            if (newCustomerTextboxes["LAST_NAME"].Text.Trim().Length < 3)
            {
                ViewMessages.LastNameTooSmall();
                return(false);
            }

            //Validate First Name
            if (newCustomerTextboxes["FIRST_NAME"].Text.Trim().Length < 3)
            {
                ViewMessages.FirstNameTooSmall();
                return(false);
            }

            return(true);
        }