Exemplo n.º 1
0
        public static DataTable CreateDataTable(string tableID, Dictionary <string, BoFieldsType> columns, UserFormBase frm)
        {
            DataTable dataTable = null;

            try {
                frm.UIAPIRawForm.DataSources.DataTables.Add(tableID);
                dataTable = frm.UIAPIRawForm.DataSources.DataTables.Item(tableID);

                columns.AsParallel().ForAll(column => {
                    dataTable.Columns.Add("C_" + column.Key, column.Value);
                });
            }
            catch (Exception ex) {
                SAPException.Handle(ex, "(Create DataTable)");
            }
            return(dataTable);
        }
Exemplo n.º 2
0
        public static void Fill <T>(string tableID, DataTable dataTable, Matrix mtx, List <string> columns, T[] data)
        {
            try {
                if (!Object.ReferenceEquals(data, null))
                {
                    dataTable.Rows.Clear();

                    Parallel.For(0, data.Length, row => {
                        dataTable.Rows.Add();
                    });

                    Task.Factory.StartNew(() => {
                        Parallel.For(0, data.Length, row => {
                            dataTable.SetValue("C_#", row, row + 1);
                        });
                    });

                    Parallel.ForEach(Partitioner.Create(0, data.Length), (range, state) => {
                        for (int i = range.Item1; i < range.Item2; i++)
                        {
                            Parallel.ForEach(columns.Skip(1), column => {
                                dataTable.SetValue("C_" + column, i, data[i].GetType().GetProperty(column).GetValue(data[i], null));
                            });
                        }
                    });
                    Bind(mtx, tableID, columns);
                }
                else
                {
                    ClearMtx(mtx);
                }
            }
            catch (AggregateException ae) {
                ae.Handle(e => {
                    SAPException.Handle(e, "(AE)");
                    return(true);
                });
            }
            catch (Exception ex) {
                SAPException.Handle(ex, "(FillMatrix0)");
            }
        }