200 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			200 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.ComponentModel;
 | |
| using System.Data;
 | |
| using System.Drawing;
 | |
| using System.Text;
 | |
| using System.Windows.Forms;
 | |
| using VEPROMS.CSLA.Library;
 | |
| 
 | |
| namespace WinApp
 | |
| {
 | |
| 	public partial class frmGroups : Form
 | |
| 	{
 | |
| 		public frmGroups(int gid)
 | |
| 		{
 | |
| 			InitializeComponent();
 | |
| 			_gid = gid;
 | |
| 		}
 | |
| 		private int _gid;
 | |
| 		private Group _group;
 | |
| 		private void frmGroup_Load(object sender, EventArgs e)
 | |
| 		{
 | |
| 			groupInfoListBindingSource.DataSource = GroupInfoList.Get();
 | |
| 			userInfoListBindingSource.DataSource = UserInfoList.Get();
 | |
| 			lbGroups.SelectedValue = _gid;
 | |
| 			SetupDetail();
 | |
| 			SetupButtons();
 | |
| 		}
 | |
| 		private void BeforeFormClosing(object sender, FormClosingEventArgs e)
 | |
| 		{
 | |
| 			e.Cancel = (SaveAsNeeded() == DialogResult.Cancel);
 | |
| 		}
 | |
| 		private DialogResult SaveAsNeeded()
 | |
| 		{
 | |
| 			if (_group != null && _group.IsSavable)
 | |
| 			{
 | |
| 				DialogResult dr = MessageBox.Show("Do you want to save changes", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
 | |
| 				if (dr == DialogResult.Yes) Save();
 | |
| 				if (dr == DialogResult.No) Cancel();
 | |
| 				// TODO: Need a Cancel
 | |
| 				return dr;
 | |
| 			}
 | |
| 			return DialogResult.Yes;
 | |
| 		}
 | |
| 		private void SetupDetail()
 | |
| 		{
 | |
| 			if (lbGroups.SelectedValue != null)
 | |
| 			{
 | |
| 				int gid = (int)lbGroups.SelectedValue;
 | |
| 				if (_group == null || _group.GID != gid)
 | |
| 				{
 | |
| 					if (SaveAsNeeded() != DialogResult.Cancel)
 | |
| 					{
 | |
| 						_group = Group.Get(gid);
 | |
| 						groupBindingSource.DataSource = _group;
 | |
| 						groupMembershipsBindingSource.DataSource = _group.GroupMemberships;
 | |
| 						groupAssignmentsBindingSource.DataSource = _group.GroupAssignments;
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private void lbGroup_SelectedValueChanged(object sender, EventArgs e)
 | |
| 		{
 | |
| 			SetupDetail();
 | |
| 		}
 | |
| 		private void SetupButtons()
 | |
| 		{
 | |
| 			if (_group != null)
 | |
| 			{
 | |
| 				btnSave.Enabled = _group.IsSavable;
 | |
| 				btnCancel.Enabled = _group.IsDirty;
 | |
| 				btnNew.Enabled = _group.IsValid;
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				btnSave.Enabled = false;
 | |
| 				btnCancel.Enabled = false;
 | |
| 				btnNew.Enabled = true;
 | |
| 			}
 | |
| 		}
 | |
| 		private void CurrentItemChanged(object sender, EventArgs e)
 | |
| 		{
 | |
| 			SetupButtons();
 | |
| 		}
 | |
| 		private void btnCancel_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			Cancel();
 | |
| 		}
 | |
| 		private void btnSave_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			Save();
 | |
| 		}
 | |
| 		private void btnNew_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			New();
 | |
| 		}
 | |
| 		private void Cancel()
 | |
| 		{
 | |
| 			_group.CancelEdit();
 | |
| 			_group.BeginEdit();
 | |
| 		}
 | |
| 		private void Save()
 | |
| 		{
 | |
| 			groupBindingSource.RaiseListChangedEvents = false;
 | |
| 			groupMembershipsBindingSource.RaiseListChangedEvents = false;
 | |
| 			groupBindingSource.EndEdit();
 | |
| 			groupMembershipsBindingSource.EndEdit();
 | |
| 
 | |
| 			try
 | |
| 			{
 | |
| 				Group temp = _group.Clone();
 | |
| 				_group = temp.Save();
 | |
| 				_group.BeginEdit();
 | |
| 				groupBindingSource.DataSource = null;
 | |
| 				groupMembershipsBindingSource.DataSource = null;
 | |
| 				int gid = _group.GID;
 | |
| 				groupInfoListBindingSource.DataSource = GroupInfoList.Get();
 | |
| 				lbGroups.SelectedValue = gid;
 | |
| 				groupBindingSource.DataSource = _group;
 | |
| 				groupMembershipsBindingSource.DataSource = _group.GroupMemberships;
 | |
| 			}
 | |
| 			catch (Csla.DataPortalException ex)
 | |
| 			{
 | |
| 				MessageBox.Show(ex.BusinessException.ToString(),
 | |
| 				"Error saving", MessageBoxButtons.OK,
 | |
| 				MessageBoxIcon.Exclamation);
 | |
| 			}
 | |
| 			catch (Exception ex)
 | |
| 			{
 | |
| 				MessageBox.Show(ex.ToString(), "Error saving",
 | |
| 				MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
 | |
| 			}
 | |
| 			finally
 | |
| 			{
 | |
| 				groupBindingSource.RaiseListChangedEvents = true;
 | |
| 				groupMembershipsBindingSource.RaiseListChangedEvents = true;
 | |
| 				groupBindingSource.ResetBindings(false);
 | |
| 				groupMembershipsBindingSource.ResetBindings(false);
 | |
| 			}
 | |
| 			SetupButtons();
 | |
| 		}
 | |
| 		public void New()
 | |
| 		{
 | |
| 			if (SaveAsNeeded() != DialogResult.Cancel)
 | |
| 			{
 | |
| 				_group = Group.New();
 | |
| 				groupBindingSource.DataSource = _group;
 | |
| 				groupMembershipsBindingSource.DataSource = _group.GroupMemberships;
 | |
| 			}
 | |
| 		}
 | |
| 		private void btnNewGA_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			using (frmUserSelect f = new frmUserSelect())
 | |
| 			{
 | |
| 				f.ShowDialog();
 | |
| 				if (f.DialogResult == DialogResult.OK)
 | |
| 				{
 | |
| 					_group.GroupMemberships.Add(User.Get(f.UID));   // KBR using?
 | |
| 					SetupButtons();
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private void btnRemoveGA_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			if (this.groupMembershipsDataGridView.SelectedRows.Count > 0)
 | |
| 			{
 | |
| 				int uid = int.Parse(
 | |
| 					this.groupMembershipsDataGridView.SelectedRows[0].Cells[0].Value.ToString());
 | |
| 				MessageBox.Show("Conversion error");
 | |
| 				//TODO KBR: _group.GroupMemberships.Remove(uid);
 | |
| 			}
 | |
| 		}
 | |
| 
 | |
| 		private void btnRemoveAssign_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			if (this.groupAssignmentsDataGridView.SelectedRows.Count > 0)
 | |
| 			{
 | |
| 				int rid = int.Parse(
 | |
| 					this.groupAssignmentsDataGridView.SelectedRows[0].Cells[1].Value.ToString());
 | |
| 				int folderid = int.Parse(
 | |
| 					this.groupAssignmentsDataGridView.SelectedRows[0].Cells[2].Value.ToString());
 | |
| 				MessageBox.Show("Conversion error");
 | |
| 				//TODO KBR: _group.GroupAssignments.Remove(folderid, rid);
 | |
| 			}
 | |
| 
 | |
| 		}
 | |
| 
 | |
| 		private void btnNewAssign_Click(object sender, EventArgs e)
 | |
| 		{
 | |
| 			using (frmAssignmentSelect f = new frmAssignmentSelect(_group))
 | |
| 			{
 | |
| 				f.ShowDialog();
 | |
| 				if (f.DialogResult == DialogResult.OK)
 | |
| 				{
 | |
| 					//TODO: Do I need to refresh Assignments?
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| } |