예제 #1
0
        private void btnViewResults_Click(object sender, EventArgs e)
        {
            List<ProjectResult> results = new List<ProjectResult>();
            String fName = "";
            using (OpenFileDialog openDlg = new OpenFileDialog())
            {
                openDlg.Title = "Open Project Results";
                openDlg.Filter = "XML File|*.xml";
                openDlg.ShowDialog();

                if (!String.IsNullOrEmpty(openDlg.FileName))
                {
                    fName = openDlg.FileName;
                    FileStream reader = new FileStream(openDlg.FileName, FileMode.Open, FileAccess.Read);
                    XmlDocument projects = new System.Xml.XmlDocument();
                    projects.Load(reader);
                    XmlNodeList nList = projects.GetElementsByTagName("Project");

                    foreach (XmlNode node in nList)
                    {
                        ProjectResult res = new ProjectResult();
                        XmlNodeList children = node.ChildNodes;
                        //id attribute has project name
                        res.ProjectName = node.Attributes["id"].InnerText;

                        //project level data
                        res.TotalCost = Double.Parse(children[0].InnerText);
                        res.TotalEI = Double.Parse(children[1].InnerText);
                        res.TotalDuration = Double.Parse(children[2].InnerText);

                        res.SelectedAssemblies = new List<Assembly>();
                        //get selected assemblies for each project
                        for (int i = 3; i < children.Count; i++)
                        {
                            XmlNode component = children[i];
                            XmlNodeList compData = component.ChildNodes;
                            Assembly assem = new Assembly();
                            assem.Category = component.Attributes["id"].Value;
                            assem.AssemblyName = compData[0].InnerText;
                            assem.Cost = Double.Parse(compData[1].InnerText);
                            assem.CO2 = Double.Parse(compData[2].InnerText);
                            assem.Duration = Double.Parse(compData[3].InnerText);
                            res.SelectedAssemblies.Add(assem);
                        }

                        if (!results.Contains(res))
                            results.Add(res);
                    }
                }
            }

            if (results.Count <= 0)
                return;

            using (ResultsForm resFrm = new ResultsForm())
            {
                resFrm.FileName = fName;
                resFrm.Results = results;
                resFrm.ShowDialog();
            }
        }
예제 #2
0
        public List<Assembly> RetrieveWallInfo()
        {
            List<Assembly> assemblies = new List<Assembly>();
            ICollection<Element> walls = getElementsOfCategory(doc, BuiltInCategory.OST_Walls, typeof(Wall));

            foreach (Element e in walls)
            {
                Wall w = null;
                WallType wType = null;
                w = (Wall)e;
                Assembly assem = new Assembly();
                wType = w.WallType;
                if (wType.Kind == WallKind.Basic)
                {
                    Parameter assemName = wType.get_Parameter("Assembly Description");
                    assem.AssemblyName = assemName.AsString();
                    Parameter assemCode = wType.get_Parameter("Assembly Code");
                    assem.AssemblyCode = assemCode.AsString();
                    assem.Category = AssemblyUtil.GetCategoryFromCode(assem.AssemblyCode);
                    //get all materials associated with this assembly
                    List<AssemMaterial> mats = new List<AssemMaterial>();

                    foreach (Material m in w.Materials)
                    {
                        // MessageBox.Show(String.Format("{0} : {1}: Area = {2}", assemName.AsString(), m.Name, w.GetMaterialArea(m)));
                        AssemMaterial mat = new AssemMaterial();
                        mat.Name = m.Name;
                        mats.Add(mat);
                    }
                    assem.Materials = mats;

                    //get area and volume for each assembly
                    foreach (Parameter p in w.Parameters)
                    {
                        if (p.Definition.Name.Equals("Area"))
                        {
                            if (p.HasValue)
                            {
                                assem.Area = p.AsDouble();
                            }
                        }
                        else if (p.Definition.Name.Equals("Volume"))
                        {
                            if (p.HasValue)
                            {
                                assem.Volume = p.AsDouble();
                            }
                        }
                    }
                    //if(!assemblies.Contains(assem))
                    assemblies.Add(assem);
                }
            }
            return assemblies;
        }
