Beispiel #1
0
        private void BuidAccountsTreeView()
        {
            using (Services.AccountServices abs = new Services.AccountServices())
            {
                var tree = abs.QueryByWithDescendants();
                //var tree = abs.QueryByWithDescendants(x => x.Parent == null ).ToList();

                foreach (var t in tree.ToList())
                {
                    treeView1.Nodes.Add(CreateTreeView(t));
                }
            }
        }
Beispiel #2
0
        private void SaveChanges(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(AccountEdit))
            {
                GetAccountData(_accEditCtrl?.GetData());
                if (ModifyAccount.Count == 0)
                {
                    return;
                }

                using (var abs = new Services.AccountServices())
                {
                    var bt = abs.Query();

                    foreach (var a in ModifyAccount)
                    {
                        switch (a.ModifyStauts)
                        {
                        case 1:    // modify
                            var acc = abs.QueryBy(x => x.Id == a.Id).FirstOrDefault();
                            if (acc != null)
                            {
                                // acc.AssistBy?.Clear();

                                //var changedacc = bt.Attach(acc);

                                //changedacc.Entity.AssistBy.Clear();
                                //changedacc.Entity.CopyNodeValue(a);

                                //acc.AssistBy.Clear();
                                acc.CopyNodeValue(a);
                            }
                            break;

                        case 2:    //new
                            if (a.Parent != null)
                            {
                                var pEntity = bt.Where(x => x.Id == a.Parent.Id).FirstOrDefault();

                                var p = bt.Attach(pEntity);
                                if (p.Entity.Child == null)
                                {
                                    p.Entity.Child = new List <Models.Tree>();
                                }
                                p.Entity.Child.Add(a);
                            }
                            else
                            {
                                bt.Add((Models.Accounts)a);
                            }
                            break;

                        case 3:    //delete
                            var delacc = abs.QueryByWithDescendants(x => x.Id == a.Id).FirstOrDefault();
                            // DeleteData(bt, delacc);

                            if (delacc != null)
                            {
                                bt.Attach(delacc);
                                bt.Remove(delacc);
                            }
                            break;
                        }

                        a.ModifyStauts = 0;
                    }

                    ModifyAccount.Clear();
                    abs.SaveChanges();
                }
            }
            else
            {
                MessageBox.Show("Save List");
            }
        }