Beispiel #1
0
        /// <summary>
        /// Metodo per la creazione della tabella sulla quale verrà costruita la SmartGrid
        /// </summary>
        private void CreateTable()
        {
            StringBuilder sb = new StringBuilder();

            #region Create Table
            sb.AppendLine("<table id=\"" + TableName + "\" class=\"table table-striped display select\" style=\"cursor: pointer\">");

            sb.AppendLine("<thead>");
            #region Header
            ListSmartGridColumnInfo.ForEach(x =>
            {
                x.Attribute.ColumnTypes.ForEach(
                    y =>
                {
                    switch (y)
                    {
                    case SmartGridAttribute.ColumnTypeEnum.Text:
                    case SmartGridAttribute.ColumnTypeEnum.TextNoFilter:
                    case SmartGridAttribute.ColumnTypeEnum.Date:
                    case SmartGridAttribute.ColumnTypeEnum.Currency:
                    case SmartGridAttribute.ColumnTypeEnum.Decimal2Places:
                    case SmartGridAttribute.ColumnTypeEnum.Decimal4Places:
                    case SmartGridAttribute.ColumnTypeEnum.Select:
                        sb.AppendLine("<th>" + x.Attribute.Title + "</th>");
                        break;

                    case SmartGridAttribute.ColumnTypeEnum.CheckBox:
                        sb.AppendLine("<th class=\"text-center\"><input id='select_all' title='Seleziona tutto' type='checkbox' /><span class=\"fakeCheck\" onclick=\"fakeCheckClick(this)\"></span></th>");
                        break;

                    default:
                        sb.AppendLine("<th></th>");
                        break;
                    }
                });
            });
            #endregion

            sb.AppendLine("</thead>");

            sb.AppendLine("<tfoot class=\"filterRow\" >");
            #region Footer
            ListSmartGridColumnInfo.ForEach(x =>
            {
                x.Attribute.ColumnTypes.ForEach(
                    y =>
                {
                    switch (y)
                    {
                    case SmartGridAttribute.ColumnTypeEnum.Text:
                        sb.AppendLine("<th data-title=\"" + x.Attribute.Title + "\"></th>");
                        break;

                    case SmartGridAttribute.ColumnTypeEnum.Select:
                        sb.AppendLine("<th class=\"IncludiFiltroSelect\"></th>");
                        break;

                    case SmartGridAttribute.ColumnTypeEnum.CheckBox:
                        sb.AppendLine("<th class=\"EscludiFiltro text-center\"><input id='btnMultipleAction' type='button' class='btn btn-success' value='" + x.Attribute.ButtonMultipleActionName + "' /></th>");
                        break;

                    default:
                        sb.AppendLine("<th class=\"EscludiFiltro\"></th>");
                        break;
                    }
                });
            });
            #endregion
            sb.AppendLine("</tfoot>");

            sb.AppendLine("</table>");
            #endregion

            divSmartGrid.InnerHtml = sb.ToString();
        }
Beispiel #2
0
        /// <summary>
        /// Metodo che inizializza lo UserControl con gli elementi base della SmartGrid e salva in sessione i dati necessari alla renderizzazione della SmartGrid
        /// </summary>
        /// <param name="objects">DataSource della SmartGrid</param>
        /// <param name="lengthMenu">Permette la selezione del numero di righe della SmartGrid</param>
        /// <param name="horizontalSearch">Abilita la ricerca orizzontale</param>
        private void SetDataSource <T>(List <T> objects, bool lengthMenu, bool horizontalSearch, List <ButtonTypeEnum> btns)
        {
            try
            {
                List <object> Objects = objects.Cast <object>().ToList();
                GetProperyInfo <T>(objects);

                if (ListSmartGridColumnInfo == null || ListSmartGridColumnInfo.Count == 0)
                {
                    return;
                }
                CreateTable();

                int width = 100 / ListSmartGridColumnInfo
                            .Count(x => x.Attribute.Visible);
                List <object> Columns     = new List <object>(),
                              ColumnsDefs = new List <object>();
                int index = 0;
                ListSmartGridColumnInfo
                .ToList()
                .ForEach(x =>
                {
                    if (x.Attribute.isDataRowKey)
                    {
                        DataRowKey = x.PropertyName;
                        MultipleActionDataValue = !x.Attribute.MultipleActionDataField.StartsWith("!");
                        MultipleActionDataField = x.Attribute.MultipleActionDataField.Substring(MultipleActionDataValue ? 0 : 1);
                    }
                    x.Attribute.ColumnTypes.ForEach(
                        y =>
                    {
                        object col, colDef;
                        switch (y)
                        {
                        case SmartGridAttribute.ColumnTypeEnum.DetailColumn:
                        case SmartGridAttribute.ColumnTypeEnum.EditColumn:
                        case SmartGridAttribute.ColumnTypeEnum.DeleteColumn:
                            col    = new CustomColumn(x, y);
                            colDef = new StringColumnDef();
                            break;

                        case SmartGridAttribute.ColumnTypeEnum.CheckBox:
                        case SmartGridAttribute.ColumnTypeEnum.Date:
                            col    = new StringColumn(x, width, y, false);
                            colDef = new CostumColumnDef(x, index, y);
                            break;

                        case SmartGridAttribute.ColumnTypeEnum.Currency:
                        case SmartGridAttribute.ColumnTypeEnum.Decimal2Places:
                        case SmartGridAttribute.ColumnTypeEnum.Decimal4Places:
                            col    = new StringColumn(x, width, y, true);
                            colDef = new CostumColumnDef(x, index, y);
                            break;

                        default:
                            col    = new StringColumn(x, width, y);
                            colDef = new StringColumnDef();
                            break;
                        }
                        Columns.Add(col);
                        ColumnsDefs.Add(colDef);
                        index++;
                    });
                });

                SmartGridData smartGridData  = new SmartGridData();
                var           jsonSerialiser = new JavaScriptSerializer();

                bool btnFeatures = false;
                if (btns != null && btns.Count > 0)
                {
                    List <string> renderedButtons = new List <string>();
                    btns.ForEach(x => { renderedButtons.Add(x.ToString()); });
                    btnFeatures           = true;
                    smartGridData.Buttons = jsonSerialiser.Serialize(renderedButtons);
                }
                smartGridData.sDom        = string.Format(sDom, lengthMenu ? "l" : "", btnFeatures ? "B" : "", horizontalSearch ? "f" : "");
                smartGridData.Objects     = jsonSerialiser.Serialize(Objects);
                smartGridData.Columns     = jsonSerialiser.Serialize(Columns);
                smartGridData.ColumnsDefs = jsonSerialiser.Serialize(ColumnsDefs);

                System.Web.HttpContext.Current.Session.Add("SmartGridData", smartGridData);
            }
            catch (Exception /*ex*/)
            {
                //Logger.LogException(ex);
                (Page as SmartGridWebSite.Default).errors.Add("Errore in fase di caricamento della SmartGrid");
            }
        }