ListBaseControl..::..GetDataSource Method
Default action will load the data fields defined in the BusinessObject. Method that can be overridden.
Namespace:
AdvantageCMS.Core.Admin.BaseClassesAssembly: AdvantageCMS.Core (in AdvantageCMS.Core.dll)
Syntax
[CategoryAttribute] [DescriptionAttribute] [BrowsableAttribute] [DefaultValueAttribute] [DesignerSerializationVisibilityAttribute] [BindableAttribute] public virtual DataTable GetDataSource()
Return Value
Bindable datasource (Default is datatable)Examples
This example will show how to return a subset list and retrieve properties from other objects to be shown for display.
Objects used "Order" for a vehicle Purchase, and "Vehicle" the information about the vehicle.
Public Properties not shown (FromDate, ToDate, TypeFilter).
ReceiveToolActionArgs is implemented to show caching.
C#
public override DataTable GetDataSource() { var t = GetPageSessionObject<DataTable>(DataSourceKey); if (t != null) return t; var lst = new List<ObjectKeyCriteria>(); ObjectKeyCriteria oCriteria1 = new ObjectKeyCriteria() { Key = "ListDate", Value = FromDate, Comparison = eComparison.GreaterOrEquals, DataType = eObjectKeyCriteriaDataType.Date }; lst.Add(oCriteria1); ObjectKeyCriteria oCriteria2 = new ObjectKeyCriteria() { Key = "ListDate", Value = ToDate, Comparison = eComparison.LessOrEquals, DataType = eObjectKeyCriteriaDataType.Date }; lst.Add(oCriteria2); if (ActiveInventory != null) { ObjectKeyCriteria oCriteria3 = new ObjectKeyCriteria() { Key = "IsRemoved", Value = Convert.ToBoolean(!ActiveInventory), Comparison = eComparison.Equals, DataType = eObjectKeyCriteriaDataType.Bool }; lst.Add(oCriteria3); } List<Vehicle> list = ModuleEngine.GetPublishedObjectsBykey<Vehicle>(lst); var result= CreateDataList(list); SetPageSessionObject(DataSourceKey, result); return result; }
C#
public DataTable CreateDataList(List<Vehicle> datasource) { formatColumns(); DataTable dt = new DataTable("Vehicles"); dt.Columns.Add("MasterID", typeof(Guid)); dt.Columns.Add("PublishStatus",typeof(int)); dt.Columns.Add("Version", typeof(int)); dt.Columns.Add("VIN", typeof(string)); dt.Columns.Add("ModelYear", typeof(string)); dt.Columns.Add("Make", typeof(string)); dt.Columns.Add("Model", typeof(string)); dt.Columns.Add("Trim", typeof(string)); dt.Columns.Add("StockNumber", typeof(string)); dt.Columns.Add("ListDate", typeof(DateTime)); dt.Columns.Add("DaysInStock", typeof(Int32)); dt.Columns.Add("Condition", typeof(string)); dt.Columns.Add("SalePrice", typeof(double)); dt.Columns.Add("IsRemoved", typeof(bool)); dt.Columns.Add("IsBuyNowEnabled", typeof(string)); dt.Columns.Add("IsUsingLockedRate", typeof(string)); dt.Columns.Add("IsCPOVehicle", typeof(string)); dt.Columns.Add("IsCashable", typeof(string)); dt.Columns.Add("ImageURL", typeof(string)); dt.PrimaryKey = new DataColumn[] { dt.Columns["MasterID"] }; EVSVehicleEngine vEngine = new AdvantageVehicleSystem.Engine.EVSVehicleEngine(CurrentSql, AdminDomain.DomainID, AdminLanguageID); string disclaimer; foreach (Vehicle v in datasource) { dt.Rows.Add( v.MasterID, v.PublishStatus, v.Version, v.VIN, v.ModelYear, v.Make, v.Model, v.Trim, v.StockNumber, v.ListDate, v.DaysInStock, v.Condition.ToString(), v.SalePrice, v.IsRemoved.ToString(), formatField(v.IsBuyNowEnabled, "fa fa-check", "fa fa-times"), formatField(v.IsUsingLockedRate, "fa fa-lock", "fa fa-unlock"), formatField(v.IsCPOVehicle(CPORules), "fa fa-check", "fa fa-times"), formatField(vEngine.IsVehicleCashable(v, out disclaimer), "fa fa-check", "fa fa-times"), string.IsNullOrEmpty(v.ImageURL) ? "" : $"<img src='{v.ImageURL}' height='80px' class='left;' />" ); } dt.AcceptChanges(); return dt; } private string formatField(bool value, string classTrue, string classFalse) { return string.Format("<div class='{0}' ></div>", value ? classTrue : classFalse); }
C#
public override void ReceiveToolActionArgs(ToolActionArgs e) { try { EVSVehicleEngine vEngine = new AdvantageVehicleSystem.Engine.EVSVehicleEngine(CurrentSql, AdminDomain.DomainID, AdminLanguageID); if (e.CommandName != eCMSActions.Delete) { var objRecord = GetPrimaryObjectByMasterId<Vehicle>(e.MasterId); DataTable SummaryRecord = GetSummaryRecordByMasterID(e.MasterId); var orig = GetPageSessionObject<DataTable>(DataSourceKey) as DataTable; if (orig == null) return; DataRow r = orig.Rows.Find(e.MasterId); //Return no record? Remove from list! if (SummaryRecord.Rows.Count == 0) { //remove from list orig.Rows.Remove(r); SetPageSessionObject<DataTable>(DataSourceKey, orig); //rebindGrid(true); return; } string disclaimer; DataRow nr = orig.NewRow(); nr["MasterID"] = objRecord.MasterID; nr["PublishStatus"] = objRecord.PublishStatus; nr["Version"] = objRecord.Version; nr["VIN"] = objRecord.VIN; nr["ModelYear"] = objRecord.ModelYear; nr["Make"] = objRecord.Make; nr["Model"] = objRecord.Model; nr["Trim"] = objRecord.Trim; nr["StockNumber"] = objRecord.StockNumber; nr["ListDate"] = objRecord.ListDate; nr["DaysInStock"] = objRecord.DaysInStock; nr["Condition"] = objRecord.Condition; nr["SalePrice"] = objRecord.SalePrice; nr["IsRemoved"] = objRecord.IsRemoved.ToString(); nr["IsBuyNowEnabled"] = formatField(objRecord.IsBuyNowEnabled, "fa fa-check", "fa fa-times"); nr["IsUsingLockedRate"] = formatField(objRecord.IsUsingLockedRate, "fa fa-lock", "fa fa-unlock"); nr["IsCPOVehicle"] = formatField(objRecord.IsCPOVehicle(CPORules), "fa fa-check", "fa fa-times"); nr["IsCashable"] = formatField(vEngine.IsVehicleCashable(objRecord, out disclaimer), "fa fa-check", "fa fa-times"); nr["ImageURL"] = string.IsNullOrEmpty(objRecord.ImageURL) ? "" : $"<img src='{objRecord.ImageURL}' height='80px' class='left;' />"; int i = orig.Rows.IndexOf(r); //found it? Replace if (i > -1) { orig.Rows.RemoveAt(i); orig.Rows.InsertAt(nr, i); SetPageSessionObject<DataTable>(DataSourceKey, orig); //rebindGrid(false); return; } //Didn't find it...add at bottom orig.Rows.Add(nr); orig.AcceptChanges(); SetPageSessionObject<DataTable>(DataSourceKey, orig); } } catch { SetPageSessionObject(DataSourceKey, null); } }