Ejemplo n.º 1
0
        public static void SaveGridSettings(Telerik.Web.UI.RadGrid gridInstance, eGrid grid, string userName)
        {
            var masterTable        = gridInstance.MasterTableView;
            var groupByExpressions = masterTable.GroupByExpressions.Cast <GridGroupByExpression>();
            var allColumns         = masterTable.Columns.Cast <GridColumn>().Concat(masterTable.AutoGeneratedColumns);

            var losFormatter = new LosFormatter();

            var serializeViewState = new Func <IStateManager, string>(sm =>
            {
                using (var writer = new StringWriter())
                {
                    losFormatter.Serialize(writer, sm.SaveViewState());
                    return(writer.ToString());
                }
            });

            var gridState = new GridState
            {
                GroupByExpressionViewStates = groupByExpressions.Select(gbe => serializeViewState(gbe)),
                SortExpressionsViewState    = serializeViewState(masterTable.SortExpressions),
                FilterExpression            = masterTable.FilterExpression,
                ColumnStates = allColumns.ToDictionary(
                    c => c.UniqueName,
                    c => new GridColumnState {
                    Visible = c.Visible, Width = c.HeaderStyle.Width, OrderIndex = c.OrderIndex
                }),
            };

            Orchestrator.DataAccess.SystemSettings.SaveGridSettings(userName, (int)grid, gridState.Serialize(), null);
        }
Ejemplo n.º 2
0
        protected void grd_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            Telerik.Web.UI.RadGrid grdBusinessType = (Telerik.Web.UI.RadGrid)source;

            HiddenField  hidBusinessTypeID = (HiddenField)grdBusinessType.Parent.FindControl("hidBusinessTypeID");
            HtmlTableRow rowTitle          = (HtmlTableRow)grdBusinessType.Parent.FindControl("rowTitle");
            HtmlTableRow rowGrid           = (HtmlTableRow)grdBusinessType.Parent.FindControl("rowGrid");

            if (hidBusinessTypeID != null && grdBusinessType != null && AllUninvoicedWorkForOrganisation != null)
            {
                rowTitle.Style["display"] = "";
                rowGrid.Style["display"]  = "";

                string businessTypeID = string.Empty;

                if (hidBusinessTypeID.Value == string.Empty)
                {
                    businessTypeID          = ((System.Data.DataRowView)((RepeaterItem)grdBusinessType.Parent.Parent.Parent).DataItem).Row["BusinessTypeID"].ToString();
                    hidBusinessTypeID.Value = businessTypeID;
                }
                else
                {
                    businessTypeID = hidBusinessTypeID.Value;
                }

                AllUninvoicedWorkForOrganisation.Tables[0].DefaultView.RowFilter = "BusinessTypeID = " + businessTypeID;
                grdBusinessType.DataSource = AllUninvoicedWorkForOrganisation.Tables[0].DefaultView;

                if (AllUninvoicedWorkForOrganisation.Tables[0].DefaultView.Count < 1)
                {
                    rowTitle.Style["display"] = "none";
                    rowGrid.Style["display"]  = "none";
                }
            }
        }
Ejemplo n.º 3
0
    public static void CustomPaging(ref Telerik.Web.UI.RadGrid objDataGrid, GridViewPageEventArgs e, System.Data.DataTable dt)
    {
        if (objDataGrid != null)
        {
            if (dt != null)
            {
                DataView dv = new DataView(dt);
                dv.Sort = objDataGrid.Attributes["SortExpression"];
                if (objDataGrid.Attributes["SortASC"] == "No")
                {
                    dv.Sort += " DESC";
                }

                //objDataGrid.PageIndex = e.NewPageIndex;
                //objDataGrid.CurrentPageIndex = e.NewPageIndex;
                objDataGrid.DataSource = dv;
                objDataGrid.DataBind();

                if (objDataGrid.CurrentPageIndex == objDataGrid.PageCount - 1 & (dt.Rows.Count / objDataGrid.PageSize) <= objDataGrid.CurrentPageIndex)
                {
                    objDataGrid.CurrentPageIndex = objDataGrid.CurrentPageIndex - 1;
                }
            }
        }
    }
