//type
        #endregion
        #region Methods
        public void DocumentNumbering()
        {
            var order = _uow.AccDocumentHeaders.OrderBy(x => x.DocumentDate).ThenBy(x => x.DailyNumber).ToList();
            var getDocumentNumbering = _uow.Set <DocumentNumbering>().AsNoTracking().FirstOrDefault(x => x.AccountDocumentId == 1);
            var startNumber          = getDocumentNumbering.StartNumber;

            for (long i = 1; i < order.Count(); i++)
            {
                int ii = Convert.ToInt32(i);
                order[ii].DocumentNumber = startNumber;
                startNumber++;
            }
            _uow.SaveChanges();
            var manager = new RadDesktopAlertManager(AlertScreenPosition.TopCenter);

            var alert = new RadDesktopAlert
            {
                FlowDirection = FlowDirection.RightToLeft,
                Header        = "اطلاعات",
                Content       = ".شماره گذاری با موفقیت انجام شد",
                ShowDuration  = 2000,
            };

            manager.ShowAlert(alert);
        }
 private async void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     ////await _uow.SaveChangesAsync();
     //_virtualQueryableCollectionView.AddNew(new AccDocumentHeader() {TypeDocumentId=1 });
     //_virtualQueryableCollectionView.VirtualItemCount++;
     //AccDocumentHeaderRadGridView.Rebind();
     ////_virtualQueryableCollectionView.MoveCurrentToNext();
     //_uow.AccDocumentHeaders.Add(new AccDocumentHeader { TypeDocumentId = 1 });
     var r = _uow.SaveChanges();
 }
Esempio n. 3
0
 public int DeleteGL(GL gL)
 {
     if (HasTL(gL.GLId) == false)
     {
         _uow.GLs.Attach(gL);
         _uow.GLs.Remove(gL);
         return(_uow.SaveChanges());
     }
     else
     {
         return(0);
     }
 }
Esempio n. 4
0
 public int DeleteSL(SL sL)
 {
     if (HasItem(sL.SLId) == false)
     {
         _uow.SLs.Attach(sL);
         _uow.SLs.Remove(sL);
         return(_uow.SaveChanges());
     }
     else
     {
         return(0);
     }
 }
Esempio n. 5
0
 public int DeleteDL(DL dL)
 {
     if (HasItem(dL.DLId) == false)
     {
         _uow.DLs.Attach(dL);
         _uow.DLs.Remove(dL);
         return(_uow.SaveChanges());
     }
     else
     {
         return(0);
     }
 }
Esempio n. 6
0
        public void Save()
        {
            if (BankAccount != null)
            {
                //stop Entity Framework from trying to save/insert child objects?
                var items = BankAccounts.ToList();
                for (int i = 0; i < items.Count; i++)
                {
                    if (items[i].Bank != null)
                    {
                        _uow.Entry(items[i].Bank).State = EntityState.Detached;
                    }
                    if (items[i].AccountType != null)
                    {
                        _uow.Entry(items[i].AccountType).State = EntityState.Detached;
                    }
                    if (items[i].CurrencyType != null)
                    {
                        _uow.Entry(items[i].CurrencyType).State = EntityState.Detached;
                    }
                }
            }



            var x = _uow.SaveChanges();
        }
Esempio n. 7
0
        public void Save()
        {
            var SelectedStocks = Stocks.Where(x => x.IsSelected == true);

            Product.Stocks.Clear();
            foreach (var stock in SelectedStocks)
            {
                //if (!Product.Stocks.Any(x => x.StockId == stock.StockId))
                Product.Stocks.Add(stock);
                //else
                //    Product.Stocks.Add(stock);
            }
            var ss = _uow.Entry <Product>(Product).State;

            _uow.SaveChanges();
        }
        public void Save()
        {
            var stcDocumentHeader = StcDocumentHeaders.CurrentItem as StcDocumentHeader;

            if (stcDocumentHeader != null)
            {
                //stop Entity Framework from trying to save/insert child objects?
                //var items = stcDocumentHeader.StcDocumentItems.ToList();
                //for (int i = 0; i < items.Count; i++)
                //{
                //    if (items[i].DL1 != null)
                //        _uow.Entry(items[i].DL1).State = EntityState.Detached;
                //    if (items[i].DL2 != null)
                //        _uow.Entry(items[i].DL2).State = EntityState.Detached;
                //    if (items[i].Currency != null)
                //        _uow.Entry(items[i].Currency).State = EntityState.Detached;
                //}
            }
            _uow.SaveChanges();
        }
