Files
ayanova7/source/WinFormApp/UserInfoCertificationsForm.cs
2018-06-29 19:47:36 +00:00

384 lines
15 KiB
C#

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using GZTW.AyaNova.BLL;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using log4net;
namespace AyaNova
{
/// <summary>
/// Summary description for UserInfoCertificationsForm.
/// </summary>
public class UserInfoCertificationsForm : 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;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Panel panel1;
private Infragistics.Win.UltraWinEditors.UltraComboEditor cbCertifications;
private System.Windows.Forms.Panel panel2;
private GZTW.WinForm.Controls.GZDateTimePicker GridCalendar;
private Infragistics.Win.Misc.UltraButton btnCertList;
private User mUser=null;
public UserInfoCertificationsForm(User UserToEdit)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
mUser=UserToEdit;
}
/// <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()
{
Infragistics.Win.UltraWinEditors.EditorButton editorButton1 = new Infragistics.Win.UltraWinEditors.EditorButton();
Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
this.Grid = new Infragistics.Win.UltraWinGrid.UltraGrid();
this.panel1 = new System.Windows.Forms.Panel();
this.cbCertifications = new Infragistics.Win.UltraWinEditors.UltraComboEditor();
this.panel2 = new System.Windows.Forms.Panel();
this.btnCertList = new Infragistics.Win.Misc.UltraButton();
this.GridCalendar = new GZTW.WinForm.Controls.GZDateTimePicker();
((System.ComponentModel.ISupportInitialize)(this.Grid)).BeginInit();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.cbCertifications)).BeginInit();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.GridCalendar)).BeginInit();
this.SuspendLayout();
//
// Grid
//
this.Grid.Dock = System.Windows.Forms.DockStyle.Fill;
this.Grid.Location = new System.Drawing.Point(0, 0);
this.Grid.Name = "Grid";
this.Grid.Size = new System.Drawing.Size(592, 318);
this.Grid.TabIndex = 0;
this.Grid.AfterRowsDeleted += new System.EventHandler(this.Grid_AfterRowsDeleted);
this.Grid.ClickCellButton += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.Grid_ClickCellButton);
//
// panel1
//
this.panel1.Controls.Add(this.Grid);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 55);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(592, 318);
this.panel1.TabIndex = 1;
//
// cbCertifications
//
this.cbCertifications.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cbCertifications.AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend;
appearance1.Image = global::AyaNova.Resource1.New16;
editorButton1.Appearance = appearance1;
this.cbCertifications.ButtonsLeft.Add(editorButton1);
this.cbCertifications.Location = new System.Drawing.Point(0, 28);
this.cbCertifications.MaxDropDownItems = 25;
this.cbCertifications.Name = "cbCertifications";
this.cbCertifications.Size = new System.Drawing.Size(592, 24);
this.cbCertifications.SortStyle = Infragistics.Win.ValueListSortStyle.Ascending;
this.cbCertifications.TabIndex = 2;
this.cbCertifications.EditorButtonClick += new Infragistics.Win.UltraWinEditors.EditorButtonEventHandler(this.cbCertifications_EditorButtonClick);
//
// panel2
//
this.panel2.Controls.Add(this.btnCertList);
this.panel2.Controls.Add(this.cbCertifications);
this.panel2.Controls.Add(this.GridCalendar);
this.panel2.Dock = System.Windows.Forms.DockStyle.Top;
this.panel2.Location = new System.Drawing.Point(0, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(592, 55);
this.panel2.TabIndex = 3;
//
// btnCertList
//
this.btnCertList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
appearance2.TextHAlignAsString = "Left";
this.btnCertList.Appearance = appearance2;
this.btnCertList.Location = new System.Drawing.Point(0, 0);
this.btnCertList.Name = "btnCertList";
this.btnCertList.Size = new System.Drawing.Size(592, 28);
this.btnCertList.TabIndex = 152;
this.btnCertList.Tag = "";
this.btnCertList.Text = "LT:UserCertification.Label.List";
this.btnCertList.UseHotTracking = Infragistics.Win.DefaultableBoolean.True;
this.btnCertList.Click += new System.EventHandler(this.btnCertList_Click);
//
// GridCalendar
//
this.GridCalendar.GZEnabled = true;
this.GridCalendar.GZReadOnly = false;
this.GridCalendar.Location = new System.Drawing.Point(557, 0);
this.GridCalendar.Name = "GridCalendar";
this.GridCalendar.Size = new System.Drawing.Size(38, 24);
this.GridCalendar.TabIndex = 151;
this.GridCalendar.Visible = false;
//
// UserInfoCertificationsForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.ClientSize = new System.Drawing.Size(592, 373);
this.Controls.Add(this.panel1);
this.Controls.Add(this.panel2);
this.Name = "UserInfoCertificationsForm";
this.ShowInTaskbar = false;
this.Closing += new System.ComponentModel.CancelEventHandler(this.UserInfoCertificationsForm_Closing);
this.Load += new System.EventHandler(this.UserInfoCertificationsForm_Load);
((System.ComponentModel.ISupportInitialize)(this.Grid)).EndInit();
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.cbCertifications)).EndInit();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.GridCalendar)).EndInit();
this.ResumeLayout(false);
}
#endregion
// __ _ _ ___ ____ __ __ __ __ __ ___ ___
// / _)( )( )/ __)(_ _)/ \( \/ ) / _)/ \( \( _)
// ( (_ )()( \__ \ )( ( () )) ( ( (_( () )) ) )) _)
// \__) \__/ (___/ (__) \__/(_/\/\_) \__)\__/(___/(___)
//
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#region Form load / close
//variable to hold user form settings
//UIUserFormSetting mFormSetting;
private ControlContainerEditor ccGridDateTimeEditor = null;
private void UserInfoCertificationsForm_Load(object sender, System.EventArgs e)
{
//case 1039 //log.Debug("UserInfoCertificationsForm_Load");
this.Icon = Resource1.UserCertificate16icon;
//See if user has any rights to be here...
//(this is done here to ensure that no matter what happens if a user has no rights they can't get here
//useful in case we miss a way of getting to a User edit screen from elsewhere in the program)
if(AyaBizUtils.Right("Object.UserCertificationAssigned")< (int)SecurityLevelTypes.ReadOnly)//Less than read only instead of NoAccess to catch records where it's zero instead of 1
{
//Inform them of their wicked ways and boot them out of here...
MessageBox.Show(string.Format(
Util.LocaleText.GetLocalizedText("Error.Security.NotAuthorizedToRetrieve"),
Util.LocaleText.GetLocalizedText("O.UserCertificationAssigned")));
this.Close();
return;
}
ccGridDateTimeEditor = new ControlContainerEditor();
ccGridDateTimeEditor.EditingControl = GridCalendar;
//this.GridCalendar.MaskInput=Util.LocaleDateTimeMask();
Util.BindField(Grid,"DataSource",mUser,"UserCertifications");
Util.GridPreLocalize("UserCertificationAssigned",Grid.DisplayLayout.Bands[0]);
Util.GridHideEditableBizObjectInternalFields(Grid);
Grid.DisplayLayout.Bands[0].Columns["UserID"].Hidden=true;
PopulateGridValueLists();
Grid.DisplayLayout.Override.HeaderClickAction=HeaderClickAction.SortSingle;
Grid.DisplayLayout.Override.AllowAddNew=AllowAddNew.No;
Grid.DisplayLayout.Override.AllowDelete=DefaultableBoolean.True;
Grid.DisplayLayout.Bands[0].Columns["UserCertificationID"].CellActivation=Activation.NoEdit;
Grid.DisplayLayout.Bands[0].Columns["ValidStartDate"].Editor = ccGridDateTimeEditor;
Grid.DisplayLayout.Bands[0].Columns["ValidStopDate"].Editor = ccGridDateTimeEditor;
Grid.DisplayLayout.Override.AllowUpdate=DefaultableBoolean.True;
Util.Localize(this);
Grid.DisplayLayout.Bands[0].Columns["UserCertificationID"].Header.Caption=Util.LocaleText.GetLocalizedText("O.UserCertification");
FillAvailableCertificationsCombo();
Util.LoadFormCustomization("UserInfoCertifications", this, null, false);
if ((SecurityLevelTypes)AyaBizUtils.Right("Object.UserCertificationAssigned") > SecurityLevelTypes.ReadWrite)
Util.GridAddDeleteButton(Grid);
else
Util.GridRemoveDeleteButton(Grid);
//Set rights
Util.SetAccess((AyaBizUtils.Right("Object.UserCertificationAssigned")< (int)SecurityLevelTypes.ReadWrite),this,(AyaBizUtils.Right("Object.UserCertificationAssigned")< (int)SecurityLevelTypes.ReadWriteDelete) );
}
private void UserInfoCertificationsForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//case 1039 //log.Debug("UserInfoCertificationsForm_Closing");
Grid.UpdateData();
Util.SaveFormCustomization("UserInfoCertifications", this, null, false);
}
#endregion
/// <summary>
/// Populate the drop down lists inside the grid
/// so they display and can select the correct underlying
/// value
/// </summary>
private void PopulateGridValueLists()
{
//case 1039 //log.Debug("PopulateGridValueLists");
//wipe old ones
Grid.DisplayLayout.ValueLists.Clear();
//Populate value lists
ValueList vl=Grid.DisplayLayout.ValueLists.Add("Certifications");
//NVCHANGED
GenericNVList l=GenericNVList.GetList("aUserCertification","aID","aName",true,true,false);
//Loop through the items in the list and put them
//into the valuelist
for(int x=0;x<l.Count;x++)
{
ValueListItem vli=vl.ValueListItems.Add(new Guid(((DictionaryEntry)l.BindableList[x]).Key.ToString()),
((DictionaryEntry)l.BindableList[x]).Value.ToString());
}
//Bind value lists to correct columns in grid
Grid.DisplayLayout.Bands[0].Columns["UserCertificationID"].ValueList=Grid.DisplayLayout.ValueLists["Certifications"];
//Set column to dropdownlist style so that user can not type an invalid value in a cell
//but must select from the list only
Grid.DisplayLayout.Bands[0].Columns["UserCertificationID"].Style=Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
Grid.DisplayLayout.Bands[0].Columns["UserCertificationID"].AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend;
}
/// <summary>
/// refresh combo with Certifications not previously added
/// </summary>
private void FillAvailableCertificationsCombo()
{
//case 1039 //log.Debug("FillAvailableCertificationsCombo");
cbCertifications.Items.Clear();
//NVCHANGED
GenericNVList l=GenericNVList.GetList("aUserCertification","aID","aName",true,true,false);
//Loop through the items in the list and put them
//into the valuelist if they aren't already selected
for(int x=0;x<l.Count;x++)
{
if(!mUser.UserCertifications.ContainsCertification(((DictionaryEntry)l.BindableList[x]).Key.ToString()))
cbCertifications.Items.Add(new Guid(((DictionaryEntry)l.BindableList[x]).Key.ToString()),
((DictionaryEntry)l.BindableList[x]).Value.ToString());
}
}
/// <summary>
/// Add item to grid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cbCertifications_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
//case 1039 //log.Debug("cbCertifications_EditorButtonClick");
if(cbCertifications.SelectedItem==null) return;
if((Guid)cbCertifications.SelectedItem.DataValue!=Guid.Empty)
{
UserCertificationAssigned usa=mUser.UserCertifications.Add(mUser);
usa.UserCertificationID=(Guid)cbCertifications.SelectedItem.DataValue;
FillAvailableCertificationsCombo();
}
}
/// <summary>
/// refresh combo
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_AfterRowsDeleted(object sender, System.EventArgs e)
{
//case 1039 //log.Debug("Grid_AfterRowsDeleted");
FillAvailableCertificationsCombo();
}
private void btnCertList_Click(object sender, System.EventArgs e)
{
//case 1039 //log.Debug("btnCertList_Click");
GenericListForm g11 = new GenericListForm();
UserCertifications uc = UserCertifications.GetItems();
g11.GridDataSource=uc;
g11.ShowDialog();
FillAvailableCertificationsCombo();
PopulateGridValueLists();
}
private void Grid_ClickCellButton(object sender, CellEventArgs e)
{
//case 1105
if (e.Cell.Column.Key == "REMOVE")
{
Grid.DisplayLayout.ActiveRow.Delete();
}
}
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
}