예제 #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);
            }
        }
        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);
            }
        }
        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);
            }
        }
예제 #4
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 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);
            }
        }
예제 #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 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);
            }
        }
예제 #8
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);
            }
        }