Breaking Change: Changed Kot/Voucher Table Name to Guid Foreign key

Breaking Change: Renamed Discontinued to IsActive and added NA field to products.
Cleanup: Removed not used attributes
Change: RoleConstants changed to simple string
Feature: Table Create/Edit/Reorder and Modifier Create/Edit Form
Feature: Bills now show the Tax name from the database and not a hack
This commit is contained in:
tanshu
2014-10-16 16:41:55 +05:30
parent 69617949bd
commit da929ad036
76 changed files with 3472 additions and 1175 deletions

View File

@ -28,36 +28,13 @@
/// </summary>
private void InitializeComponent()
{
this.lstRoles = new System.Windows.Forms.ListBox();
this.lstGroupRoles = new System.Windows.Forms.ListBox();
this.cmbGroup = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.btnAddSelected = new System.Windows.Forms.Button();
this.btnAddAll = new System.Windows.Forms.Button();
this.btnRemoveSelected = new System.Windows.Forms.Button();
this.btnRemoveAll = new System.Windows.Forms.Button();
this.clbRoles = new System.Windows.Forms.CheckedListBox();
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lstGroups
//
this.lstRoles.FormattingEnabled = true;
this.lstRoles.Location = new System.Drawing.Point(12, 59);
this.lstRoles.Name = "lstGroups";
this.lstRoles.ScrollAlwaysVisible = true;
this.lstRoles.Size = new System.Drawing.Size(183, 225);
this.lstRoles.TabIndex = 0;
//
// lstUserGroups
//
this.lstGroupRoles.FormattingEnabled = true;
this.lstGroupRoles.Location = new System.Drawing.Point(274, 59);
this.lstGroupRoles.Name = "lstUserGroups";
this.lstGroupRoles.ScrollAlwaysVisible = true;
this.lstGroupRoles.Size = new System.Drawing.Size(183, 225);
this.lstGroupRoles.TabIndex = 1;
//
// cmbGroup
//
this.cmbGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@ -66,7 +43,7 @@
this.cmbGroup.Name = "cmbGroup";
this.cmbGroup.Size = new System.Drawing.Size(375, 21);
this.cmbGroup.TabIndex = 2;
this.cmbGroup.SelectedIndexChanged += new System.EventHandler(this.cmbUsers_SelectedIndexChanged);
this.cmbGroup.SelectedIndexChanged += new System.EventHandler(this.cmbGroup_SelectedIndexChanged);
//
// label1
//
@ -77,83 +54,45 @@
this.label1.TabIndex = 4;
this.label1.Text = "Group Name";
//
// label2
// clbRoles
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 43);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(76, 13);
this.label2.TabIndex = 5;
this.label2.Text = "Pending Roles";
this.clbRoles.FormattingEnabled = true;
this.clbRoles.Location = new System.Drawing.Point(12, 39);
this.clbRoles.Name = "clbRoles";
this.clbRoles.Size = new System.Drawing.Size(445, 184);
this.clbRoles.TabIndex = 21;
this.clbRoles.Format += new System.Windows.Forms.ListControlConvertEventHandler(this.clbRoles_Format);
//
// label3
// btnCancel
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(271, 43);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 13);
this.label3.TabIndex = 6;
this.label3.Text = "Assigned Roles";
this.btnCancel.Location = new System.Drawing.Point(382, 236);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 75);
this.btnCancel.TabIndex = 23;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnAddSelected
// btnOk
//
this.btnAddSelected.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnAddSelected.Location = new System.Drawing.Point(201, 105);
this.btnAddSelected.Name = "btnAddSelected";
this.btnAddSelected.Size = new System.Drawing.Size(67, 25);
this.btnAddSelected.TabIndex = 7;
this.btnAddSelected.Text = ">";
this.btnAddSelected.UseVisualStyleBackColor = true;
this.btnAddSelected.Click += new System.EventHandler(this.btnAddSelected_Click);
//
// btnAddAll
//
this.btnAddAll.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnAddAll.Location = new System.Drawing.Point(201, 136);
this.btnAddAll.Name = "btnAddAll";
this.btnAddAll.Size = new System.Drawing.Size(67, 25);
this.btnAddAll.TabIndex = 8;
this.btnAddAll.Text = ">>";
this.btnAddAll.UseVisualStyleBackColor = true;
this.btnAddAll.Click += new System.EventHandler(this.btnAddAll_Click);
//
// btnRemoveSelected
//
this.btnRemoveSelected.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnRemoveSelected.Location = new System.Drawing.Point(201, 167);
this.btnRemoveSelected.Name = "btnRemoveSelected";
this.btnRemoveSelected.Size = new System.Drawing.Size(67, 25);
this.btnRemoveSelected.TabIndex = 9;
this.btnRemoveSelected.Text = "<";
this.btnRemoveSelected.UseVisualStyleBackColor = true;
this.btnRemoveSelected.Click += new System.EventHandler(this.btnRemoveSelected_Click);
//
// btnRemoveAll
//
this.btnRemoveAll.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnRemoveAll.Location = new System.Drawing.Point(201, 198);
this.btnRemoveAll.Name = "btnRemoveAll";
this.btnRemoveAll.Size = new System.Drawing.Size(67, 25);
this.btnRemoveAll.TabIndex = 10;
this.btnRemoveAll.Text = "<<";
this.btnRemoveAll.UseVisualStyleBackColor = true;
this.btnRemoveAll.Click += new System.EventHandler(this.btnRemoveAll_Click);
this.btnOk.Location = new System.Drawing.Point(301, 236);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 75);
this.btnOk.TabIndex = 22;
this.btnOk.Text = "&Ok";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// AssignGroupRoles
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(469, 323);
this.Controls.Add(this.btnRemoveAll);
this.Controls.Add(this.btnRemoveSelected);
this.Controls.Add(this.btnAddAll);
this.Controls.Add(this.btnAddSelected);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.clbRoles);
this.Controls.Add(this.label1);
this.Controls.Add(this.cmbGroup);
this.Controls.Add(this.lstGroupRoles);
this.Controls.Add(this.lstRoles);
this.MaximizeBox = false;
this.Name = "AssignGroupRoles";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
@ -166,15 +105,10 @@
#endregion
private System.Windows.Forms.ListBox lstRoles;
private System.Windows.Forms.ListBox lstGroupRoles;
private System.Windows.Forms.ComboBox cmbGroup;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnAddSelected;
private System.Windows.Forms.Button btnAddAll;
private System.Windows.Forms.Button btnRemoveSelected;
private System.Windows.Forms.Button btnRemoveAll;
private System.Windows.Forms.CheckedListBox clbRoles;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
}
}

