public static void addNewOrder(MyTextBox locationTextbox, ComboBox paymentMethod, DateTimePicker orderDatePicker,
                                       ComboBox customerIdsComboBox, BindingNavigator bindingNavigatorOrders, NewOrder newOrderForm)
        {
            if (!validateFields(locationTextbox, paymentMethod, customerIdsComboBox))
            {
                return;
            }

            try
            {
                int last_page = bindingNavigatorOrders.BindingSource.Count;

                NewOrderDAO.addNewOrder(locationTextbox.Text, paymentMethod.GetItemText(paymentMethod.SelectedItem),
                                        orderDatePicker.Value.Date, customerIdsComboBox.GetItemText(customerIdsComboBox.SelectedItem));


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

                db.BindOrderData(App.GetOrderLabels(), bindingNavigatorOrders);

                bindingNavigatorOrders.BindingSource.Position = last_page;

                // Added!
                newOrderForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        public static void updateOrdersProducts(TextBox amountTextbox, BindingNavigator bindingNavigatorOrdersProducts,
                                                UpdateOrdersProducts updateOrdersProductsForm, int idOrder, int idProduct)
        {
            float n;

            if (!float.TryParse(amountTextbox.Text, out n))
            {
                ViewMessages.AmountNotValid();
                return;
            }

            try
            {
                int currentPage = bindingNavigatorOrdersProducts.BindingSource.Position;

                UpdateOrdersProductsDAO.updateOrdersProducts(float.Parse(amountTextbox.Text), idOrder, idProduct);

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

                db.BindOrdersProductsData(App.GetOrdersProductsLabels(), bindingNavigatorOrdersProducts);

                bindingNavigatorOrdersProducts.BindingSource.Position = currentPage;

                // Updated!
                updateOrdersProductsForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }
        public static void updateProduct(Dictionary <String, TextBox> productValueLabels, BindingNavigator bindingNavigatorProducts,
                                         UpdateProduct updateProductForm, int productId)
        {
            if (!validateFields(productValueLabels))
            {
                return;
            }

            try
            {
                int currentPage = bindingNavigatorProducts.BindingSource.Position;

                UpdateProductDAO.updateProduct(productValueLabels["LABEL"].Text, productValueLabels["CATEGORY"].Text, int.Parse(productValueLabels["RESERVE"].Text),
                                               float.Parse(productValueLabels["SELLING_PRICE"].Text), productValueLabels["MANUFACTURER"].Text, productId);


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

                db.BindProductsData(App.GetProductLabels(), bindingNavigatorProducts);

                bindingNavigatorProducts.BindingSource.Position = currentPage;

                // Updated!
                updateProductForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }
        public static void updateOrder(ComboBox customerId_combobox, ComboBox paymentMethod_combobox, TextBox location_Textbox, DateTimePicker orderDatePicker,
                                       BindingNavigator bindingNavigatorOrders, UpdateOrder updateOrderForm, int orderId)
        {
            if (!validateFields(customerId_combobox, paymentMethod_combobox, location_Textbox))
            {
                return;
            }

            try
            {
                int currentPage = bindingNavigatorOrders.BindingSource.Position;

                UpdateOrderDAO.updateOrder(orderDatePicker.Value.Date, Int32.Parse(customerId_combobox.GetItemText(customerId_combobox.SelectedItem)),
                                           paymentMethod_combobox.GetItemText(paymentMethod_combobox.SelectedItem), location_Textbox.Text, orderId);


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

                db.BindOrderData(App.GetOrderLabels(), bindingNavigatorOrders);

                bindingNavigatorOrders.BindingSource.Position = currentPage;

                // Updated!
                updateOrderForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }
Пример #6
0
        public static void UpdateCustomer(PictureBox pictureBox, Dictionary <String, MyTextBox> updateCustomerTextboxes, Dictionary <String, Label> customerValueLabels,
                                          PictureBox customerPictureBox, RichTextBox comments_richTextbox, DateTime birthDate, BindingNavigator bindingNavigatorCustomers, UpdateCustomer updateCustomerForm)
        {
            if (!NewCustomerController.ValidateFields(updateCustomerTextboxes, !updateCustomerTextboxes["AFM"].Text.Equals(customerValueLabels["AFM"].Text)))
            {
                return;
            }

            // Refresh the Binding Navigator if customer was updated succesfully
            try
            {
                UpdateCustomerDAO.UpdateCustomer(pictureBox, comments_richTextbox, birthDate, updateCustomerTextboxes, Int32.Parse(customerValueLabels["CUSTOMER_ID"].Text));

                int currentPage = bindingNavigatorCustomers.BindingSource.Position;
                foreach (KeyValuePair <String, Label> entry in App.GetCustomerLabels())
                {
                    entry.Value.DataBindings.Clear();
                }

                db.BindCustomerData(App.GetCustomerLabels(), App.getCommentsRichTextbox(), bindingNavigatorCustomers);
                bindingNavigatorCustomers.BindingSource.Position = currentPage;

                AppDAO.LoadCustomerPhoto(customerPictureBox, Int32.Parse(customerValueLabels["CUSTOMER_ID"].Text));

                // Updated!
                updateCustomerForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }
        public static void addNewProduct(Dictionary <String, TextBox> newProductTextboxes, BindingNavigator productsBindingNavigator, NewProduct newProductForm)
        {
            if (!validateFields(newProductTextboxes))
            {
                return;
            }

            try
            {
                int last_page = productsBindingNavigator.BindingSource.Count;

                NewProductDAO.addNewProduct(newProductTextboxes["LABEL"].Text, newProductTextboxes["CATEGORY"].Text, Int32.Parse(newProductTextboxes["RESERVE"].Text),
                                            float.Parse(newProductTextboxes["SELLING_PRICE"].Text), newProductTextboxes["MANUFACTURER"].Text);


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

                db.BindProductsData(App.GetProductLabels(), productsBindingNavigator);

                productsBindingNavigator.BindingSource.Position = last_page;

                // Added!
                newProductForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }
        public static bool validateFields(Dictionary <String, TextBox> newProductTextboxes)
        {
            if (newProductTextboxes["SELLING_PRICE"].Text.Equals("") || newProductTextboxes["LABEL"].Text.Equals("") ||
                newProductTextboxes["RESERVE"].Text.Equals(""))
            {
                ViewMessages.FillRequiredFields();
                return(false);
            }

            int n;

            if (!int.TryParse(newProductTextboxes["RESERVE"].Text, out n))
            {
                ViewMessages.ReserveNotValid();
                return(false);
            }

            float k;

            if (!float.TryParse(newProductTextboxes["SELLING_PRICE"].Text, out k))
            {
                ViewMessages.SellingPriceNotValid();
                return(false);
            }

            return(true);
        }
        public static bool validateFields(ComboBox customerId_combobox, ComboBox paymentMethod_combobox, TextBox deliveryLocation)
        {
            if (deliveryLocation.Text.Equals("") || paymentMethod_combobox.GetItemText(paymentMethod_combobox.SelectedItem).Equals("") ||
                customerId_combobox.GetItemText(customerId_combobox.SelectedItem).Equals(""))
            {
                ViewMessages.FillRequiredFields();
                return(false);
            }

            return(true);
        }
        public static bool validateFields(MyTextBox locationTextbox, ComboBox paymentMethod, ComboBox customerIdsComboBox)
        {
            if (locationTextbox.Text.Equals("") || paymentMethod.GetItemText(paymentMethod.SelectedItem).Equals("") ||
                customerIdsComboBox.GetItemText(customerIdsComboBox.SelectedItem).Equals(""))
            {
                ViewMessages.FillRequiredFields();
                return(false);
            }

            return(true);
        }
Пример #11
0
 public static void DeleteRelationship(Dictionary <string, Label> ordersProductsValueLabels, BindingNavigator bindingNavigatorOrdersProducts)
 {
     if (ViewMessages.DeleteRelationshipDialog() == DialogResult.No)
     {
         return;
     }
     AppDAO.DeleteRelationship(Int32.Parse(ordersProductsValueLabels["ORDER_ID_F"].Text));
     foreach (KeyValuePair <string, Label> entry in ordersProductsValueLabels)
     {
         entry.Value.DataBindings.Clear();
     }
     db.BindOrdersProductsData(ordersProductsValueLabels, bindingNavigatorOrdersProducts);
 }
Пример #12
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);
        }
Пример #13
0
        public static void DeleteProduct(Dictionary <string, Label> productValueLabels, BindingNavigator bindingNavigatorProduct)
        {
            if (!productCanBeDeleted(productValueLabels["PRODUCT_ID"].Text))
            {
                ViewMessages.CannotDeleteProduct();
                return;
            }

            if (ViewMessages.DeleteProductDialog() == DialogResult.No)
            {
                return;
            }
            AppDAO.DeleteProduct(Int32.Parse(productValueLabels["PRODUCT_ID"].Text));
            foreach (KeyValuePair <string, Label> entry in productValueLabels)
            {
                entry.Value.DataBindings.Clear();
            }
            db.BindProductsData(productValueLabels, bindingNavigatorProduct);
        }
Пример #14
0
        public static void DeleteOrder(Dictionary <string, Label> orderValueLabels, BindingNavigator bindingNavigatorOrder)
        {
            if (!orderCanBeDeleted(orderValueLabels["ORDER_ID"].Text))
            {
                ViewMessages.CannotDeleteOrder();
                return;
            }

            if (ViewMessages.DeleteOrderDialog() == DialogResult.No)
            {
                return;
            }
            AppDAO.DeleteOrder(Int32.Parse(orderValueLabels["ORDER_ID"].Text));
            foreach (KeyValuePair <string, Label> entry in orderValueLabels)
            {
                entry.Value.DataBindings.Clear();
            }
            db.BindOrderData(orderValueLabels, bindingNavigatorOrder);
        }
Пример #15
0
        public static void DeleteCustomer(Dictionary <string, Label> customerValueLabels, RichTextBox commentsRichTextBox, BindingNavigator bindingNavigatorCustomer)
        {
            if (!customerCanBeDeleted(customerValueLabels["CUSTOMER_ID"].Text))
            {
                ViewMessages.CannotDeleteCustomer();
                return;
            }

            if (ViewMessages.DeleteCustomerDialog() == DialogResult.No)
            {
                return;
            }
            AppDAO.DeleteCustomer(Int32.Parse(customerValueLabels["CUSTOMER_ID"].Text));
            foreach (KeyValuePair <string, Label> entry in customerValueLabels)
            {
                entry.Value.DataBindings.Clear();
            }
            db.BindCustomerData(customerValueLabels, commentsRichTextBox, bindingNavigatorCustomer);
        }
Пример #16
0
        public static bool validateFields(TextBox amount, ComboBox orderIdComboBox, ComboBox productIdComboBox)
        {
            if (amount.Text.Equals("") || orderIdComboBox.GetItemText(orderIdComboBox.SelectedItem).Equals("") ||
                productIdComboBox.GetItemText(productIdComboBox.SelectedItem).Equals(""))
            {
                ViewMessages.FillRequiredFields();
                return(false);
            }

            float n;

            if (!float.TryParse(amount.Text, out n))
            {
                ViewMessages.AmountNotValid();
                return(false);
            }


            return(true);
        }
Пример #17
0
        public static void addNewOrdersProducts(TextBox amountTextBox, ComboBox orderIdComboBox, ComboBox productIdComboBox,
                                                BindingNavigator bindingNavigatorOrdersProducts, NewOrdersProducts newOrderProductsForm)
        {
            if (!validateFields(amountTextBox, orderIdComboBox, productIdComboBox))
            {
                return;
            }

            try
            {
                int   last_page = bindingNavigatorOrdersProducts.BindingSource.Count;
                int   orderId   = Int32.Parse(orderIdComboBox.GetItemText(orderIdComboBox.SelectedItem));
                int   productId = Int32.Parse(productIdComboBox.GetItemText(productIdComboBox.SelectedItem));
                float amount    = float.Parse(amountTextBox.Text);

                // Check for DUPLICATE KEY
                if (NewOrdersProductsDAO.checkIfKeyAlreadyExists(orderId, productId))
                {
                    ViewMessages.DuplicateKeyError();
                    return;
                }

                NewOrdersProductsDAO.addNewOrdersProducts(orderId, productId, amount);

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

                db.BindOrdersProductsData(App.GetOrdersProductsLabels(), bindingNavigatorOrdersProducts);

                bindingNavigatorOrdersProducts.BindingSource.Position = last_page;

                // Added!
                newOrderProductsForm.Close();
            }
            catch (SqlException e)
            {
                ViewMessages.ExceptionOccured(e);
            }
        }