Ejemplo n.º 1
0
        private void UpdateMaterialSettings()
        {
            selectedMaterial.CalculateTotals();

            txt_Name.Text        = selectedMaterial.Name;
            txt_Description.Text = selectedMaterial.Description;
            cbb_Category.Text    = selectedMaterial.Category;
            txt_Density.Text     = selectedMaterial.Density.ToString();
            txt_ECI.Text         = selectedMaterial.ECI.ToString();
            //txt_EEI.Text = selectedMaterial.EEI.ToString();

            txt_A1_A3.Text         = Math.Round(selectedMaterial.ECI_A1A3, 4).ToString();
            txt_A1_A3_Setting.Text = selectedMaterial.GetCarboProperty("ECI_A1A3_Settings").Value;

            txt_A4.Text         = Math.Round(selectedMaterial.ECI_A4, 4).ToString();
            txt_A4_Setting.Text = selectedMaterial.GetCarboProperty("ECI_A4_Settings").Value;

            txt_A5.Text         = Math.Round(selectedMaterial.ECI_A5, 4).ToString();
            txt_A5_Setting.Text = selectedMaterial.GetCarboProperty("ECI_A5_Settings").Value;

            txt_B1_B5.Text         = Math.Round(selectedMaterial.ECI_B1B5, 4).ToString();
            txt_B1_B5_Setting.Text = selectedMaterial.GetCarboProperty("ECI_B1B5_Settings").Value;

            txt_C1_C4.Text         = Math.Round(selectedMaterial.ECI_C1C4, 4).ToString();
            txt_C1_C4_Setting.Text = selectedMaterial.GetCarboProperty("ECI_C1C4_Settings").Value;

            txt_D.Text         = Math.Round(selectedMaterial.ECI_D, 4).ToString();
            txt_D_Setting.Text = selectedMaterial.GetCarboProperty("ECI_D_Settings").Value;

            string calc = "";

            calc  = "B1B5 x (A1-A3 + A4 + A5 + B1-B5 + C1C4 + ECI_D) = ECI Total" + Environment.NewLine;
            calc += Math.Round(Utils.ConvertMeToDouble(txt_B1_B5.Text), 2) +
                    " x (" + Math.Round(Utils.ConvertMeToDouble(txt_A1_A3.Text), 2) +
                    " + " + Math.Round(Utils.ConvertMeToDouble(txt_A4.Text), 2) +
                    " + " + Math.Round(Utils.ConvertMeToDouble(txt_A5.Text), 2) +
                    " + " + Math.Round(Utils.ConvertMeToDouble(txt_C1_C4.Text), 2) +
                    " + " + Math.Round(Utils.ConvertMeToDouble(txt_D.Text), 2) +
                    " ) = " + Math.Round(Utils.ConvertMeToDouble(txt_ECI.Text), 2);
            Calc.Content = calc;

            chk_Locked.IsChecked = selectedMaterial.isLocked;

            if (selectedMaterial.isLocked == true)
            {
                grd_Edit.Visibility = Visibility.Hidden;
            }
            else
            {
                grd_Edit.Visibility = Visibility.Visible;
            }
        }
