/// <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 LinqServerModeSearchTop_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; } //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 = "qry_ID"; //"OrderID"; //a key expression is required if (_companyid > 0 && _userid > 0) { //var _query = new linq_classesDataContext().view_orders.Where(_filter); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_contactID == _userid).OrderByDescending(c => c.qry_ID).Take(10); //c => c.CompanyID == 7 e.QueryableSource = _nquery; //Int32 _count = _nquery.Count(); } else if (_companyid == -1 && _userid > 0) //internal user { //var _nquery = new linq_classesDataContext().view_orders.OrderBy("orderix").OrderByDescending(c => c.OrderIx).Take(10); //.Where(c => c.OrderNumber == -1 ); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_employeeID == _userid).OrderByDescending(c => c.qry_ID).Take(10); //c => c.CompanyID == 7 //_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.linq_query_logDataContext().db_query_logs.Where(c => c.qry_ID == -1); //_count = _nquery.Count(); e.QueryableSource = _nquery; } } catch (Exception ex) { this.dxlblerr5.Text = ex.Message.ToString(); this.dxlblerr5.Visible = true; } }
/// <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 LinqServerModeSearchTop_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; } //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 = "qry_ID"; //"OrderID"; //a key expression is required if (_companyid > 0 && _userid > 0) { //var _query = new linq_classesDataContext().view_orders.Where(_filter); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_contactID == _userid).OrderByDescending(c => c.qry_ID).Take(10); //c => c.CompanyID == 7 e.QueryableSource = _nquery; //Int32 _count = _nquery.Count(); } else if (_companyid == -1 && _userid > 0) //internal user { //var _nquery = new linq_classesDataContext().view_orders.OrderBy("orderix").OrderByDescending(c => c.OrderIx).Take(10); //.Where(c => c.OrderNumber == -1 ); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_employeeID == _userid).OrderByDescending(c => c.qry_ID).Take(10); //c => c.CompanyID == 7 //_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.linq_query_logDataContext().db_query_logs.Where(c => c.qry_ID == -1); //_count = _nquery.Count(); e.QueryableSource = _nquery; } } catch (Exception ex) { this.dxlblerr5.Text = ex.Message.ToString(); this.dxlblerr5.Visible = true; } }
/// <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 linqservermodesearch_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e) { ParameterCollection _params = new ParameterCollection(); if (Session["user"] != null) { UserClass _thisuser = (UserClass)Session["user"]; Int32 _id = _thisuser.UserId; Parameter _p = new Parameter(); //dynamic queries using system.Linq.dynamic + Dynamic.cs library e.KeyExpression = "qry_ID"; //a key expression is required if (_thisuser.CompanyId != -1) //external company not WWI so search in bycontactid { //var _query = new linq_classesDataContext().view_orders.Where(_filter); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_contactID == _id); //.Where(c => c.qry_source == "OV"); restrict by query source too? //_count = _query.Count(); e.QueryableSource = _nquery; } else //search in byemployeeid { //var _query = new linq_classesDataContext().view_orders.Where(_filter); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_employeeID == _id); //.Where(c => c.qry_source=="OV"); //_count = _query.Count(); e.QueryableSource = _nquery; } } else { string _userip = userRequestingIP(); e.KeyExpression = "qry_ID"; //a key expression is required //var _query = new linq_classesDataContext().view_orders.Where(_filter); //09/09/2011 don't load by IP, not very secure, just default to 0 records //var _nquery = new linq_classesDataContext().db_query_logs.Where(c => c.log_ip == _userip).Where(c => c.by_employeeID == 0).Where(c => c.by_contactID == 0); //.Where(c => c.qry_source == "OV"); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_employeeID == -1).Where(c => c.by_contactID == -1); //.Where(c => c.qry_source == "OV"); //_count = _query.Count(); e.QueryableSource = _nquery; } }//end linq server mode
/// <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 linqservermodesearch_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e) { ParameterCollection _params = new ParameterCollection(); if (Session["user"] != null) { UserClass _thisuser = (UserClass)Session["user"]; Int32 _id = _thisuser.UserId; Parameter _p = new Parameter(); //dynamic queries using system.Linq.dynamic + Dynamic.cs library e.KeyExpression = "qry_ID"; //a key expression is required if (_thisuser.CompanyId != -1) //external company not WWI so search in bycontactid { //var _query = new linq_classesDataContext().view_orders.Where(_filter); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_contactID == _id); //.Where(c => c.qry_source == "OV"); restrict by query source too? //_count = _query.Count(); e.QueryableSource = _nquery; } else //search in byemployeeid { //var _query = new linq_classesDataContext().view_orders.Where(_filter); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_employeeID == _id); //.Where(c => c.qry_source=="OV"); //_count = _query.Count(); e.QueryableSource = _nquery; } } else { string _userip = userRequestingIP(); e.KeyExpression = "qry_ID"; //a key expression is required //var _query = new linq_classesDataContext().view_orders.Where(_filter); //09/09/2011 don't load by IP, not very secure, just default to 0 records //var _nquery = new linq_classesDataContext().db_query_logs.Where(c => c.log_ip == _userip).Where(c => c.by_employeeID == 0).Where(c => c.by_contactID == 0); //.Where(c => c.qry_source == "OV"); var _nquery = new linq.linq_query_logDataContext().db_query_logs.Where(c => c.by_employeeID == -1).Where(c => c.by_contactID == -1); //.Where(c => c.qry_source == "OV"); //_count = _query.Count(); e.QueryableSource = _nquery; } }//end linq server mode