Esempio n. 9
0
        public void SaveChanges(EditableAccDocumentHeader selectedHeader)
        {
            var existingParent = _uow.AccDocumentHeaders
                                 .Where(p => p.AccDocumentHeaderId == selectedHeader.AccDocumentHeaderId)
                                 .Include(p => p.AccDocumentItems)
                                 .SingleOrDefault();

            if (existingParent != null)
            {
                // Update parent
                _uow.Entry(existingParent).CurrentValues.SetValues(selectedHeader);

                // Delete AccDocumentItems
                //foreach (var existingChild in existingParent.AccDocumentItems.ToList())
                //{
                //    if (!selectedHeader.AccDocumentItems.Any(c => c.AccDocumentItemId == existingChild.AccDocumentItemId))
                //        _uow.AccDocumentItems.Remove(existingChild);
                //}


                //// Update and Insert AccDocumentItems
                //foreach (var childModel in selectedHeader.AccDocumentItems)
                //{
                //    var existingChild = existingParent.AccDocumentItems
                //        .SingleOrDefault(c => c.AccDocumentItemId == childModel.AccDocumentItemId);

                //    if (existingChild != null)
                //        // Update child
                //        _uow.Entry(existingChild).CurrentValues.SetValues(childModel);
                //    else
                //    {
                //        // Insert child
                //        var newChild = new AccDocumentItem
                //        {
                //            SLId = childModel.SLId,
                //            DL1Id = childModel.DL1Id,
                //            DL2Id = childModel.DL2Id
                //            ,
                //            Debit = childModel.Debit,
                //            Credit = childModel.Credit,
                //            Description1 = childModel.Description1,
                //            Description2 = childModel.Description2
                //        };// AutoMapper.Mapper.Map<EditableAccDocumentItem, AccDocumentItem>(childModel);// new AccDocumentItem
                //          //{
                //          //    //Data = childModel.Data,
                //          //    ////...
                //          //};
                //        existingParent.AccDocumentItems.Add(newChild);
                //    }
                //}

                _uow.SaveChanges();
            }
        }
Esempio n. 10
0
 //public int GetLastRow()
 //{
 //    if (_uow.AccDocumentItems.Any())
 //        return _uow.AccDocumentItems.Select(x => x.AccRow).Max();
 //    return 1;
 //}
 public void  AddAccDocumentItemsAsync(IEnumerable <AccDocumentItem> accDocumentItem)
 {
     //  _uow.AccDocumentItems.AddRange(accDocumentItem);
     foreach (var item in accDocumentItem)
     {
         //var st = _uow.Entry(item).State;
         //_uow.AccDocumentItems.Attach(item);
         _uow.Set <AccDocumentItem>().AddOrUpdate(x => x.AccDocumentItemId, item);
     }
     // await _uow.SaveChangesAsync().ConfigureAwait(false);
     _uow.SaveChanges();
 }
