Example #1
0
        private void delete2_Click(object sender, RoutedEventArgs e)
        {
            DataGridRow dgRow       = (DataGridRow)(gridDepartment.ItemContainerGenerator.ContainerFromItem(gridDepartment.SelectedItem));
            Department  selectedDep = gridDepartment.Items[gridDepartment.SelectedIndex] as Department;
            string      textToFind  = Convert.ToString(selectedDep.DepartmentID);

            if (whoUse.Hierarchy == Hierarchy.Clubmember || whoUse.Hierarchy == Hierarchy.Customer || whoUse.Hierarchy == Hierarchy.Worker)
            {
                MessageBox.Show("You are not allowed to delete this item");
            }
            else
            {
                try
                {
                    List <object> wentedList = itsBL.queryByString(Classes.Department, stringFields.departmentID, textToFind);
                    if (wentedList == null)
                    {
                        throw new Exception("there is no item to delete");
                    }
                    Department deleteDep = wentedList.Cast <Department>().ElementAt(0);
                    itsBL.remove(deleteDep);
                    itsBL.saveDataToFile();
                    MessageBox.Show("item sucessfuly deleted");
                    tablePanel.Children.Clear();
                    DepartmentT showProduct = new DepartmentT(itsBL, Permanent, whoUse);
                    tablePanel.Children.Add(showProduct);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #2
0
 public void ShowTable(List <object> table)
 {
     if (table == null || table.Count == 0)
     {
         MessageBox.Show("there are no items to show");
     }
     else
     {
         //List<object> showList = table;
         DepartmentT showDepartment = new DepartmentT(itsBL, table, user);
         tableShow.Children.Clear();
         tableShow.Children.Add(showDepartment);
     }
 }
Example #3
0
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            DataGridRow dgRow       = (DataGridRow)(gridDepartment.ItemContainerGenerator.ContainerFromItem(gridDepartment.SelectedItem));
            Department  selectedDep = gridDepartment.Items[gridDepartment.SelectedIndex] as Department;

            if (dgRow == null)
            {
                return;
            }

            DataGridDetailsPresenter dgdPresenter = FindVisualChild <DataGridDetailsPresenter>(dgRow);

            DataTemplate template    = dgdPresenter.ContentTemplate;
            TextBox      textBoxName = (TextBox)template.FindName("editName", dgdPresenter);

            if (whoUse.Hierarchy == Hierarchy.Clubmember || whoUse.Hierarchy == Hierarchy.Customer || whoUse.Hierarchy == Hierarchy.Worker)
            {
                textBoxName.IsReadOnly = true;
                MessageBox.Show("You are not allowed to edit this field");
            }
            else
            {
                if (textBoxName == null)
                {
                    MessageBox.Show("you have to write somthing");
                }
                else
                {
                    if (textBoxName.Text.Length < 1)
                    {
                        throw new Exception("Invalid First Name, Must Have Atleast One Character");
                    }
                    selectedDep.Name = textBoxName.Text;
                    try
                    {
                        itsBL.edit(selectedDep);
                        itsBL.saveDataToFile();
                        MessageBox.Show("Changes have been done");
                        tablePanel.Children.Clear();
                        DepartmentT showProduct = new DepartmentT(itsBL, Permanent, whoUse);
                        tablePanel.Children.Add(showProduct);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Example #4
0
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            DataGridRow dgRow        = (DataGridRow)(gridEmployee.ItemContainerGenerator.ContainerFromItem(gridEmployee.SelectedItem));
            Employee    selectedEmpo = gridEmployee.Items[gridEmployee.SelectedIndex] as Employee;

            if (dgRow == null)
            {
                return;
            }

            DataGridDetailsPresenter dgdPresenter = FindVisualChild <DataGridDetailsPresenter>(dgRow);

            DataTemplate template      = dgdPresenter.ContentTemplate;
            TextBox      textBoxFName  = (TextBox)template.FindName("editFirstName", dgdPresenter);
            TextBox      textBoxLName  = (TextBox)template.FindName("editLastName", dgdPresenter);
            TextBox      textBoxDepID  = (TextBox)template.FindName("editDepID", dgdPresenter);
            TextBox      textBoxSalary = (TextBox)template.FindName("editSalary", dgdPresenter);
            TextBox      textBoxSuper  = (TextBox)template.FindName("editSuper", dgdPresenter);

            if (whoUse.Hierarchy == Hierarchy.Clubmember || whoUse.Hierarchy == Hierarchy.Customer || whoUse.Hierarchy == Hierarchy.Worker)
            {
                textBoxFName.IsReadOnly  = true;
                textBoxLName.IsReadOnly  = true;
                textBoxDepID.IsReadOnly  = true;
                textBoxSalary.IsReadOnly = true;
                textBoxSuper.IsReadOnly  = true;
                MessageBox.Show("You are not allowed to edit this field");
            }
            else
            {
                if (textBoxFName == null || textBoxLName == null || textBoxDepID == null || textBoxSalary == null || textBoxSuper == null)
                {
                    MessageBox.Show("you have to fill all the empty fields");
                }
                else
                {
                    try
                    {
                        if (textBoxFName.Text.Length < 1)
                        {
                            throw new Exception("Invalid First Name, Must Have Atleast One Character");
                        }
                        selectedEmpo.FirstName = textBoxFName.Text;
                        if (textBoxFName.Text.Length < 1)
                        {
                            throw new Exception("Invalid Last Name, Must Have Atleast One Character");
                        }
                        selectedEmpo.LastName = textBoxLName.Text;
                        InputCheck.isInt(textBoxDepID.Text, " department ID ");
                        selectedEmpo.DepartmentID = Convert.ToInt32(textBoxDepID.Text);
                        InputCheck.isDouble(textBoxSalary.Text, " salary ");
                        selectedEmpo.Salary = Convert.ToDouble(textBoxSalary.Text);
                        InputCheck.isInt(textBoxSuper.Text, " supervisor ID ");
                        selectedEmpo.SupervisorID = Convert.ToInt32(textBoxSuper.Text);

                        itsBL.edit(selectedEmpo);
                        itsBL.saveDataToFile();
                        MessageBox.Show("Changes have been done");
                        tablePanel.Children.Clear();
                        DepartmentT showProduct = new DepartmentT(itsBL, Permanent, whoUse);
                        tablePanel.Children.Add(showProduct);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Example #5
0
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            DataGridRow dgRow        = (DataGridRow)(gridProduct.ItemContainerGenerator.ContainerFromItem(gridProduct.SelectedItem));
            Product     selectedProd = gridProduct.Items[gridProduct.SelectedIndex] as Product;

            if (dgRow == null)
            {
                return;
            }

            DataGridDetailsPresenter dgdPresenter = FindVisualChild <DataGridDetailsPresenter>(dgRow);

            DataTemplate template     = dgdPresenter.ContentTemplate;
            TextBox      textBoxName  = (TextBox)template.FindName("editName", dgdPresenter);
            TextBox      textBoxLoc   = (TextBox)template.FindName("editLocation", dgdPresenter);
            TextBox      textBoxStock = (TextBox)template.FindName("editStock", dgdPresenter);
            TextBox      textBoxPrice = (TextBox)template.FindName("editPrice", dgdPresenter);
            TextBox      textBoxWhen  = (TextBox)template.FindName("editWhen", dgdPresenter);
            ComboBox     textBoxType  = (ComboBox)template.FindName("Atype", dgdPresenter);

            editType = textBoxType.Text;

            if (whoUse.Hierarchy == Hierarchy.Clubmember || whoUse.Hierarchy == Hierarchy.Customer || whoUse.Hierarchy == Hierarchy.Worker)
            {
                textBoxName.IsReadOnly  = true;
                textBoxLoc.IsReadOnly   = true;
                textBoxStock.IsReadOnly = true;
                textBoxPrice.IsReadOnly = true;
                textBoxWhen.IsReadOnly  = true;
                textBoxType.IsReadOnly  = true;
                MessageBox.Show("You are not allowed to edit this field");
            }
            else
            {
                if (editType == "Home And Garden")
                {
                    editType = "HomeAndGarden";
                }
                if (textBoxName == null || textBoxLoc == null || textBoxStock == null || textBoxPrice == null || textBoxWhen == null || textBoxType == null)
                {
                    MessageBox.Show("you have to fill all the empty fields");
                }
                else
                {
                    try
                    {
                        selectedProd.Name = textBoxName.Text;
                        if (textBoxName.Text.Length < 1)
                        {
                            throw new Exception("Invalid First Name, Must Have Atleast One Character");
                        }
                        InputCheck.isType(editType);
                        selectedProd.Type = (Backend.Type)Enum.Parse(typeof(Backend.Type), editType);
                        InputCheck.isInt(textBoxLoc.Text, " location (Department ID) ");
                        selectedProd.Location = Convert.ToInt32(textBoxLoc.Text);
                        InputCheck.isInt(textBoxStock.Text, " units in stock ");
                        selectedProd.StockCount = Convert.ToInt32(textBoxStock.Text);
                        InputCheck.isDouble(textBoxPrice.Text, " price ");
                        selectedProd.Price = Convert.ToDouble(textBoxPrice.Text);
                        InputCheck.isInt(textBoxWhen.Text, " 'when to order' ");
                        selectedProd.WhenToOrder = Convert.ToInt32(textBoxWhen.Text);

                        itsBL.edit(selectedProd);
                        itsBL.saveDataToFile();
                        MessageBox.Show("Changes have been done");
                        tablePanel.Children.Clear();
                        DepartmentT showProduct = new DepartmentT(itsBL, permanent, whoUse);
                        tablePanel.Children.Add(showProduct);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }