private void TsbGroupAddClick(object sender, EventArgs e) { var grps = _dsSecurity.Tables["Group"].AsEnumerable(); var usrgrps = _dsSecurity.Tables["UsrGrp"].AsEnumerable(); // // Reserva o usuário atual // DataRowView currentUser = _bsUser.Current as DataRowView; var userGroups = from grp in grps join usrgrp in usrgrps on grp["Name"] equals usrgrp["GroupName"] into joinedGroup from jndGrp in joinedGroup where (string)jndGrp["UserName"] == (string)currentUser["Name"] select new { GroupName = grp["Name"], Description = grp["Description"] }; var allGroups = from grp in grps select new { GroupName = grp["Name"], Description = grp["Description"] }; var working = allGroups.Except(userGroups); DataTable avlGrps = _dsSecurity.Tables["Group"].Clone(); avlGrps.Clear(); foreach (var record in working) { DataRow nRow = avlGrps.NewRow(); nRow["Name"] = record.GroupName.ToString(); nRow["Description"] = record.Description.ToString(); avlGrps.Rows.Add(nRow); avlGrps.AcceptChanges(); } using (GroupListForm groupListForm = new GroupListForm(avlGrps)) { if (groupListForm.ShowDialog() == DialogResult.OK) { //DataRowView currentUser = _bsUser.Current as DataRowView; DataRowView newGroup = _bsGroup.AddNew() as DataRowView; DataRowView selectedGroup = groupListForm.listBox1.SelectedItem as DataRowView; newGroup["UserName"] = currentUser["Name"]; newGroup["Name"] = selectedGroup["Name"]; newGroup["Description"] = selectedGroup["Description"]; _bsGroup.EndEdit(); _bsGroup.ResetCurrentItem(); DataTable dtUsrGrp = _dsSecurity.Tables["UsrGrp"]; DataRow newUsrGrp = dtUsrGrp.NewRow(); newUsrGrp["GroupName"] = newGroup["Name"]; newUsrGrp["UserName"] = newGroup["UserName"]; dtUsrGrp.Rows.Add(newUsrGrp); } } }
private void TsbGroupAddClick(object sender, EventArgs e) { var grps = _dsSecurity.Tables["Group"].AsEnumerable(); var usrgrps = _dsSecurity.Tables["UsrGrp"].AsEnumerable(); // // Reserva o usuário atual // DataRowView currentUser = _bsUser.Current as DataRowView; var userGroups = from grp in grps join usrgrp in usrgrps on grp["Name"] equals usrgrp["GroupName"] into joinedGroup from jndGrp in joinedGroup where (string)jndGrp["UserName"] == (string)currentUser["Name"] select new { GroupName = grp["Name"], Description = grp["Description"] }; var allGroups = from grp in grps select new { GroupName = grp["Name"], Description = grp["Description"] }; var working = allGroups.Except(userGroups); DataTable avlGrps = _dsSecurity.Tables["Group"].Clone(); avlGrps.Clear(); foreach(var record in working) { DataRow nRow = avlGrps.NewRow(); nRow["Name"] = record.GroupName.ToString(); nRow["Description"] = record.Description.ToString(); avlGrps.Rows.Add(nRow); avlGrps.AcceptChanges(); } using (GroupListForm groupListForm = new GroupListForm(avlGrps)) { if (groupListForm.ShowDialog() == DialogResult.OK) { //DataRowView currentUser = _bsUser.Current as DataRowView; DataRowView newGroup = _bsGroup.AddNew() as DataRowView; DataRowView selectedGroup = groupListForm.listBox1.SelectedItem as DataRowView; newGroup["UserName"] = currentUser["Name"]; newGroup["Name"] = selectedGroup["Name"]; newGroup["Description"] = selectedGroup["Description"]; _bsGroup.EndEdit(); _bsGroup.ResetCurrentItem(); DataTable dtUsrGrp = _dsSecurity.Tables["UsrGrp"]; DataRow newUsrGrp = dtUsrGrp.NewRow(); newUsrGrp["GroupName"] = newGroup["Name"]; newUsrGrp["UserName"] = newGroup["UserName"]; dtUsrGrp.Rows.Add(newUsrGrp); } } }