private void ButtonGroupSaveClick(object sender, EventArgs e) { var g = (ComputerPartGroup) treeViewGroupsAndParts.SelectedNode.Tag; var parentId = (int) comboBoxGroupParents.SelectedValue; using (var dbContext = new ComputerSetDatabaseContext()) { dbContext.ComputerPartGroups.Attach(g); g.Name = textBoxName.Text; g.Parent = parentId == -1 ? null : dbContext.ComputerPartGroups.Single(x => x.Id == parentId); g.Show = checkBoxGroupShow.Checked; //TODO: g.Sequence dbContext.SaveChanges(); DiagMsg(string.Format("zapisano nowe wartości - {0}", g.Name)); } }
private void ButtonAddNewGroupClick(object sender, EventArgs e) { var g = new ComputerPartGroup {Name = "_Nowa grupa", Show = false}; using (var dbContext = new ComputerSetDatabaseContext()) { var lastSequence = dbContext.ComputerPartGroups.Max(x => x.Sequence); g.Sequence = ++lastSequence; dbContext.ComputerPartGroups.Add(g); dbContext.SaveChanges(); } buttonAddNewGroup.Enabled = false; buttonAddNewPart.Enabled = false; buttonDeleteSelected.Enabled = false; treeViewGroupsAndParts.Nodes.Clear(); InitializeTreeView(); DiagMsg(string.Format("utworzono nową grupę.")); }