Ejemplo n.º 4
0
 protected void gridSelectFirstRow(Telerik.Web.UI.RadGrid grid)
 {
     if (grid.Items.Count > 0)
     {
         if (grid.SelectedItems.Count == 0)
         {
             grid.MasterTableView.Items[0].Selected = true;
             grid.SelectedIndexes.Add(0);
         }
         //else
         //{
         //    grid.MasterTableView.Items[0].Selected = false;
         //}
     }
 }
Ejemplo n.º 5
0
    public static void CustomSorting(ref Telerik.Web.UI.RadGrid objDataGrid, System.Web.UI.WebControls.GridViewSortEventArgs e, System.Data.DataTable dt)
    {
        if (objDataGrid != null)
        {
            if (dt != null)
            {
                //DataGrid dgActivityStatus = ((System.Web.UI.WebControls.DataGrid)source);

                object strSort = objDataGrid.Attributes["SortExpression"];
                object strASC  = objDataGrid.Attributes["SortASC"];

                objDataGrid.Attributes["SortExpression"] = e.SortExpression;
                objDataGrid.Attributes["SortASC"]        = "Yes";
                if (Convert.ToString(e.SortExpression) == Convert.ToString(strSort))
                {
                    if (Convert.ToString(strASC) == "Yes")
                    {
                        objDataGrid.Attributes["SortASC"] = "No";
                    }
                    else
                    {
                        objDataGrid.Attributes["SortASC"] = "Yes";
                    }
                }

                DataView dv = dt.DefaultView;
                dv.Sort = objDataGrid.Attributes["SortExpression"];
                if (objDataGrid.Attributes["SortASC"] == "No")
                {
                    dv.Sort = dv.Sort + " " + "DESC";
                }


                objDataGrid.DataSource = dv;
                objDataGrid.DataBind();
            }
        }
    }
Ejemplo n.º 6
0
        protected void grd_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridFooterItem)
            {
                Telerik.Web.UI.RadGrid grdBusinessType   = (Telerik.Web.UI.RadGrid)sender;
                HiddenField            hidBusinessTypeID = (HiddenField)grdBusinessType.Parent.FindControl("hidBusinessTypeID");

                AllUninvoicedWorkForOrganisation.Tables[2].DefaultView.RowFilter = "BusinessTypeID = " + hidBusinessTypeID.Value;
                Label lblPalletTotal = (Label)e.Item.FindControl("lblTotalUninvoiced");

                if (AllUninvoicedWorkForOrganisation.Tables[2].DefaultView.Count > 0)
                {
                    Decimal totalValue = Convert.ToDecimal(AllUninvoicedWorkForOrganisation.Tables[2].DefaultView[0].Row["Total Rate"]);
                    lblPalletTotal.Text = totalValue.ToString("C");
                }
                else
                {
                    lblPalletTotal.Text = 0d.ToString("C");
                }
            }
            else if (e.Item is GridDataItem)
            {
                DataRowView        drv             = (DataRowView)e.Item.DataItem;
                HtmlGenericControl spnPalletSpaces = (HtmlGenericControl)e.Item.FindControl("spnPalletSpaces");
                if (spnPalletSpaces != null)
                {
                    switch (spnPalletSpaces.InnerText)
                    {
                    case "0.25":
                        spnPalletSpaces.InnerText = "¼";
                        break;

                    case "0.5":
                        spnPalletSpaces.InnerText = "½";
                        break;

                    default:
                        break;
                    }
                }

                int orderID = (int)drv["OrderID"];


                SetupHasPodLink(e, drv);


                Repeater repReferences = (Repeater)e.Item.FindControl("repReferences");
                repReferences.DataSource =
                    drv.Row.Table.DataSet.Tables[3].Select("OrderID = " + orderID);
                repReferences.DataBind();
                if ((int)drv["jobStateID"] == 1)
                {
                    e.Item.BackColor = System.Drawing.Color.White;
                }
                if ((int)drv["jobStateID"] == 2)
                {
                    e.Item.BackColor = System.Drawing.Color.FromArgb(204, 255, 204);
                }
                if ((int)drv["jobStateID"] == 3)
                {
                    e.Item.BackColor = System.Drawing.Color.FromArgb(153, 255, 153);
                }
                if ((int)drv["jobStateID"] == 4)
                {
                    e.Item.BackColor = System.Drawing.Color.LightBlue;
                }
                if ((int)drv["jobStateID"] == 5)
                {
                    e.Item.BackColor = System.Drawing.Color.MistyRose;
                }
                if ((int)drv["jobStateID"] == 6)
                {
                    e.Item.BackColor = System.Drawing.Color.PaleVioletRed;
                }
                if ((int)drv["jobStateID"] == 7)
                {
                    e.Item.BackColor = System.Drawing.Color.Yellow;
                }
                if ((int)drv["jobStateID"] == 8)
                {
                    e.Item.BackColor = System.Drawing.Color.Gold;
                }
                if ((int)drv["jobStateID"] == 9)
                {
                    e.Item.BackColor = System.Drawing.Color.Khaki;
                }
            }
        }