View File

@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Helpers;
using System.Threading;
using Tanshu.Accounts.Repository;
using System.Linq;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
namespace Tanshu.Accounts.PointOfSale
{
@ -22,98 +16,71 @@ namespace Tanshu.Accounts.PointOfSale
private void AssignGroupRoles_Load(object sender, EventArgs e)
{
FillUsers();
FillGroups();
}
private void FillUsers()
private void FillGroups()
{
cmbGroup.DisplayMember = "Name";
cmbGroup.ValueMember = "GroupID";
cmbGroup.DataSource = MembershipBI.GetGroups();
using (var bi = new GroupBI())
cmbGroup.DataSource = bi.List();
}
private void cmbUsers_SelectedIndexChanged(object sender, EventArgs e)
private void cmbGroup_SelectedIndexChanged(object sender, EventArgs e)
{
GetLists();
}
private void GetLists()
{
IList<Role> roles;
IList<Role> roleGroups;
if (cmbGroup.SelectedValue == null)
{
roles = MembershipBI.GetRoles();
roleGroups = new List<Role>();
}
GetRoles(null);
else
{
int groupID = (int)cmbGroup.SelectedValue;
roles = MembershipBI.GetRolesNotOfGroup(groupID);
roleGroups = MembershipBI.GetRolesOfGroup(groupID);
}
RefreshRoles(roles, roleGroups);
}
private void RefreshRoles(IList<Role> roles, IList<Role> roleGroups)
{
lstRoles.DisplayMember = "Name";
lstRoles.ValueMember = "RoleID";
lstRoles.DataSource = roles;
lstGroupRoles.DisplayMember = "Name";
lstGroupRoles.ValueMember = "RoleID";
lstGroupRoles.DataSource = roleGroups;
btnAddAll.Enabled = btnAddSelected.Enabled = roles.Count > 0;
btnRemoveAll.Enabled = btnRemoveSelected.Enabled = roleGroups.Count > 0;
GetRoles((Guid)cmbGroup.SelectedValue);
}
private void btnAddSelected_Click(object sender, EventArgs e)
private void GetRoles(Guid? groupID)
{
if (lstRoles.SelectedItem != null)
using (var bi = new GroupBI())
{
var groupID = (Guid)cmbGroup.SelectedValue;
var roleID = (Guid)lstRoles.SelectedValue;
MembershipBI.AddRoleToGroup(roleID, groupID);
GetLists();
var roles = bi.RoleList();
clbRoles.DataSource = roles;
if (groupID.HasValue)
{
var group = bi.Get(x => x.GroupID == groupID.Value);
for (int i = 0; i < clbRoles.Items.Count; i++)
{
var item = (Role)clbRoles.Items[i];
if (item.Groups.Any(x => x.Group == group))
{
clbRoles.SetItemChecked(i, true);
}
}
}
}
}
private void btnRemoveSelected_Click(object sender, EventArgs e)
private void btnCancel_Click(object sender, EventArgs e)
{
if (lstGroupRoles.SelectedItem != null)
{
var groupID = (Guid)cmbGroup.SelectedValue;
var roleID = (Guid)lstGroupRoles.SelectedValue;
MembershipBI.RemoveRoleFromGroup(roleID, groupID);
GetLists();
}
this.Close();
}
private void btnAddAll_Click(object sender, EventArgs e)
private void btnOk_Click(object sender, EventArgs e)
{
var groupID = (Guid)cmbGroup.SelectedValue;
Guid roleID;
for (var i = 0; i <= lstRoles.Items.Count - 1; i++)
if (cmbGroup.SelectedValue != null)
Save((Guid)cmbGroup.SelectedValue);
}
private void Save(Guid groupID)
{
using (var bi = new GroupBI())
{
roleID = ((Role)lstRoles.Items[i]).RoleID;
MembershipBI.AddRoleToGroup(roleID, groupID);
var group = bi.Get(x => x.GroupID == groupID);
bi.Update(group, clbRoles.CheckedItems.OfType<Role>());
bi.SaveChanges();
}
GetLists();
MessageBox.Show("Update / Save Successful");
}
private void btnRemoveAll_Click(object sender, EventArgs e)
private void clbRoles_Format(object sender, ListControlConvertEventArgs e)
{
var groupID = (Guid)cmbGroup.SelectedValue;
Guid roleID;
for (var i = 0; i <= lstGroupRoles.Items.Count - 1; i++)
{
roleID = ((Role)lstGroupRoles.Items[i]).RoleID;
MembershipBI.RemoveRoleFromGroup(roleID, groupID);
}
GetLists();
e.Value = ((Role)e.ListItem).Name;
}
}
}

