private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ValidateFields())
                {
                    if (isEditmode)
                    {
                        double valor = 0;
                        if (txtUoM.Visibility == Visibility.Visible && txtQuantity.Visibility == Visibility.Visible)
                        {
                            valor = (Convert.ToDouble(txtCostOperation.Text) * Convert.ToDouble(txtQuantity.Text));
                        }
                        else
                        {
                            valor = CalculateCostOperation(dpTimeProcess.Text, Convert.ToDouble(txtCostOperation.Text));
                        }

                        txtCostOperation.Text = Math.Round(valor, 2).ToString();
                        var treeview = _mainWindow.tvBOM.SelectedItem as TreeViewItem;
                        if (treeview != null)
                        {
                            treeview.Header = txtOperation.Text.Replace("|", "") + " | " + operationService.GetDescriptionOp(txtOperation.Text) + "| " + "Tempo de Processamento = " + dpTimeProcess.Text + " | Custo: " + txtCostOperation.Text + "| OBS: " + txtObs.Text.Replace("|", "") + " | U.Medida: " + txtUoM.Text + " | Quantidade: " + txtQuantity.Text;
                            this.Close();
                        }
                    }
                    else
                    {
                        double valor = 0;
                        if (txtUoM.Visibility == Visibility.Visible && txtQuantity.Visibility == Visibility.Visible)
                        {
                            valor = (Convert.ToDouble(txtCostOperation.Text) * Convert.ToDouble(txtQuantity.Text));
                        }
                        else
                        {
                            valor = CalculateCostOperation(dpTimeProcess.Text, Convert.ToDouble(txtCostOperation.Text));
                        }

                        txtCostOperation.Text = Math.Round(valor, 2).ToString();
                        if (_mainWindow.level1 == true)
                        {
                            FillLevel1();
                        }
                        else if (_mainWindow.level2 == true)
                        {
                            FillLevel2();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                if (isEditmode == true)
                {
                    isException = true;
                }
            }
            finally
            {
                if (isException)
                {
                    isEditmode  = true;
                    isException = false;
                }
                else
                {
                    isEditmode = false;
                }
            }
        }
        private List <TreeViewItem> OpControlsList()
        {
            List <TreeViewItem> list = new List <TreeViewItem>();
            Button btn = new Button
            {
                Name        = "btnOperation2",
                Cursor      = Cursors.Arrow,
                Background  = null,
                BorderBrush = null,
                Content     = new PackIcon {
                    Kind = PackIconKind.Plus, Foreground = Brushes.DarkCyan
                },
            };

            TreeViewItem chilItemOp = new TreeViewItem
            {
                IsExpanded = true,
                Header     = new StackPanel
                {
                    Name        = "StackPanelOp1",
                    Orientation = Orientation.Horizontal,
                    Children    =
                    {
                        new Label {
                            Content = "Operação nv.2", Width = 109, Foreground = Brushes.DarkCyan, FontWeight = FontWeights.Bold
                        },
                        btn
                    }
                }
            };

            list.Add(chilItemOp);

            foreach (var item in bomService.GetOperationsBOM(txtItem.Text))
            {
                string   timeString = item.ProcessingTime.ToString() + "000";
                double   timeDouble = Convert.ToDouble(timeString);
                double   time       = TimeSpan.FromMilliseconds(timeDouble).TotalHours;
                string   timeStr    = string.Empty;
                string   timeTemp   = TimeSpan.FromHours(time).ToString("h\\:mm");
                string[] vet2       = timeTemp.Split(':');
                if (time.ToString().Contains(","))
                {
                    string[] vet = time.ToString().Split(',');
                    timeStr = vet[0] + ":" + vet2[1];
                }
                else
                {
                    timeStr = time.ToString() + ":" + vet2[1];
                }
                if (timeStr.Length == 4)
                {
                    timeStr = "0" + timeStr;
                }
                TreeViewItem chilItem = new TreeViewItem();
                chilItem.Name = "tvOpLevel1";
                if (item.Notes == string.Empty)
                {
                    chilItem.Header = item.Operation.Replace("|", "") + " | " + opService.GetDescriptionOp(item.Operation).Replace("|", "") + "| " + "Tempo de Processamento = " + timeStr + " | U.Medida: " + "" + " | Quantidade: " + item.Qty;
                }
                else
                {
                    chilItem.Header = item.Operation.Replace("|", "") + " | " + opService.GetDescriptionOp(item.Operation).Replace("|", "") + "| " + "Tempo de Processamento = " + timeStr + " | OBS: " + item.Notes.Replace("|", "") + " | U.Medida: " + "" + " | Quantidade: " + item.Qty;;
                }

                chilItemOp.Items.Add(chilItem);
            }

            return(list);
        }