Esempio n. 11
0
 public void ApplyPermission(List <int> actionIds, bool hasAccess, bool isMenu = true)
 {
     using (var uow = new SainaDbContext())
     {
         uow.Accesses.Where(x => actionIds.Contains(x.OperationId ?? 0)).ToList().ForEach(x => x.HasAccess = hasAccess);
         if (isMenu)
         {
             items.SelectMany(x => x.Views).SelectMany(x => x.Operations).Where(x => actionIds.Contains(x.OperationId)).ToList().ForEach(x => x.HasAccess = hasAccess);
         }
         uow.SaveChanges();
     }
 }
        public void Loaded()
        {
            _uow = new SainaDbContext();
            var ids = new List <int> {
                1, 3, 4, 5, 6
            };

            TypeDocuments          = _uow.TypeDocuments.Where(x => !ids.Contains(x.TypeDocumentId)).ToList();
            SLs                    = _uow.SLs.Where(x => x.Status == true).ToList();
            DLs                    = _uow.DLs.ToList();
            SLStandardDescriptions = _uow.SLStandardDescriptions.ToList();
            Currencies             = _uow.Currencies.ToList();

            AccDocumentHeaders = new QueryableCollectionView(_uow.AccDocumentHeaders.Include(x => x.AccDocumentItems.Select(s => s.SL)).Where(x => _uow.ShamsiToMiladi(x.DocumentDate, "Saal") == _appContextService.CurrentFinancialYear.ToString() &&
                                                                                                                                              (HeaderId == 0 || x.AccDocumentHeaderId == HeaderId) &&
                                                                                                                                              (TypeEnum == 0 || x.TypeDocumentId == TypeEnum)).OrderBy(x => x.DocumentNumber).ToList());


            _appContextService.PropertyChanged += (sender, eventArgs) =>
            {
                try
                {
                    if (eventArgs.PropertyName == "CurrentFinancialYear")
                    {
                        var dateDocument = _appContextService.CurrentFinancialYear;
                        ids = new List <int> {
                            1, 3, 4, 5, 6
                        };
                        TypeDocuments          = _uow.TypeDocuments.Where(x => !ids.Contains(x.TypeDocumentId)).ToList();
                        SLs                    = _uow.SLs.Where(x => x.Status == true).ToList();
                        DLs                    = _uow.DLs.ToList();
                        SLStandardDescriptions = _uow.SLStandardDescriptions.ToList();
                        Currencies             = _uow.Currencies.ToList();
                        // AccDocumentHeaders = new QueryableCollectionView(_uow.AccDocumentHeaders.Include(x => x.AccDocumentItems).Where(x => _uow.ShamsiToMiladi(x.DocumentDate, "Saal") == _appContextService.CurrentFinancialYear.ToString()).ToList());
                        AccDocumentHeaders = new QueryableCollectionView(_uow.AccDocumentHeaders.Include(x => x.AccDocumentItems.Select(s => s.SL)).Where(x => _uow.ShamsiToMiladi(x.DocumentDate, "Saal") == _appContextService.CurrentFinancialYear.ToString() &&
                                                                                                                                                          (HeaderId == 0 || x.AccDocumentHeaderId == HeaderId) &&
                                                                                                                                                          (TypeEnum == 0 || x.TypeDocumentId == TypeEnum)).OrderBy(x => x.DocumentNumber).ToList());
                    }
                }
                catch (Exception)
                { }
            };
            AccDocumentHeaders.CollectionChanged += AccDocumentHeaders_CollectionChanged;


            _uow.SaveChanges();
        }
        public void LoadRefresh()
        {
            _uow = new SainaDbContext();
            var ids = new List <int> {
                1, 3, 4, 5, 6
            };

            TypeDocuments          = _uow.TypeDocuments.Where(x => !ids.Contains(x.TypeDocumentId)).ToList();
            SLs                    = _uow.SLs.Where(x => x.Status == true).ToList();
            DLs                    = _uow.DLs.ToList();
            SLStandardDescriptions = _uow.SLStandardDescriptions.ToList();
            Currencies             = _uow.Currencies.ToList();
            AccDocumentHeaders     = new QueryableCollectionView(_uow.AccDocumentHeaders.Include(x => x.AccDocumentItems.Select(s => s.SL)).Where(x => _uow.ShamsiToMiladi(x.DocumentDate, "Saal") == _appContextService.CurrentFinancialYear.ToString()
                                                                                                                                                  ).ToList());
            AccDocumentHeaders.CollectionChanged += AccDocumentHeaders_CollectionChanged;
            _uow.SaveChanges();
        }
        private async void OnDraft()
        {
            //_uow.AccDocumentHeaders.
            AccDocumentHeader.Status = StatusEnum.Draft;
            //_accDocumentItemListViewModel.SaveCommand.Execute(null);
            var test0 = _uow.Entry(testAccDocumentHeader).State;

            testAccDocumentHeader = Mapper.Map <EditableAccDocumentHeader, AccDocumentHeader>(_accDocumentHeader, testAccDocumentHeader);
            var test   = _uow.Entry(testAccDocumentHeader).State;
            var test2v = _uow.Entry(testAccDocumentHeader.AccDocumentItems.First()).State;

            testAccDocumentHeader.AccDocumentItems = Mapper.Map(AccDocumentItemListViewModel.AccDocumentItems.ToList(), testAccDocumentHeader.AccDocumentItems);
            ////IEnumerable<AccDocumentItem> itemsToBeDeleted = new List<AccDocumentItem>();
            ////Mapper.Map(AccDocumentItemListViewModel.ItemsToBeDeleted, itemsToBeDeleted);
            var test2 = _uow.Entry(testAccDocumentHeader.AccDocumentItems.First()).State;

            _uow.SaveChanges();

            //await _accDocumentHeadersService.SaveHeaderAndItemsAsync(testAccDocumentHeader, testAccDocumentHeader.AccDocumentItems, itemsToBeDeleted);
        }
        public bool SaveSystemSettingSaleModel(SystemSettingSaleModel systemSettingSaleModel)
        {
            var dict = systemSettingSaleModel.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)
                       .ToDictionary(prop => prop.Name, prop => prop?.GetValue(systemSettingSaleModel, null)?.ToString() ?? "");
            var keyValues = _keyValues.Where(x => dict.Keys.Contains(x.Key)).ToList();

            if (keyValues.Any())
            {
                keyValues.ForEach(x => x.Value = dict[x.Key]);
            }
            else
            {
                foreach (var item in dict)
                {
                    _keyValues.Add(new KeyValue {
                        Key = item.Key, Value = item.Value
                    });
                }
                //_uow.SaveChanges();
            }
            return(_uow.SaveChanges() != 0);
        }
Esempio n. 16
0
 internal void AddBankAccount(BankAccount bankAccount)
 {
     _uow.BankAccounts.Add(bankAccount);
     _uow.SaveChanges();
 }
