예제 #1
0
        // load XML and remap parameters


        private void button1_Click(object sender, EventArgs e)
        {
            metaData.Clear();
            metaData.ReadXml(metaDataName);
            Subjects   = metaData.Tables["Subjects"];
            Properties = metaData.Tables["Properties"];
            int nRows = Subjects.Rows.Count;

            Assigns_Properties = metaData.Tables["Assigns_Properties"];
            var results1 = from p in Properties.AsEnumerable()
                           join r in Assigns_Properties.AsEnumerable() on p.Field <string>("freeBIM_Guid") equals r.Field <string>("Guid_Property")
                               where r.Field <string>("Guid_Subject") == "1"
                           select new
            {
                name  = (string)p["Name_Loc"],
                phase = (string)r["Guid_Phase"],
                desc  = (string)p["Description_Loc"]
            };


            DataTable result1 = new DataTable();

            result1.Columns.Add("Name");
            result1.Columns.Add("Description");
            result1.Columns.Add("Phase");

            foreach (var item in results1)
            {
                DataRow newRow = result1.NewRow();
                newRow["Name"]        = item.name;
                newRow["Description"] = item.desc;
                newRow["Phase"]       = item.phase;

                result1.Rows.Add(newRow);
                Console.WriteLine(item.name);
            }

            dataGridView4.DataSource = result1;

            // Measures für einen bestimmten Parameter/Kategorie
            // Tables: Assigns_Measures, Rvt_Guid_parameter, Measures,
            Assigns_Measures   = metaData.Tables["Assigns_Measures"];
            Measures           = metaData.Tables["Measures"];
            Rvt_Guid_parameter = rvt_parameter_mapping.Tables["Rvt_guid_parameter_mapping"];


            var results2 = from m in Measures.AsEnumerable()
                           join a in Assigns_Measures.AsEnumerable() on m.Field <string>("freeBIM_Guid") equals a.Field <string>("Guid_Measure")
                           join r in Rvt_Guid_parameter.AsEnumerable() on a.Field <string>("Guid_Property") equals r.Field <string>("freeBIM_Guid")
                           select new{
                freeBIM_Guid = (string)r["freeBIM_Guid"],
                rvt_ID       = (string)r["rvt_Parameter_ID"],
                Measure      = (string)m["Name_Loc"]
            };

            DataTable result2 = new DataTable();

            result2.Columns.Add("Name");
            result2.Columns.Add("freeBIM_Guid");
            foreach (var item in results2)
            {
                DataRow newRow = result2.NewRow();
                newRow["freeBIM_Guid"] = item.freeBIM_Guid;
                newRow["Name"]         = item.Measure;

                result2.Rows.Add(newRow);
                Console.WriteLine(item.Measure);
            }

            dataGridView5.DataSource = result2;
        }
