Exemplo n.º 1
0
        public static ToolButton CreateToolButton(IDataGrid grid, string service, Func<bool> onViewSubmit,
            string title = "Excel")
        {
            return new ToolButton
            {
                Title = title,
                CssClass = "export-xlsx-button",
                OnClick = delegate
                {
                    if (!onViewSubmit())
                        return;

                    var request = Q.DeepClone(((ListRequest)grid.GetView().Params));
                    request.Take = 0;
                    request.Skip = 0;

                    var sortBy = grid.GetView().SortBy;
                    if (sortBy != null)
                        request.Sort = sortBy;

                    request.IncludeColumns = new List<string>();
                    foreach (var column in grid.GetGrid().GetColumns())
                        request.IncludeColumns.Add(column.Identifier ?? column.Field);

                    Q.Externals.PostToService(new PostToServiceOptions
                    {
                        Service = service,
                        Request = request,
                        Target = "_blank"
                    });
                }
            };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Merges the data grid specified into the current data grid instance
        /// </summary>
        /// <param name="grid">The data grid to merge</param>
        public void Merge
        (
            IDataGrid grid
        )
        {
            if (grid == null)
            {
                throw new ArgumentNullException("grid");
            }

            foreach (var row in grid)
            {
                var rowData = new Dictionary <string, object>();

                foreach (var item in row)
                {
                    rowData.Add(item.Key, item.Value);
                }

                AddRow
                (
                    rowData.ToArray()
                );
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Converts a data grid to an XML document representation
 /// </summary>
 /// <param name="grid">The data grid to serialize</param>
 /// <returns>The XML document generated</returns>
 public static XmlDocument ToXml
 (
     this IDataGrid grid
 )
 {
     return(new GridToXmlSerializer().Serialize
            (
                grid
            ));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Converts a data grid to a JSON string representation
 /// </summary>
 /// <param name="grid">The data grid to serialize</param>
 /// <returns>The JSON content generated</returns>
 public static string ToJson
 (
     this IDataGrid grid
 )
 {
     return(new GridToJsonSerializer().Serialize
            (
                grid
            ));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Constructs a new data grid row with a new key-value collection
        /// </summary>
        /// <param name="grid">The data grid reference</param>
        /// <param name="values">The values to add to the row</param>
        protected internal DataGridRow
        (
            IDataGrid grid,
            params KeyValuePair <string, object>[] values
        )
        {
            if (grid == null)
            {
                throw new ArgumentNullException("grid");
            }

            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            if (values.Length == 0)
            {
                throw new ArgumentException
                      (
                          "At least one value is required to create a data grid row."
                      );
            }

            this.Grid = grid;

            _columnValues = new Dictionary <string, object>();

            // Add the column values to the row but also pad the row with blanks where values are missing
            foreach (var column in grid.GetColumnNames())
            {
                if (values.Any(m => m.Key == column))
                {
                    var matchingItem = values.First
                                       (
                        m => m.Key.ToLower() == column.ToLower()
                                       );

                    _columnValues.Add
                    (
                        column,
                        matchingItem.Value
                    );
                }
                else
                {
                    _columnValues.Add
                    (
                        column,
                        null
                    );
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts the data grid specified to a CSV new data string
        /// </summary>
        /// <param name="grid">The data grid binder to convert</param>
        /// <returns>A string that represents the data grid in CSV format</returns>
        public string Serialize
        (
            IDataGrid grid
        )
        {
            if (grid == null || grid.Count() == 0)
            {
                return(String.Empty);
            }

            var configuration = new CsvConfiguration()
            {
                Delimiter       = ",",
                HasHeaderRecord = true,
                Quote           = '"'
            };

            using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                    using (var csv = new CsvWriter(writer, configuration))
                    {
                        // Create the CSV headings
                        grid.GetColumnNames().ToList().ForEach
                        (
                            m => csv.WriteField(m)
                        );

                        csv.NextRecord();

                        // Create a CSV record for every row in the data grid
                        foreach (var row in grid)
                        {
                            foreach (var cell in row)
                            {
                                // Get a string representation of the cells value
                                var value =
                                    (
                                        cell.Value == null ? String.Empty : cell.Value.ToString()
                                    );

                                csv.WriteField(value);
                            }

                            csv.NextRecord();
                        }

                        // Reset the memory stream and writers
                        writer.Flush();
                        stream.Position = 0;

                        return(new StreamReader(stream).ReadToEnd());
                    }
        }
        public GridRowSelectionMixin(IDataGrid grid)
        {
            this.grid = grid;
            this.idField = grid.GetView().IdField;

            grid.GetGrid().OnClick.Subscribe((e, p) => {
                if (J(e.Target).HasClass("select-item"))
                {
                    e.PreventDefault();

                    var item = grid.GetView().GetItem(p.row);
                    var id = item[idField].toString();

                    if (include.ContainsKey(id))
                        include.Remove(id);
                    else
                        include[id] = true;

                    for (var i = 0; i < grid.GetView().GetLength(); i++)
                        grid.GetGrid().UpdateRow(i);

                    UpdateSelectAll();
                }
            });

            grid.GetGrid().OnHeaderClick.Subscribe((e, u) =>
            {
                if (e.IsDefaultPrevented())
                    return;

                if (J(e.Target).HasClass("select-all-items"))
                {
                    e.PreventDefault();
                    var view = grid.GetView();

                    if (include.Count > 0)
                        include.Clear();
                    else
                    {
                        foreach (var x in grid.GetView().GetItems())
                        {
                            var id = x[idField];
                            include[id.toString()] = true;
                        }
                    }
                    UpdateSelectAll();
                    grid.GetView().SetItems(grid.GetView().GetItems(), true);
                }
            });

            grid.GetView().OnRowsChanged.Subscribe((e, u) => UpdateSelectAll());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the Grid viewModel that corresponds
        /// to the UniqueID passed as parameter.
        /// </summary>
        /// <param name="uniqueID">Grid UniqueID</param>
        /// <returns></returns>
        private IDataGrid getGrid(string uniqueID)
        {
            var obj = (object)ViewManager.GetObject(uniqueID);

            if (obj != null)
            {
                IDataGrid grid = obj as IDataGrid;
                if (grid != null)
                {
                    return(grid);
                }
            }
            // Warning: No grid was found.
            return(null);
        }
        /// <summary>
        /// Creates C_AdvancedDataGrid control in specified mode
        /// </summary>
        public C_AdvancedDataGrid(GridMode mode)
        {
            InitializeComponent();
            basegrid    = null;
            excel_on    = false;
            initialized = false;

            try
            {
                this.Initialize(mode);
            }
            catch (Exception ex)
            {
                this.ErrorMessage("Failed to initialize the control. " + Environment.NewLine + ex.ToString());
            }
        }
Exemplo n.º 10
0
        public void UpdateOrderApproval(IDataGrid recapView, IModel model)
        {
            var result = new List <String>();

            for (int loopIndex = 0; loopIndex < recapView.rowCount; loopIndex++)
            {
                if ((bool)recapView.getRowVellValue(loopIndex, Constants.SELECT_ALL_RECORDS))
                {
                    var data = recapView.getData(loopIndex);

                    if (data.OrderChangeStatus == Constants.PENDING)
                    {
                        result.Add(data.Value);
                    }
                }
            }

            model.update(result);
        }
Exemplo n.º 11
0
        public static void Update <TItem>(IDataGrid grid,
                                          Func <TItem, bool> getSelected)
            where TItem : class, new()
        {
            var grd     = grid.As <DataGrid <TItem, object> >();
            var toolbar = grd.Element.Children(".s-Toolbar");

            if (toolbar.Length == 0)
            {
                return;
            }

            var btn = toolbar.GetWidget <Toolbar>()
                      .FindButton("select-all-button");

            var items = grd.View.GetItems();

            btn.ToggleClass("checked", items.Count > 0 && !items.Some(x => !getSelected(x)));
        }
Exemplo n.º 12
0
        public static ToolButton CreateToolButton(IDataGrid grid, string service, Func <bool> onViewSubmit,
                                                  string title = "Excel")
        {
            return(new ToolButton
            {
                Title = title,
                CssClass = "export-xlsx-button",
                OnClick = delegate
                {
                    if (!onViewSubmit())
                    {
                        return;
                    }

                    var request = Q.DeepClone(((ListRequest)grid.GetView().Params));
                    request.Take = 0;
                    request.Skip = 0;

                    var sortBy = grid.GetView().SortBy;
                    if (sortBy != null)
                    {
                        request.Sort = sortBy;
                    }

                    request.IncludeColumns = new List <string>();
                    foreach (var column in grid.GetGrid().GetColumns())
                    {
                        request.IncludeColumns.Add(column.Identifier ?? column.Field);
                    }

                    Q.Externals.PostToService(new PostToServiceOptions
                    {
                        Service = service,
                        Request = request,
                        Target = "_blank"
                    });
                }
            });
        }
Exemplo n.º 13
0
        public FivePanelsView(IDataGrid <CGContext> g)
        {
            _dg = g;

            //this.AutosizesSubviews = false;
        }
Exemplo n.º 14
0
 /// <summary>
 /// 將會於 生命週期事件 OnInitialized / OnAfterRenderAsync 觸發此方法
 /// </summary>
 /// <param name="razorPage">當前元件的物件</param>
 /// <param name="dataGrid">當前 Grid 的元件</param>
 public void Setup(IRazorPage razorPage, IDataGrid dataGrid)
 {
     thisView      = razorPage;
     this.dataGrid = dataGrid;
 }
Exemplo n.º 15
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider != null && context != null)
            {
                IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (service == null || context.Instance == null)
                {
                    return(value);
                }
                IDataGrid eg = context.Instance as IDataGrid;
                DataGridViewColumnCollection cols;
                if (eg != null)
                {
                    DlgEditColumns dlgCols = new DlgEditColumns();
                    cols = value as DataGridViewColumnCollection;
                    if (cols == null)
                    {
                        cols = new DataGridViewColumnCollection((DataGridView)eg);
                    }
                    dlgCols.LoadData(cols);
                    eg.DisableColumnChangeNotification = true;
                    if (service.ShowDialog(dlgCols) == DialogResult.OK)
                    {
                        value = cols;
                        eg.OnChangeColumns(cols);
                    }
                    eg.DisableColumnChangeNotification = false;
                }

                {
                    IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost));
                    if (host == null)
                    {
                        IComponent ic = context.Instance as IComponent;
                        if (ic != null && ic.Site != null)
                        {
                            host = ic.Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
                        }
                    }
                    if (host == null)
                    {
                        return(value);
                    }
                    if (dataGridViewColumnCollectionDialog == null)
                    {
                        dataGridViewColumnCollectionDialog = CreateColumnCollectionDialog(provider, value as DataGridViewColumnCollection, context.Instance as DataGridView);
                    }
                    if (dataGridViewColumnCollectionDialog == null)
                    {
                        return(value);
                    }
                    //Unfortunately we had to make property which returns inner datagridview
                    //to access it here because we need to pass DataGridView into SetLiveDataGridView () method
                    DataGridView grid = context.Instance as DataGridView;
                    //we have to set Site property because it will be accessed inside SetLiveDataGridView () method
                    //and by default it's usually null, so if we do not set it here, we will get exception inside SetLiveDataGridView ()
                    //var oldSite = grid.Site;
                    //grid.Site = ((UserControl) context.Instance).Site;
                    //execute SetLiveDataGridView () via reflection
                    SetLiveDataGridView(dataGridViewColumnCollectionDialog, grid);
                    using (DesignerTransaction transaction = host.CreateTransaction("DataGridViewColumnCollectionTransaction"))
                    {
                        if (service.ShowDialog(dataGridViewColumnCollectionDialog) == DialogResult.OK)
                        {
                            transaction.Commit();
                            if (eg != null)
                            {
                                cols = value as DataGridViewColumnCollection;
                                eg.OnChangeColumns(cols);
                                IDevClass dc = eg.GetDevClass();
                                if (dc != null)
                                {
                                    dc.NotifyChange(eg, context.PropertyDescriptor.Name);
                                }
                            }
                        }
                        else
                        {
                            transaction.Cancel();
                        }
                    }
                }
            }
            return(value);
        }
Exemplo n.º 16
0
        public FivePanelsView(IDataGrid <IGraphics> g)
        {
            _dg = g;

            //this.AutosizesSubviews = false;
        }
Exemplo n.º 17
0
 public void Setup(IRazorPage razorPage, IDataGrid dataGrid)
 {
     thisRazorComponent = razorPage;
     this.dataGrid      = dataGrid;
 }
Exemplo n.º 18
0
 public static void DistributeLayerData <TLayer>(IDataGrid dataGrid)
 {
     // TODO: TLayer runtime casting and DataAny checks if they fit their `TValue` type necessary
 }
        /// <summary>
        /// Initializes this control in specified mode
        /// </summary>
        public void Initialize(GridMode mode)
        {
            try
            {
                //clean up resources of current control
                this.Controls.Clear();

                if (initialized && excel_on)
                {
                    (basegrid as AdvancedDataGrid).Destroy();

                    excel_on = false;
                }
                basegrid    = null;
                initialized = false;

                //initialize control based on chosen mode
                switch (mode)
                {
                case GridMode.Substitute:
                    basegrid = new SubstituteGrid.S_AdvancedDataGrid();
                    excel_on = false;
                    this.Controls.Add((Control)basegrid);
                    (basegrid as Control).Dock = DockStyle.Fill;
                    initialized = true;
                    break;

                case GridMode.Excel:
                    basegrid = new AdvancedDataGrid();
                    (basegrid as AdvancedDataGrid).InitializeExcel();
                    excel_on = true;
                    this.Controls.Add((Control)basegrid);
                    (basegrid as Control).Dock = DockStyle.Fill;
                    initialized = true;
                    break;

                case GridMode.Auto:
                    try
                    {
                        //tries to initialize excel mode
                        basegrid = new AdvancedDataGrid();
                        (basegrid as AdvancedDataGrid).InitializeExcel();
                        excel_on = true;
                    }
                    catch (Exception)
                    {
                        //on fail, tries to use substitute mode
                        basegrid = new SubstituteGrid.S_AdvancedDataGrid();
                        excel_on = false;
                    }
                    this.Controls.Add((Control)basegrid);
                    (basegrid as Control).Dock = DockStyle.Fill;
                    initialized = true;
                    break;
                }
            }
            catch (Exception)
            {
                this.excel_on    = false;
                this.initialized = false;
                this.basegrid    = null;
                throw;
            }
        }
Exemplo n.º 20
0
        public GridRowSelectionMixin(IDataGrid grid)
        {
            this.grid    = grid;
            this.idField = grid.GetView().IdField;

            grid.GetGrid().OnClick.Subscribe((e, p) => {
                if (J(e.Target).HasClass("select-item"))
                {
                    e.PreventDefault();

                    var item = grid.GetView().GetItem(p.row);
                    var id   = item[idField].toString();

                    if (include.ContainsKey(id))
                    {
                        include.Remove(id);
                    }
                    else
                    {
                        include[id] = true;
                    }

                    for (var i = 0; i < grid.GetView().GetLength(); i++)
                    {
                        grid.GetGrid().UpdateRow(i);
                    }

                    UpdateSelectAll();
                }
            });

            grid.GetGrid().OnHeaderClick.Subscribe((e, u) =>
            {
                if (e.IsDefaultPrevented())
                {
                    return;
                }

                if (J(e.Target).HasClass("select-all-items"))
                {
                    e.PreventDefault();
                    var view = grid.GetView();

                    if (include.Count > 0)
                    {
                        include.Clear();
                    }
                    else
                    {
                        foreach (var x in grid.GetView().GetItems())
                        {
                            var id = x[idField];
                            include[id.toString()] = true;
                        }
                    }
                    UpdateSelectAll();
                    grid.GetView().SetItems(grid.GetView().GetItems(), true);
                }
            });

            grid.GetView().OnRowsChanged.Subscribe((e, u) => UpdateSelectAll());
        }
Exemplo n.º 21
0
        /// <summary>
        /// Serializes a data grid to an XML document
        /// </summary>
        /// <param name="grid">The data grid</param>
        /// <returns>An XmlDocument containing the grids data</returns>
        public XmlDocument Serialize
        (
            IDataGrid grid
        )
        {
            if (grid == null)
            {
                return(new XmlDocument());
            }

            var document = new XmlDocument();

            // The XML declaration is recommended, but not mandatory
            var xmlDeclaration = document.CreateXmlDeclaration
                                 (
                "1.0",
                "UTF-8",
                null
                                 );

            var rootNode = document.CreateElement
                           (
                "DataGrid"
                           );

            document.InsertBefore
            (
                xmlDeclaration,
                document.DocumentElement
            );

            foreach (var row in grid)
            {
                var rowNode = document.CreateElement
                              (
                    "Item"
                              );

                foreach (var cell in row)
                {
                    // Get a string representation of the cells value
                    var value =
                        (
                            cell.Value == null ? String.Empty : cell.Value.ToString()
                        );

                    // Create the cell node and append it to the row node
                    var cellNode = document.CreateElement
                                   (
                        cell.Key
                                   );

                    cellNode.InnerText = value;
                    rowNode.AppendChild(cellNode);
                }

                rootNode.AppendChild(rowNode);
            }

            document.AppendChild(rootNode);

            return(document);
        }
 public FivePanelsView(Context c, IDataGrid <IGraphics> g) : base(c)
 {
     _dg = g;
 }
Exemplo n.º 23
0
        /// <summary>
        /// Serializes a data grid to a JSON document
        /// </summary>
        /// <param name="grid">The data grid</param>
        /// <returns>A JSON string containing the grids data</returns>
        public string Serialize
        (
            IDataGrid grid
        )
        {
            if (grid == null || grid.Count() == 0)
            {
                return(String.Empty);
            }

            var jsonBuilder = new StringBuilder();
            var rowCount    = grid.Count();
            var columnCount = grid.GetColumnNames().Length;
            var rowNumber   = 1;

            jsonBuilder.Append("{\n");

            jsonBuilder.Append
            (
                "\t\"{0}\": [\n".With
                (
                    grid.Name
                )
            );

            foreach (var row in grid)
            {
                var columnNumber = 1;

                jsonBuilder.Append("\t{\n");

                foreach (var cell in row)
                {
                    // Get a string representation of the cells value
                    var value =
                        (
                            cell.Value == null ? String.Empty : cell.Value.ToString()
                        );

                    // Create a JSON property template
                    var template =
                        (
                            (columnNumber < columnCount)
                            ? "\t\t\"{0}\": \"{1}\",\n"
                            : "\t\t\"{0}\": \"{1}\"\n"
                        );

                    // Add the column name and value to the JSON items properties
                    jsonBuilder.Append
                    (
                        template.With(cell.Key, value)
                    );

                    columnNumber++;
                }

                jsonBuilder.Append
                (
                    (rowNumber < rowCount)
                        ? "\t},\n"
                        : "\t}\n"
                );

                rowNumber++;
            }

            jsonBuilder.Append("]}");

            return(jsonBuilder.ToString());
        }