예제 #3
0
        public Boolean saveAssembly(Assembly assem)
        {
            Boolean saved = false;
            using (OleDbConnection conn = this.getConnection())
            {
                int assemblyID = -1;
                conn.Open();

                //Save the Assembly information to the databaseS
                using (OleDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        using (OleDbCommand comm = conn.CreateCommand())
                        {
                            comm.Transaction = trans;
                            comm.CommandType = CommandType.Text;

                            comm.CommandText = "SELECT ID FROM Assembly WHERE AssemName = ?";
                            comm.Parameters.AddWithValue("@name", assem.AssemblyName);

                            object obj = comm.ExecuteScalar();
                            if (obj != null && !(obj is DBNull))
                                assemblyID = (int)obj;

                            if (assemblyID < 0)
                            {
                                ClearCommandData(comm);
                                comm.CommandText = "INSERT INTO Assembly(AssemName, Description, AssemblyCode, Category) VALUES (?,?,?,?)";
                                comm.Parameters.AddWithValue("@name", assem.AssemblyName);
                                if (String.IsNullOrEmpty(assem.Description))
                                    comm.Parameters.AddWithValue("@desc", "");
                                else
                                    comm.Parameters.AddWithValue("@desc", assem.Description);
                                comm.Parameters.AddWithValue("@code", assem.AssemblyCode);
                                comm.Parameters.AddWithValue("@cat", assem.Category);

                                comm.ExecuteNonQuery();

                                comm.CommandText = "SELECT @@IDENTITY";
                                obj = comm.ExecuteScalar();
                                if (obj != null && !(obj is DBNull))
                                    assemblyID = (int)obj;
                            }
                        }
                        //DesignOption inserted.
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        saved = false;
                    }
                }

                int matID = -1;
                //Save any new Materials to the database.
                //Includes Labor data and Material Summary
                //Associate each material with the given assembly
                using (OleDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        foreach (AssemMaterial mat in assem.Materials)
                        {
                            using (OleDbCommand comm = conn.CreateCommand())
                            {
                                comm.Transaction = trans;
                                comm.CommandType = CommandType.Text;
                                comm.CommandText = "SELECT ID FROM Material WHERE MatName = ? and Description = ?;";
                                comm.Parameters.AddWithValue("@name", mat.Name);
                                comm.Parameters.AddWithValue("@desc", mat.Description);

                                Object obj = comm.ExecuteScalar();

                                if (!(obj is DBNull) && (obj != null))
                                    matID = (int)obj;

                                if (matID < 0)
                                {
                                    ClearCommandData(comm);
                                    comm.CommandText = "INSERT INTO Material (MatName, Description, CostPerUnit, CO2PerUnit, Unit, "
                                                     + "R_Value) values (?,?,?,?,?,?)";
                                    comm.Parameters.AddWithValue("@name", mat.Name);
                                    comm.Parameters.AddWithValue("@desc", mat.Description);
                                    comm.Parameters.AddWithValue("@cost", mat.CostPerUnit);
                                    comm.Parameters.AddWithValue("@c02", mat.CO2PerUnit);
                                    comm.Parameters.AddWithValue("@unit", mat.Unit);
                                    comm.Parameters.AddWithValue("@rval", mat.RValue);

                                    comm.ExecuteNonQuery();

                                    ClearCommandData(comm);
                                    comm.CommandText = "SELECT @@IDENTITY";

                                    obj = comm.ExecuteScalar();

                                    if (!(obj is DBNull) && (obj != null))
                                        matID = (int)obj;

                                    //insert Labor Data
                                    ClearCommandData(comm);
                                    comm.CommandText = "Insert into Labor (LaborCost, LaborHours, MaterialID, DailyOutput) "
                                                        + "values (?, ?, ?, ?)";
                                    comm.Parameters.AddWithValue("@cost", mat.Labor.Cost);
                                    comm.Parameters.AddWithValue("@hours", mat.Labor.Hours);
                                    comm.Parameters.AddWithValue("@mat", matID);
                                    comm.Parameters.AddWithValue("@out", mat.Labor.DailyOutPut);
                                    comm.ExecuteNonQuery();

                                    //insert material summaries (usually 8)
                                    for (int i = 0; i < 8; i++)
                                    {
                                        List<double> phases = mat.Summary.GetSummaryByType((MaterialSummary.SummaryType)i);
                                        if (phases.Count != 5)
                                            continue;
                                        ClearCommandData(comm);
                                        int typeID = -1;
                                        comm.CommandText = "SELECT ID FROM SummaryType WHERE SummaryName=?";
                                        comm.Parameters.AddWithValue("@type", (MaterialSummary.summaries[i]));
                                        Object typeObj = null;
                                        typeObj = comm.ExecuteScalar();

                                        if (!(typeObj is DBNull) && (typeObj != null))
                                            typeID = (int)typeObj;
                                        if (typeID < 0)
                                            continue;

                                        ClearCommandData(comm);
                                        comm.CommandText = "Insert into MaterialSummary (MaterialID, SummaryTypeID, Manufacturing, "
                                                            + "Construction, Maintenance, EndofLife, Operation) "
                                                            + "values (?, ?, ?, ?, ?, ?, ?)";
                                        comm.Parameters.AddWithValue("@mat", matID);
                                        comm.Parameters.AddWithValue("@type", typeID);
                                        comm.Parameters.AddWithValue("@manu", phases[(int)MaterialSummary.SummaryPhase.MANUFACTURING]);
                                        comm.Parameters.AddWithValue("@const", phases[(int)MaterialSummary.SummaryPhase.CONSTRUCTION]);
                                        comm.Parameters.AddWithValue("@main", phases[(int)MaterialSummary.SummaryPhase.MAINTENANCE]);
                                        comm.Parameters.AddWithValue("@end", phases[(int)MaterialSummary.SummaryPhase.END_OF_LIFE]);
                                        comm.Parameters.AddWithValue("@oper", phases[(int)MaterialSummary.SummaryPhase.OPERATION]);
                                        comm.ExecuteNonQuery();
                                    }
                                }

                                ClearCommandData(comm);

                                comm.CommandText = "INSERT INTO Assem_Mat (MaterialID, AssemblyID) values (?,?);";
                                comm.Parameters.AddWithValue("@mat", matID);
                                comm.Parameters.AddWithValue("@assem", assemblyID);
                                comm.ExecuteNonQuery();
                            }
                        }
                        trans.Commit();
                        saved = true;
                    }
                    catch
                    {
                        trans.Rollback();
                        saved = false;
                    }
                }
                conn.Close();
            }

            return saved;
        }
