Exemplo n.º 1
0
        private void CreateNewTGroupEntity(string name)
        {
            if (_context == null)
            {
                return;
            }

            var newEntity = new TGroupClass()
            {
                //id = maxId,
                name = name
            };

            _context.TGroupProperty.Add(newEntity);
        }
Exemplo n.º 2
0
        private void saveGroup_Button_Click(object sender, EventArgs e)
        {
            if (workMode.Equals("Edit"))
            {
                TreeNode currentNode = treeView1.SelectedNode;

                if (tGroupContext == null)
                {
                    return;
                }

                int    id   = Convert.ToInt32(groupId_TextBox.Text);
                string name = groupName_TextBox.Text;

                var TGroupEntityForUpdate = tGroupContext.TGroupProperty.FirstOrDefault(x => x.id == id);
                if (TGroupEntityForUpdate == null)
                {
                    MessageBox.Show(@"Объект, предназначенный для обновления, не найден");
                    return;
                }

                TGroupEntityForUpdate.name    = name;
                groupEditing_GroupBox.Enabled = false;
                tGroupContext.SaveChanges();
            }
            else if (workMode == "Add")
            {
                TreeNode currentNode = treeView1.SelectedNode;

                if (currentNode.Name.Contains("TProperty"))
                {
                    return;
                }
                var name     = currentNode.Name;
                int parentId = Convert.ToInt32(Regex.Replace(name, @"[^\d]+", ""));

                //find maxId in group
                int maxId = -1;
                foreach (var entity in tGroupEntities)
                {
                    if (entity.id > maxId)
                    {
                        maxId = entity.id;
                    }
                }
                maxId++;


                if (!groupName_TextBox.Text.Equals(""))
                {
                    var groupEntity = new TGroupClass()
                    {
                        id   = maxId,
                        name = groupName_TextBox.Text
                    };
                    tGroupEntities.Add(groupEntity);

                    TreeNode newNode = new TreeNode()
                    {
                        Text = groupName_TextBox.Text,
                        Name = maxId + "|Group"
                    };

                    var relationEntity = new TRelationClass()
                    {
                        idPparent = parentId,
                        idChild   = maxId
                    };


                    TreeNode tech = new TreeNode()
                    {
                        Text = "TechnicalGroup",
                        Name = "TechnicalGroup"
                    };
                    newNode.Nodes.Add(tech);
                    currentNode.Nodes.Add(newNode);
                    tGroupContext.SaveChanges();

                    tRelationEntities.Add(relationEntity);
                    tRelationContext.SaveChanges();
                }
                groupId_TextBox.Enabled       = true;
                groupId_TextBox.Text          = "";
                groupEditing_GroupBox.Enabled = false;
            }
        }