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.UltraWinToolbars; using Infragistics.Win.UltraWinGrid; using System.IO; using log4net; namespace AyaNova { /// /// Summary description for DocsForm. /// public class DocsForm : 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 tbManager; private System.Windows.Forms.Panel DocsForm_Fill_Panel; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _DocsForm_Toolbars_Dock_Area_Left; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _DocsForm_Toolbars_Dock_Area_Right; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _DocsForm_Toolbars_Dock_Area_Top; private Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea _DocsForm_Toolbars_Dock_Area_Bottom; private System.Windows.Forms.OpenFileDialog dlgOpenFile; private System.Windows.Forms.HelpProvider helpProvider1; private System.ComponentModel.IContainer components; public DocsForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("tbDocs"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool1 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Open"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool2 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Add"); Infragistics.Win.UltraWinToolbars.ButtonTool buttonTool3 = new Infragistics.Win.UltraWinToolbars.ButtonTool("LT:UI.Command.Add"); 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.Command.Open"); Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance(); Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance(); this.Grid = new Infragistics.Win.UltraWinGrid.UltraGrid(); this.tbManager = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(this.components); this.DocsForm_Fill_Panel = new System.Windows.Forms.Panel(); this._DocsForm_Toolbars_Dock_Area_Left = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this._DocsForm_Toolbars_Dock_Area_Right = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this._DocsForm_Toolbars_Dock_Area_Top = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this._DocsForm_Toolbars_Dock_Area_Bottom = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea(); this.dlgOpenFile = new System.Windows.Forms.OpenFileDialog(); this.helpProvider1 = new System.Windows.Forms.HelpProvider(); ((System.ComponentModel.ISupportInitialize)(this.Grid)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.tbManager)).BeginInit(); this.DocsForm_Fill_Panel.SuspendLayout(); 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(656, 274); this.Grid.TabIndex = 0; this.Grid.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(this.Grid_InitializeRow); this.Grid.BeforeRowInsert += new Infragistics.Win.UltraWinGrid.BeforeRowInsertEventHandler(this.Grid_BeforeRowInsert); // // tbManager // this.tbManager.DesignerFlags = 1; this.tbManager.DockWithinContainer = this; this.tbManager.DockWithinContainerBaseType = typeof(System.Windows.Forms.Form); this.tbManager.ShowFullMenusDelay = 500; ultraToolbar1.DockedColumn = 0; ultraToolbar1.DockedRow = 0; ultraToolbar1.NonInheritedTools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { buttonTool1, buttonTool2}); ultraToolbar1.Text = "tbDocs"; this.tbManager.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] { ultraToolbar1}); this.tbManager.ToolbarSettings.AllowCustomize = Infragistics.Win.DefaultableBoolean.False; this.tbManager.ToolbarSettings.AllowFloating = Infragistics.Win.DefaultableBoolean.False; this.tbManager.ToolbarSettings.AllowHiding = Infragistics.Win.DefaultableBoolean.False; appearance1.Image = global::AyaNova.Resource1.New32; buttonTool3.SharedPropsInternal.AppearancesLarge.Appearance = appearance1; appearance2.Image = global::AyaNova.Resource1.New16; buttonTool3.SharedPropsInternal.AppearancesSmall.Appearance = appearance2; buttonTool3.SharedPropsInternal.Caption = "LT:UI.Command.Add"; appearance3.Image = global::AyaNova.Resource1.Open32; buttonTool4.SharedPropsInternal.AppearancesLarge.Appearance = appearance3; appearance4.Image = global::AyaNova.Resource1.Open16; buttonTool4.SharedPropsInternal.AppearancesSmall.Appearance = appearance4; buttonTool4.SharedPropsInternal.Caption = "LT:UI.Command.Open"; this.tbManager.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { buttonTool3, buttonTool4}); this.tbManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.tbManager_ToolClick); // // DocsForm_Fill_Panel // this.DocsForm_Fill_Panel.Controls.Add(this.Grid); this.DocsForm_Fill_Panel.Cursor = System.Windows.Forms.Cursors.Default; this.DocsForm_Fill_Panel.Dock = System.Windows.Forms.DockStyle.Fill; this.DocsForm_Fill_Panel.Location = new System.Drawing.Point(0, 27); this.DocsForm_Fill_Panel.Name = "DocsForm_Fill_Panel"; this.DocsForm_Fill_Panel.Size = new System.Drawing.Size(656, 274); this.DocsForm_Fill_Panel.TabIndex = 0; // // _DocsForm_Toolbars_Dock_Area_Left // this._DocsForm_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._DocsForm_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control; this._DocsForm_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left; this._DocsForm_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText; this._DocsForm_Toolbars_Dock_Area_Left.Location = new System.Drawing.Point(0, 27); this._DocsForm_Toolbars_Dock_Area_Left.Name = "_DocsForm_Toolbars_Dock_Area_Left"; this._DocsForm_Toolbars_Dock_Area_Left.Size = new System.Drawing.Size(0, 274); this._DocsForm_Toolbars_Dock_Area_Left.ToolbarsManager = this.tbManager; // // _DocsForm_Toolbars_Dock_Area_Right // this._DocsForm_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._DocsForm_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control; this._DocsForm_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right; this._DocsForm_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText; this._DocsForm_Toolbars_Dock_Area_Right.Location = new System.Drawing.Point(656, 27); this._DocsForm_Toolbars_Dock_Area_Right.Name = "_DocsForm_Toolbars_Dock_Area_Right"; this._DocsForm_Toolbars_Dock_Area_Right.Size = new System.Drawing.Size(0, 274); this._DocsForm_Toolbars_Dock_Area_Right.ToolbarsManager = this.tbManager; // // _DocsForm_Toolbars_Dock_Area_Top // this._DocsForm_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._DocsForm_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control; this._DocsForm_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top; this._DocsForm_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText; this._DocsForm_Toolbars_Dock_Area_Top.Location = new System.Drawing.Point(0, 0); this._DocsForm_Toolbars_Dock_Area_Top.Name = "_DocsForm_Toolbars_Dock_Area_Top"; this._DocsForm_Toolbars_Dock_Area_Top.Size = new System.Drawing.Size(656, 27); this._DocsForm_Toolbars_Dock_Area_Top.ToolbarsManager = this.tbManager; // // _DocsForm_Toolbars_Dock_Area_Bottom // this._DocsForm_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping; this._DocsForm_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control; this._DocsForm_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom; this._DocsForm_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText; this._DocsForm_Toolbars_Dock_Area_Bottom.Location = new System.Drawing.Point(0, 301); this._DocsForm_Toolbars_Dock_Area_Bottom.Name = "_DocsForm_Toolbars_Dock_Area_Bottom"; this._DocsForm_Toolbars_Dock_Area_Bottom.Size = new System.Drawing.Size(656, 0); this._DocsForm_Toolbars_Dock_Area_Bottom.ToolbarsManager = this.tbManager; // // dlgOpenFile // this.dlgOpenFile.Multiselect = true; // // DocsForm // this.AllowDrop = true; this.AutoScaleBaseSize = new System.Drawing.Size(6, 15); this.ClientSize = new System.Drawing.Size(656, 301); this.Controls.Add(this.DocsForm_Fill_Panel); this.Controls.Add(this._DocsForm_Toolbars_Dock_Area_Left); this.Controls.Add(this._DocsForm_Toolbars_Dock_Area_Right); this.Controls.Add(this._DocsForm_Toolbars_Dock_Area_Bottom); this.Controls.Add(this._DocsForm_Toolbars_Dock_Area_Top); this.helpProvider1.SetHelpNavigator(this, System.Windows.Forms.HelpNavigator.Topic); this.Name = "DocsForm"; this.helpProvider1.SetShowHelp(this, true); this.ShowInTaskbar = false; this.Text = "LT:AssignedDoc.Label.List"; this.Closing += new System.ComponentModel.CancelEventHandler(this.DocsForm_Closing); this.Load += new System.EventHandler(this.DocsForm_Load); this.DragDrop += new System.Windows.Forms.DragEventHandler(this.DocsForm_DragDrop); this.DragEnter += new System.Windows.Forms.DragEventHandler(this.DocsForm_DragEnter); ((System.ComponentModel.ISupportInitialize)(this.Grid)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.tbManager)).EndInit(); this.DocsForm_Fill_Panel.ResumeLayout(false); this.ResumeLayout(false); } #endregion // __ _ _ ___ ____ __ __ __ __ __ ___ ___ // / _)( )( )/ __)(_ _)/ \( \/ ) / _)/ \( \( _) // ( (_ )()( \__ \ )( ( () )) ( ( (_( () )) ) )) _) // \__) \__/ (___/ (__) \__/(_/\/\_) \__)\__/(___/(___) // #region load / close //variable to hold user form settings //UIUserFormSetting mFormSetting; private void DocsForm_Load(object sender, System.EventArgs e) { //case 1039 //log.Debug("DocsForm_Load"); // // helpProvider1 // this.helpProvider1.HelpNamespace = Util.BaseHelpUrl + "Documents.htm"; Cursor.Current = Cursors.WaitCursor; this.Visible=false; this.Icon = Resource1.Documents16icon; Util.LoadFormCustomization("DocsForm", this, tbManager, false); Util.LocalizeHelperInsertMenu(tbManager, this); //case 1810 InitGrid(); Util.Localize(this); this.Visible=true; Cursor.Current = Cursors.Default; } private void DocsForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //case 1039 //log.Debug("DocsForm_Closing"); Grid.UpdateData(); Util.SaveGridLayout("AssignedDocs","","",Grid); Util.SaveFormCustomization("DocsForm", this, tbManager, false); } #endregion #region Properties private AssignedDocs mDocs; /// /// record to edit /// set by caller /// public AssignedDocs DocsToEdit { set { mDocs=value; } } private RootObjectTypes mRootObjectType; /// /// /// public RootObjectTypes RootObjectType { set { mRootObjectType=value; } } //case 1584 private RootObjectTypes mExactObjectType; /// /// /// public RootObjectTypes ExactObjectType { set { mExactObjectType = value; } } private Guid mRootObjectID; /// /// /// public Guid RootObjectID { set { mRootObjectID=value; } } #endregion #region Grid init /// /// Intialize grid /// private void InitGrid() { //case 1039 //log.Debug("InitGrid"); Grid.DataSource=mDocs; Util.GridPreLocalize("AssignedDoc",Grid.DisplayLayout.Bands[0]); Util.FetchGridLayout("AssignedDocs","",Grid); //Hide most workorder item fields foreach(UltraGridColumn c in Grid.DisplayLayout.Bands[0].Columns) { c.Hidden=true; } Grid.DisplayLayout.Bands[0].Columns["URL"].Hidden=false; Grid.DisplayLayout.Bands[0].Columns["Description"].Hidden=false; Grid.DisplayLayout.Bands[0].Columns["Created"].Hidden=false; Grid.DisplayLayout.Bands[0].Columns["Creator"].Hidden=false; Grid.DisplayLayout.Bands[0].Columns["Description"].CellAppearance.Image=null; Grid.DisplayLayout.Bands[0].Columns["Created"].SortComparer = new Util.AYStringToDateComparer(); //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #region ======== Users value list ======== //Clear any previous value list from this column //gridScheduledUsers.DisplayLayout.Bands[0].Columns["UserID"].ValueList=null; //Add all potential active items ValueList vlUsers=new ValueList(); UserPickList UList= UserPickList.GetList(false); foreach(UserPickList.UserPickListInfo ui in UList) { vlUsers.ValueListItems.Add(ui.ID,ui.Name); } //Show sorted alphabetically vlUsers.SortStyle=ValueListSortStyle.Ascending; //Bind value lists to correct columns in grid Grid.DisplayLayout.Bands[0].Columns["Creator"].ValueList=vlUsers; //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["Creator"].Style=Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList) Grid.DisplayLayout.Bands[0].Columns["Creator"].AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend; #endregion Grid.DisplayLayout.Bands[0].Columns["Creator"].CellActivation=Activation.ActivateOnly; Grid.DisplayLayout.Bands[0].Columns["Created"].CellActivation=Activation.ActivateOnly; Grid.DisplayLayout.Override.HeaderClickAction=HeaderClickAction.SortSingle; Grid.DisplayLayout.Override.AllowAddNew=AllowAddNew.TemplateOnBottom; //Allow empty string entry on grid Util.SetTextColumnsNullable(Grid); //Very important as if their caption is not changed it will result in their grid position //not being saved (which is actually a bug to be addressed) Grid.DisplayLayout.Bands[0].Columns["Creator"].Header.Caption=Util.LocaleText.GetLocalizedText("Common.Label.Creator"); Grid.DisplayLayout.Bands[0].Columns["Created"].Header.Caption=Util.LocaleText.GetLocalizedText("Common.Label.Created"); } #endregion #region Drag and drop docs private void DocsForm_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { Util.DragDrop(e,mDocs,mRootObjectType,mRootObjectID,mExactObjectType); } private void DocsForm_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { Util.DragEnter(e); } #endregion #region Toolbar commands / file dialog private void tbManager_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.Command.Add": // ButtonTool { if(dlgOpenFile.ShowDialog()==DialogResult.OK) { string[] files = dlgOpenFile.FileNames; if ( files != null ) { foreach(string file in files) { AssignedDoc doc=mDocs.Add(mRootObjectType,mRootObjectID, mExactObjectType); doc.Description=System.IO.Path.GetFileName(file); doc.URL=file; } } } foreach(UltraGridRow r in Grid.Rows) { if(r.Cells["Description"].Appearance.Image==null) SetIcon(r); } } break; case "LT:UI.Command.Delete": // ButtonTool // Place code here break; case "LT:UI.Command.Open": // ButtonTool { if(Grid.ActiveRow!=null) { Util.OpenDocumentURL(Grid.ActiveRow.Cells["URL"].Value.ToString()); } } break; } } #endregion #region manual entry private void Grid_BeforeRowInsert(object sender, Infragistics.Win.UltraWinGrid.BeforeRowInsertEventArgs e) { //case 1039 //log.Debug("Grid_BeforeRowInsert"); mDocs.Add(mRootObjectType,mRootObjectID, mExactObjectType); //e.Cancel=true; } #endregion #region Grid events private void Grid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { SetIcon(e.Row); } /// /// set the icon for the file type indicated /// /// private void SetIcon(UltraGridRow r) { //case 1039 //log.Debug("SetIcon"); string ext=""; string url=""; if(r.Cells["URL"].Value==null || r.Cells["URL"].Value.ToString()=="") { //blank icon or none I guess. return; } url=r.Cells["URL"].Value.ToString(); if(url.ToLower().StartsWith("http") || url.ToLower().StartsWith("ftp")) { ext=".url"; } else if( url.ToLower().StartsWith("mailto")) { r.Cells["Description"].Appearance.Image = Resource1.Memo16;// Util.Image("UserMail16.png"); return; } else ext=Path.GetExtension(r.Cells["URL"].Value.ToString()); System.Drawing.Icon ic=null; if(ext.ToLower().EndsWith("exe")) { //get it from the executable file itself ic = Util.IconHandler.IconFromFile(url, Util.IconSize.Small, 0); } else { ic = Util.IconHandler.IconFromExtension(ext, Util.IconSize.Small); } if(ic!=null) r.Cells["Description"].Appearance.Image=ic.ToBitmap(); } #endregion } }