Esempio n. 17
0
        private void ContextMenuClick(object sender, RoutedEventArgs e)
        {
            if (this.ClickedTreeViewItem == null)
            {
                return;
            }

            ProductRack item = this.ClickedTreeViewItem.DataContext as ProductRack;

            if (item == null)
            {
                return;
            }

            string header = (e.OriginalSource as RadMenuItem).Header as string;

            switch (header)
            {
            case "New Child":
                ChildListWindow childListWindow = SmObjectFactory.Container.GetInstance <ChildListWindow>();

                var tree = childListWindow.DataContext as ChildListWindowViewModel;

                childListWindow.ShowDialog();
                ProductRack newChild = new ProductRack();
                newChild.ProductRackTitle = childListWindow.titleTextbox.Text;
                using (var uow = new SainaDbContext())
                {
                    // uow.ProductRacks.Include(Parent).Add(Parent(newChild));
                    item.Items.Add(newChild);

                    uow.ProductRacks.Add(item);
                    uow.SaveChanges();
                    item.IsExpanded = true;     // Ensure that the new child is visible
                }

                //  item.Items.Add(newChild)

                break;

            case "New Sibling":
                childListWindow = SmObjectFactory.Container.GetInstance <ChildListWindow>();
                ProductRack newSibling = new ProductRack();
                newSibling.ProductRackTitle = childListWindow.titleTextbox.Text;

                item.Parent.Items.Add(newSibling);
                break;

            case "Delete":
                using (var uow = new SainaDbContext())
                {
                    item.Parent.Items.Remove(item);
                    //    uow.ProductRacks.Remove(item);
                    uow.SaveChanges();
                }

                break;

            case "Edit":
                using (var uow = new SainaDbContext())
                {
                    this.ClickedTreeViewItem.IsInEditMode = true;
                    uow.SaveChanges();
                }
                break;

            case "Select":
                this.ClickedTreeViewItem.IsSelected = true;
                break;
            }
        }
Esempio n. 18
0
 public void Save()
 {
     var r = _uow.SaveChanges();
 }