예제 #4
0
        public List<Assembly> RetrieveFloorInfo()
        {
            List<Assembly> assemblies = new List<Assembly>();
            ICollection<Element> floors = getElementsOfCategory(doc, BuiltInCategory.OST_StructuralFoundation, typeof(Floor));

            foreach (Element e in floors)
            {
                Floor floor = null;
                FloorType fType = null;
                floor = (Floor)e;
                Assembly assem = new Assembly();
                fType = floor.FloorType;

                Parameter assemName = fType.get_Parameter("Assembly Description");

                assem.AssemblyName = floor.Name;
                //assem.AssemblyName = assemName.AsString();
                Parameter assemCode = fType.get_Parameter("Assembly Code");
                if (String.IsNullOrEmpty(assemCode.AsString()))
                    assem.AssemblyCode = "A1030";
                else
                    assem.AssemblyCode = assemCode.AsString();
                assem.Category = AssemblyUtil.GetCategoryFromCode(assem.AssemblyCode);
                //get all materials associated with this assembly
                List<AssemMaterial> mats = new List<AssemMaterial>();
                foreach (Material m in floor.Materials)
                {
                    AssemMaterial mat = new AssemMaterial();
                    mat.Name = m.Name;
                    mats.Add(mat);
                }
                assem.Materials = mats;

                //get area and volume for each assembly
                foreach (Parameter p in floor.Parameters)
                {
                    if (p.Definition.Name.Equals("Area"))
                    {
                        if (p.HasValue)
                        {
                            assem.Area = p.AsDouble();
                        }
                    }
                    else if (p.Definition.Name.Equals("Volume"))
                    {
                        if (p.HasValue)
                        {
                            assem.Volume = p.AsDouble();
                        }
                    }
                }
                //if(!assemblies.Contains(assem))
                assemblies.Add(assem);
            }
            return assemblies;
        }
