/// <summary> /// this code is used with LinqServerModeDataSource_Selecting so we can run in server mode /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void LinqServerModePodTop_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e) { try { Int32 _companyid = -1; //after testing default to empty string Int32 _userid = -1; //company id: always add as a search param as user must be logged in //if (Page.Session["user"] != null) if (Page.Session["user"] != null) { _companyid = (Int32)((UserClass)Page.Session["user"]).CompanyId; _userid = (Int32)((UserClass)Page.Session["user"]).UserId; } //020513 search over last 12 months int _months = 12; DateTime _minDate = DateTime.Now.AddMonths(0 - _months); //dynamic queries using system.Linq.dynamic + Dynamic.cs library //20/10/2010 we have build a unique index (OrderIx) from OrderId, TitleId, ContainerSubId as usual primary keys are not going to //be unique in the view. aspxgrid only works properly when it has a unique key e.KeyExpression = "OrderIx"; //"OrderID"; //a key expression is required if (_companyid > 0 && _userid > 0) { //020513 get from date range startdate + N months //var _nquery = new linq_classesDataContext().view_orders.Where(c => c.CompanyID == _companyid && c.ContactID == _userid).OrderByDescending(c => c.OrderID).Take(10); //c => c.CompanyID == 7 var _nquery = new linq.linq_view_orders_udfDataContext().view_orders_by_age(_minDate, _months).Where(c => c.CompanyID == _companyid && c.ContactID == _userid).OrderByDescending(c => c.OrderID).Take(10); e.QueryableSource = _nquery; //Int32 _count = _nquery.Count(); } else if (_companyid == -1 && _userid > 0) //internal user { //var _nquery = new linq_classesDataContext().view_orders.OrderByDescending(c => c.OrderID).Take(10); //c => c.CompanyID == 7 var _nquery = new linq.linq_view_orders_udfDataContext().view_orders_by_age(_minDate, _months).OrderByDescending(c => c.OrderID).Take(10); //_count = _nquery.Count(); e.QueryableSource = _nquery; } else //they should never reach this as must be logged in to get dashboard but just a precaution { //var _nquery = new linq_classesDataContext().view_orders.OrderBy("OrderID").OrderByDescending(c => c.OrderID).Take(10); var _nquery = new linq.linq_view_orders_udfDataContext().view_orders_by_age(_minDate, _months).OrderBy("OrderID").OrderByDescending(c => c.OrderID).Take(10); //_count = _nquery.Count(); e.QueryableSource = _nquery; } } catch (Exception ex) { this.dxlblerr4.Text = ex.Message.ToString(); this.dxlblerr4.Visible = true; } }
//end load #region grid databinding /// <summary> /// this code is used with LinqServerModeDataSource_Selecting so we can run in server mode /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void LinqServerModePod_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e) { Int32 _companyid = -1; //after testing default to empty string SessionParameterPasser _sessionWrapper = new SessionParameterPasser(); ParameterCollection _params = new ParameterCollection(); //check if session created from advanced search, in which case we can use the parameters passed back string _query = ""; int _mode = this.dxhfsource.Contains("mode") ? wwi_func.vint(this.dxhfsource["mode"].ToString()) : 1; //default mode to quick search //a simplified version of the methods used in order tracking - no history but advanced search is available if (_sessionWrapper["query"] != null && _mode == 2) { _query = _sessionWrapper["query"].ToString(); } else { _query = get_filter(); } //company id: always add as a search param if user is logged in //if (Page.Session["user"] != null) //company id: always add as a search param if user is logged in UNLESS _mode = -1 which we can use to bypass params if (Page.Session["user"] != null) { _companyid = (Int32)((UserClass)Page.Session["user"]).CompanyId; if (_companyid != -1) //-1 is a WWI company { Parameter _p = return_default_view(-1); if (_p != null) { _params.Add(_p); } } } //now rebuild query with additional parameters string _f = ""; if (_params.Count > 0) { foreach (Parameter p in _params) { string _a = _f != "" ? " AND " : ""; _f += _a + "(" + p.Name.ToString() + "==" + p.DefaultValue.ToString() + ")"; } if (_query != "") { _query = _f + " AND " + _query; } else { _query = _f; } } //get start date from dll value //e.g if search is for last 12 months dllvalue 1 start date = current date - (1 * 12) months //if search is for 2-3 years dllvalue 3 start date = current date - (3 * 12) months int _dllvalue = this.dxcboRange.Value != null?wwi_func.vint(this.dxcboRange.Value.ToString()) : 1; //number of months to include after start date int _months = 12; //multiply base * 12 to get start date int _lowest = 0 - (_dllvalue * 12); DateTime _minDate = DateTime.Now.AddMonths(_lowest); //dynamic queries using system.Linq.dynamic + Dynamic.cs library //20/10/2010 we have build a unqiue index (OrderIx) from OrderId, TitleId, ContainerSubId as usual primary keys are not going to //be unique in the view. aspxgrid only works properly when it has a unique key e.KeyExpression = "OrderIx"; //"OrderID"; //a key expression is required if (!string.IsNullOrEmpty(_query)) { //var _nquery = new linq_classesDataContext().view_orders.Where(_query); //c => c.CompanyID == 7 var _nquery = new linq.linq_view_orders_udfDataContext().view_orders_by_age(_minDate, _months).Where(_query); //c => c.CompanyID == 7 e.QueryableSource = _nquery; //Int32 _count = _nquery.Count(); } else //default to display nothing in grid { //var _nquery = new linq_classesDataContext().view_orders.Where(c => c.OrderNumber == -1); var _nquery = new linq.linq_view_orders_udfDataContext().view_orders_by_age(_minDate, _months).Where(c => c.OrderNumber == -1); //_count = _nquery.Count(); e.QueryableSource = _nquery; } }