Exemple #1
0
        public DataSourse GetData(string constr)
        {
            DataSourse dataSourse = new DataSourse();
            string     dbName     = constr.Substring(0, constr.IndexOf(";")).Substring(constr.IndexOf("=") + 1);
            IDbObject  dbObject   = (IDbObject) new DataAccess();

            dbObject.DbConnectStr = constr;
            List <string>    tables = dbObject.GetTables(dbName);
            List <TableData> list1  = new List <TableData>();
            List <Reference> list2  = new List <Reference>();

            if (tables != null && tables.Count > 0)
            {
                foreach (string tableName in tables)
                {
                    TableData tableData = new TableData();
                    tableData.Code = tableName;
                    tableData.Name = tableName;
                    tableData.Id   = tableName;
                    List <string> list3          = new List <string>();
                    DataTable     columnInfoList = dbObject.GetColumnInfoList(dbName, tableName);
                    List <Column> list4          = new List <Column>();
                    foreach (DataRow row in (InternalDataCollectionBase)columnInfoList.Rows)
                    {
                        Column column1 = new Column();
                        column1.Code      = DataRowExtensions.Field <string>(row, 1).Trim();
                        column1.Comment   = DataRowExtensions.Field <string>(row, 15).Trim();
                        column1.DataType  = DataRowExtensions.Field <string>(row, 2).Trim();
                        column1.Displayed = "true";
                        Column column2 = column1;
                        string str1    = tableName;
                        int    num     = DataRowExtensions.Field <int>(row, 0);
                        string str2    = num.ToString();
                        string str3    = str1 + str2;
                        column2.Id = str3;
                        Column column3 = column1;
                        num = DataRowExtensions.Field <int>(row, 3);
                        string str4 = num.ToString();
                        column3.Length    = str4;
                        column1.Mandatory = DataRowExtensions.Field <string>(row, 13).Trim() == "√" ? "" : "1";
                        column1.Name      = DataRowExtensions.Field <string>(row, 1).Trim();
                        column1.TableCode = tableName;
                        column1.TableId   = tableData.Id;
                        if (DataRowExtensions.Field <string>(row, 7).Trim() != "d")
                        {
                            list3.Add(column1.Id);
                        }
                        list4.Add(column1);
                    }
                    tableData.Columns = list4;
                    if (list3.Count > 0)
                    {
                        tableData.PrimaryKey = new Key()
                        {
                            KeyId     = Guid.NewGuid().ToString(),
                            ColumnRef = list3.ToArray()
                        }
                    }
                    ;
                    list1.Add(tableData);
                }
            }
            if (list1 != null && list1.Count > 0)
            {
                foreach (TableData tableData in list1)
                {
                    TableData tab = tableData;
                    foreach (DataRow dataRow in (InternalDataCollectionBase)dbObject.GetTableRefrence(dbName, tab.Code).Rows)
                    {
                        DataRow   item = dataRow;
                        Reference r    = new Reference();
                        r.ParentTable          = Enumerable.SingleOrDefault <string>(Enumerable.Select <TableData, string>(Enumerable.Where <TableData>((IEnumerable <TableData>)list1, (Func <TableData, bool>)(t => t.Code == DataRowExtensions.Field <string>(item, 1).Trim())), (Func <TableData, string>)(t => t.Id)));
                        r.ParentTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) =>
                        {
                            var fAnonymousType2 = new
                            {
                                t = t,
                                f = f
                            };
                            return(fAnonymousType2);
                        }), param0 => param0.t.Id == r.ParentTable), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 2).Trim()), param0 => param0.f.Id));
                        r.Id                  = Guid.NewGuid().ToString();
                        r.ChildTable          = tab.Id;
                        r.ChildTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) =>
                        {
                            var fAnonymousType2 = new
                            {
                                t = t,
                                f = f
                            };
                            return(fAnonymousType2);
                        }), param0 => param0.t.Id == tab.Id), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 0).Trim()), param0 => param0.f.Id));
                        list2.Add(r);
                    }
                }
            }
            dataSourse.ListTable     = list1;
            dataSourse.ListReference = list2;
            DataTable       vieWs = dbObject.GetVIEWs(dbName);
            List <ViewData> list5 = new List <ViewData>();

            if (vieWs != null && vieWs.Rows != null && vieWs.Rows.Count > 0)
            {
                foreach (DataRow row in (InternalDataCollectionBase)vieWs.Rows)
                {
                    string str = DataRowExtensions.Field <string>(row, 0);
                    if (!string.IsNullOrWhiteSpace(str))
                    {
                        string    objectViewInfo = dbObject.GetObjectViewInfo(dbName, str);
                        DataTable dataTable      = dbObject.QueryViewInfo(dbName, str);
                        ViewData  viewData       = new ViewData();
                        viewData.Code     = str;
                        viewData.Name     = str;
                        viewData.Id       = str;
                        viewData.SQLQuery = objectViewInfo;
                        List <Column> list3 = new List <Column>();
                        foreach (DataColumn dataColumn in (InternalDataCollectionBase)dataTable.Columns)
                        {
                            list3.Add(new Column()
                            {
                                Name = dataColumn.ColumnName,
                                Code = dataColumn.ColumnName,
                                Id   = Guid.NewGuid().ToString()
                            });
                        }
                        viewData.Columns = list3;
                        list5.Add(viewData);
                    }
                }
            }
            dataSourse.ListView = list5;
            return(dataSourse);
        }
    }