private void Update_Click(object sender, RoutedEventArgs e)
        {
            string newName = UpdateNewNameTB.Text.Trim();
            string oldName = UpdateOldNameTB.Text.Trim();

            if (commander.IsInputInvalid(newName, "New name") || commander.IsInputInvalid(oldName, "Old name"))
            {
                MessageBox.Show("Empty or default value is invalid for updating");
                return;
            }
            if (commander.ExistsInDatabaseByNameCaseInsensitive(OSHome.DbSources.Categories, newName, out string found))
            {
                MessageBox.Show($"Category named {newName} already exists in database.");
                return;
            }
            if (!commander.ExistsInDatabaseByNameCaseSensitive(OSHome.DbSources.Categories, oldName))
            {
                MessageBox.Show($"Category named {oldName} doesn't exists in database.");
                return;
            }
            if (!commander.FinalAcceptancePrompt())
            {
                return;
            }
            Categories categoryToUpdate = new Categories();

            categoryToUpdate = db.Categories.Single(x => x.category_name == oldName);
            categoryToUpdate.category_name = newName;
            db.SaveChanges();
            categoriesDataGrid.Items.Refresh();
            UpdateNewNameTB.Text = "New name";
            UpdateOldNameTB.Text = "Old name";
            MessageBox.Show($"Successfully updated: {oldName} into: {newName}.");
        }
        private void Update_Click(object sender, RoutedEventArgs e)
        {
            string stringId    = UpdateIDTB.Text.Trim();
            string newLastName = UpdateLastNameTB.Text.Trim();

            if (commander.IsInputInvalid(stringId, "ID") || !int.TryParse(stringId, out int id) || !commander.LettersInputOnly(newLastName))
            {
                MessageBox.Show($"{stringId} is not valid id.");
                return;
            }
            if (!commander.ExistsInDatabaseByID(OSHome.DbSources.Employees, id))
            {
                MessageBox.Show($"Employee doesn't exist in database.");
                return;
            }
            var    emp         = db.Employees.Single(x => x.employee_id == id);
            string oldLastName = emp.employee_name;

            if (oldLastName == newLastName)
            {
                MessageBox.Show($"New last name is same as existing last name.");
                return;
            }
            if (!commander.FinalAcceptancePrompt())
            {
                return;
            }
            emp.employee_name = newLastName;
            db.SaveChanges();
            employeesDataGrid.Items.Refresh();
            UpdateIDTB.Text       = "ID";
            UpdateLastNameTB.Text = "New last name";
            MessageBox.Show($"Successfully updated employee: {emp.employee_first_name} {oldLastName} into: {emp.employee_first_name} {newLastName}");
        }
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            string value = RemoveNameTB.Text.Trim();

            if (commander.IsInputInvalid(value, "Producer name or ID"))
            {
                MessageBox.Show($"Input value is default or empty, type correct value.");
                return;
            }
            if (int.TryParse(value, out int parsedIntValue))
            {
                if (!commander.ExistsInDatabaseByID(OSHome.DbSources.Producers, parsedIntValue))
                {
                    MessageBox.Show($"Producer with ID: {parsedIntValue} doesn't exists in database.");
                    return;
                }
            }
            else
            {
                if (!commander.ExistsInDatabaseByNameCaseSensitive(OSHome.DbSources.Producers, value))
                {
                    MessageBox.Show($"Producer with name: {value} doesn't exists in database.");
                    return;
                }
            }
            if (parsedIntValue == 0)
            {
                int producerId = db.Producers.Single(x => x.producer_name == value).producer_id;
                if (commander.IsAssignedToEntity(OSHome.DbSources.Producers, producerId))
                {
                    MessageBox.Show($"Producer is already assigned to product, can't remove.");
                    return;
                }
                if (!commander.FinalAcceptancePrompt())
                {
                    return;
                }
                commander.RemoveFromDb(OSHome.DbSources.Producers, producerId);
            }
            else
            {
                if (commander.IsAssignedToEntity(OSHome.DbSources.Producers, parsedIntValue))
                {
                    MessageBox.Show($"Producer is already assigned to product, can't remove.");
                    return;
                }
                if (!commander.FinalAcceptancePrompt())
                {
                    return;
                }
                commander.RemoveFromDb(OSHome.DbSources.Producers, parsedIntValue);
            }
            MessageBox.Show("Producer successfully removed from database.");
            RemoveNameTB.Text = "Producer name or ID";
        }
Example #4
0
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            string stringId = RemoveIDTB.Text.Trim();

            if (commander.IsInputInvalid(stringId, "ID") || !int.TryParse(stringId, out int id))
            {
                MessageBox.Show($"{stringId} is not valid id.");
                return;
            }
            if (!commander.ExistsInDatabaseByID(OSHome.DbSources.Products, id) || commander.IsAssignedToEntity(OSHome.DbSources.Products, id))
            {
                MessageBox.Show($"Product doesn't exist in database or is already assigned to some order.");
                return;
            }
            if (!commander.FinalAcceptancePrompt())
            {
                return;
            }
            commander.RemoveFromDb(OSHome.DbSources.Products, id);
            MessageBox.Show($"Successfully removed from database.");
            RemoveIDTB.Text = "ID";
        }
Example #5
0
        private void Update_Click(object sender, RoutedEventArgs e)
        {
            string stringNewFen = UpdateFENTB.Text.Trim();
            string stringId     = UpdateIdNTB.Text.Trim();

            if (commander.IsInputInvalid(stringNewFen, "New FEN") || commander.IsInputInvalid(stringId, "ID"))
            {
                MessageBox.Show($"Invalid input");
                return;
            }
            if (stringNewFen.Length < 8)
            {
                MessageBox.Show($"FEN must consist of 8-10 letter or digits.");
                return;
            }
            if (!commander.LettersAndDigitsInputOnly(stringNewFen))
            {
                MessageBox.Show($"FEN must consist of letters or digits only, {stringNewFen} is not valid FEN number");
                return;
            }
            if (!int.TryParse(stringId, out int id))
            {
                MessageBox.Show($"Invalid id.");
                return;
            }
            if (!commander.ExistsInDatabaseByID(OSHome.DbSources.Clients, id))
            {
                MessageBox.Show($"No client with ID: {id} in database.");
                return;
            }
            Clients existingClient = db.Clients.Single(x => x.client_id == id);

            if (existingClient.firm_evidence_number == stringNewFen)
            {
                MessageBox.Show($"New FEN is same as existing FEN.");
                return;
            }
            if (!commander.FinalAcceptancePrompt())
            {
                return;
            }
            existingClient.firm_evidence_number = stringNewFen;
            db.SaveChanges();
            clientsDataGrid.Items.Refresh();
            MessageBox.Show($"Successfully updated FEN number for client: ID: {existingClient.client_id}, {existingClient.client_first_name} {existingClient.client_name}.");
            UpdateFENTB.Text = "New FEN";
            UpdateIdNTB.Text = "ID";
        }