Files
ayanova7/source/WinFormApp/SecurityGroupsForm.cs
2018-08-30 15:33:01 +00:00

442 lines
19 KiB
C#

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using GZTW.AyaNova.BLL;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win;
using log4net;
namespace AyaNova
{
/// <summary>
/// Summary description for SecurityGroupsForm.
/// </summary>
public class SecurityGroupsForm : System.Windows.Forms.Form
{
// Create a logger for use in this class
//case 1039 private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Infragistics.Win.UltraWinGrid.UltraGrid Grid;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsManager ToolBarManager;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _SecurityGroupsForm_Toolbars_Dock_Area_Left;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _SecurityGroupsForm_Toolbars_Dock_Area_Right;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _SecurityGroupsForm_Toolbars_Dock_Area_Top;
private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _SecurityGroupsForm_Toolbars_Dock_Area_Bottom;
private System.Windows.Forms.HelpProvider helpProvider1;
private System.ComponentModel.IContainer components;
public SecurityGroupsForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
//
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("SecurityGroupsToolBar");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.New");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.Refresh");
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool3 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.Refresh");
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool4 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Toolbar.New");
Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
this.Grid = new Infragistics.Win.UltraWinGrid.UltraGrid();
this.ToolBarManager = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(this.components);
this._SecurityGroupsForm_Toolbars_Dock_Area_Left = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._SecurityGroupsForm_Toolbars_Dock_Area_Right = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._SecurityGroupsForm_Toolbars_Dock_Area_Top = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
this.helpProvider1 = new System.Windows.Forms.HelpProvider();
((System.ComponentModel.ISupportInitialize)(this.Grid)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ToolBarManager)).BeginInit();
this.SuspendLayout();
//
// Grid
//
this.Grid.Cursor = System.Windows.Forms.Cursors.Hand;
this.Grid.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ResizeAllColumns;
this.Grid.DisplayLayout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
this.Grid.Dock = System.Windows.Forms.DockStyle.Fill;
this.Grid.Location = new System.Drawing.Point(0, 26);
this.Grid.Name = "Grid";
this.Grid.Size = new System.Drawing.Size(536, 499);
this.Grid.TabIndex = 1;
this.Grid.Text = "SecurityGroups form";
this.Grid.ClickCellButton += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.Grid_ClickCellButton);
this.Grid.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Grid_KeyUp);
this.Grid.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Grid_MouseDown);
//
// ToolBarManager
//
this.ToolBarManager.DesignerFlags = 1;
this.ToolBarManager.DockWithinContainer = this;
this.ToolBarManager.DockWithinContainerBaseType = typeof(System.Windows.Forms.Form);
this.ToolBarManager.MdiMergeable = false;
this.ToolBarManager.ShowFullMenusDelay = 500;
ultraToolbar1.DockedColumn = 0;
ultraToolbar1.DockedRow = 0;
ultraToolbar1.NonInheritedTools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool1,
buttonTool2});
ultraToolbar1.Text = "SecurityGroupsToolBar";
this.ToolBarManager.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] {
ultraToolbar1});
this.ToolBarManager.ToolbarSettings.AllowCustomize = Infragistics.Win.DefaultableBoolean.False;
this.ToolBarManager.ToolbarSettings.AllowFloating = Infragistics.Win.DefaultableBoolean.False;
this.ToolBarManager.ToolbarSettings.AllowHiding = Infragistics.Win.DefaultableBoolean.False;
appearance1.Image = global::AyaNova.Resource1.Refresh32;
buttonTool3.SharedPropsInternal.AppearancesLarge.Appearance = appearance1;
appearance2.Image = global::AyaNova.Resource1.Refresh16;
buttonTool3.SharedPropsInternal.AppearancesSmall.Appearance = appearance2;
buttonTool3.SharedPropsInternal.Caption = "LT:UI.Toolbar.Refresh";
buttonTool3.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText;
appearance3.Image = global::AyaNova.Resource1.New32;
buttonTool4.SharedPropsInternal.AppearancesLarge.Appearance = appearance3;
appearance4.Image = global::AyaNova.Resource1.New16;
buttonTool4.SharedPropsInternal.AppearancesSmall.Appearance = appearance4;
buttonTool4.SharedPropsInternal.Caption = "LT:UI.Toolbar.New";
buttonTool4.SharedPropsInternal.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText;
this.ToolBarManager.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] {
buttonTool3,
buttonTool4});
this.ToolBarManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.ToolBarManager_ToolClick);
//
// _SecurityGroupsForm_Toolbars_Dock_Area_Left
//
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control;
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left;
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText;
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.Location = new System.Drawing.Point(0, 26);
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.Name = "_SecurityGroupsForm_Toolbars_Dock_Area_Left";
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.Size = new System.Drawing.Size(0, 499);
this._SecurityGroupsForm_Toolbars_Dock_Area_Left.ToolbarsManager = this.ToolBarManager;
//
// _SecurityGroupsForm_Toolbars_Dock_Area_Right
//
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control;
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right;
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText;
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.Location = new System.Drawing.Point(536, 26);
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.Name = "_SecurityGroupsForm_Toolbars_Dock_Area_Right";
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.Size = new System.Drawing.Size(0, 499);
this._SecurityGroupsForm_Toolbars_Dock_Area_Right.ToolbarsManager = this.ToolBarManager;
//
// _SecurityGroupsForm_Toolbars_Dock_Area_Top
//
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control;
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top;
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText;
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.Location = new System.Drawing.Point(0, 0);
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.Name = "_SecurityGroupsForm_Toolbars_Dock_Area_Top";
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.Size = new System.Drawing.Size(536, 26);
this._SecurityGroupsForm_Toolbars_Dock_Area_Top.ToolbarsManager = this.ToolBarManager;
//
// _SecurityGroupsForm_Toolbars_Dock_Area_Bottom
//
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control;
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom;
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText;
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.Location = new System.Drawing.Point(0, 525);
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.Name = "_SecurityGroupsForm_Toolbars_Dock_Area_Bottom";
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.Size = new System.Drawing.Size(536, 0);
this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom.ToolbarsManager = this.ToolBarManager;
//
// SecurityGroupsForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(536, 525);
this.ControlBox = false;
this.Controls.Add(this.Grid);
this.Controls.Add(this._SecurityGroupsForm_Toolbars_Dock_Area_Left);
this.Controls.Add(this._SecurityGroupsForm_Toolbars_Dock_Area_Right);
this.Controls.Add(this._SecurityGroupsForm_Toolbars_Dock_Area_Bottom);
this.Controls.Add(this._SecurityGroupsForm_Toolbars_Dock_Area_Top);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.helpProvider1.SetHelpKeyword(this, "");
this.helpProvider1.SetHelpNavigator(this, System.Windows.Forms.HelpNavigator.Topic);
this.Name = "SecurityGroupsForm";
this.helpProvider1.SetShowHelp(this, true);
this.Text = "SecurityGroupsForm";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form_Closing);
this.Load += new System.EventHandler(this.Form_Load);
((System.ComponentModel.ISupportInitialize)(this.Grid)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.ToolBarManager)).EndInit();
this.ResumeLayout(false);
}
#endregion
// __ _ _ ___ ____ __ __ __ __ __ ___ ___
// / _)( )( )/ __)(_ _)/ \( \/ ) / _)/ \( \( _)
// ( (_ )()( \__ \ )( ( () )) ( ( (_( () )) ) )) _)
// \__) \__/ (___/ (__) \__/(_/\/\_) \__)\__/(___/(___)
//
#region Grid Preparation, Display and Events
private void Form_Load(object sender, System.EventArgs e)
{
//
// helpProvider1
//
this.helpProvider1.HelpNamespace = Util.BaseHelpUrl + "security_groups_grid.htm";
Util.LoadFormCustomization("SecurityGroupsForm", this, ToolBarManager, true);
ToolBarManager.Tools["LT:UI.Toolbar.New"].SharedProps.Visible=AyaBizUtils.Right("Object.SecurityGroup")> (int)SecurityLevelTypes.ReadOnly;
Grid.DataSource=SecurityGroupList.GetEmptyList();
Grid.DisplayLayout.Override.AllowRowFiltering=DefaultableBoolean.False;
Grid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.SortSingle;
//Set the caption to be on the left side of the grid
Grid.DisplayLayout.CaptionAppearance.TextHAlign = HAlign.Left;
Util.Localize(this);
BindGrid(false);
Grid.DisplayLayout.Bands[0].Columns["LT_O_SecurityGroup"].Style=Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
foreach(UltraGridColumn c in Grid.DisplayLayout.Bands[0].Columns)
{
c.CellActivation=Activation.ActivateOnly;
}
//Case 240
Util.GridStyler(Grid);
}
/// <summary>
/// When form closes it will save
/// (main form must call close on this form for this to work)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Util.SaveFormCustomization("SecurityGroupsForm", this, ToolBarManager, true);
}
/// <summary>
/// Rebind the control to the data source based on the latest
/// user filter and sort settings
/// </summary>
private void BindGrid(bool bReverseSort)
{
//case 1039 //log.Debug("BindGrid - entering");
Cursor.Current=Cursors.WaitCursor;
bool bFiltered=false;
Grid.DataSource=SecurityGroupList.GetList(Util.GetGridSortAndFilterXML(Grid.DisplayLayout.Bands[0],bReverseSort,ref bFiltered));
Grid.Text=Util.LocaleText.GetLocalizedText("SecurityGroup.Label.List")+" ("+Grid.Rows.FilteredInRowCount.ToString()+")";
Util.SetGridFilteredStyle(Grid,bFiltered);
//case 1039 //if(log.IsDebugEnabled) //case 1039 //log.Debug("BindGrid - finished (" + Grid.Text + ")");
Grid.EndUpdate();
Cursor.Current = Cursors.Default;
}
#endregion
#region Selection and Editing
Infragistics.Win.UIElement ElementLastClicked;
/// <summary>
/// This is whacky Infragistics stuff, where normally we would
/// just do someting like override Row.OnDoubleClick we can't
/// do that with a grid because it's rows don't have a click event
///
/// To know which row is clicked on we need to always keep
/// track of what element of the grid was last clicked on
/// so that later on we can (in doubleclick) pre-know what was
/// clicked in the first click of the double click.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ElementLastClicked = Grid.DisplayLayout.UIElement.ElementFromPoint(new System.Drawing.Point(e.X, e.Y));
//Handle right click
if( e.Button == MouseButtons.Right)
{
GridNameValueCellItem nvb=Util.NameValueButtonRightClicked(Grid,e);
if(nvb!=null)
{
Util.DisplayObjectContextMenu(nvb.RootObjectType,nvb.Value,this);
}
//else
//{
// UltraGridBand b=Util.BandRightClicked(Grid/*NAME OF GRID HERE, REST IS STOCK TO ANY FORM*/,e);
// if(b!=null)
// {
// UtilGridColumnSelector c = new UtilGridColumnSelector();
// c.BandToEdit=b;
// c.ShowDialog(this);
// }
//}
}
}
private void Grid_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
EditRecord((GridNameValueCellItem)e.Cell.Value,e.Cell.Row.Index);
}
/// <summary>
/// Handle a key down in addition to a mouse click
/// this allows user to hit enter to select from the grid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Space || e.KeyCode==Keys.Enter)
{
UltraGridCell c = Grid.ActiveCell;
if(c!=null)
{
if(c.Value.GetType().ToString()=="GZTW.AyaNova.BLL.GridNameValueCellItem")
{
e.Handled=true;
EditRecord((GridNameValueCellItem)c.Value,c.Row.Index);
}
}
}
}
/// <summary>
/// Open record for editing then update grid afterwards
/// </summary>
/// <param name="i"></param>
/// <param name="nRowToScrollTo"></param>
private void EditRecord(GridNameValueCellItem i, int nRowToScrollTo)
{
//Make sure there is something to edit
if(i==null || i.Value==Guid.Empty)
return;
bool bRefreshGrid=Util.EditRecord(i.RootObjectType,i.Value);
if(bRefreshGrid)
{
Grid.BeginUpdate();
BindGrid(false);
if(nRowToScrollTo<Grid.Rows.Count)
Grid.ActiveRow=Grid.Rows[nRowToScrollTo];
}
}
#endregion
#region MenuMerging
public Infragistics.Win.UltraWinToolbars.UltraToolbarsManager ToolBar
{
get
{
Util.Localize(ToolBarManager);
return ToolBarManager;
}
}
#endregion
#region Menu tool items
private void ToolBarManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
//case 1039 //if(log.IsDebugEnabled) //case 1039 //log.Debug("ToolClick: "+e.Tool.Key);
switch (e.Tool.Key)
{
case "LT:UI.Toolbar.New": // ButtonTool
SecurityGroupInfoForm cf=new SecurityGroupInfoForm();
cf.SecurityGroupToEdit=GZTW.AyaNova.BLL.SecurityGroup.NewItem();
cf.Visible=false;
cf.ShowDialog();
break;
case "LT:UI.Toolbar.Refresh": // ButtonTool
Grid.BeginUpdate();
BindGrid(false);
break;
}
}
#endregion
}
}