View File

@ -28,45 +28,22 @@
/// </summary>
private void InitializeComponent()
{
this.lstGroups = new System.Windows.Forms.ListBox();
this.lstUserGroups = new System.Windows.Forms.ListBox();
this.cmbUsers = new System.Windows.Forms.ComboBox();
this.cmbUser = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.btnAddSelected = new System.Windows.Forms.Button();
this.btnAddAll = new System.Windows.Forms.Button();
this.btnRemoveSelected = new System.Windows.Forms.Button();
this.btnRemoveAll = new System.Windows.Forms.Button();
this.clbGroups = new System.Windows.Forms.CheckedListBox();
this.btnCancel = new System.Windows.Forms.Button();
this.btnOk = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lstGroups
// cmbUser
//
this.lstGroups.FormattingEnabled = true;
this.lstGroups.Location = new System.Drawing.Point(12, 59);
this.lstGroups.Name = "lstGroups";
this.lstGroups.ScrollAlwaysVisible = true;
this.lstGroups.Size = new System.Drawing.Size(183, 225);
this.lstGroups.TabIndex = 0;
//
// lstUserGroups
//
this.lstUserGroups.FormattingEnabled = true;
this.lstUserGroups.Location = new System.Drawing.Point(274, 59);
this.lstUserGroups.Name = "lstUserGroups";
this.lstUserGroups.ScrollAlwaysVisible = true;
this.lstUserGroups.Size = new System.Drawing.Size(183, 225);
this.lstUserGroups.TabIndex = 1;
//
// cmbGroup
//
this.cmbUsers.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbUsers.FormattingEnabled = true;
this.cmbUsers.Location = new System.Drawing.Point(72, 12);
this.cmbUsers.Name = "cmbGroup";
this.cmbUsers.Size = new System.Drawing.Size(276, 21);
this.cmbUsers.TabIndex = 2;
this.cmbUsers.SelectedIndexChanged += new System.EventHandler(this.cmbUsers_SelectedIndexChanged);
this.cmbUser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbUser.FormattingEnabled = true;
this.cmbUser.Location = new System.Drawing.Point(72, 12);
this.cmbUser.Name = "cmbUser";
this.cmbUser.Size = new System.Drawing.Size(385, 21);
this.cmbUser.TabIndex = 2;
this.cmbUser.SelectedIndexChanged += new System.EventHandler(this.cmbUsers_SelectedIndexChanged);
//
// label1
//
@ -77,83 +54,45 @@
this.label1.TabIndex = 4;
this.label1.Text = "User Name";
//
// label2
// clbGroups
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 43);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(83, 13);
this.label2.TabIndex = 5;
this.label2.Text = "Pending Groups";
this.clbGroups.FormattingEnabled = true;
this.clbGroups.Location = new System.Drawing.Point(12, 39);
this.clbGroups.Name = "clbGroups";
this.clbGroups.Size = new System.Drawing.Size(445, 184);
this.clbGroups.TabIndex = 22;
this.clbGroups.Format += new System.Windows.Forms.ListControlConvertEventHandler(this.clbGroups_Format);
//
// label3
// btnCancel
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(271, 43);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(87, 13);
this.label3.TabIndex = 6;
this.label3.Text = "Assigned Groups";
this.btnCancel.Location = new System.Drawing.Point(382, 236);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 75);
this.btnCancel.TabIndex = 25;
this.btnCancel.Text = "&Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnAddSelected
// btnOk
//
this.btnAddSelected.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnAddSelected.Location = new System.Drawing.Point(201, 105);
this.btnAddSelected.Name = "btnAddSelected";
this.btnAddSelected.Size = new System.Drawing.Size(67, 25);
this.btnAddSelected.TabIndex = 7;
this.btnAddSelected.Text = ">";
this.btnAddSelected.UseVisualStyleBackColor = true;
this.btnAddSelected.Click += new System.EventHandler(this.btnAddSelected_Click);
//
// btnAddAll
//
this.btnAddAll.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnAddAll.Location = new System.Drawing.Point(201, 136);
this.btnAddAll.Name = "btnAddAll";
this.btnAddAll.Size = new System.Drawing.Size(67, 25);
this.btnAddAll.TabIndex = 8;
this.btnAddAll.Text = ">>";
this.btnAddAll.UseVisualStyleBackColor = true;
this.btnAddAll.Click += new System.EventHandler(this.btnAddAll_Click);
//
// btnRemoveSelected
//
this.btnRemoveSelected.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnRemoveSelected.Location = new System.Drawing.Point(201, 167);
this.btnRemoveSelected.Name = "btnRemoveSelected";
this.btnRemoveSelected.Size = new System.Drawing.Size(67, 25);
this.btnRemoveSelected.TabIndex = 9;
this.btnRemoveSelected.Text = "<";
this.btnRemoveSelected.UseVisualStyleBackColor = true;
this.btnRemoveSelected.Click += new System.EventHandler(this.btnRemoveSelected_Click);
//
// btnRemoveAll
//
this.btnRemoveAll.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btnRemoveAll.Location = new System.Drawing.Point(201, 198);
this.btnRemoveAll.Name = "btnRemoveAll";
this.btnRemoveAll.Size = new System.Drawing.Size(67, 25);
this.btnRemoveAll.TabIndex = 10;
this.btnRemoveAll.Text = "<<";
this.btnRemoveAll.UseVisualStyleBackColor = true;
this.btnRemoveAll.Click += new System.EventHandler(this.btnRemoveAll_Click);
this.btnOk.Location = new System.Drawing.Point(301, 236);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 75);
this.btnOk.TabIndex = 24;
this.btnOk.Text = "&Ok";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// AssignUserGroups
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(469, 323);
this.Controls.Add(this.btnRemoveAll);
this.Controls.Add(this.btnRemoveSelected);
this.Controls.Add(this.btnAddAll);
this.Controls.Add(this.btnAddSelected);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.clbGroups);
this.Controls.Add(this.label1);
this.Controls.Add(this.cmbUsers);
this.Controls.Add(this.lstUserGroups);
this.Controls.Add(this.lstGroups);
this.Controls.Add(this.cmbUser);
this.MaximizeBox = false;
this.Name = "AssignUserGroups";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
@ -166,15 +105,10 @@
#endregion
private System.Windows.Forms.ListBox lstGroups;
private System.Windows.Forms.ListBox lstUserGroups;
private System.Windows.Forms.ComboBox cmbUsers;
private System.Windows.Forms.ComboBox cmbUser;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnAddSelected;
private System.Windows.Forms.Button btnAddAll;
private System.Windows.Forms.Button btnRemoveSelected;
private System.Windows.Forms.Button btnRemoveAll;
private System.Windows.Forms.CheckedListBox clbGroups;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOk;
}
}