Ejemplo n.º 7
0
        private static void LoadSettings_OldMethod(Telerik.Web.UI.RadGrid gridInstance, string settings, IEnumerable <string> columnsToHide)
        {
            var columnOrdersAndWidths = Enumerable.Empty <Pair>();
            var visibleColumns        = Enumerable.Empty <bool>();

            if (!string.IsNullOrWhiteSpace(settings))
            {
                object[] gridSettings;

                using (var reader = new StringReader(settings))
                {
                    var formatter = new LosFormatter();
                    gridSettings = (object[])formatter.Deserialize(reader);
                }

                if (gridSettings.Count() == 5)
                {
                    //Load groupBy
                    var groupByExpressions = gridInstance.MasterTableView.GroupByExpressions;
                    groupByExpressions.Clear();

                    var savedGroupByExpressions = (object[])gridSettings[0];

                    foreach (var obj in savedGroupByExpressions)
                    {
                        var expression = new GridGroupByExpression();
                        ((IStateManager)expression).LoadViewState(obj);
                        groupByExpressions.Add(expression);
                    }

                    //Load sort expressions
                    var sortExpressions = gridInstance.MasterTableView.SortExpressions;
                    sortExpressions.Clear();
                    ((IStateManager)sortExpressions).LoadViewState(gridSettings[1]);

                    columnOrdersAndWidths = (IEnumerable <Pair>)gridSettings[2];
                    visibleColumns        = ((IEnumerable)gridSettings[4]).Cast <bool>();

                    //Load filter expression
                    gridInstance.MasterTableView.FilterExpression = (string)gridSettings[3];
                }
            }

            var allColumns = gridInstance.MasterTableView.Columns.Cast <GridColumn>().Concat(gridInstance.MasterTableView.AutoGeneratedColumns);

            if (allColumns.Count() == columnOrdersAndWidths.Count())
            {
                int i = 0;

                foreach (var column in allColumns)
                {
                    var columnOrderAndWidth = columnOrdersAndWidths.ElementAt(i);
                    column.OrderIndex      = (int)columnOrderAndWidth.First;
                    column.ItemStyle.Width = column.HeaderStyle.Width = (Unit)columnOrderAndWidth.Second;
                    column.Visible         = visibleColumns.ElementAt(i);
                    i++;
                }
            }
            else
            {
                // Column count doesn't match saved data, so use columnsToHide to set column visibility instead
                foreach (var column in allColumns)
                {
                    column.Visible &= !columnsToHide.Contains(column.UniqueName);
                }
            }
        }
