private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtResultValue.Text.Trim() != string.Empty && Convert.ToDouble(txtResultValue.Text.Trim()) > 0)
                {
                    txtStandardCost.Text = 0.ToString();
                }

                if (isEditmode)
                {
                    txtCostValue.Text = CalculateCostValue().ToString();
                    if (txtItem.Text != string.Empty)
                    {
                        GetThisComponent();
                        var treeview = _mainWindow.tvBOM.SelectedItem as TreeViewItem;
                        if (treeview != null)
                        {
                            if (itemsService.GetNatureItem(txtItem.Text) == 22413314)
                            {
                                if (txtObs.Text == string.Empty)
                                {
                                    treeview.Header = componentObj.Component.Replace("|", "") + " | " + itemsService.GetDescriptionItem(componentObj.Component).Replace("|", "") + "| Quantidade: " + componentObj.Qty + " | Valor R$: " + componentObj.Costvalue + " | Imagem= " + componentObj.PathFile1.Replace("|", "") + " | Custo R1: " + componentObj.R1Costvalue + " | Desenho: " + componentObj.DrawingComponent;
                                }
                                else
                                {
                                    treeview.Header = componentObj.Component.Replace("|", "") + " | " + itemsService.GetDescriptionItem(componentObj.Component).Replace("|", "") + " | Quantidade: " + componentObj.Qty + " | Valor R$: " + componentObj.Costvalue + " | OBS: " + componentObj.Obs.Replace("|", "") + " | Imagem= " + componentObj.PathFile1.Replace("|", "") + " | Custo R1: " + componentObj.R1Costvalue + " | Desenho: " + componentObj.DrawingComponent;
                                }
                                this.Close();
                            }
                            else if (itemsService.GetNatureItem(txtItem.Text) == 22413312)
                            {
                                Button btn = new Button
                                {
                                    Name        = "btnComponent1",
                                    Cursor      = Cursors.Hand,
                                    Background  = null,
                                    BorderBrush = null,
                                    Content     = new PackIcon {
                                        Kind = PackIconKind.Check, Foreground = Brushes.Green
                                    },
                                };

                                treeview.IsExpanded = true;
                                if (txtObs.Text == string.Empty)
                                {
                                    treeview.Header = new StackPanel
                                    {
                                        Orientation = Orientation.Horizontal,
                                        Children    =
                                        {
                                            new TextBlock {
                                                Text = componentObj.Component.Replace("|", "") + " | " + itemsService.GetDescriptionItem(componentObj.Component).Replace("|", "") + " | Quantidade: " + componentObj.Qty + " | Valor R$: " + componentObj.Costvalue + " | Imagem= " + componentObj.PathFile1.Replace("|", "") + " | Custo R1: " + componentObj.R1Costvalue + " | Desenho: " + componentObj.DrawingComponent
                                            },
                                            btn
                                        }
                                    };
                                }
                                else
                                {
                                    treeview.Header = new StackPanel
                                    {
                                        Orientation = Orientation.Horizontal,
                                        Children    =
                                        {
                                            new TextBlock {
                                                Text = componentObj.Component.Replace("|", "") + " | " + itemsService.GetDescriptionItem(componentObj.Component).Replace("|", "") + " | Quantidade: " + componentObj.Qty + " | Valor R$: " + componentObj.Costvalue + " | OBS: " + componentObj.Obs.Replace("|", "") + " | Imagem= " + componentObj.PathFile1.Replace("|", "") + " | Custo R1: " + componentObj.R1Costvalue + " | Desenho: " + componentObj.DrawingComponent
                                            },
                                            btn
                                        }
                                    };
                                }


                                if (treeview.Items.Count == 0)
                                {
                                    if (treeview.Name == "treeViewLv1")
                                    {
                                        treeview.Items.Add(CompControls());
                                        treeview.Items.Add(OpControls());
                                    }
                                    else if (treeview.Name == "tvLevel2")
                                    {
                                        treeview.Items.Add(CompControls2());
                                        treeview.Items.Add(OpControls2());
                                    }
                                }

                                this.Close();
                            }
                        }
                    }
                }
                else
                {
                    if (txtItem.Text != string.Empty)
                    {
                        txtCostValue.Text = CalculateCostValue().ToString();
                        GetThisComponent();
                        if (_mainWindow.level1 == true)
                        {
                            FillLevel1();
                        }
                        else if (_mainWindow.level2 == true)
                        {
                            FillLevel2();
                        }
                        else if (_mainWindow.level3 == true)
                        {
                            FillLevel3();
                        }
                    }
                }
            }
            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;
                }
            }
        }