View File

@ -27,94 +27,66 @@ namespace Tanshu.Accounts.PointOfSale
private void FillUsers()
{
cmbUsers.DisplayMember = "Name";
cmbUsers.ValueMember = "UserID";
cmbUser.DisplayMember = "Name";
cmbUser.ValueMember = "UserID";
using (var bi = new UserBI())
cmbUsers.DataSource = bi.List();
cmbUser.DataSource = bi.List();
}
private void cmbUsers_SelectedIndexChanged(object sender, EventArgs e)
{
GetLists();
}
private void GetLists()
{
IList<Group> groups;
IList<Group> userGroups;
if (cmbUsers.SelectedValue == null)
{
groups = MembershipBI.GetGroups();
userGroups = new List<Group>();
}
if (cmbUser.SelectedValue == null)
GetGroups(null);
else
{
var userid = (Guid)cmbUsers.SelectedValue;
groups = MembershipBI.GetGroupsNotOfUser(userid);
userGroups = MembershipBI.GetGroupsOfUser(userid);
}
RefreshRoles(groups, userGroups);
}
private void RefreshRoles(IList<Group> groups, IList<Group> userGroups)
{
lstGroups.DisplayMember = "Name";
lstGroups.ValueMember = "GroupID";
lstGroups.DataSource = groups;
lstUserGroups.DisplayMember = "Name";
lstUserGroups.ValueMember = "GroupID";
lstUserGroups.DataSource = userGroups;
btnAddAll.Enabled = btnAddSelected.Enabled = groups.Count > 0;
btnRemoveAll.Enabled = btnRemoveSelected.Enabled = userGroups.Count > 0;
GetGroups((Guid)cmbUser.SelectedValue);
}
private void btnAddSelected_Click(object sender, EventArgs e)
private void GetGroups(Guid? userID)
{
if (lstGroups.SelectedItem != null)
using (var bi = new UserBI())
{
var userID = (Guid)cmbUsers.SelectedValue;
var groupID = (Guid)lstGroups.SelectedValue;
MembershipBI.AddUserToGroup(userID, groupID);
GetLists();
var groups = bi.GroupList();
clbGroups.DataSource = groups;
if (userID.HasValue)
{
var user = bi.Get(x => x.UserID == userID.Value);
for (int i = 0; i < clbGroups.Items.Count; i++)
{
var item = (Group)clbGroups.Items[i];
if (item.UserGroups.Any(x => x.User == user))
{
clbGroups.SetItemChecked(i, true);
}
}
}
}
}
private void btnRemoveSelected_Click(object sender, EventArgs e)
private void btnOk_Click(object sender, EventArgs e)
{
if (lstUserGroups.SelectedItem != null)
{
Guid userID = (Guid)cmbUsers.SelectedValue;
Guid groupID = (Guid)lstUserGroups.SelectedValue;
MembershipBI.RemoveUserFromGroup(userID, groupID);
GetLists();
}
if (cmbUser.SelectedValue != null)
Save((Guid)cmbUser.SelectedValue);
}
private void btnAddAll_Click(object sender, EventArgs e)
private void Save(Guid userID)
{
var userID = (Guid)cmbUsers.SelectedValue;
Guid groupID;
for (var i = 0; i <= lstGroups.Items.Count - 1; i++)
using (var bi = new UserBI())
{
groupID = ((Group)lstGroups.Items[i]).GroupID;
MembershipBI.AddUserToGroup(userID, groupID);
var user = bi.Get(x => x.UserID == userID);
bi.Update(user, clbGroups.CheckedItems.OfType<Group>());
bi.SaveChanges();
}
GetLists();
MessageBox.Show("Update / Save Successful");
}
private void btnRemoveAll_Click(object sender, EventArgs e)
private void btnCancel_Click(object sender, EventArgs e)
{
var userID = (Guid)cmbUsers.SelectedValue;
Guid groupID;
for (var i = 0; i <= lstUserGroups.Items.Count - 1; i++)
{
groupID = ((Group)lstUserGroups.Items[i]).GroupID;
MembershipBI.RemoveUserFromGroup(userID, groupID);
}
GetLists();
this.Close();
}
private void clbGroups_Format(object sender, ListControlConvertEventArgs e)
{
e.Value = ((Group)e.ListItem).Name;
}
}
}