Ejemplo n.º 8
0
        public static void LoadSettings(Telerik.Web.UI.RadGrid gridInstance, eGrid grid, out IEnumerable <string> columnsToHide, string userName)
        {
            var settingsRow = DataAccess.SystemSettings.GetGridSettings(userName, (int)grid).Tables[0].AsEnumerable().FirstOrDefault();

            var settings = string.Empty;

            columnsToHide = Enumerable.Empty <string>();

            if (settingsRow != null)
            {
                if (!settingsRow.IsNull("DATA"))
                {
                    settings = settingsRow.Field <string>("DATA");
                }

                if (!settingsRow.IsNull("ColumnsToHide"))
                {
                    columnsToHide = settingsRow.Field <string>("ColumnsToHide").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }
            }

            var masterTable = gridInstance.MasterTableView;
            var allColumns  = masterTable.Columns.Cast <GridColumn>().Concat(masterTable.AutoGeneratedColumns);

            if (!string.IsNullOrWhiteSpace(settings) || columnsToHide.Any())
            {
                var gridState = GridState.Deserialize(settings);

                #region Old Load Method

                // The following 5 lines are only in place to allow people to upgrade from any older version of HE to the latest version without losing their saved grid settings.
                // For any future release of HE these saved settings will have been migrated to the new format so these lines can be removed.
                if (gridState == null)
                {
                    LoadSettings_OldMethod(gridInstance, settings, columnsToHide);
                    SaveGridSettings(gridInstance, grid, userName);
                    return;
                }

                #endregion Old Load Method

                var losFormatter = new LosFormatter();

                var deserializeViewState = new Action <string, IStateManager>((s, sm) =>
                {
                    using (var reader = new StringReader(s))
                    {
                        try
                        {
                            var viewState = losFormatter.Deserialize(reader);
                            sm.LoadViewState(viewState);
                        }
                        catch
                        {
                            // Don't throw an exception if the grid data can't be deserialised... sometimes this can happen if the Telerik controls have been updated to a more recent version.
                        }
                    }
                });

                // Load group by expressions
                var groupByExpressions = masterTable.GroupByExpressions;
                groupByExpressions.Clear();

                foreach (var vs in gridState.GroupByExpressionViewStates)
                {
                    var expression = new GridGroupByExpression();
                    deserializeViewState(vs, expression);
                    groupByExpressions.Add(expression);
                }

                // Load sort expressions
                var sortExpressions = masterTable.SortExpressions;
                sortExpressions.Clear();
                deserializeViewState(gridState.SortExpressionsViewState, sortExpressions);

                // Load filter expression
                masterTable.FilterExpression = gridState.FilterExpression;

                foreach (var column in allColumns)
                {
                    if (gridState.ColumnStates.ContainsKey(column.UniqueName))
                    {
                        var columnState = gridState.ColumnStates[column.UniqueName];
                        column.OrderIndex      = columnState.OrderIndex;
                        column.ItemStyle.Width = column.HeaderStyle.Width = columnState.Width;
                        column.Visible         = columnState.Visible;
                    }
                }
            }

            columnsToHide = from c in allColumns where !c.Visible select c.UniqueName;
        }
Ejemplo n.º 9
0
        public static void LoadSettings(Telerik.Web.UI.RadGrid gridInstance, eGrid grid, string userName)
        {
            IEnumerable <string> columnsToHide;

            LoadSettings(gridInstance, grid, out columnsToHide, userName);
        }
