| public void SaveSettings(int reportid, string reportname) |
| { |
| object[] gridSettings = new object[4]; |
| |
| //Save groupBy |
| GridGroupByExpressionCollection groupByExpressions = this.MasterTableView.GroupByExpressions; |
| object[] groupExpressions = new object[groupByExpressions.Count]; |
| |
| int count = 0; |
| foreach (GridGroupByExpression expression in groupByExpressions) |
| { |
| groupExpressions[count] = ((IStateManager)expression).SaveViewState(); |
| count++; |
| } |
| |
| gridSettings[0] = groupExpressions; |
| |
| //Save sort expressions |
| gridSettings[1] = ((IStateManager)this.MasterTableView.SortExpressions).SaveViewState(); |
| |
| //Save columns order and visibility |
| int columnsLength = this.MasterTableView.Columns.Count + |
| this.MasterTableView.AutoGeneratedColumns.Length; |
| |
| string[] columnOrder = new string[columnsLength]; |
| bool[] columnVisible = new bool[columnsLength]; |
| |
| ArrayList allColumns = new ArrayList(columnsLength); |
| |
| allColumns.AddRange(this.MasterTableView.Columns); |
| allColumns.AddRange(this.MasterTableView.AutoGeneratedColumns); |
| |
| int i = 0; |
| foreach (Telerik.Web.UI.GridColumn column in allColumns) |
| { |
| columnOrder[i] = column.UniqueName; |
| columnVisible[i] = column.Visible; |
| i++; |
| } |
| |
| gridSettings[2] = columnOrder; |
| |
| //Save filter expression |
| gridSettings[3] = (object)this.MasterTableView.FilterExpression; |
| |
| RemoteUser _user = ((RemoteUser)Context.User); |
| |
| SqlHelper.Execute("user_custom_report_create_p" , _user.UserId , reportid , reportname, _user.CurrentCustomerID , _user.CurrentPeriod , GridHelper.Serialize(columnOrder, GridHelper.SeralizeType.LOS) ,GridHelper.Serialize(gridSettings[1], GridHelper.SeralizeType.LOS), GridHelper.Serialize(gridSettings[3], GridHelper.SeralizeType.LOS), GridHelper.Serialize(gridSettings[0], GridHelper.SeralizeType.LOS) , GridHelper.Serialize(columnVisible, GridHelper.SeralizeType.LOS)); |
| |
| |
| } |
| |
| |
| |
| //this method should be called on PageInit |
| public void LoadSettings(int reportid) |
| { |
| |
| object[] _columns = new object[5]; |
| RemoteUser _user = ((RemoteUser)Context.User); |
| |
| |
| // go get the report settings |
| // if we cant find the reportid for this userid, throw an exception |
| |
| DataTable _tbl = SqlHelper.ExecuteDataset("user_custom_report_get_p" , _user.UserId , reportid).Tables[0]; |
| |
| if (_tbl.Rows.Count == 0) |
| throw new Exception("The user custom report is not valid + userid: " + _user.UserId.ToString() + " reportid: " + reportid.ToString()); |
| |
| //TODO: check security to make sure the user has access to the customerid |
| //if ( _user.Customers. _tbl.Rows[0]["CustomerID"].ToString() |
| |
| |
| HttpContext.Current.Session["CustomerID"] = _user.CurrentCustomerID = _tbl.Rows[0]["CustomerID"].ToString(); |
| HttpContext.Current.Session["BillYYYYMM"] = _user.CurrentPeriod = _tbl.Rows[0]["billyyyymm"].ToString(); |
| |
| |
| // Now get the string array of columns and use this.AddColumns |
| this.AddColumns((string[])GridHelper.DeSerialize(_tbl.Rows[0]["columns"].ToString() , GridHelper.SeralizeType.LOS)); |
| |
| //Load groupBy |
| this.MasterTableView.GroupByExpressions.Clear(); |
| int count = 0; |
| foreach (object obj in ((object[])GridHelper.DeSerialize(_tbl.Rows[0]["groupby"].ToString() , GridHelper.SeralizeType.LOS))) |
| { |
| GridGroupByExpression expression = new GridGroupByExpression(); |
| ((IStateManager)expression).LoadViewState(obj); |
| this.MasterTableView.GroupByExpressions.Add(expression); |
| count++; |
| } |
| |
| |
| //Load sort expressions |
| this.MasterTableView.SortExpressions.Clear(); |
| ((IStateManager)this.MasterTableView.SortExpressions).LoadViewState((GridHelper.DeSerialize(_tbl.Rows[0]["sort"].ToString(), GridHelper.SeralizeType.LOS))); |
| |
| |
| |
| this.MasterTableView.FilterExpression = (GridHelper.DeSerialize(_tbl.Rows[0]["filter"].ToString() , GridHelper.SeralizeType.LOS)).ToString(); |
| |
| } |
| |