예제 #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            metaData.Clear();
            metaData.ReadXml(metaDataName);
            rvt_parameter_mapping.Clear();
            rvt_parameter_mapping.ReadXml(mappingDataName);
            Subjects         = metaData.Tables["Subjects"];
            Properties       = metaData.Tables["Properties"];
            prop_par_mapping = rvt_parameter_mapping.Tables["prop_par_mapping"];
            parameters       = rvt_parameter_mapping.Tables["Parameters"];

            int category_int = -2000011;
            // First find the Properties relevant for the subjects, the list is a result from the category and the inheritance chain

            List <string> parents = new List <string> {
                "E1", "E81"
            };

            Assigns_Properties = metaData.Tables["Assigns_Properties"];
            DataTable element_props = new DataTable();

            string[] cols2     = { "Property_ID", "bSDD_Guid", "Name_Loc", "Description", "bIsInIFC_PSet" };
            Type[]   dataTypes = { typeof(string), typeof(string), typeof(string), typeof(string), typeof(bool) };
            for (int i = 0; i < cols2.Count(); i++)
            {
                element_props.Columns.Add(cols2[i], dataTypes[i]);
            }

            var result = from p in Properties.AsEnumerable()
                         join r in Assigns_Properties.AsEnumerable() on p.Field <string>("freeBIM_Guid") equals r.Field <string>("Guid_Property")
                             where parents.Contains(r.Field <string>("Guid_Subject"))
                         select new
            {
                Property_ID   = (string)p["freeBIM_Guid"],
                bSDD_Guid     = p["bSDD_Guid"] == null  ? "" : p["bSDD_Guid"].ToString(),
                Name_Loc      = p["Name_Loc"] == null ? "" : p["Name_Loc"].ToString(),
                bIsInIFC_PSet = p["bIsInIFC_PSet"] == null || p["bIsInIFC_PSet"].ToString().Length == 0 ? false : Convert.ToBoolean(p["bIsInIFC_PSet"]),
                Description   = p["Description_Loc"] == null ? "" : p["Description_Loc"].ToString()
            };

            foreach (var item in result)
            {
                DataRow newRow = element_props.NewRow();
                newRow["Property_ID"]   = item.Property_ID;
                newRow["bsDD_Guid"]     = item.bSDD_Guid;
                newRow["Name_Loc"]      = item.Name_Loc;
                newRow["bIsInIFC_PSet"] = item.bIsInIFC_PSet;
                newRow["Description"]   = item.Description;
                element_props.Rows.Add(newRow);
            }

            var pars_mapped_query = from m in prop_par_mapping.AsEnumerable()
                                    join p in Properties.AsEnumerable() on m.Field <string>("Prop_ID") equals p.Field <string>("freeBIM_Guid")
                                    join par in parameters.AsEnumerable() on m.Field <Int32>("Parameter_ID") equals par.Field <Int32>("ID")
                                        where m.Field <Int32>("Category_int") == category_int
                                    select new
            {
                Prop_ID      = p["freeBIM_Guid"].ToString(),
                ParName      = par["name_deu"] == null ? "" : par["name_deu"].ToString(),
                Type_Code    = par["Type_Code"] == null ? "" : par["Type_Code"].ToString(),
                Parameter_ID = m["Parameter_ID"],
                bIsType      = par["bIsType"] == null || par["bIsType"].ToString().Length == 0 ? false : par["bIsType"]
            };

            string[] cols  = { "Prop_ID", "ParName", "bIsType", "Type_Code", "Parameter_ID" };
            Type[]   types = { typeof(string), typeof(string), typeof(bool), typeof(string), typeof(Int32) };

            DataTable pars_mapped = new DataTable();

            for (int i = 0; i < cols.Count(); i++)
            {
                pars_mapped.Columns.Add(cols[i], types[i]);
            }

            foreach (var item in pars_mapped_query)
            {
                DataRow newRow = pars_mapped.NewRow();
                newRow["Prop_ID"]      = item.Prop_ID;
                newRow["ParName"]      = item.ParName;
                newRow["Type_Code"]    = item.Type_Code;
                newRow["Parameter_ID"] = item.Parameter_ID;
                newRow["bIsType"]      = item.bIsType;
                pars_mapped.Rows.Add(newRow);
            }

            var query = from prop in element_props.AsEnumerable()
                        join mapped in pars_mapped.AsEnumerable() on prop.Field <string>("Property_ID") equals mapped.Field <string>("Prop_ID") into j
                        from mapped in j.DefaultIfEmpty()
                        select new
            {
                Prop_ID       = prop.Field <string>("Property_ID"),
                PropName      = prop.Field <string>("Name_Loc") == null ? "" : prop.Field <string>("Name_Loc").ToString(),
                Description   = prop.Field <string>("Description") == null ? "" : prop.Field <string>("Description").ToString(),
                bSDD_Guid     = prop.Field <string>("bSDD_Guid") == null ? "" : prop.Field <string>("bSDD_Guid").ToString(),
                bIsInIFC_PSet = prop["bIsInIFC_PSet"] == null || prop["bIsInIFC_PSet"].ToString().Length == 0 ? false : Convert.ToBoolean(prop["bIsInIFC_PSet"]),
                Type_Code     = mapped == null ? "" : mapped.Field <string>("Type_Code").ToString(),
                ParName       = mapped == null ? "" : mapped.Field <string>("ParName").ToString(),
                bIsType       = mapped == null ? false : mapped.Field <bool>("bIsType"),
                Parameter_ID  = mapped == null ? 0 : mapped.Field <Int32>("Parameter_ID")
            };

            //             sql = "select parameters.ID as ID, Code, Name, parameters.Description as Description, `Order`, data_types.Description as Data_Type, unit_types.Unit as Unit, parameters.GUID as GUID, parameters.bIsType as bIsType,  ";
            //             sql += "bHide, rvt_parameters.Type_Code as Type_Code, rvt_parameters.name_deu as ParName, rvt_Parameter_ID ";

            string[] cols3  = { "Prop_ID", "PropName", "Description", "bIsType", "Type_Code", "ParName", "bIsInIFC_PSet", "bSDD_Guid", "Parameter_ID" };
            Type[]   types3 = { typeof(string), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(string), typeof(bool), typeof(string), typeof(Int32) };

            DataTable dt_par_element = new DataTable();

            for (int i = 0; i < cols3.Count(); i++)
            {
                dt_par_element.Columns.Add(cols3[i], types3[i]);
            }

            foreach (var item in query)
            {
                DataRow newRow = dt_par_element.NewRow();
                newRow["Prop_ID"]       = item.Prop_ID;
                newRow["PropName"]      = item.PropName;
                newRow["Description"]   = item.Description;
                newRow["bIsType"]       = item.bIsType;
                newRow["Type_Code"]     = item.Type_Code;
                newRow["ParName"]       = item.ParName;
                newRow["bIsInIFC_PSet"] = item.bIsInIFC_PSet;
                newRow["bSDD_Guid"]     = item.bSDD_Guid;
                newRow["Parameter_ID"]  = item.Parameter_ID;
                dt_par_element.Rows.Add(newRow);
            }
        }