Ejemplo n.º 10
0
        protected void grd_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridHeaderItem)
            {
                CheckBox chk = e.Item.FindControl("chkHeader") as CheckBox;
                if (chk != null)
                {
                    chk.Attributes.Add("onclick",
                                       string.Format("javascript:HandleGridSelection({0});", ((RadGrid)sender).ClientID));
                }
            }

            if (e.Item is GridDataItem)
            {
                DataRowView drv = (DataRowView)(e.Item.DataItem);
                e.Item.Style["background-color"] = Orchestrator.WebUI.Utilities.GetJobStateColourForHTML((eJobState)drv.Row["JobStateID"]);

                HyperLink lnkPOD = (HyperLink)e.Item.FindControl("lnkPOD");
                bool      hasPod = (bool)drv["HasPOD"];

                if (hasPod)
                {
                    lnkPOD.ForeColor   = System.Drawing.Color.Blue;
                    lnkPOD.NavigateUrl = drv.Row["ScannedFormPDF"].ToString().Trim();
                    lnkPOD.Text        = "Yes";
                }
                else
                {
                    var orderStatus = (eOrderStatus)drv["OrderStatusID"];

                    if (orderStatus == eOrderStatus.Delivered || orderStatus == eOrderStatus.Invoiced)
                    {
                        int orderID = (int)drv["OrderID"];
                        lnkPOD.Text        = "No";
                        lnkPOD.ForeColor   = System.Drawing.Color.Blue;
                        lnkPOD.NavigateUrl = @"javascript:OpenPODWindow(" + orderID + ")";
                    }
                    else
                    {
                        lnkPOD.Text    = "N/A";
                        lnkPOD.ToolTip = "Not Delivered";
                        lnkPOD.Style.Add("text-decoration", "none");
                    }
                }

                HtmlGenericControl spnExtraCharges = (HtmlGenericControl)e.Item.FindControl("spnExtraCharges");
                DisplayExtrasInformation(drv.Row, spnExtraCharges);

                HtmlGenericControl spnPalletSpaces = (HtmlGenericControl)e.Item.FindControl("spnPalletSpaces");
                if (spnPalletSpaces != null)
                {
                    switch (spnPalletSpaces.InnerText)
                    {
                    case "0.25":
                        spnPalletSpaces.InnerText = "¼";
                        break;

                    case "0.5":
                        spnPalletSpaces.InnerText = "½";
                        break;

                    default:
                        break;
                    }
                }

                CheckBox chk = e.Item.FindControl("chkRow") as CheckBox;
                if (chk != null)
                {
                    if ((int)drv.Row["JobStateID"] == (int)eJobState.Invoiced || (int)drv.Row["JobStateID"] == (int)eJobState.Cancelled || (bool)drv.Row["IsBeingInvoiced"])
                    {
                        chk.Enabled = false;
                    }
                    else
                    {
                        chk.Attributes.Add("onclick",
                                           string.Format("javascript:ChangeOrderList(event, this, {0});", ((DataRowView)e.Item.DataItem)["OrderID"].ToString()));
                    }
                }
            }

            if (e.Item is GridFooterItem)
            {
                Telerik.Web.UI.RadGrid grdBusinessType   = (Telerik.Web.UI.RadGrid)sender;
                HiddenField            hidBusinessTypeID = (HiddenField)grdBusinessType.Parent.FindControl("hidBusinessTypeID");

                AllWorkForOrganisation.Tables[2].DefaultView.RowFilter = "BusinessTypeID = " + hidBusinessTypeID.Value;
                Label lblTotalOrderCharge = (Label)e.Item.FindControl("lblTotalOrderCharge");

                if (AllWorkForOrganisation.Tables[2].DefaultView.Count == 0)
                {
                    lblTotalOrderCharge.Text = 0d.ToString("C");
                }
                else
                {
                    DataRow summaryRow = AllWorkForOrganisation.Tables[2].DefaultView[0].Row;
                    Decimal totalValue = Convert.ToDecimal(summaryRow["Total Rate"]);
                    lblTotalOrderCharge.Text = totalValue.ToString("C");

                    HtmlGenericControl spnExtrasBreakdown = (HtmlGenericControl)e.Item.FindControl("spnExtrasBreakdown");
                    DisplayExtrasInformation(summaryRow, spnExtrasBreakdown);
                }
            }
        }