예제 #5
0
        public List<Assembly> RetrieveRoofingInfo()
        {
            List<Assembly> assemblies = new List<Assembly>();
            ICollection<Element> roofing = getElementsOfCategory(doc, BuiltInCategory.OST_Roofs, typeof(RoofBase));

            foreach (Element e in roofing)
            {
                RoofBase roof = null;
                RoofType rType = null;
                roof = (RoofBase)e;
                Assembly assem = new Assembly();
                rType = roof.RoofType;

                Parameter assemName = rType.get_Parameter("Assembly Description");
                assem.AssemblyName = assemName.AsString();
                Parameter assemCode = rType.get_Parameter("Assembly Code");
                assem.AssemblyCode = assemCode.AsString();
                assem.Category = AssemblyUtil.GetCategoryFromCode(assem.AssemblyCode);
                //get all materials associated with this assembly
                List<AssemMaterial> mats = new List<AssemMaterial>();
                foreach (Material m in roof.Materials)
                {
                    AssemMaterial mat = new AssemMaterial();
                    mat.Name = m.Name;
                    mats.Add(mat);
                }
                assem.Materials = mats;

                //get area and volume for each assembly
                foreach (Parameter p in roof.Parameters)
                {
                    if (p.Definition.Name.Equals("Area"))
                    {
                        if (p.HasValue)
                        {
                            assem.Area = p.AsDouble();
                        }
                    }
                    else if (p.Definition.Name.Equals("Volume"))
                    {
                        if (p.HasValue)
                        {
                            assem.Volume = p.AsDouble();
                        }
                    }
                }
                //if(!assemblies.Contains(assem))
                assemblies.Add(assem);
            }
            return assemblies;
        }
예제 #6
0
 public List<Assembly> getComponentOptions(BuildingComponent bComp, int projID)
 {
     List<Assembly> assemblies = new List<Assembly>();
     using (OleDbConnection conn = this.getConnection())
     {
         conn.Open();
         using (OleDbCommand comm = conn.CreateCommand())
         {
             comm.CommandType = CommandType.Text;
             comm.CommandText = "SELECT AssemName, Description, AssemblyCode, Category FROM Assembly WHERE ID IN (SELECT AssemblyID from Comp_Assem WHERE ComponentID = (Select ID FROM BuildingComponent WHERE ComponentName = ? and ProjectID = ?));";
             comm.Parameters.AddWithValue("@name", bComp.Name);
             comm.Parameters.AddWithValue("@projID", projID);
             using (OleDbDataReader reader = comm.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     Assembly assem = new Assembly();
                     assem.AssemblyName = reader["AssemName"].ToString();
                     assem.Description = reader["Description"].ToString();
                     assem.AssemblyCode = reader["AssemblyCode"].ToString();
                     assem.Category = reader["Category"].ToString();
                     assemblies.Add(assem);
                 }
             }
             foreach (Assembly a in assemblies)
             {
                 a.Materials = getMaterialsByAssemblyName(a.AssemblyName);
             }
         }
         conn.Close();
     }
     return assemblies;
 }
