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

2351 lines
107 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 Infragistics.Win.UltraWinGrid;
using GZTW.AyaNova.BLL;
using System.Threading;
using CSLA.Security;
using Infragistics.Win;
namespace AyaNova
{
public partial class MainGrid : 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);
public MainGrid()
{
InitializeComponent();
Util.Localize(this);
//Add items localized for TopRows combo box
this.cbTop.Items.Add(-1,Util.LocaleText.GetLocalizedText("UI.Label.FirstRowsAll"));
#if(DEBUG)
//this.cbTop.Items.Add(5, "TEST 5");
#endif
this.cbTop.Items.Add(100, Util.LocaleText.GetLocalizedText("UI.Label.FirstRows100"));
this.cbTop.Items.Add(500, Util.LocaleText.GetLocalizedText("UI.Label.FirstRows500"));
this.cbTop.Items.Add(1000, Util.LocaleText.GetLocalizedText("UI.Label.FirstRows1000"));
//save a reference to the filter drop down editor button for transmogrification
filterButton = cbFilters.ButtonsRight[0] as Infragistics.Win.UltraWinEditors.EditorButton;
//Determine users rights to filter objects and cache that info
filterAccessRights = (SecurityLevelTypes)AyaBizUtils.Right("Object.GridFilter");
filterButtonCanUse=(filterAccessRights > SecurityLevelTypes.ReadOnly);
cbFilters.ButtonsRight[0].Visible = filterButtonCanUse;
//case 556
//display initial unchecked image in row selector header
Grid.DisplayLayout.Override.RowSelectorHeaderAppearance.ImageBackground = Resource1.UnChecked16;
Grid.DisplayLayout.Override.SelectedRowAppearance.FontData.Underline = DefaultableBoolean.True;
Grid.DisplayLayout.Override.SelectedRowAppearance.FontData.Bold = DefaultableBoolean.True;
Grid.DisplayLayout.Override.RowSelectorStyle = HeaderStyle.XPThemed;
}
// __ _ _ ___ ____ __ __ __ __ __ ___ ___
// / _)( )( )/ __)(_ _)/ \( \/ ) / _)/ \( \( _)
// ( (_ )()( \__ \ )( ( () )) ( ( (_( () )) ) )) _)
// \__) \__/ (___/ (__) \__/(_/\/\_) \__)\__/(___/(___)
//
#region Properties
//case 776
public string CurrentGridFilterCriteria
{
get
{
return Util.gGridLastViews[sCurrentListKey].ViewXML;
}
}
//case 941
public RootObjectTypes BaseObjectType
{
get
{
return baseObject;
}
}
public object ListObject
{
get
{
return Grid.DataSource;
}
}
public System.Collections.Generic.List<Guid> SelectedIDList
{
get
{
return SelectedIDs(false);
}
}
#endregion
#region Workorder changed event handler
//case 697
/// <summary>
/// This method is to refresh any workorders based grid if a work order is saved
/// the workorder form adds this event handler to the workorder form's updated event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void w_WorkorderUpdated(object sender, EventArgs e)
{
if (baseObject == RootObjectTypes.WorkorderService ||
baseObject == RootObjectTypes.WorkorderQuote ||
baseObject == RootObjectTypes.WorkorderPreventiveMaintenance)
{
BindData(true);
}
}
#endregion
#region Form events
bool bLoading = true;
private void MainGrid_Load(object sender, EventArgs e)
{
//
// helpProvider1
//
this.helpProvider1.HelpNamespace = Util.BaseHelpUrl + "adding_editing_and_deleting_da.htm";
//GridCalendar.MaskInput = Util.LocaleDateTimeMask();
bLoading = false;
if (!AyaBizUtils.Lite && AyaBizUtils.GlobalSettings.MainGridAutoRefresh)//case 1487
{
//case 700
#if (DEBUG)
//testing interval
this.timerGridRefresh.Interval = 30000;
#else
//5 minutes
timerGridRefresh.Interval=300000;
#endif
timerGridRefresh.Enabled = true;
timerGridRefresh.Start();
}
}
private void MainGrid_FormClosing(object sender, FormClosingEventArgs e)
{
if (!AyaBizUtils.Lite)
{
//case 700
timerGridRefresh.Stop();
timerGridRefresh.Enabled = false;
}
if (sCurrentListKey != "")
{
SaveGridLayout(false);
Util.SaveFormCustomization("MainGrid_" + sCurrentListKey, this, ToolBarManager, true);
}
//case 1553
User u = User.GetItem(User.CurrentThreadUserID);
u.MainGridLastRowCount = (int)cbTop.SelectedItem.DataValue;
u.Save();
}
#endregion
#region Caching (info saved to ease flipping between grids in a session)
//Save users rights to filters to quickly determine
//if save / open button should be displayed
//Set in form constructor
SecurityLevelTypes filterAccessRights;
//editor button on filter drop down
//used to quickly change text of it
Infragistics.Win.UltraWinEditors.EditorButton filterButton;
private string filterButtonSave = Util.LocaleText.GetLocalizedText("UI.Command.Save");
private string filterButtonOpen = Util.LocaleText.GetLocalizedText("UI.Command.Open");
//If user has rights to use filter button then this will be true
private bool filterButtonCanUse = false;
//A cache to hold display attributes previously reflected for performance
//This is used for the life of the application as it does not change
private Dictionary<string,Dictionary<string,DisplayAttribute>> displayCache=new Dictionary<string,Dictionary<string,DisplayAttribute>>();
/// <summary>
/// Return a cached displayattributes collection
/// for the object type passed in.
///
/// If not in cache, adds to cache
/// </summary>
/// <param name="t">Type of read only collection object</param>
/// <returns></returns>
private Dictionary<string, DisplayAttribute> DisplayAttributes(Type t)
{
if (!displayCache.ContainsKey(t.Name))
displayCache.Add(t.Name, AyaBizUtils.GetDisplayAttributes(t));
return displayCache[t.Name];
}
Dictionary<string, DisplayAttribute> currentDisplayAttributes;
/// <summary>
/// A shortcut for initialize row to know if there is any color to deal with
/// </summary>
private bool hasColoredColumns = false;
//A cache to hold the colored column key names and the column that sets their color
private Dictionary<string, string> colorColumns = new Dictionary<string, string>();
//A cache to hold the max results selection for each list
//for the life of the session
private Dictionary<string, int> listMaxResults = new Dictionary<string, int>();
private int GetListMaxResults()
{
if (!listMaxResults.ContainsKey(sCurrentListKey))
{
//Case 316 - workaround so MIAD gets all rows by default
if (AyaBizUtils.REGTO == "Miad Systems Ltd")
listMaxResults.Add(sCurrentListKey, 0);
else
{
//case 1553
User u = User.GetItem(User.CurrentThreadUserID);
foreach (ValueListItem vi in cbTop.Items)
{
if ((int)vi.DataValue == u.MainGridLastRowCount)
{
cbTop.SelectedItem = vi;
break;
}
}
listMaxResults.Add(sCurrentListKey,cbTop.SelectedIndex);
}
}
return listMaxResults[sCurrentListKey];
}
//A cache to hold read only collection lists previously retrieved
//this used only to hold the lists when user changes do different lists and back again
//it's refreshed when any change is made that would affect the dataset returned
private Dictionary<string, object> listCache = new Dictionary<string, object>();
/// <summary>
/// Fetch the read only collection object based on the key passed in
///
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private object GetListObject(string key, bool Refresh, string FilterXML)
{
if (Refresh && listCache.ContainsKey(key))
listCache.Remove(key);
if (!listCache.ContainsKey(key))
{
listCache.Add(key,ListFactory.GetList(key, FilterXML, System.Convert.ToInt32(cbTop.Value)));
}
//Get the display attributes so they can be known before grid is bound
//to data source so that initializerow and other early events can
//use this info
currentDisplayAttributes = DisplayAttributes(listCache[key].GetType());
PreBindInitialize();
return listCache[key];
}
#endregion
#region Grid load data, load and save layout and decorate handling
string sCurrentListKey = "";
RootObjectTypes baseObject = RootObjectTypes.Nothing;
//Added 12 July 2006 to allow grid to filter some lists
//Used to indicate a particular list is not filterable
//using the standard method (i.e. search grid)
bool bFilterable = true;
#region load
//variable to hold user form settings
//UIUserFormSetting mFormSetting;
/// <summary>
/// Called by main form1 to display list requested
/// </summary>
/// <param name="listKey"></param>
public void ShowList(string listKey, bool force)
{
//case 534
//a list needs to be displayed freshly whether it's visible or not already
//if it's already visible this code just refreshes it
if (force && (sCurrentListKey == listKey))
{
//switch the filter drop down to unsaved
bLoading = true;
//Default ID value when users changes settings in grid
cbFilterAddAndSelectUnsavedItem();
bLoading = false;
//case 700
if(!AyaBizUtils.Lite) timerGridRefresh.Stop();
BindData(true);
if (!AyaBizUtils.Lite) timerGridRefresh.Start();
SetGridFilters(Grid.DisplayLayout.Bands[0], Util.gGridLastViews[sCurrentListKey].ViewFilter);
return;
}
if (sCurrentListKey != "")
SaveGridLayout(false);
if (sCurrentListKey != listKey)
{
//case 700
if (!AyaBizUtils.Lite) timerGridRefresh.Stop();
//Save prior list here
if(!string.IsNullOrEmpty(sCurrentListKey))
Util.SaveFormCustomization("MainGrid_" + sCurrentListKey, this, ToolBarManager, true);
sCurrentListKey = listKey;
//Load new list here
Util.LoadFormCustomization("MainGrid_" + sCurrentListKey, this, ToolBarManager, true);
//Added 12 July 2006 to allow grid to filter some lists
bFilterable = true;
if (sCurrentListKey == "SearchResultList" || sCurrentListKey == "AyaFileList")
bFilterable = false;
//Set the max results combo to the last selected
//value (returns the default if not set before)
//for the scurrentlistkey
//And set the last filter
bLoading = true;
cbTop.SelectedIndex=GetListMaxResults();
//Added 12 July 2006 to allow grid to filter some lists
if (bFilterable)
{
//This line essentially turns off row filtering by the grid so that the
//queries can handle it instead
Grid.DisplayLayout.Override.RowFilterAction = RowFilterAction.AppearancesOnly;
//use this for testing to ensure that no filterd out rows ever appear disabled so
//that we know the grid is in accordance with sql for the filters set
//Grid.DisplayLayout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
//Load the list of filters into the combo and select the last filter
//that was in use, if it's not in the list then unsaved will be selected
LoadFilterList(Util.gGridLastViews[sCurrentListKey].FilterID);
//ensure a force sets to unsaved filter
if (force)
{
//switch the filter drop down to unsaved
bLoading = true;
//Default ID value when users changes settings in grid
cbFilterAddAndSelectUnsavedItem();
bLoading = false;
}
this.ToolBarManager.Tools["filter"].SharedProps.Visible = true;
}
else
{
//This line essentially turns on row filtering by the grid so that
//unfilterable lists can be filtered in the grid itself
Grid.DisplayLayout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
this.ToolBarManager.Tools["filter"].SharedProps.Visible = false;
}
bLoading = false;
//Set the datasource to null
//so that the previous column settings don't carry over to the
//next datasource
//I.E. if a user goes from workorders list with column order settings
//to workorderitems with no column order settings, because some of the
//columns have the same name was carrying over the settings
Grid.DataSource = null;
//Two of the lists require row selectors (quotes and pm's) so
//disable by default for the others and those items can enable below if required
//Case 556 - now need row selectors for all printable lists
Grid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;
Grid.DisplayLayout.Override.SelectTypeRow = SelectType.Extended;
Grid.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.SeparateElement;
Grid.DisplayLayout.Override.RowSelectorStyle = HeaderStyle.Default;
//INVENTORY: special handling for inventory form which is the only hiearchical form
//and requires row selectors to show the expansion indicators for serial numbers
if (sCurrentListKey == "PartWarehouseInventoryList")
{
//Common.Label.SerialNumber
Grid.DisplayLayout.Override.ExpansionIndicator = ShowExpansionIndicator.CheckOnDisplay;
Grid.DisplayLayout.ViewStyle = ViewStyle.MultiBand;
}
else
{
Grid.DisplayLayout.Override.ExpansionIndicator = ShowExpansionIndicator.Never;
Grid.DisplayLayout.ViewStyle = ViewStyle.SingleBand;
}
//SEARCH: special settings
if (sCurrentListKey == "SearchResultList" )
{
Grid.DisplayLayout.Bands[0].Override.HeaderClickAction = HeaderClickAction.SortSingle;
this.ToolBarManager.Tools["LT:UI.Command.Search"].SharedProps.Visible = true;
edSearchTerms.Visible = true;
}
else
{
Grid.DisplayLayout.Bands[0].Override.HeaderClickAction = HeaderClickAction.ExternalSortSingle;
this.ToolBarManager.Tools["LT:UI.Command.Search"].SharedProps.Visible = false;
edSearchTerms.Visible = false;
}
//AyaFileList: special settings
if (sCurrentListKey == "AyaFileList")
{
this.ToolBarManager.Tools["LT:UI.Command.Delete"].SharedProps.Visible = (AyaBizUtils.Right("Object.AyaFile") > (int)SecurityLevelTypes.ReadOnly);
}
else
{
this.ToolBarManager.Tools["LT:UI.Command.Delete"].SharedProps.Visible = false;
}
//REPORTLIST: special settings
if (sCurrentListKey == "ReportList")
{
this.ToolBarManager.Tools["LT:Report.Label.ImportLayout"].SharedProps.Visible = (AyaBizUtils.Right("Object.Report") > (int)SecurityLevelTypes.ReadOnly);
}
else
{
this.ToolBarManager.Tools["LT:Report.Label.ImportLayout"].SharedProps.Visible = false;
}
//QuoteList: special settings
if (sCurrentListKey == "WorkorderQuoteList")
{
Grid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;
this.ToolBarManager.Tools["LT:WorkorderQuote.Label.GenerateServiceWorkorder"].SharedProps.Visible = true;
}
else
{
this.ToolBarManager.Tools["LT:WorkorderQuote.Label.GenerateServiceWorkorder"].SharedProps.Visible = false;
}
//PMList: special settings
if (sCurrentListKey == "WorkorderPMList")
{
Grid.DisplayLayout.Override.RowSelectors = DefaultableBoolean.True;
this.ToolBarManager.Tools["LT:WorkorderPreventiveMaintenance.Label.GenerateServiceWorkorder"].SharedProps.Visible = true;
}
else
{
this.ToolBarManager.Tools["LT:WorkorderPreventiveMaintenance.Label.GenerateServiceWorkorder"].SharedProps.Visible = false;
}
BindData(force);//case 534 (previously was just false always)
baseObject = (RootObjectTypes)AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "BaseObjectType");
Util.PluginInsertMenu(ToolBarManager,new Util.PluginMenuOptionData(false,baseObject,this,null));//case 941
if (baseObject == RootObjectTypes.PurchaseOrderReceiptItem)
{
//poreceiptitem uses the rights from purchase order
ToolBarManager.Tools["LT:UI.Toolbar.New"].SharedProps.Visible =
AyaBizUtils.Right(RootObjectTypes.PurchaseOrder) > (int)SecurityLevelTypes.ReadOnly;
}
else
{
ToolBarManager.Tools["LT:UI.Toolbar.New"].SharedProps.Visible =
sCurrentListKey!="ClientServiceRequestList" && AyaBizUtils.Right(baseObject) > (int)SecurityLevelTypes.ReadOnly;
}
DecorateGrid();
if (AyaBizUtils.Right("Object.Report") < (int)SecurityLevelTypes.ReadOnly)
{
ToolBarManager.Tools["LT:UI.Toolbar.Print"].SharedProps.Visible = false;
}
else
{
ToolBarManager.Tools["LT:UI.Toolbar.Print"].SharedProps.Visible = true;
Util.ReportFillList(this.ToolBarManager.Tools["REPORTLIST"],
System.Convert.ToString(AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "ReportKey")),
System.Convert.ToString(AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "DetailedReportKey")));
}
//case 941
//This form was previously relying on the rights to the baseobject exclusively
//in order to decide if the New button should display or not.
//So lists that were not to have a new button had their baseobject set to Nothing
//but now we need to know the baseobject type for the plugin processing so
//Each of those lists needs to be checked for and button hidden if not new-able
switch (sCurrentListKey)
{
case "PartWarehouseInventoryList":
case "WorkorderItemPartRequestList":
case "SearchResultList":
case "AyaFileList"://case 1002
case "ReportList"://case 1313
ToolBarManager.Tools["LT:UI.Toolbar.New"].SharedProps.Visible = false;
break;
}
//case 1172 - no new users please
if (AyaBizUtils.Lite && sCurrentListKey == "UserList") ToolBarManager.Tools["LT:UI.Toolbar.New"].SharedProps.Visible = false;
//case 700
if (!AyaBizUtils.Lite) timerGridRefresh.Start();
}
}
GridFilterPickList gridFilterList = null;
/// <summary>
/// Load the filter list based on the current gridlist
/// </summary>
private void LoadFilterList(Guid SelectedItem)
{
if (gridFilterList == null)
{
gridFilterList=GridFilterPickList.GetList(User.GetItem((((BusinessPrincipal)Thread.CurrentPrincipal).ID)));
}
this.cbFilters.Items.Clear();
bool bFilterSelected = false;
//Default ID value when first opened
//and selected by user to clear all filters from grid in one go
ValueListItem vlNone= cbFilters.Items.Add(GridFilter.NoFilterID, Util.LocaleText.GetLocalizedText("UI.Label.FilterNone"));
foreach( KeyValuePair<string,Guid> kvp in gridFilterList.GetListOfGridKey(sCurrentListKey))
{
ValueListItem vli=cbFilters.Items.Add(kvp.Value, kvp.Key);
if (kvp.Value == SelectedItem)
{
cbFilters.SelectedItem = vli;
bFilterSelected = true;
}
}
//If no match was found in the list then set a default in the combo
if (!bFilterSelected)
{
//If there are some columns filtered in the last view then
//set to unsaved
if (Util.gGridLastViews[sCurrentListKey].HasFilter)
{
cbFilterAddAndSelectUnsavedItem();
}
else
{
//nothing set in last view to filtered, no matching filter id
//so set to none
cbFilters.SelectedItem = vlNone;
}
}
}
/// <summary>
/// Called when loading or when user customizes the filters in the grid
/// </summary>
private void cbFilterAddAndSelectUnsavedItem()
{
//case 1168
if (!Util.ComboContainsGuid(cbFilters, GridFilter.UnsavedFilterID))
{
Infragistics.Win.ValueListItem vi = cbFilters.Items.Add(GridFilter.UnsavedFilterID, Util.LocaleText.GetLocalizedText("UI.Label.FilterUnsaved"));
vi.Appearance.ForeColor = Color.Red;
vi.Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True;
Util.ComboSelectGuid(cbFilters, GridFilter.UnsavedFilterID);
}
}
/// <summary>
/// Bind the data source specified in scurrentlistkey
/// and optionally force a refresh of the grid
/// </summary>
/// <param name="Refresh">true=forced refresh of cache</param>
public void BindData(bool Refresh)
{
Grid.BeginUpdate();
Cursor.Current = Cursors.WaitCursor;
//Databinding triggers a sort change which we don't want as it will then retrigger a databinding
Grid.EventManager.SetEnabled(GridEventIds.BeforeSortChange, false);
if (sCurrentListKey == "SearchResultList")
Grid.DataSource = GetListObject(sCurrentListKey, Refresh, edSearchTerms.Text);
else
Grid.DataSource = GetListObject(sCurrentListKey, Refresh, Util.gGridLastViews[sCurrentListKey].ViewXML);
Grid.EventManager.SetEnabled(GridEventIds.BeforeSortChange, true);
Grid.Text = Util.LocaleText.GetLocalizedText(System.Convert.ToString(AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "LocaleKey"))) + " (" + Grid.Rows.Count.ToString() + ")";
if (sCurrentListKey == "AyaFileList")
{
Grid.Text += " ("+ AyaBizUtils.FileSizeDisplay(AyaFileStats.GetStats().TotalStoredFileData)+")";
}
Cursor.Current = Cursors.Default;
Grid.EndUpdate();
}
#endregion
#region decorate
/// <summary>
/// localize and set the column types and visibility
/// Also sets column order and filter criteria and sort direction
/// if that info is contained in a last view object
/// ** Assumes flat data source **
/// </summary>
private void DecorateGrid()
{
//Get a reference to Band[0] to reuse throughout this method
UltraGridBand band = Grid.DisplayLayout.Bands[0];
//disable events that we don't want fired during setup
Grid.EventManager.SetEnabled(EventGroups.AllEvents, false);
Grid.BeginUpdate();
band.SortedColumns.Clear();
SetGridColumnDisplayAttributes(band);
SetGridColumnOrder(band);
SetGridFilters(band, Util.gGridLastViews[sCurrentListKey].ViewFilter);
//Special cases
//special handling for inventory form which is the only hiearchical form
//and requires row selectors to show the expansion indicators for serial numbers
if (sCurrentListKey == "PartWarehouseInventoryList")
{
//
Grid.DisplayLayout.Bands[1].Columns["ID"].Hidden=true;
Grid.DisplayLayout.Bands[1].Columns["SerialNumber"].Header.Caption = Util.LocaleText.GetLocalizedText("Common.Label.SerialNumber");
}
//Case 280
if (sCurrentListKey == "SearchResultList")
{
Grid.DisplayLayout.Bands[0].Columns["LT_SearchResult_Label_Rank"].Format = "f2";
}
//Turn back on the events for the grid
Grid.EventManager.SetEnabled(EventGroups.AllEvents, true);
//Turn on initializerow event only if there is color columns to deal with
Grid.EventManager.SetEnabled(GridEventIds.InitializeRow, hasColoredColumns);
Grid.EndUpdate();
//Case 240
Util.GridStyler(Grid);
}
#region Display attributes
private void SetGridColumnDisplayAttributes(UltraGridBand band)
{
//If a user has no last view then don't hide normally visible columns in this method
bool bHasSavedLastView = (Util.gGridLastViews[sCurrentListKey].ViewOrder.Rows.Count > 0);
//case 1283
bool bCurrentUserCanViewAdminStuff = AyaBizUtils.Lite || (User.CurrentUserType == UserTypes.Administrator);
foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn cm in band.Columns)
{
//Localize column headers
//exceptions:
//Vendorlist mistakenly still uses the old ID method for object name
//since reports are stuck with it, can't change it
if (cm.Header.Caption == "LT_Vendor_Label_ID")
{
cm.Header.Caption = "LT_O_Vendor";
}
//Now localize:
if (cm.Header.Caption.StartsWith("LT_"))
cm.Header.Caption = Util.LocaleText.GetLocalizedText(cm.Header.Caption.Replace("LT_", "").Replace("_", "."));
//columns with grid attribute are not sortable or filterable
if (Util.GetSqlColumnNameAttribute(cm) == "grid")
{
cm.AllowRowFiltering = DefaultableBoolean.False;
cm.SortIndicator = SortIndicator.None;
}
else
{
cm.AllowRowFiltering = DefaultableBoolean.True;
cm.SortIndicator = SortIndicator.Disabled;//hot hot hot
}
//Catch missing display types, every list object that displays here
//must have a display type attribute on every field
if (currentDisplayAttributes[cm.Key] == null)
throw new System.ApplicationException("Missing display attribute for " + Grid.DataSource.GetType().ToString() + "." + cm.Key);
//Hide em all because the visible ones will be shown when column order is set next
//(if there is a saved last view which is checked for at the top of this method)
cm.Hidden = bHasSavedLastView;
bool bColumnIsHidden = false;
#region set display type
switch (currentDisplayAttributes[cm.Key].DisplayAs)
{
case DisplayType.Hidden:
cm.Tag = DisplayType.Hidden;
cm.Hidden = true;
bColumnIsHidden = true;
break;
case DisplayType.Button:
cm.Tag = DisplayType.Button;
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
cm.CellAppearance.Cursor = Cursors.Hand;
break;
case DisplayType.Currency:
cm.Format = "c";
cm.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
break;
case DisplayType.DateTime:
//case 1985
cm.Format = "g";
cm.EditorComponent = this.GridCalendar;
break;
case DisplayType.DateOnly:
//case 1985
cm.Format = "d";
cm.EditorComponent = this.GridCalendar;
break;
case DisplayType.TrueFalse:
//Do nothing, underlying bool value will translate to checkbox automatically
break;
case DisplayType.DecimalNumber:
cm.Format = "g29";
break;
case DisplayType.GeoCoordinate:
//Nothing for now, just a string
//cm.Format = "F";
break;
case DisplayType.Percentage:
cm.Format = "P";
break;
case DisplayType.Text:
//case 1707
// cm.CellDisplayStyle = Infragistics.Win.UltraWinGrid.CellDisplayStyle.PlainText;
cm.CellDisplayStyle = Infragistics.Win.UltraWinGrid.CellDisplayStyle.Default;
break;
case DisplayType.TimeOnly:
//case 1985
cm.Format = "t";
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Time;
break;
case DisplayType.URL_Email:
cm.Tag = DisplayType.URL_Email;
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
cm.CellAppearance.ForeColor = Color.Blue;
cm.CellAppearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.True;
cm.CellAppearance.Cursor = Cursors.Hand;
break;
case DisplayType.URL_Web:
cm.Tag = DisplayType.URL_Web;
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
cm.CellAppearance.ForeColor = Color.Blue;
cm.CellAppearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.True;
cm.CellAppearance.Cursor = Cursors.Hand;
break;
case DisplayType.URL_Document:
cm.Tag = DisplayType.URL_Document;
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
cm.CellAppearance.ForeColor = Color.Blue;
cm.CellAppearance.FontData.Underline = Infragistics.Win.DefaultableBoolean.True;
cm.CellAppearance.Cursor = Cursors.Hand;
break;
case DisplayType.WholeNumber:
//Do nothing, should default ok
break;
case DisplayType.ListAyaDayOfWeek:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("DaysOfTheWeek"))
{
ValueList vlDays = Grid.DisplayLayout.ValueLists.Add("DaysOfTheWeek");
//Day of week
vlDays.ValueListItems.Add(AyaDayOfWeek.AnyDayOfWeek, Util.LocaleText.GetLocalizedText("UI.Label.Day.Any"));
vlDays.ValueListItems.Add(AyaDayOfWeek.Monday, Util.LocaleText.GetLocalizedText("UI.Label.Day.Monday"));
vlDays.ValueListItems.Add(AyaDayOfWeek.Tuesday, Util.LocaleText.GetLocalizedText("UI.Label.Day.Tuesday"));
vlDays.ValueListItems.Add(AyaDayOfWeek.Wednesday, Util.LocaleText.GetLocalizedText("UI.Label.Day.Wednesday"));
vlDays.ValueListItems.Add(AyaDayOfWeek.Thursday, Util.LocaleText.GetLocalizedText("UI.Label.Day.Thursday"));
vlDays.ValueListItems.Add(AyaDayOfWeek.Friday, Util.LocaleText.GetLocalizedText("UI.Label.Day.Friday"));
vlDays.ValueListItems.Add(AyaDayOfWeek.Saturday, Util.LocaleText.GetLocalizedText("UI.Label.Day.Saturday"));
vlDays.ValueListItems.Add(AyaDayOfWeek.Sunday, Util.LocaleText.GetLocalizedText("UI.Label.Day.Sunday"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["DaysOfTheWeek"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
case DisplayType.ListAyaUnitsOfTime:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("UnitsOfTime"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("UnitsOfTime");
//Generate Timespans
vl.ValueListItems.Add(AyaUnitsOfTime.Minutes, Util.LocaleText.GetLocalizedText("UI.Label.TimeSpan.Minutes"));
vl.ValueListItems.Add(AyaUnitsOfTime.Hours, Util.LocaleText.GetLocalizedText("UI.Label.TimeSpan.Hours"));
vl.ValueListItems.Add(AyaUnitsOfTime.Days, Util.LocaleText.GetLocalizedText("UI.Label.TimeSpan.Days"));
//Weeks are not supported because the concept of Week is very "weak" globally :)
//and is not supported by the .net datetime.Add function for this reason
//vl.ValueListItems.Add(AyaUnitsOfTime.Weeks,Util.LocaleText.GetLocalizedText("UI.Label.TimeSpan.Weeks"));
vl.ValueListItems.Add(AyaUnitsOfTime.Months, Util.LocaleText.GetLocalizedText("UI.Label.TimeSpan.Months"));
vl.ValueListItems.Add(AyaUnitsOfTime.Years, Util.LocaleText.GetLocalizedText("UI.Label.TimeSpan.Years"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["UnitsOfTime"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
case DisplayType.ListPurchaseOrderStatus:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("POStatusList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("POStatusList");
vl.ValueListItems.Add(Guid.Empty, Util.NoSelectionString);//Case 318
vl.ValueListItems.Add(PurchaseOrderStatus.ClosedFullReceived, Util.LocaleText.GetLocalizedText("PurchaseOrder.Label.PurchaseOrderStatus.ClosedFullReceived"));
vl.ValueListItems.Add(PurchaseOrderStatus.ClosedNoneReceived, Util.LocaleText.GetLocalizedText("PurchaseOrder.Label.PurchaseOrderStatus.ClosedNoneReceived"));
vl.ValueListItems.Add(PurchaseOrderStatus.ClosedPartialReceived, Util.LocaleText.GetLocalizedText("PurchaseOrder.Label.PurchaseOrderStatus.ClosedPartialReceived"));
vl.ValueListItems.Add(PurchaseOrderStatus.OpenNotYetOrdered, Util.LocaleText.GetLocalizedText("PurchaseOrder.Label.PurchaseOrderStatus.OpenNotYetOrdered"));
vl.ValueListItems.Add(PurchaseOrderStatus.OpenOrdered, Util.LocaleText.GetLocalizedText("PurchaseOrder.Label.PurchaseOrderStatus.OpenOrdered"));
vl.ValueListItems.Add(PurchaseOrderStatus.OpenPartialReceived, Util.LocaleText.GetLocalizedText("PurchaseOrder.Label.PurchaseOrderStatus.OpenPartialReceived"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["POStatusList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
case DisplayType.ListVendorTypes:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("VendorTypeList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("VendorTypeList");
//Add initial emtpy guid value
//so that records with no value yet entered in the contacttitle
//field will be shown as an empty string
vl.ValueListItems.Add(Guid.Empty, Util.NoSelectionString);//Case 318
vl.ValueListItems.Add(VendorTypes.Manufacturer, Util.LocaleText.GetLocalizedText("Vendor.Label.VendorType.Manufacturer"));
vl.ValueListItems.Add(VendorTypes.Shipper, Util.LocaleText.GetLocalizedText("Vendor.Label.VendorType.Shipper"));
vl.ValueListItems.Add(VendorTypes.SubContractor, Util.LocaleText.GetLocalizedText("Vendor.Label.VendorType.SubContractor"));
vl.ValueListItems.Add(VendorTypes.ThirdPartyRepair, Util.LocaleText.GetLocalizedText("Vendor.Label.VendorType.ThirdPartyRepair"));
vl.ValueListItems.Add(VendorTypes.Wholesaler, Util.LocaleText.GetLocalizedText("Vendor.Label.VendorType.Wholesaler"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["VendorTypeList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
case DisplayType.ListUsers:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("UserList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("UserList");
UserPickList UList = UserPickList.GetList(false);
vl.SortStyle = ValueListSortStyle.None;
foreach (UserPickList.UserPickListInfo ui in UList)
vl.ValueListItems.Add(ui.ID, ui.Name);
//Show sorted alphabetically
vl.SortStyle = ValueListSortStyle.Ascending;
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["UserList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
case DisplayType.ListClientServiceRequestPriority:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("CSRPriorityList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("CSRPriorityList");
vl.ValueListItems.Add(ClientServiceRequestPriority.NotUrgent, Util.LocaleText.GetLocalizedText("ClientServiceRequestPriority.NotUrgent"));
vl.ValueListItems.Add(ClientServiceRequestPriority.ASAP, Util.LocaleText.GetLocalizedText("ClientServiceRequestPriority.ASAP"));
vl.ValueListItems.Add(ClientServiceRequestPriority.Emergency, Util.LocaleText.GetLocalizedText("ClientServiceRequestPriority.Emergency"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["CSRPriorityList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
case DisplayType.ListClientServiceRequestStatus:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("CSRStatusList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("CSRStatusList");
vl.ValueListItems.Add(ClientServiceRequestStatus.Accepted, Util.LocaleText.GetLocalizedText("ClientServiceRequestStatus.Accepted"));
vl.ValueListItems.Add(ClientServiceRequestStatus.Declined, Util.LocaleText.GetLocalizedText("ClientServiceRequestStatus.Declined"));
vl.ValueListItems.Add(ClientServiceRequestStatus.Open, Util.LocaleText.GetLocalizedText("ClientServiceRequestStatus.Open"));
vl.ValueListItems.Add(ClientServiceRequestStatus.Closed, Util.LocaleText.GetLocalizedText("ClientServiceRequestStatus.Closed"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["CSRStatusList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
case DisplayType.SpecialControl:
//Stuff that is list specific and needs to be
//handled in a specific way
if (cm.Key == "LT_Memo_Label_Replied")
cm.EditorComponent = GridCheckEditor;
break;
//Case 184
case DisplayType.ListUserTypes:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("UserTypeList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("UserTypeList");
//Add initial emtpy guid value
//so that records with no value yet entered in the contacttitle
//field will be shown as an empty string
vl.ValueListItems.Add(UserTypes.Administrator, Util.LocaleText.GetLocalizedText("UserTypes.Label.Administrator"));
vl.ValueListItems.Add(UserTypes.Schedulable, Util.LocaleText.GetLocalizedText("UserTypes.Label.Schedulable"));
vl.ValueListItems.Add(UserTypes.NonSchedulable, Util.LocaleText.GetLocalizedText("UserTypes.Label.NonSchedulable"));
vl.ValueListItems.Add(UserTypes.Client, Util.LocaleText.GetLocalizedText("UserTypes.Label.Client"));
vl.ValueListItems.Add(UserTypes.HeadOffice, Util.LocaleText.GetLocalizedText("UserTypes.Label.HeadOffice"));
vl.ValueListItems.Add(UserTypes.Utility, Util.LocaleText.GetLocalizedText("UserTypes.Label.UTILITY"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["UserTypeList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
//Case 353
case DisplayType.ListQuoteStatusTypes:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("QuoteStatusList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("QuoteStatusList");
vl.ValueListItems.Add(WorkorderQuoteStatusTypes.Awarded, Util.LocaleText.GetLocalizedText("WorkorderQuoteStatusTypes.Label.Awarded"));
vl.ValueListItems.Add(WorkorderQuoteStatusTypes.InProgress, Util.LocaleText.GetLocalizedText("WorkorderQuoteStatusTypes.Label.InProgress"));
vl.ValueListItems.Add(WorkorderQuoteStatusTypes.NotAwarded, Util.LocaleText.GetLocalizedText("WorkorderQuoteStatusTypes.Label.NotAwarded"));
vl.ValueListItems.Add(WorkorderQuoteStatusTypes.Submitted, Util.LocaleText.GetLocalizedText("WorkorderQuoteStatusTypes.Label.Submitted"));
//case 1556
vl.ValueListItems.Add(WorkorderQuoteStatusTypes.New, Util.LocaleText.GetLocalizedText("WorkorderQuoteStatusTypes.Label.New"));
vl.ValueListItems.Add(WorkorderQuoteStatusTypes.NotAwarded2, Util.LocaleText.GetLocalizedText("WorkorderQuoteStatusTypes.Label.NotAwarded2"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["QuoteStatusList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
//Case 410
case DisplayType.ListLoanItemRates:
//check if grid already has the value list
if (!Grid.DisplayLayout.ValueLists.Exists("LoanItemRatesList"))
{
ValueList vl = Grid.DisplayLayout.ValueLists.Add("LoanItemRatesList");
vl.ValueListItems.Add(LoanItemRates.None, Util.LocaleText.GetLocalizedText("LoanItem.Label.RateNone"));
vl.ValueListItems.Add(LoanItemRates.Hours, Util.LocaleText.GetLocalizedText("LoanItem.Label.RateHour"));
vl.ValueListItems.Add(LoanItemRates.HalfDays, Util.LocaleText.GetLocalizedText("LoanItem.Label.RateHalfDay"));
vl.ValueListItems.Add(LoanItemRates.Days, Util.LocaleText.GetLocalizedText("LoanItem.Label.RateDay"));
vl.ValueListItems.Add(LoanItemRates.Weeks, Util.LocaleText.GetLocalizedText("LoanItem.Label.RateWeek"));
vl.ValueListItems.Add(LoanItemRates.Months, Util.LocaleText.GetLocalizedText("LoanItem.Label.RateMonth"));
vl.ValueListItems.Add(LoanItemRates.Years, Util.LocaleText.GetLocalizedText("LoanItem.Label.RateYear"));
}
//set the column to use that value list
cm.ValueList = Grid.DisplayLayout.ValueLists["LoanItemRatesList"];
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate;//Case 96 for autocomplete (was DropDownList)
break;
}
#endregion
//Set custom comparer if required
switch (currentDisplayAttributes[cm.Key].CompareAs)
{
case CompareType.StringToDate:
cm.SortComparer = new Util.AYStringToDateComparer();
break;
case CompareType.StringToInt32:
cm.SortComparer = new Util.AYStringToIntComparer();
break;
}
//case 1584
RootObjectTypes cmObjectType = currentDisplayAttributes[cm.Key].RootObjectType;
if (cmObjectType == RootObjectTypes.Workorder)
{
//whups, there is no workorder object so need to translate to proper object type
if ((BaseObjectType == RootObjectTypes.WorkorderService || BaseObjectType == RootObjectTypes.PurchaseOrderReceiptItem) && cm.Key == "LT_O_Workorder")
{
cmObjectType = RootObjectTypes.WorkorderService;
}
else if (cm.Key == "LT_UI_Label_LastWorkorder")
{
cmObjectType = RootObjectTypes.WorkorderService;
}
else
cmObjectType = BaseObjectType;
}
//case 1210
if (!bColumnIsHidden && AyaBizUtils.Right(cmObjectType) == (int)SecurityLevelTypes.NoAccess)
{
cm.Hidden = true;
cm.Tag = DisplayType.Hidden;
bColumnIsHidden = true;
}
//case 1212
if (AyaBizUtils.Lite)
{
if (!bColumnIsHidden)
{
if (!currentDisplayAttributes[cm.Key].ShowInLite)
{
cm.Hidden = true;
cm.Tag = DisplayType.Hidden;
}
}
}
//case 1283
//turn admin only buttons into text if not admin
if (!bColumnIsHidden && !bCurrentUserCanViewAdminStuff && cm.Style == Infragistics.Win.UltraWinGrid.ColumnStyle.Button)
{
if (currentDisplayAttributes[cm.Key].RootObjectType == RootObjectTypes.User ||
currentDisplayAttributes[cm.Key].RootObjectType == RootObjectTypes.Region)
{
cm.Tag = null;
cm.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Default;
cm.CellAppearance.Cursor = Cursors.Default;
//case 1707
//cm.CellDisplayStyle = CellDisplayStyle.PlainText;
cm.CellDisplayStyle = CellDisplayStyle.Default;
}
}
}
}
#endregion
#region Column order
/// <summary>
/// Set the column order and various properties
/// if there is a column order collection in the last view
/// </summary>
/// <param name="band"></param>
private void SetGridColumnOrder(UltraGridBand band)
{
Grid.DisplayLayout.UseFixedHeaders = true;
int nPosition = 0;
//Check if no saved column order:
if (Util.gGridLastViews[sCurrentListKey].ViewOrder.Rows.Count == 0)
{
//set first column sort indicator if there are no column order to
//do it later below
band.Columns[0].SortIndicator = SortIndicator.None;
return;
}
//show the columns that are in the order collection
//And set their properties such as width, pinned, sort order etc
foreach (DataRow TabRow in Util.gGridLastViews[sCurrentListKey].ViewOrder.Rows)
{
string sColumnName=TabRow["UI"].ToString();
//Needed if we change a column name in code
//and user has saved view of old column name
//or if we drop a column
if(!band.Columns.Exists(sColumnName))
continue;
UltraGridColumn c = band.Columns[sColumnName];
if (c.Tag == null || ((DisplayType)c.Tag) != DisplayType.Hidden)
c.Hidden = false;
//Set sort indicator and scroll tip field for first visible column only
if (nPosition == 0)
{
if (TabRow["SORT"].ToString() == "DESC")
c.SortIndicator = SortIndicator.Descending;
else
c.SortIndicator = SortIndicator.Ascending;
//Added:12-July-2006
//Set scroll tip field
band.ScrollTipField = c.Key;
}
c.Header.VisiblePosition = nPosition++;
c.Width = System.Convert.ToInt32(TabRow["WIDTH"]);
c.Header.Fixed = (TabRow["PIN"].ToString() == "1") ? true : false;
}
}
#endregion
#region Filters
/// <summary>
/// Called from either decorategrid to use users last filters
/// or from a change in the saved filter combo box selector
/// in which case it uses the saved filter's datatable
/// </summary>
/// <param name="band"></param>
/// <param name="dtFilters"></param>
private void SetGridFilters(UltraGridBand band, DataTable dtFilter)
{
//Added 12 July 2006 to allow grid to filter some lists
if (!bFilterable) return;
//Set the column filters from the last view object
//Clear any previous column filters
band.ColumnFilters.ClearAllFilters();
//case 1795
try
{
foreach (DataRow GroupRow in dtFilter.Rows)
{
//It's possible that there is a group but no children in the case
//of certain types of criteria that we don't handle (regex etc) so check first
if (GroupRow.GetChildRows("WHEREITEMGROUP_WHEREITEM").GetLength(0) < 1)
continue;
//Get the column being filtered:
string gridColumn = GroupRow["UI"].ToString();
//convert the string representation of the logical operator enum back to a FilterLogicalOperator
FilterLogicalOperator flogOperator = (FilterLogicalOperator)Enum.Parse(typeof(FilterLogicalOperator), GroupRow["GROUPLOGICALOPERATOR"].ToString());
band.ColumnFilters[gridColumn].LogicalOperator = flogOperator;
foreach (DataRow ChildRow in GroupRow.GetChildRows("WHEREITEMGROUP_WHEREITEM"))
{
Type t;
//Get the type of the compare value
string sType = ChildRow["TYPE"].ToString();
switch (sType)
{
case "GZTW.AyaNova.BLL.AyaDayOfWeek":
t = typeof(System.String);
break;
case "GZTW.AyaNova.BLL.AyaUnitsOfTime":
t = typeof(System.String);
break;
default:
t = System.Type.GetType(sType);
break;
}
//Added 12-July-2006 to preset it to typeof string if it was previously
//not set to anything, so the odd type that got missed was causing a null reference exception
//further below in the system.convert call because t=null and if that was the last list the user had opened
//they were froze out because every restart they got the same error
if (t == null)
t = typeof(System.String);
//"GZTW.AyaNova.BLL.AyaDayOfWeek"
//Get the comparison operator
FilterComparisionOperator fcompOperator = (FilterComparisionOperator)Enum.Parse(typeof(FilterComparisionOperator), ChildRow["COMPAREOPERATOR"].ToString());
//If filter was on a gridnamevaluecellitem it might be a guid which is useless
//for setting as a filter in what is basically a string column, so
//a special UI compare value will have been set containing the string to set the filter to
//bug bug: while implementing case 173 came across this code and and am wondering what if they change the value after the filter is saved, not sure how this is supposed to work
if (ChildRow["UICOMPAREVALUE"].ToString() != "")
{
switch (t.ToString())
{
case "System.Int32":
switch (ChildRow["CM"].ToString())
{
case "aWorkorderQuote.aQuoteNumber":
case "aWorkorderPreventiveMaintenance.aPreventiveMaintenanceNumber":
case "aWorkorderService.aServiceNumber":
band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, new GridNameValueCellItem(Guid.Empty, ChildRow["UICOMPAREVALUE"].ToString(), RootObjectTypes.Nothing));
break;
default:
band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, ChildRow["UICOMPAREVALUE"].ToString());
break;
}
break;
//Added: 1-Sept-2006 test to see if this is what's the big problem all along
//What's happening is that filters that were originally on gridnamevaluecellitem
//and filtering by guid in sql server are reloaded from saved filter in db and
//end up being string comparisons instead which is all kinds of wrong.
//So far so good in testing, I'm going to see if Joyce can break it... :)
case "System.Guid":
{
band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator,
new GridNameValueCellItem(
new Guid(ChildRow["COMPAREVALUE"].ToString()),
ChildRow["UICOMPAREVALUE"].ToString(),
RootObjectTypes.Nothing));
}
break;
default:
band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, ChildRow["UICOMPAREVALUE"].ToString());
break;
}
}
else
{
//Were here because there is no uicomparevalue, that doesn't
//mean however, that there is no comparevalue so this isn't a null or empty area
//only a nongridnamevaluecellitem area
//changed 21-July-2006 to fix major fuckup change on july 19th when only blanks worked afterwards
//I am so incredibly fucking sick of these fucking grids, I might as well have just written
//my own grid filtering component from scratch (or bought one that was db friendly from the start)
if (string.IsNullOrEmpty(ChildRow["COMPAREVALUE"].ToString()))
band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, System.DBNull.Value);
else
band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, System.Convert.ChangeType(ChildRow["COMPAREVALUE"], t));
//Changed:19-July-2006
// band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, System.DBNull.Value);
//if (t == typeof(Guid))
// band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator,System.DBNull.Value);
//else if (t == typeof(Int32))
// band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, "");
//else if (t == typeof(bool))//Added: 06-July-2006 to handle blank and nonblank for bool columns
// band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, false);
//else
// band.ColumnFilters[gridColumn].FilterConditions.Add(fcompOperator, System.Convert.ChangeType(ChildRow["COMPAREVALUE"], t));
}
}
}
}
catch (Exception ex)
{
Util.Error("SetGridFilters", ex.ToString());
}
}
#endregion
/// <summary>
/// Perform ops that need to be done before the grid is bound
/// like gather up the color column info etc
/// </summary>
private void PreBindInitialize()
{
//clear the color columns dictionary which
//will be filled in below and used by initializerow
colorColumns.Clear();
hasColoredColumns = false;
//Iterate through the display attributes for the current object
//and gather any pre bind required info
foreach (KeyValuePair<string, DisplayAttribute> kvp in currentDisplayAttributes)
{
//cache colour columns here
//for use by intialize row
if (kvp.Value != null)
if (kvp.Value.Color)
{
hasColoredColumns = true;
colorColumns[kvp.Key] = kvp.Value.ColorField;
}
}
//Turn on initializerow event only if there is color columns to deal with
Grid.EventManager.SetEnabled(GridEventIds.InitializeRow, hasColoredColumns);
//Or turn it on if it's the memo grid
if(sCurrentListKey=="MemoList")
Grid.EventManager.SetEnabled(GridEventIds.InitializeRow, true);
}
#endregion
/// <summary>
/// Save the grid layout and filter to the grid last view object
/// </summary>
///
private void SaveGridLayout(bool ReverseSort)
{
//Reverse sort is required because this method gets called in the
//before sort changed event so in that case it must process as if the sort had already reversed
//in all other cases it just saves as the grid is
bool bFiltered = false;
//Added 12 July 2006 to allow grid to filter some lists
if(bFilterable)
Util.gGridLastViews[sCurrentListKey].FilterID = (Guid)cbFilters.Value;
Util.gGridLastViews[sCurrentListKey].ViewXML = Util.GetGridSortAndFilterXML(Grid.DisplayLayout.Bands[0], ReverseSort, ref bFiltered);
}
#endregion
#region Grid general events not related to filtering or sorting
/// <summary>
/// Initialize row if required
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_InitializeRow(object sender, InitializeRowEventArgs e)
{
//color?
if (hasColoredColumns)
{
foreach (KeyValuePair<string, string> kvp in colorColumns)
{
if (kvp.Value != "FIXED")
{
int nColor = (int)e.Row.Cells[kvp.Value].Value;
if (nColor != 0)
{
//Case 569
e.Row.Cells[kvp.Key].Appearance.BackColor = Color.FromArgb(nColor);
e.Row.Cells[kvp.Key].Appearance.BackColor2 = SystemColors.Window;
e.Row.Cells[kvp.Key].Appearance.BackGradientStyle = GradientStyle.Horizontal;
e.Row.Cells[kvp.Key].Appearance.ForeColor = SystemColors.WindowText;
}
}
else
{
Color clr = new Color();
//It's a preset color that is not user configurable
switch(kvp.Key)
{
case "LT_ClientServiceRequest_Label_Priority":
{
switch ((ClientServiceRequestPriority)e.Row.Cells[kvp.Key].Value)
{
case ClientServiceRequestPriority.NotUrgent:
clr = Color.Green;
break;
case ClientServiceRequestPriority.ASAP:
clr = Color.Orange;
break;
case ClientServiceRequestPriority.Emergency:
clr = Color.Red;
break;
}
e.Row.Cells[kvp.Key].Appearance.BackColor =clr;
e.Row.Cells[kvp.Key].Appearance.ForeColor = Util.InvertColor(clr);
}
break;
}
}
}
}
if (sCurrentListKey == "MemoList")
{
if ((bool)e.Row.Cells["LT_Memo_Label_Viewed"].Value == true)
{
e.Row.Appearance.FontData.Bold = DefaultableBoolean.False;
}
else
{
e.Row.Appearance.FontData.Bold = DefaultableBoolean.True;
}
}
}
Infragistics.Win.UIElement ElementLastClicked;
/// <summary>
/// MOUSE DOWN: column selector and context menu processing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_MouseDown(object sender, 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)
{
//case 773
bIgnoreClick = 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();
foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn cm in Grid.DisplayLayout.Bands[0].Columns)
{
if (cm.Tag != null && (cm.Tag is DisplayType) && ((DisplayType)cm.Tag == DisplayType.Hidden))
c.HideColumns.Add(cm.Key, 0);
}
c.BandToEdit = b;
c.ShowDialog(this);
ProcessColumnOrdering();
SaveGridLayout(false);
BindData(true);
}
bIgnoreClick = false;//case 773
}
}
}
//case 773
bool bIgnoreClick = false;
/// <summary>
/// Button clicks in grid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
//case 773
if (bIgnoreClick)
{
bIgnoreClick = false;//case 785
return;
}
if (e.Cell.Column.Tag == null || !(e.Cell.Column.Tag is DisplayType))
return;
DisplayType t = (DisplayType)e.Cell.Column.Tag;
switch (t)
{
case DisplayType.Button:
EditRecord((GridNameValueCellItem)e.Cell.Value, e.Cell.Row.Index,e);
break;
case DisplayType.URL_Document:
Util.OpenDocumentURL(e.Cell.Value);
break;
case DisplayType.URL_Email:
Util.OpenEmailURL(e.Cell.Value);
break;
case DisplayType.URL_Web:
Util.OpenWebURL(e.Cell.Value);
break;
default:
break;
}
}
/// <summary>
/// Handle a change in column order
/// and optionally requerying the database
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_AfterColPosChanged(object sender, AfterColPosChangedEventArgs e)
{
//rebind if columns were moved only
//i.e.don't do it if they were just resized
if (e.PosChanged == Infragistics.Win.UltraWinGrid.PosChanged.Moved)
{
//If the column was moved into the 0th position then
//we need to redo the sort indicator stuff
//Case 85 added || sort indicator so that moving the sorted column out of the first position triggers a
//refresh of the column sort indicator
if (e.ColumnHeaders[0].VisiblePosition == 0 || e.ColumnHeaders[0].Column.SortIndicator!=SortIndicator.Disabled)
{
ProcessColumnOrdering();
}
//save grid layout
SaveGridLayout(false);
//force refresh only if the first moved column's NEW visible position is less than 4 since
//only the first 4 columns are part of a sql order by clause anyway
//(the event arg e shows the columns new position since this is an *after* event)
if (e.ColumnHeaders[0].VisiblePosition < 4)
BindData(true);
}
}
#endregion grid general events
#region Filtering and sorting related events
private void cbTop_ValueChanged(object sender, EventArgs e)
{
if (!bLoading)
{
listMaxResults[sCurrentListKey] = cbTop.SelectedIndex;
BindData(true);
}
}
private void cbFilters_ValueChanged(object sender, EventArgs e)
{
//triggered by clear list in load filter list
//so ignore if nothing there
if (cbFilters.Value == null) return;
Guid g = (Guid)cbFilters.Value;
//Remove the unsaved view combo item if it isn't the current selection
//I.E. when a user has an unsaved view and switches to any other view
//they don't get the option of selecting "unsaved view" from the list and saving it
//as that would lead to mass user confusion
if (g != GridFilter.UnsavedFilterID)
{
Util.ComboRemoveFromListGuid(cbFilters, GridFilter.UnsavedFilterID);
}
//Set filter button text
if (filterButtonCanUse)
{
if (g == GridFilter.UnsavedFilterID)
{
cbFilters.ButtonsRight[0].Visible = true;
filterButton.Text = filterButtonSave;
}
else if (g == GridFilter.NoFilterID)
{
cbFilters.ButtonsRight[0].Visible = false;
}
else //user just selected a pre saved view
{
cbFilters.ButtonsRight[0].Visible = true;
filterButton.Text = filterButtonOpen;
}
}
//Process the selected filter if this event was user selected (i.e. not loading)
if (!bLoading)
{
if (g == GridFilter.NoFilterID)
{
Grid.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
}
else
{
//Set filters in grid to
//saved filter's settings
SetGridFilters(Grid.DisplayLayout.Bands[0], this.gridFilterList[g].ViewFilter);
}
//Here there is a problem, the filter in gridfilterlist is ok
//however after the grid is set to use it and then the filter is extracted
//from the grid it is wrong.
//so the call to set grid filter is *not* setting the grid filter the same
//as it is initially set by the user.
//Save the grid layout so bind data can use it
//and for changing lists
SaveGridLayout(false);
//Get the data
BindData(true);
}
}
private void Grid_BeforeSortChange(object sender, BeforeSortChangeEventArgs e)
{
SaveGridLayout(true);
//force a refresh since sort order affects data retrieved
BindData(true);
}
private void Grid_BeforeRowFilterDropDown(object sender, BeforeRowFilterDropDownEventArgs e)
{
Util.SetCustomFilters(e);
}
private void Grid_AfterRowFilterChanged(object sender, AfterRowFilterChangedEventArgs e)
{
//Added 12 July 2006 to allow grid to filter some lists
if (!bFilterable) return;
//switch the filter drop down to unsaved
bLoading = true;
//Default ID value when users changes settings in grid
cbFilterAddAndSelectUnsavedItem();
//Changed: 03-Aug-2006 to change dbnulls to false for a boolean column filter
//problem was that though query worked fine, the grid itself was seeing a filter of
//blank on a bool column as meaning none of the rows matched since a bool can't be blank
//so even though the correct data was showing in the grid, the grid itself was
//thinking there were no rows so users couldn't select other columns items in a filter since they
//didn't exist to the grid which is set to simply change the appearance of filtered out rows
//in effect do nothing rather than remove them. So this fixes the problem of
//users not being able to filter on other columns when a bool column has a blank filter selected
//because it becomes false and thus works properly for the grid and the sql query
if(e.NewColumnFilter.FilterConditions.Count>0 && e.Column.DataType==typeof(bool) && e.NewColumnFilter.FilterConditions[0].CompareValue==DBNull.Value)
{
e.NewColumnFilter.FilterConditions[0].CompareValue = false;
}
bLoading = false;
SaveGridLayout(false);
BindData(true);
}
/// <summary>
/// Click to open a saved filter or save an unsaved filter
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void cbFilters_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
GridFilter gf;
Guid g = (Guid)cbFilters.Value;
//If unsaved then create a new filter object and pass it to the editing form
if (g == GridFilter.UnsavedFilterID)
{
gf = GridFilter.NewItem();
//This is saved after every filter change so it's fresh
gf.FilterXML = Util.gGridLastViews[sCurrentListKey].ViewXML;
gf.GridKey = this.sCurrentListKey;
}
else
gf = GridFilter.GetItem(g);
//if existing then fetch it and pass it to the editing form
GridFilterInfoForm gfif = new GridFilterInfoForm();
gfif.GridFilterToEdit = gf;
gfif.ShowDialog();
//If filter was deleted then select no filter
//refresh grid, then refresh list of filters
if (gfif.FilterDeleted)
{
Util.ComboSelectGuid(cbFilters, GridFilter.NoFilterID);
bLoading = true;
gridFilterList = null;
LoadFilterList(GridFilter.NoFilterID);
bLoading = false;
}
else if (gfif.ChangesMade)
{
//If filter was saved then reload filter list
//without reloading grid so proper name now shows
bLoading = true;
gridFilterList = null;
LoadFilterList(gf.ID);
bLoading = false;
}
//preserve the last filter ID in use
Util.gGridLastViews[sCurrentListKey].FilterID = (Guid)cbFilters.Value;
}
#endregion filter related events
#region Column re-positioning handler
/// <summary>
/// Set all columns unsortable except for the left most visible column
/// Set the scroll tip to the first column
///
/// </summary>
/// <param name="Ascending"></param>
private void ProcessColumnOrdering()
{
Grid.EventManager.SetEnabled(GridEventIds.BeforeSortChange, false);
//Get the *visible* column order
//setting the sort to disabled for every column while doing it
int nLeftMostVisibleColumnPosition = 999;
UltraGridColumn LeftMostColumn=null;
foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn cm in Grid.DisplayLayout.Bands[0].Columns)
{
//Find the first visible column as we go through them
//(they are not stored in visible order)
if (nLeftMostVisibleColumnPosition != 0 && cm.Header.VisiblePosition < nLeftMostVisibleColumnPosition && cm.Hidden == false)
{
nLeftMostVisibleColumnPosition = cm.Header.VisiblePosition;
LeftMostColumn = cm;
}
cm.SortIndicator = SortIndicator.Disabled;
}
//Set sort indicator
if (Util.GetSqlColumnNameAttribute(LeftMostColumn) == "grid")//case 3170
LeftMostColumn.SortIndicator = SortIndicator.Disabled;
else
LeftMostColumn.SortIndicator = SortIndicator.Ascending;
//Set scroll tip field
Grid.DisplayLayout.Bands[0].ScrollTipField = LeftMostColumn.Key;
Grid.EventManager.SetEnabled(GridEventIds.BeforeSortChange, true);
}
#endregion
#region MenuMerging
public Infragistics.Win.UltraWinToolbars.UltraToolbarsManager ToolBar
{
get
{
Util.Localize(ToolBarManager);
return ToolBarManager;
}
}
#endregion
#region Edit record
/// <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, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
//Make sure there is something to edit
if (i == null || i.Value == Guid.Empty)
return;
bool bRefreshGrid = false;
//Modified for Case 41
if (sCurrentListKey == "WorkorderServiceItemList" && i.RootObjectType == RootObjectTypes.Workorder)
{
//Open workorder item instead
object o=e.Cell.Row.Cells["LT_WorkorderItem_Label_ID"].Value;
bRefreshGrid = Util.EditRecord(RootObjectTypes.WorkorderItem, (Guid)o);
}
else
bRefreshGrid = Util.EditRecord(i.RootObjectType, i.Value);
if (bRefreshGrid)
{
BindData(true);
if (nRowToScrollTo < Grid.Rows.Count)
Grid.ActiveRow = Grid.Rows[nRowToScrollTo];
}
}
#endregion
#region Toolbar code
private void ToolBarManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
switch (e.Tool.Key)
{
case "LT:UI.Toolbar.Refresh": // ButtonTool
BindData(true);
break;
case "LT:WorkorderPreventiveMaintenance.Label.GenerateServiceWorkorder": // ButtonTool
{
if (Grid.ActiveRow == null) return;
WorkorderForm f = new WorkorderForm();
f.WorkorderToEdit = Workorder.NewServiceWorkorderFromPM(((GridNameValueCellItem)Grid.ActiveRow.Cells["LT_O_WorkorderPreventiveMaintenance"].Value).Value);
f.ShowDialog();
f.Dispose();
BindData(true);
}
break;
case "LT:WorkorderQuote.Label.GenerateServiceWorkorder": // ButtonTool
{
if (Grid.ActiveRow == null) return;
WorkorderForm f = new WorkorderForm();
f.WorkorderToEdit = Workorder.NewServiceWorkorderFromQuote(((GridNameValueCellItem)Grid.ActiveRow.Cells["LT_O_WorkorderQuote"].Value).Value);
f.ShowDialog();
f.Dispose();
BindData(true);
}
break;
case "LT:Report.Label.ImportLayout": // ButtonTool
dlgOpen.Filter =
Util.LocaleText.GetLocalizedText("Report.Label.ExportLayoutFile") + "|*.ayr";
if (dlgOpen.ShowDialog() == DialogResult.OK)
{
//Import will return false if there is
//already a pre-existing report with the same
//GUID in the database
if (!Report.ImportLayout(dlgOpen.FileName))
{
//case 1039 //log.Debug("Error: report (" + dlgOpen.FileName + ") can't be imported, a report already exists with same GUID");
Util.PromptWithIconOKOnlyFromLocaleKey("Report.Label.Error.ImportDuplicate", MessageBoxIcon.Hand);
}
else
{
//case 1039 //log.Debug("Report (" + dlgOpen.FileName + ") Imported - OK");
BindData(true);
}
}
break;
case "LT:UI.Command.Delete":
{
//case 73
if (Grid.ActiveRow == null) return;
if (Util.PromptForDelete() == DialogResult.Yes)
{
AyaFile.DeleteItem(((GridNameValueCellItem)Grid.ActiveRow.Cells["LT_O_AyaFile"].Value).Value);
BindData(true);
}
}
break;
case "LT:UI.Toolbar.New": // ButtonTool
if (baseObject == RootObjectTypes.WorkorderService ||
baseObject == RootObjectTypes.WorkorderQuote ||
baseObject == RootObjectTypes.WorkorderPreventiveMaintenance )
{
//Get which client first...
WorkorderTypes wotype = WorkorderTypes.Unknown;
if (baseObject == RootObjectTypes.WorkorderService)
wotype = WorkorderTypes.TemplateService;
if (baseObject == RootObjectTypes.WorkorderQuote)
wotype = WorkorderTypes.TemplateQuote;
if (baseObject == RootObjectTypes.WorkorderPreventiveMaintenance)
wotype = WorkorderTypes.TemplatePreventiveMaintenance;
ClientSelector c = new ClientSelector(wotype);
DialogResult result = c.ShowDialog();
if (result == DialogResult.Cancel)
{
//part of diagnosis for case 1586
c.Dispose();
return;
}
//part of diagnosis for case 1586
Guid selectedTemplate = c.SelectedTemplateID;
Guid selectedClient = c.SelectedClientID;
c.Dispose();
c = null;
Workorder w = null;
try
{
if (selectedTemplate != Guid.Empty)
w = Workorder.NewItem(selectedTemplate,selectedClient);
else
w=Workorder.NewItem(baseObject);
}
catch (TrialException ex)
{
ex.ToString();//just to suppress the compiler warning which is redundant in this case
Util.PromptRestricted();
return;
}
w.ClientID = selectedClient;
if (AyaBizUtils.Lite)//case 1172
{
WorkorderFormLite wfl = new WorkorderFormLite();
wfl.WorkorderToEdit = w;
wfl.ShowDialog();
wfl.Dispose();
}
else
{
WorkorderForm wf = new WorkorderForm();
wf.WorkorderToEdit = w;
//Case 677
wf.Show();
}
//wf.Dispose();
//BindData(true);
}
else if (//TEMPLATE?
baseObject == RootObjectTypes.WorkorderServiceTemplate ||
baseObject == RootObjectTypes.WorkorderQuoteTemplate ||
baseObject == RootObjectTypes.WorkorderPreventiveMaintenanceTemplate)
{
Workorder w = null;
try
{
w = Workorder.NewItem(baseObject);
}
catch (TrialException ex)
{
ex.ToString();//Just to suppress the compiler warning
Util.PromptRestricted();
return;
}
WorkorderForm wf = new WorkorderForm();
wf.WorkorderToEdit = w;
//Case 677
wf.Show();
//wf.Dispose();
//BindData(true);
}
else if (baseObject == RootObjectTypes.PurchaseOrderReceiptItem)
{
PurchaseOrderReceiptSelectVendor psv = new PurchaseOrderReceiptSelectVendor();
DialogResult dr = psv.ShowDialog();
if (dr == DialogResult.Cancel || psv.SelectedVendor == Guid.Empty)
{
//Cancel
return;
}
//OK was selected so prompt for user to select open PO's for the vendor...
PurchaseOrderReceiptSelectVendorsPurchaseOrders p = new PurchaseOrderReceiptSelectVendorsPurchaseOrders(psv.SelectedVendor);
dr = p.ShowDialog();
if (dr == DialogResult.Cancel)
{
//Cancel
return;
}
//Get settings
DataSet ds = p.SelectedPurchaseOrders;
//start a new receipt object
PurchaseOrderReceipt por = PurchaseOrderReceipt.NewItem();
//por.ReceivedDate=DBUtil.CurrentWorkingDateTime;
por.VendorID = psv.SelectedVendor;
//Add selected purchase order contents to receiving...
foreach (DataRow r in ds.Tables[0].Rows)
{
por.AddContentsOfPurchaseOrder((Guid)r["PO"]);
}
PurchaseOrderReceiptInfoForm porForm = new PurchaseOrderReceiptInfoForm(false);
porForm.PurchaseOrderReceiptToEdit = por;
porForm.ShowDialog();
porForm.Dispose();
BindData(true);
}
else
{
//Not a workorder so pass to edit record to handle
if (Util.EditRecord(baseObject, AyaBizUtils.NewObjectGuid) == true)
{
BindData(true);
}
}
break;
case "REPORTLIST": // ListTool
if (sCurrentListKey == "PartWarehouseInventoryList")
{
#region special reporting for inventory
PartWarehouseInventoryList pwil = null;
if (this.Grid.Selected.Rows.Count == 0)
{
pwil = (PartWarehouseInventoryList)Grid.DataSource;
}
else
{
//One or more are selected so
//get the data through the list factory
pwil = (PartWarehouseInventoryList)ListFactory.GetList(
"PartWarehouseInventoryList",
Util.gGridLastViews[sCurrentListKey].ViewXML,
System.Convert.ToInt32(cbTop.Value), SelectedIDs(false)
);
}
ReportDataSet ds;
ds = new ReportDataSet();
ds.ReadXmlSchema(AyaBizUtils.GetAssemblyDataSetSchema("PartByWarehouseInventoryListSchema.xsd"));
ds.ShowOnlyStartingWith = "Inventory";
DataRow r = null;
foreach (PartWarehouseInventoryList.PartWarehouseInventoryListInfo i in pwil)
{
r = ds.Tables["Inventory"].NewRow();
r["LT_O_PartAssembly"] = i.LT_O_PartAssembly.Display;
r["LT_O_PartCategory"] = i.LT_O_PartCategory.Display;
r["LT_O_PartWarehouse"] = i.LT_O_PartWarehouse.Display;
r["LT_O_Part"] = i.LT_O_Part.Display;
r["ID"] = i.ID;
r["LT_PartByWarehouseInventory_Label_QuantityOnHand"] = i.LT_PartByWarehouseInventory_Label_QuantityOnHand;
r["LT_PartByWarehouseInventory_Label_QuantityOnOrder"] = i.LT_PartByWarehouseInventory_Label_QuantityOnOrder;
r["LT_PartByWarehouseInventory_Label_MinStockLevel"] = i.LT_PartByWarehouseInventory_Label_MinStockLevel;
r["LT_PartByWarehouseInventory_Label_ReorderQuantity"] = i.LT_PartByWarehouseInventory_Label_ReorderQuantity;
r["LT_Part_Label_Cost"] = i.LT_Part_Label_Cost;
r["LT_Part_Label_Retail"] = i.LT_Part_Label_Retail;
//case 460
r["LT_Part_Label_WholesalerID"] = i.LT_Part_Label_WholesalerID.Display;
r["LT_Part_Label_AlternativeWholesalerID"] = i.LT_Part_Label_AlternativeWholesalerID.Display;
ds.Tables["Inventory"].Rows.Add(r);
if (i.LT_PartSerial_Label_List.Count > 0)
{
//Case 236
//before fix was creating and inserting row outside of inner foreach loop resulting in only
//one serial number ever being displayed in report
foreach (PartSerialPickList.PartSerialPickListInfo ppi in i.LT_PartSerial_Label_List)
{
r = ds.Tables["SN"].NewRow();
r["LT_Common_Label_SerialNumber"] = ppi.SerialNumber;
r["PartByWarehouseInventoryID"] = i.ID;
ds.Tables["SN"].Rows.Add(r);
}
}
}
Util.ReportHandleToolClick(e.Tool, PartWarehouseInventoryList.ReportKey, ds);
Util.ReportFillList(this.ToolBarManager.Tools["REPORTLIST"], PartWarehouseInventoryList.ReportKey, "");
#endregion
return;
}
string sReportKey=System.Convert.ToString(AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "ReportKey"));
string sReportKeyDetailed = System.Convert.ToString(AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "DetailedReportKey"));
//Summary report?
if (Util.ReportHandleToolClickIsSummary(e.Tool))
{
//If no separate items are selected then
//just pass the data from the grid to the report directly
//saving a requery
if (this.Grid.Selected.Rows.Count == 0)
{
Util.ReportHandleToolClick(e.Tool,
sReportKey,
Grid.DataSource);
}
else
{
//One or more are selected so
//get the data through the list factory
if (sCurrentListKey == "SearchResultList")
Util.ReportHandleToolClick(e.Tool,
sReportKeyDetailed,
ListFactory.GetList(
sReportKey,
edSearchTerms.Text,
System.Convert.ToInt32(cbTop.Value), SelectedIDs(true))
);
else
Util.ReportHandleToolClick(e.Tool,
sReportKey,
ListFactory.GetList(
sReportKey,
Util.gGridLastViews[sCurrentListKey].ViewXML,
System.Convert.ToInt32(cbTop.Value), SelectedIDs(false))
);
}
}
else
{
//Detailed report, get the data through the list factory as always
Util.ReportHandleToolClick(e.Tool,
sReportKeyDetailed,
ListFactory.GetList(
sReportKeyDetailed,
Util.gGridLastViews[sCurrentListKey].ViewXML,
System.Convert.ToInt32(cbTop.Value), SelectedIDs(true))
);
}
Util.ReportFillList(this.ToolBarManager.Tools["REPORTLIST"],
sReportKey,
sReportKeyDetailed);
break;
}
}
public List<Guid> SelectedIDs(bool detailed)
{
List<Guid> l = new List<Guid>();
if (this.Grid.Selected.Rows.Count == 0)
return l;
object o = null;
if (detailed)
o=AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "IDFieldDetailed");
else
o=AyaBizUtils.GetBizObjectStaticPropertyValue(Grid.DataSource, "IDField");
if (o == null)
return l;
string IDField = o.ToString();
//sometimes the ID field is in a button and sometimes it's a hidden guid filed
bool FieldIsGuid = true;
if (Grid.Selected.Rows[0].Cells[IDField].Value is GridNameValueCellItem)
FieldIsGuid = false;
//Get the id's for the selected rows
foreach (UltraGridRow r in Grid.Selected.Rows)
{
if (FieldIsGuid)
l.Add((Guid)r.Cells[IDField].Value);
else
l.Add(((GridNameValueCellItem)r.Cells[IDField].Value).Value);
}
return l;
}
#endregion toolbarclicks
#region Search related
/// <summary>
/// User clicks on search button in search form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void edSearchTerms_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
{
BindData(true);
}
/// <summary>
/// Allow enter key to initiate search
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void edSearchTerms_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
BindData(true);
}
#endregion
#region Row selection
/// <summary>
/// select all rows? Case 556
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_MouseUp(object sender, MouseEventArgs e)
{
UIElement ui = Grid.DisplayLayout.UIElement.ElementFromPoint(new Point(e.X, e.Y));
if (ui is RowSelectorHeaderUIElement)
{
bool bIsSelected=(Grid.DisplayLayout.Override.RowSelectorHeaderAppearance.BackColor==SystemColors.Highlight);
SelectAllRows(!bIsSelected);
}
}
/// <summary>
/// case 556 called by mouse action and programmatically
/// </summary>
/// <param name="selected"></param>
private void SelectAllRows(bool select)
{
if (select)
{
this.Grid.Selected.Rows.AddRange(this.Grid.Rows.GetFilteredInNonGroupByRows());
Grid.DisplayLayout.Override.RowSelectorHeaderAppearance.BackColor = SystemColors.Highlight;
Grid.DisplayLayout.Override.RowSelectorHeaderAppearance.ImageBackground = Resource1.Checked16;
}
else
{
this.Grid.Selected.Rows.Clear();
Grid.DisplayLayout.Override.RowSelectorHeaderAppearance.BackColor = SystemColors.Control;
Grid.DisplayLayout.Override.RowSelectorHeaderAppearance.ImageBackground = Resource1.UnChecked16;
}
}
#endregion
#region case 700 autorefresh timer
private void timerGridRefresh_Tick(object sender, EventArgs e)
{
timerGridRefresh.Stop();
if (AyaBizUtils.GlobalSettings.MainGridAutoRefresh)//case 1487
{
if (sCurrentListKey != "SearchResultList")
BindData(true);
timerGridRefresh.Start();
}
}
#endregion
//--------------------------------------------
}
}