Ejemplo n.º 2
0
        private CarboDatabase tryParseData(DataTable dt)
        {
            CarboDatabase result = new CarboDatabase();

            //List<String> fieldNameList = new List<string>();
            List <CarboMaterial> resultList = new List <CarboMaterial>();

            //Reach row is one element
            //Loop through datatab;e

            //int newIdNr = 10000;
            //int columncount = 0;

            PropertyInfo[]      propertyValues   = typeof(CarboMaterial).GetProperties();
            List <PropertyInfo> fullPropertyList = propertyValues.ToList();
            int propertyValuesCount = propertyValues.Length;

            foreach (DataRow dr in dt.Rows)
            {
                CarboMaterial       newMaterial  = new CarboMaterial();
                List <PropertyInfo> propertyList = new List <PropertyInfo>();
                foreach (PropertyInfo prInf in fullPropertyList)
                {
                    propertyList.Add(prInf);
                }
                //Set Id;
                //newMaterial.Id = newIdNr;
                //columncount = 0;
                bool valueisParameter = false;;

                foreach (DataColumn dc in dt.Columns)
                {
                    string ccolumnName   = dc.ColumnName.ToString().Trim();
                    string messageString = "";

                    for (int i = 0; i < propertyList.Count; i++)
                    {
                        PropertyInfo property     = propertyList[i];
                        string       propertyName = property.Name.ToString();

                        if (propertyName == ccolumnName)
                        {
                            string value = dr[dc].ToString();

                            //The column is a propery value, thus it need to be added as such
                            try
                            {
                                //Improved:

                                if (property.PropertyType == typeof(bool))
                                {
                                    int  parcedIntValue;
                                    bool isInt = false;

                                    isInt = int.TryParse(value, out parcedIntValue);

                                    if (isInt == false)
                                    {
                                        parcedIntValue = 0;
                                    }

                                    bool boolValue = Convert.ToBoolean(Convert.ToInt32(parcedIntValue));
                                    property.SetValue(newMaterial, boolValue);
                                }
                                else if (property.PropertyType == typeof(int))
                                {
                                    int  parcedIntValue;
                                    bool isInt = false;

                                    isInt = int.TryParse(value, out parcedIntValue);

                                    if (isInt == false)
                                    {
                                        parcedIntValue = 0;
                                    }

                                    //must be int
                                    property.SetValue(newMaterial, parcedIntValue);
                                }
                                else if (property.PropertyType == typeof(double))
                                {
                                    double parsedDoubleValue = 0;
                                    bool   isDouble          = false;

                                    isDouble = double.TryParse(value, out parsedDoubleValue);

                                    if (isDouble == false)
                                    {
                                        parsedDoubleValue = 0;
                                    }

                                    property.SetValue(newMaterial, parsedDoubleValue);
                                }
                                else if (property.PropertyType == typeof(string))
                                {
                                    if (value == null)
                                    {
                                        value = "";
                                    }

                                    property.SetValue(newMaterial, value);
                                }
                                else
                                {
                                    //Skip
                                }

                                //OLD

                                /*
                                 * if (isDouble == true)
                                 * {
                                 *  //Handle as number or bolean
                                 *
                                 *  if (property.PropertyType == typeof(bool))
                                 *  {
                                 *      bool boolValue = Convert.ToBoolean(Convert.ToInt32(value));
                                 *      property.SetValue(newMaterial, boolValue);
                                 *  }
                                 *  else
                                 *  {
                                 *      if (property.PropertyType == typeof(int))
                                 *      {
                                 *          //must be int
                                 *          property.SetValue(newMaterial, parcedIntValue);
                                 *      }
                                 *      else
                                 *      {
                                 *          //must be double
                                 *          //parsedDoubleValue = Math.Round(parsedDoubleValue, 2);
                                 *          property.SetValue(newMaterial, parsedDoubleValue);
                                 *      }
                                 *          //see if is int or double
                                 *  }
                                 * }
                                 * else
                                 * {
                                 *  //is string
                                 *  property.SetValue(newMaterial, value);
                                 * }
                                 */


                                //Value Successfully added
                                valueisParameter = false;

                                //removethePropertyFromlistToSpeedThingsUpNextRound;
                                propertyList.Remove(property);

                                //End the loop and go to next column
                                break;
                            }
                            catch (Exception ex)
                            {
                                messageString += value + " : " + ex.Message;
                            }
                        }
                        else
                        {
                            valueisParameter = true;
                        }
                    }

                    if (valueisParameter == true)
                    {
                        // If its not a property it will be added as a free parameter.

                        /*
                         * try
                         * {
                         *
                         *  CarboProperty newProperty = new CarboProperty();
                         *
                         *  string propertyValue = dr[dc].ToString();
                         *  string propertyName = ccolumnName;
                         *
                         *  newProperty.PropertyName = propertyName;
                         *  newProperty.Value = propertyValue;
                         *
                         *  if (ccolumnName.StartsWith("_"))
                         *  {
                         *      //This is a material
                         *      newProperty.PropertyName = propertyName.TrimStart('_');
                         *      newMaterial.Properties.Add(newProperty);
                         *  }
                         *  else
                         *  {
                         *      //This is a property
                         *      newMaterial.Properties.Add(newProperty);
                         *  }
                         * }
                         * catch (Exception ex)
                         * {
                         *  messageString += ex.Message;
                         * }
                         */
                    }

                    //columncount++;
                }
                newMaterial.CalculateTotals();
                resultList.Add(newMaterial);
                //lbl_Status.Text = newOption.Name;

                //lbl_Status.Refresh();
                //this.Refresh();
                //Next Id Nr:
                //newIdNr++;
            }
            //result.Floortype = -1;
            //result.FloorTypeName = txt_TypeName.Text;
            //result.FloorTypeDescription = txt_Description.Text;
            result.setData(resultList);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the details to the selected material
        /// </summary>
        private void UpdateMaterialSettings()
        {
            if (selectedMaterial != null)
            {
                selectedMaterial.CalculateTotals();

                txt_Name.Text        = selectedMaterial.Name;
                txt_Description.Text = selectedMaterial.Description;
                cbb_Category.Text    = selectedMaterial.Category;
                txt_Density.Text     = selectedMaterial.Density.ToString();
                txt_ECI.Text         = selectedMaterial.ECI.ToString();
                txt_EPDLink.Text     = selectedMaterial.EPDurl;

                chx_A4_Manual.IsChecked    = selectedMaterial.ECI_A4_Override;
                chx_A5_Manual.IsChecked    = selectedMaterial.ECI_A5_Override;
                chx_B1_B5_Manual.IsChecked = selectedMaterial.ECI_B1B5_Override;
                chx_C1_C4_Manual.IsChecked = selectedMaterial.ECI_C1C4_Override;
                chx_D_Manual.IsChecked     = selectedMaterial.ECI_D_Override;


                //Materials
                SetA1A3();
                //Construction
                SetA4();
                //Transport
                SetA5();
                //Transport
                SetB1B5();
                //End of Life
                SetC1C4();
                //End of Life
                SetD();
                //Mix
                SetMix();

                string calc = "";

                calc  = "B4 x (A1-A3 + A4 + A5 + B1-B7 + C1-C4 + D + Mix) = ECI Total" + Environment.NewLine;
                calc += Math.Round(Utils.ConvertMeToDouble(selectedMaterial.materialB1B5Properties.B4.ToString()), 4) +
                        " x (" + Math.Round(Utils.ConvertMeToDouble(txt_A1_A3.Text), 4) +
                        " + " + Math.Round(Utils.ConvertMeToDouble(txt_A4.Text), 4) +
                        " + " + Math.Round(Utils.ConvertMeToDouble(txt_A5.Text), 4) +
                        " + " + Math.Round(Utils.ConvertMeToDouble(txt_B1_B5.Text), 4) +
                        " + " + Math.Round(Utils.ConvertMeToDouble(txt_C1_C4.Text), 4) +
                        " + " + Math.Round(Utils.ConvertMeToDouble(txt_D.Text), 4) +
                        " + " + Math.Round(Utils.ConvertMeToDouble(txt_Mix.Text), 4) +
                        " ) = " + Math.Round(Utils.ConvertMeToDouble(txt_ECI.Text), 5);
                Calc.Content = calc;

                chk_Locked.IsChecked = selectedMaterial.isLocked;

                if (selectedMaterial.isLocked == true)
                {
                    grd_Edit.Visibility = Visibility.Hidden;
                }
                else
                {
                    grd_Edit.Visibility = Visibility.Visible;
                }
            }
        }