예제 #7
0
        public void CalculateWallAssemblies(Type ty)
        {
            double totalVolume = 0.0;
            double totalArea = 0.0;

            //hold total volume for each assembly code
            assemblyVolumes = new Dictionary<Assembly, double>();
            assemblyAreas = new Dictionary<Assembly, double>();

            ICollection<Element> walls = getElementsOfCategory(doc, BuiltInCategory.OST_Walls, ty);
            foreach (Element e in walls)
            {
                Wall w = null;
                WallType wType = null;
                w = (Wall)e;
                Assembly assem = new Assembly();
                wType = w.WallType;
                if (wType.Kind == WallKind.Basic)
                {
                    //Write Assembly Name
                    Parameter assemName = wType.get_Parameter("Assembly Description");
                    assem.AssemblyName = assemName.AsString();

                    //Write Assembly Code
                    Parameter assemCode = wType.get_Parameter("Assembly Code");
                    assem.AssemblyCode = assemCode.AsString();
                    List<AssemMaterial> mats = new List<AssemMaterial>();
                    foreach (Material m in w.Materials)
                    {
                        AssemMaterial mat = new AssemMaterial();
                        mat.Name = m.Name;
                        mats.Add(mat);
                    }
                    assem.Materials = mats;
                    foreach (Parameter p in w.Parameters)
                    {
                        if (p.Definition.Name.Equals("Area"))
                        {
                            if (p.HasValue)
                            {

                                if (assemblyAreas.ContainsKey(assem))
                                {
                                    double area = assemblyAreas[assem];
                                    totalArea += area;
                                    assemblyAreas[assem] = area + p.AsDouble();
                                }
                                else
                                    assemblyAreas.Add(assem, p.AsDouble());
                            }
                        }
                        else if (p.Definition.Name.Equals("Volume"))
                        {
                            if (p.HasValue)
                            {
                                if (assemblyVolumes.ContainsKey(assem))
                                {
                                    double vol = assemblyVolumes[assem];
                                    totalVolume += vol;
                                    assemblyVolumes[assem] = vol + p.AsDouble();
                                }
                                else
                                    assemblyVolumes.Add(assem, p.AsDouble());
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
        public double getAssemblyCost(Assembly assem)
        {
            double cost = -1.0;
            using (OleDbConnection conn = this.getConnection())
            {
                conn.Open();
                using (OleDbCommand comm = conn.CreateCommand())
                {
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = "SELECT SUM(costperunit) as AssemblyCost " +
                                       "FROM Material WHERE id in " +
                                       "(select materialID from assem_mat where assemblyid = " +
                                       "(select id from Assembly where AssemName = ?));";
                    comm.Parameters.AddWithValue("@name", assem.AssemblyName);
                    Object obj = comm.ExecuteScalar();

                    if (!(obj is DBNull) && (obj != null))
                        cost = (double)obj;
                }
                conn.Close();
            }
            return cost;
        }
예제 #9
0
        public List<Assembly> getComponentAssemblies(BuildingComponent bComp)
        {
            List<Assembly> assemblies = new List<Assembly>();
            using (OleDbConnection conn = this.getConnection())
            {
                conn.Open();
                using (OleDbCommand comm = conn.CreateCommand())
                {
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = "SELECT AssemName, Description, AssemblyCode " +
                                       "FROM Assembly WHERE " +
                                       "id in (select AssemblyID from comp_assem where componentID = " +
                                       "(select id from BuildingComponent where ComponentName = ?));";
                    comm.Parameters.AddWithValue("@name", bComp.Name);

                    using (OleDbDataReader reader = comm.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Assembly a = new Assembly();
                            //Basic assembly information
                            a.AssemblyName = reader["AssemName"].ToString();
                            a.Description = reader["Description"].ToString();
                            a.AssemblyCode = reader["AssemblyCode"].ToString();
                            assemblies.Add(a);
                        }
                    }
                    foreach (Assembly a in assemblies)
                    {
                        a.Materials = getMaterialsByAssemblyName(a.AssemblyName);
                    }
                }
                conn.Close();
            }
            return assemblies;
        }
예제 #10
0
        public List<Assembly> getAssemblRangeByCategory(String category, int nRows, int group)
        {
            List<Assembly> assemblies = new List<Assembly>();
            using (OleDbConnection conn = this.getConnection())
            {
                conn.Open();
                using (OleDbCommand comm = conn.CreateCommand())
                {
                    int rowCount = -1;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = "Select count(*) FROM Assembly WHERE Category=?";
                    comm.Parameters.AddWithValue("@cat", category);

                    Object obj = comm.ExecuteScalar();
                    if (!(obj is DBNull) && (obj != null))
                        rowCount = (int)obj;

                    int grab = rowCount - ((group - 1) * nRows);
                    if (grab <= 0)
                        return assemblies;
                    comm.Parameters.Clear();
                    comm.CommandText = "Select TOP " + nRows + " * From (Select TOP " + grab +
                        " * From (Select ID, AssemName, Description, AssemblyCode FROM Assembly " +
                        "WHERE Category=?) Order By ID DESC) Order By ID ASC";
                    comm.Parameters.AddWithValue("@cat", category);

                    using (OleDbDataReader reader = comm.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Assembly a = new Assembly();
                            //Basic assembly information
                            a.AssemblyName = reader["AssemName"].ToString();
                            a.Description = reader["Description"].ToString();
                            a.AssemblyCode = reader["AssemblyCode"].ToString();
                            a.Category = category;
                            a.Materials = getMaterialsByAssemblyName(a.AssemblyName);
                            assemblies.Add(a);
                        }
                    }
                }
                conn.Close();
            }
            return assemblies;
        }
예제 #11
0
        public List<Assembly> getAssembliesByCode(String code)
        {
            List<Assembly> assemblies = new List<Assembly>();
            using (OleDbConnection conn = this.getConnection())
            {
                conn.Open();
                using (OleDbCommand comm = conn.CreateCommand())
                {
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = "Select AssemName, Description from Assembly Where AssemblyCode=?";
                    comm.Parameters.AddWithValue("@code", code);

                    using (OleDbDataReader reader = comm.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Assembly a = new Assembly();
                            //Basic assembly information
                            a.AssemblyName = reader["AssemName"].ToString();
                            a.Description = reader["Description"].ToString();
                            a.AssemblyCode = code;
                            a.Materials = getMaterialsByAssemblyName(a.AssemblyName);
                            assemblies.Add(a);
                        }
                    }
                }
                conn.Close();
            }
            return assemblies;
        }
예제 #12
0
        public List<Assembly> getAssembliesByCategory(String category, int max)
        {
            List<Assembly> assemblies = new List<Assembly>();
            using (OleDbConnection conn = this.getConnection())
            {
                conn.Open();
                using (OleDbCommand comm = conn.CreateCommand())
                {
                    comm.CommandType = CommandType.Text;
                    if (max < 0)
                        comm.CommandText = "Select AssemName, Description, AssemblyCode FROM Assembly WHERE Category=?";
                    else
                        comm.CommandText = "Select TOP " + max + " AssemName, Description, AssemblyCode FROM Assembly WHERE Category=?";
                    comm.Parameters.AddWithValue("@cat", category);

                    using (OleDbDataReader reader = comm.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Assembly a = new Assembly();
                            //Basic assembly information
                            a.AssemblyName = reader["AssemName"].ToString();
                            a.Description = reader["Description"].ToString();
                            a.AssemblyCode = reader["AssemblyCode"].ToString();
                            a.Category = category;
                            a.Materials = getMaterialsByAssemblyName(a.AssemblyName);
                            assemblies.Add(a);
                        }
                    }
                }
                conn.Close();
            }
            return assemblies;
        }
예제 #13
0
 private void FillData(Assembly assem)
 {
     lbMaterials.Items.Clear();
     txtCO2.Clear();
     txtTotalArea.Clear();
     txtTotalVolume.Clear();
     txtCost.Clear();
     txtCategory.Text = assem.Category;
     double cost = assem.CalculateCostPerUnit();
     txtAssemblyCost.Text = (cost > 0) ? String.Format("{0:C}", cost) : "Unknown";
     double CO2 = assem.CalculateCO2PerUnit();
     txtAssemblyCO2.Text = (CO2 > 0) ? CO2.ToString() : "Unknown";
     foreach (AssemMaterial m in assem.Materials)
         lbMaterials.Items.Add(m);
 }
예제 #14
0
        private Boolean Equals(Assembly that)
        {
            if (that == null)
                return false;

            return this.AssemblyName.Equals(that.AssemblyName) && this.AssemblyCode.Equals(that.AssemblyCode);
        }