Esempio n. 19
0
        private void ContextMenuClick(object sender, RoutedEventArgs e)
        {
            //GL gl = ClickedTreeViewItem.DataContext as GL;
            //TL tl = ClickedTreeViewItem.DataContext as TL;
            var SystemAccountingSettingModel = _systemAccountingSettingsService.GetSystemAccountingSettingModel();

            int.TryParse(SystemAccountingSettingModel.GLLength, out int SystemAccountingSettingModelGLLength);

            // var SystemAccountingSettingModelGLLength = int.Parse(SystemAccountingSettingModel.GLLength);
            long   lastGLCode   = _gLsService.GetLastGLCode() + 1;
            var    lastGLLenght = (lastGLCode.ToString()).Length;
            string tag          = (e.OriginalSource as RadMenuItem).Tag as string;

            if (ClickedTreeViewItem == null)
            {
                if (lastGLLenght == SystemAccountingSettingModelGLLength)
                {
                    AddGLTreeItemWindow addGLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddGLTreeItemWindow>();
                    var treeGL = addGLTreeItemWindow0.DataContext as AddGLTreeItemWindowViewModel;
                    //   treeGL.GL = gl;
                    treeGL.SaveClicked += (g) =>
                    {
                        //addTLTreeItemWindow0.DataItem.GL = gl;
                        g.ImageUrl = "../../Resources/cian.png";
                        _vm.AddGL(g);
                        g.GLId = _vm.GetGLId(g.GLCode);
                        _vm.Items.Add(g);
                        //_vm.Save();
                        addGLTreeItemWindow0.Close();
                        // gl.TLs.Add(addTLTreeItemWindow0.DataItem);
                        //     gl.IsExpanded = true; // Ensure that the new child is visible
                        //using (var uow = new SainaDbContext())
                        //{
                        //    uow.GLs.Add(g);
                        //    uow.SaveChanges();
                        //    addGLTreeItemWindow0.Close();
                        //}
                    };
                    addGLTreeItemWindow0.Width    = 1000;
                    addGLTreeItemWindow0.Height   = 500;
                    addGLTreeItemWindow0.CanClose = true;
                    addGLTreeItemWindow0.Owner    = Window.GetWindow(this);
                    addGLTreeItemWindow0.Show();
                }
                else
                {
                    DialogParameters parameters = new DialogParameters();
                    parameters.OkButtonContent = "بستن";
                    parameters.Header          = "اخطار";
                    parameters.Content         = " شماره گذاری این حساب  به پایان رسیده است";
                    RadWindow.Alert(parameters);
                }
            }
            else if (ClickedTreeViewItem.DataContext is GL gl)
            {
                if (tag == "newGL")
                {
                    if (_accessUtility.HasAccess(70))
                    {
                        if (lastGLLenght == SystemAccountingSettingModelGLLength)
                        {
                            AddGLTreeItemWindow addGLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddGLTreeItemWindow>();
                            var treeGL = addGLTreeItemWindow0.DataContext as AddGLTreeItemWindowViewModel;
                            //   treeGL.GL = gl;
                            treeGL.SaveClicked += (g) =>
                            {
                                //addTLTreeItemWindow0.DataItem.GL = gl;
                                g.ImageUrl = "../../Resources/cian.png";
                                _vm.AddGL(g);
                                g.GLId = _vm.GetGLId(g.GLCode);
                                _vm.Items.Add(g);
                                //_vm.Save();
                                addGLTreeItemWindow0.Close();
                                // gl.TLs.Add(addTLTreeItemWindow0.DataItem);
                                gl.IsExpanded = true; // Ensure that the new child is visible
                                                      //using (var uow = new SainaDbContext())
                                                      //{
                                                      //    uow.GLs.Add(g);
                                                      //    uow.SaveChanges();
                                                      //    addGLTreeItemWindow0.Close();
                                                      //}
                            };
                            addGLTreeItemWindow0.Width    = 1000;
                            addGLTreeItemWindow0.Height   = 500;
                            addGLTreeItemWindow0.CanClose = true;
                            addGLTreeItemWindow0.Owner    = Window.GetWindow(this);
                            addGLTreeItemWindow0.Show();
                        }

                        else
                        {
                            DialogParameters parameters = new DialogParameters();
                            parameters.OkButtonContent = "بستن";
                            parameters.Header          = "اخطار";
                            parameters.Content         = " شماره گذاری این حساب  به پایان رسیده است";
                            RadWindow.Alert(parameters);
                        }
                    }
                    // break;
                }
                else if (tag == "newTL")
                {
                    if (_accessUtility.HasAccess(70))
                    {
                        AddTLTreeItemWindow addTLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddTLTreeItemWindow>();
                        var treeTL = addTLTreeItemWindow0.DataContext as AddTLTreeItemWindowViewModel;

                        treeTL.TL           = new TL();
                        treeTL.TL.GLId      = gl.GLId;
                        treeTL.TL.GL        = gl;
                        treeTL.SaveClicked += (t) =>
                        {
                            //addTLTreeItemWindow0.DataItem.GL = gl;
                            //t.GLId = gl.GLId;
                            t.ImageUrl = "../../Resources/cian.png";
                            _vm.AddTL(t);
                            t.GLId = _vm.GetTLId(t.TLCode);
                            gl.TLs.Add(t);
                            //_vm.Save();
                            addTLTreeItemWindow0.Close();
                            gl.IsExpanded = true; // Ensure that the new child is visible
                                                  //using (var uow = new SainaDbContext())
                                                  //{
                                                  //    uow.TLs.Add(t);
                                                  //    //uow.Entry(gl).State = EntityState.Modified;
                                                  //    var vv = uow.SaveChanges();
                                                  //    addTLTreeItemWindow0.Close();
                                                  //}
                        };
                        addTLTreeItemWindow0.Width    = 1000;
                        addTLTreeItemWindow0.Height   = 500;
                        addTLTreeItemWindow0.CanClose = true;
                        addTLTreeItemWindow0.Owner    = Window.GetWindow(this);
                        addTLTreeItemWindow0.Show();
                    }
                }
                else if (tag == "edit")
                {
                    if (_accessUtility.HasAccess(71))
                    {
                        AddGLTreeItemWindow addGLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddGLTreeItemWindow>();
                        var treeGL = addGLTreeItemWindow0.DataContext as AddGLTreeItemWindowViewModel;
                        treeGL.GL = gl;
                        using (var uow = new SainaDbContext())
                        {
                            var hasGL = uow.GLs.FirstOrDefault(x => x.GLId == gl.GLId)?.TLs?.Any() == true;
                            if (hasGL == true)
                            {
                                addGLTreeItemWindow0.gLCodeTextbox.IsEnabled = false;
                            }
                            treeGL.SaveClicked += (g) =>
                            {
                                //addTLTreeItemWindow0.DataItem.GL = gl;
                                g.GLId     = gl.GLId;
                                g.ImageUrl = "../../Resources/cian.png";
                                // gl.TLs.Add(addTLTreeItemWindow0.DataItem);
                                gl.IsExpanded = true; // Ensure that the new child is visible
                                                      // _vm.Save();

                                uow.GLs.Attach(g);
                                uow.Entry <GL>(g).State = EntityState.Modified;
                                //  uow.GLs(g);
                                var x = uow.SaveChanges();
                                addGLTreeItemWindow0.Close();
                            };
                        }
                        addGLTreeItemWindow0.Width    = 1000;
                        addGLTreeItemWindow0.Height   = 500;
                        addGLTreeItemWindow0.CanClose = true;
                        addGLTreeItemWindow0.Owner    = Window.GetWindow(this);
                        addGLTreeItemWindow0.Show();
                    }
                    // break;
                }
                else if (tag == "delete")
                {
                    if (_accessUtility.HasAccess(72))
                    {
                        using (var uow = new SainaDbContext())
                        {
                            var hasGL = uow.GLs.FirstOrDefault(x => x.GLId == gl.GLId)?.TLs?.Any() == true;

                            if (hasGL == false)
                            {
                                DialogParameters parameters = new DialogParameters();
                                parameters.OkButtonContent     = "بله، مطمئنم";
                                parameters.CancelButtonContent = "خیر";
                                parameters.Header  = "اخطار";
                                parameters.Content = "آیا برای حذف  مطمئن هستید؟";
                                parameters.Closed  = OnClosed;
                                RadWindow.Confirm(parameters);
                                _dialogResult = _dialogResult == true;
                                // _dialogResult == true;
                            }
                            else
                            {
                                DialogParameters parameters = new DialogParameters();
                                parameters.OkButtonContent = "بستن";
                                parameters.Header          = "اخطار";
                                parameters.Content         = ".امکان حذف وجود ندارد";
                                // parameters.Closed = OnClosed;
                                RadWindow.Alert(parameters);
                                _dialogResult = false;
                            }
                            if (_dialogResult == true)
                            {
                                //  uow.GLs.Attach(gl);
                                var test = uow.GLs.ToList().Select(x => x.GLId);
                                _vm.Items.Remove(gl);
                                uow.Database.ExecuteSqlCommand($"Delete Info.GLs where  GLId={gl.GLId} ");
                                // uow.RejectChanges();
                                // uow.GLs.Attach(new GL { GLId = gl.GLId });
                                //uow.Entry<GL>(gl).State = EntityState.Deleted;
                                //// uow.GLs.Remove(new GL { GLId=gl.GLId});
                                uow.SaveChanges();
                                var manager = new RadDesktopAlertManager(AlertScreenPosition.TopCenter, new Point(0, 0), 100);

                                var alert = new RadDesktopAlert
                                {
                                    FlowDirection = FlowDirection.RightToLeft,
                                    Header        = "اطلاعات",
                                    Content       = ".حذف با موفقیت انجام شد",
                                    ShowDuration  = 5000,
                                };
                                manager.ShowAlert(alert);
                            }
                        }
                    }
                }
            }
            else if (ClickedTreeViewItem.DataContext is TL tl)
            {
                if (tag == "newTL")
                {
                    if (_accessUtility.HasAccess(70))
                    {
                        AddTLTreeItemWindow addTLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddTLTreeItemWindow>();
                        gl = tl.GL;
                        var treeTL = addTLTreeItemWindow0.DataContext as AddTLTreeItemWindowViewModel;
                        treeTL.TL      = new TL();
                        treeTL.TL.GLId = gl.GLId;
                        treeTL.TL.GL   = gl;
                        //treeTL.SelectedGL = gl;
                        //treeTL.TL = new TL { GL = gl, GLId = gl.GLId };
                        treeTL.SaveClicked += (t) =>
                        {
                            //   t.GLId = gl.GLId;
                            t.ImageUrl = "../../Resources/cian.png";
                            _vm.AddTL(t);
                            t.GLId = _vm.GetTLId(t.TLCode);
                            gl.TLs.Add(t);
                            addTLTreeItemWindow0.Close();

                            gl.IsExpanded = true; // Ensure that the new child is visible
                                                  //using (var uow = new SainaDbContext())
                                                  //{
                                                  //    uow.TLs.Add(t);
                                                  //   // uow.Entry(gl).State = EntityState.Modified;

                            //    uow.SaveChanges();
                            //    addTLTreeItemWindow0.Close();
                            //}
                        };
                        addTLTreeItemWindow0.Width    = 1000;
                        addTLTreeItemWindow0.Height   = 500;
                        addTLTreeItemWindow0.CanClose = true;
                        addTLTreeItemWindow0.Owner    = Window.GetWindow(this);
                        addTLTreeItemWindow0.Show();
                    }
                }
                else if (tag == "newSL")
                {
                    if (_accessUtility.HasAccess(70))
                    {
                        AddSLTreeItemWindow addSLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddSLTreeItemWindow>();
                        var treeSL = addSLTreeItemWindow0.DataContext as AddSLTreeItemWindowViewModel;
                        treeSL.SL      = new SL();
                        treeSL.SL.TLId = tl.TLId;
                        treeSL.SL.TL   = tl;
                        //treeSL.SelectedTL = tl;
                        //treeSL.SL = new SL { TL = tl, TLId = tl.TLId };
                        treeSL.SaveClicked += (s) =>
                        {
                            //addTLTreeItemWindow0.DataItem.GL = gl;
                            // s.TLId = tl.TLId;
                            s.ImageUrl = "../../Resources/cian.png";
                            _vm.AddSL(s);
                            s.TLId = _vm.GetSLId(s.SLCode);

                            tl.SLs.Add(s);
                            // _vm.Save();
                            addSLTreeItemWindow0.Close();
                            tl.IsExpanded = true; // Ensure that the new child is visible
                                                  //using (var uow = new SainaDbContext())
                                                  //{
                                                  //    uow.SLs.Add(s);
                                                  //    uow.Entry(tl).State = EntityState.Modified;

                            //    uow.SaveChanges();
                            //    addSLTreeItemWindow0.Close();
                            //}
                        };
                        addSLTreeItemWindow0.Width    = 1000;
                        addSLTreeItemWindow0.Height   = 500;
                        addSLTreeItemWindow0.CanClose = true;
                        addSLTreeItemWindow0.Owner    = Window.GetWindow(this);
                        addSLTreeItemWindow0.Show();
                    }
                }
                else if (tag == "edit")
                {
                    if (_accessUtility.HasAccess(71))
                    {
                        AddTLTreeItemWindow addTLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddTLTreeItemWindow>();
                        var treeTL = addTLTreeItemWindow0.DataContext as AddTLTreeItemWindowViewModel;
                        treeTL.TL = tl;
                        using (var uow = new SainaDbContext())
                        {
                            var hasTL = uow.TLs.FirstOrDefault(x => x.TLId == tl.TLId)?.SLs?.Any() == true;
                            if (hasTL == true)
                            {
                                addTLTreeItemWindow0.tLCodeTextbox.IsEnabled = false;
                            }
                            treeTL.SaveClicked += (t) =>
                            {
                                //addTLTreeItemWindow0.DataItem.GL = gl;
                                t.TLId     = tl.TLId;
                                t.ImageUrl = "../../Resources/cian.png";
                                // gl.TLs.Add(addTLTreeItemWindow0.DataItem);
                                tl.IsExpanded = true; // Ensure that the new child is visible

                                uow.TLs.Attach(t);
                                uow.Entry <TL>(t).State = EntityState.Modified;
                                //  uow.GLs(g);
                                //  uow.GLs(g);
                                uow.SaveChanges();
                                addTLTreeItemWindow0.Close();
                            };
                        }
                        addTLTreeItemWindow0.Width    = 1000;
                        addTLTreeItemWindow0.Height   = 500;
                        addTLTreeItemWindow0.CanClose = true;
                        addTLTreeItemWindow0.Owner    = Window.GetWindow(this);
                        addTLTreeItemWindow0.Show();
                    }
                }
                else if (tag == "delete")
                {
                    if (_accessUtility.HasAccess(72))
                    {
                        using (var uow = new SainaDbContext())
                        {
                            var hasTL = uow.TLs.FirstOrDefault(x => x.TLId == tl.TLId)?.SLs?.Any() == true;

                            if (hasTL == false)
                            {
                                DialogParameters parameters = new DialogParameters();
                                parameters.OkButtonContent     = "بله، مطمئنم";
                                parameters.CancelButtonContent = "خیر";
                                parameters.Header  = "اخطار";
                                parameters.Content = "آیا برای حذف  مطمئن هستید؟";
                                parameters.Closed  = OnClosed;
                                RadWindow.Confirm(parameters);
                                _dialogResult = _dialogResult == true;
                                // _dialogResult == true;
                            }
                            else
                            {
                                DialogParameters parameters = new DialogParameters();
                                parameters.OkButtonContent = "بستن";
                                parameters.Header          = "اخطار";
                                parameters.Content         = ".امکان حذف وجود ندارد";
                                // parameters.Closed = OnClosed;
                                RadWindow.Alert(parameters);
                                _dialogResult = false;
                            }
                            if (_dialogResult == true)
                            {
                                //  uow.GLs.Attach(gl);
                                //   var test = uow.TLs.ToList().Select(x => x.TLId);
                                foreach (var item in _vm.Items)
                                {
                                    item.TLs.Remove(tl);
                                }
                                uow.Database.ExecuteSqlCommand($"Delete Info.TLs where  TLId={tl.TLId} ");
                                // uow.RejectChanges();
                                // uow.GLs.Attach(new GL { GLId = gl.GLId });
                                //uow.Entry<GL>(gl).State = EntityState.Deleted;
                                //// uow.GLs.Remove(new GL { GLId=gl.GLId});
                                uow.SaveChanges();
                                var manager = new RadDesktopAlertManager(AlertScreenPosition.TopCenter, new Point(0, 0), 100);

                                var alert = new RadDesktopAlert
                                {
                                    FlowDirection = FlowDirection.RightToLeft,
                                    Header        = "اطلاعات",
                                    Content       = ".حذف با موفقیت انجام شد",
                                    ShowDuration  = 5000,
                                };
                                manager.ShowAlert(alert);
                            }
                        }
                    }
                }
            }
            else if (ClickedTreeViewItem.DataContext is SL)
            {
                SL sl = ClickedTreeViewItem.DataContext as SL;

                if (tag == "newSL")
                {
                    if (_accessUtility.HasAccess(70))
                    {
                        AddSLTreeItemWindow addSLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddSLTreeItemWindow>();

                        tl = sl.TL;
                        var treeSL = addSLTreeItemWindow0.DataContext as AddSLTreeItemWindowViewModel;
                        treeSL.SL           = new SL();
                        treeSL.SL.TLId      = tl.TLId;
                        treeSL.SL.TL        = tl;
                        treeSL.SaveClicked += (s) =>
                        {
                            s.TLId     = tl.TLId;
                            s.ImageUrl = "../../Resources/cian.png";
                            tl.SLs.Add(s);
                            _vm.AddSL(s);
                            // _vm.Save();
                            addSLTreeItemWindow0.Close();

                            tl.IsExpanded = true;     // Ensure that the new child is visible
                                                      //using (var uow = new SainaDbContext())
                                                      //{
                                                      //    uow.SLs.Add(s);
                            ////    uow.Entry(tl).State = EntityState.Modified;

                            //    uow.SaveChanges();
                            //    addSLTreeItemWindow0.Close();
                            //}
                        };


                        addSLTreeItemWindow0.Width    = 1000;
                        addSLTreeItemWindow0.Height   = 500;
                        addSLTreeItemWindow0.CanClose = true;
                        addSLTreeItemWindow0.Owner    = Window.GetWindow(this);
                        addSLTreeItemWindow0.Show();
                    }
                }
                else if (tag == "edit")
                {
                    if (_accessUtility.HasAccess(71))
                    {
                        AddSLTreeItemWindow addSLTreeItemWindow0 = SmObjectFactory.Container.GetInstance <AddSLTreeItemWindow>();
                        var treeSL = addSLTreeItemWindow0.DataContext as AddSLTreeItemWindowViewModel;
                        treeSL.SL = sl;
                        using (var uow = new SainaDbContext())
                        {
                            var hasItem = uow.AccDocumentItems.Any(x => x.SLId == sl.SLId);
                            if (hasItem == true)
                            {
                                addSLTreeItemWindow0.sLCodeTextbox.IsEnabled = false;
                                addSLTreeItemWindow0.DL1.IsEnabled           = false;
                                addSLTreeItemWindow0.DL2.IsEnabled           = false;
                            }
                            treeSL.SaveClicked += (s) =>
                            {
                                //addTLTreeItemWindow0.DataItem.GL = gl;
                                s.SLId     = sl.SLId;
                                s.ImageUrl = "../../Resources/cian.png";
                                // gl.TLs.Add(addTLTreeItemWindow0.DataItem);
                                sl.IsExpanded = true; // Ensure that the new child is visible

                                uow.SLs.Attach(s);
                                uow.Entry <SL>(s).State = EntityState.Modified;
                                //  uow.GLs(g);
                                uow.SaveChanges();
                                addSLTreeItemWindow0.Close();
                            };
                        }
                        addSLTreeItemWindow0.Width    = 1000;
                        addSLTreeItemWindow0.Height   = 500;
                        addSLTreeItemWindow0.CanClose = true;
                        addSLTreeItemWindow0.Owner    = Window.GetWindow(this);
                        addSLTreeItemWindow0.Show();
                    }
                }
                else if (tag == "delete")
                {
                    if (_accessUtility.HasAccess(72))
                    {
                        using (var uow = new SainaDbContext())
                        {
                            var hasItem = uow.AccDocumentItems.Any(x => x.SLId == sl.SLId);


                            if (hasItem == false)
                            {
                                DialogParameters parameters = new DialogParameters();
                                parameters.OkButtonContent     = "بله، مطمئنم";
                                parameters.CancelButtonContent = "خیر";
                                parameters.Header  = "اخطار";
                                parameters.Content = "آیا برای حذف  مطمئن هستید؟";
                                parameters.Closed  = OnClosed;
                                RadWindow.Confirm(parameters);
                                _dialogResult = _dialogResult == true;
                                // _dialogResult == true;
                            }
                            else
                            {
                                DialogParameters parameters = new DialogParameters();
                                parameters.OkButtonContent = "بستن";
                                parameters.Header          = "اخطار";
                                parameters.Content         = ".امکان حذف وجود ندارد";
                                // parameters.Closed = OnClosed;
                                RadWindow.Alert(parameters);
                                _dialogResult = false;
                            }
                            if (_dialogResult == true)
                            {
                                //  uow.GLs.Attach(gl);
                                //   var test = uow.TLs.ToList().Select(x => x.TLId);
                                foreach (var item in _vm.Items)
                                {
                                    foreach (var x in item.TLs)
                                    {
                                        if (x.SLs.Remove(sl))
                                        {
                                            break;
                                        }
                                    }
                                }
                                uow.Database.ExecuteSqlCommand($"Delete Info.SLs where  SLId={sl.SLId} ");
                                // uow.RejectChanges();
                                // uow.GLs.Attach(new GL { GLId = gl.GLId });
                                //uow.Entry<GL>(gl).State = EntityState.Deleted;
                                //// uow.GLs.Remove(new GL { GLId=gl.GLId});
                                uow.SaveChanges();
                                var manager = new RadDesktopAlertManager(AlertScreenPosition.TopCenter, new Point(0, 0), 100);

                                var alert = new RadDesktopAlert
                                {
                                    FlowDirection = FlowDirection.RightToLeft,
                                    Header        = "اطلاعات",
                                    Content       = ".حذف با موفقیت انجام شد",
                                    ShowDuration  = 5000,
                                };
                                manager.ShowAlert(alert);
                            }
                        }
                    }
                }
            }
        }
 public void Save()
 {
     _uow.SaveChanges();
 }
 public int SaveChanges()
 {
     return(_uow.SaveChanges());
 }