protected void dxgaugeTotals_CustomCallback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { try { ParameterCollection _params = new ParameterCollection(); string _query = ""; float[] _values = { 0, 0, 0, 0 }; //containers, weight, cube (cbm), pallets //*************** //21.10.2014 Paul Edwards for delivery tracking and container check which DeliveryID's are visible for this company //check individual contact ID iso string _contactid = ((UserClass)Page.Session["user"]).UserId.ToString(); IList <string> _deliveryids = null; _deliveryids = wwi_func.array_from_xml("xml\\contact_iso.xml", "contactlist/contact[id='" + _contactid + "']/deliveryids/deliveryid/value"); if (_deliveryids.Count > 0) { //don't use sql IN(n) as linq won't parse the statement string _deliveries = "(DeliveryAddress==" + string.Join(" OR DeliveryAddress==", _deliveryids.Select(i => i.ToString()).ToArray()) + ")"; _params.Add("NULL", _deliveries); //select for this company off list } //**************** string _f = ""; if (_params.Count > 0) { foreach (Parameter p in _params) { string _pname = p.Name.ToString(); string _op = "AND"; string[] _check = _pname.Split("_".ToCharArray()); _pname = _check[0].ToString(); _op = _check.Length > 1 ? _check[1].ToString() : _op; string _a = _f != "" ? " " + _op + " " : ""; _f += _pname != "NULL" ? _a + "(" + _pname + "==" + p.DefaultValue.ToString() + ")" : _a + "(" + p.DefaultValue.ToString() + ")"; } if (_query != "") { _query = _f + " AND " + _query; } else { _query = _f; } } //**************** //get starting ETS and ending ETS for current date //convert(datetime,'28/03/2013 10:32',103) //if no datetimes seelcted default to 0/01/1900 so no data displayed DateTime?_ets = DateTime.Now; //**************** //important! need a key id or error=key expression is undefined //e.KeyExpression = "ContainerIdx"; //10.11/2014 if necessary send to datatable then use datatable.compute method on clientname to summarise without showing //breakdown by delivery address if (!string.IsNullOrEmpty(_query)) { linq.linq_aggregate_containers_udfDataContext _ct = new linq.linq_aggregate_containers_udfDataContext(); IEnumerator <linq.aggregate_containers_by_etsResult> _in = _ct.aggregate_containers_by_ets(_ets, _ets).Where(_query).GetEnumerator(); while (_in.MoveNext()) { linq.aggregate_containers_by_etsResult _c = _in.Current; _values[0] += (float)_c.ContainerCount; _values[1] += (float)_c.SumWeight; _values[2] += (float)_c.SumCbm; _values[3] += (float)_c.SumPackages; } } //bind aggregates to guage for (int _ix = 0; _ix < _values.Length; _ix++) { ((LinearGauge)this.dxguageTotals.Gauges[_ix]).Scales[0].Value = _values[_ix]; } //end for } catch (Exception ex) { this.dxlblerr1.Text = ex.Message.ToString(); this.dxlblerr1.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 linqAggregates_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e) { ParameterCollection _params = new ParameterCollection(); string _query = ""; if (Page.Session["shipmentsloaded"] != null) { //*************** //21.10.2014 Paul Edwards for delivery tracking and container check which DeliveryID's are visible for this company //check individual contact ID iso string _contactid = ((UserClass)Page.Session["user"]).UserId.ToString(); IList <string> _deliveryids = null; _deliveryids = wwi_func.array_from_xml("xml\\contact_iso.xml", "contactlist/contact[id='" + _contactid + "']/deliveryids/deliveryid/value"); if (_deliveryids.Count > 0) { //don't use sql IN(n) as linq won't parse the statement string _deliveries = "(DeliveryAddress==" + string.Join(" OR DeliveryAddress==", _deliveryids.Select(i => i.ToString()).ToArray()) + ")"; _params.Add("NULL", _deliveries); //select for this company off list } else { string _conmpanyid = ((UserClass)Page.Session["user"]).CompanyId.ToString(); _params.Add("DeliveryAddress", _conmpanyid); } //**************** //now rebuild query with additional parameters AFTER page is loaded string _f = ""; if (_params.Count > 0) { foreach (Parameter p in _params) { string _pname = p.Name.ToString(); string _op = "AND"; string[] _check = _pname.Split("_".ToCharArray()); _pname = _check[0].ToString(); _op = _check.Length > 1 ? _check[1].ToString() : _op; string _a = _f != "" ? " " + _op + " " : ""; _f += _pname != "NULL" ? _a + "(" + _pname + "==" + p.DefaultValue.ToString() + ")" : _a + "(" + p.DefaultValue.ToString() + ")"; } if (_query != "") { _query = _f + " AND " + _query; } else { _query = _f; } } } //22.10.14 Paul Edwards Session["shipmentsloaded"] allows us to init the grid with no data //Session["containersloaded"] is null on 1st page init when we call selecting event for grid //When Javascript Grid.Init is called Grid.CustomCallback event is fired which sets Session["containersloaded"] = true and allows filter query to build //This gives a slight delay allowing the page to load BEFORE the grid is populated for a better user experience //**************** //get starting ETS date for deliveries from xml file (which maqes it easy to change if necessary) //convert(datetime,'28/03/2013 10:32',103) //if no datetimes seelcted default to 0/01/1900 so no data displayed DateTime?_ets1 = this.dxdt1.Value != null?wwi_func.vdatetime(this.dxdt1.Value.ToString()) : new DateTime(1900, 1, 1); DateTime?_ets2 = this.dxdt2.Value != null?wwi_func.vdatetime(this.dxdt2.Value.ToString()) : new DateTime(1900, 1, 1); if (_ets1 > _ets2) { DateTime?_temp = _ets1; _ets1 = _ets2; _ets2 = _temp; } //**************** //important! need a key id or error=key expression is undefined e.KeyExpression = "ContainerIdx"; //10.11/2014 if necessary send to datatable then use datatable.compute method on clientname to summarise without showing //breakdown by delivery address if (!string.IsNullOrEmpty(_query)) { //var _query = new linq_classesDataContext().view_orders.Where(_filter); //290413 using new userdefined inline table function so we can parametise with month range from current date //var _nquery = new linq_view_orders_udfDataContext().view_orders_by_age(1, 12).Where(_query); //c => c.CompanyID == 7 var _nquery = new linq.linq_aggregate_containers_udfDataContext().aggregate_containers_by_ets(_ets1, _ets2).Where(_query); //c => c.CompanyID == 7 e.QueryableSource = _nquery; //Int32 _count = _nquery.Count(); //if (!String.IsNullOrEmpty(_name)) //{ // append_to_query_log(_query, _name); // this.gridContainer.SettingsText.Title = "Search results: " + _name; //} } else //default to display nothing until page is loaded { //var _nquery = new linq_classesDataContext().view_order_2s.Where(c => c.OrderNumber == -1); var _nquery = new linq.linq_aggregate_containers_udfDataContext().aggregate_containers_by_ets(_ets1, _ets2).Where(c => c.ContainerIdx == 0); //c => c.CompanyID == 7 //_count = _nquery.Count(); e.QueryableSource = _nquery; } //this.dxgridShipments.GroupBy(this.dxgridShipments.Columns["colDeliveryAddress"], 0); }