Ejemplo n.º 1
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            Globals.ThisAddIn.fromCO2Emission = false;
            bool itemSelected = true;

            //Check whether all the energy sources have the CO2 emission factor and check whether all the factors are valid numbers
            Globals.ThisAddIn.CO2EmissionFactors = new Dictionary <string, string>();
            foreach (object obj in parentCheckListBox.CheckedItems)
            {
                Control[] collection = this.Controls.Find(STR_TXT_CO2EMISSION_PREFIX + obj.ToString(), true);
                if (collection.Length > 0)
                {
                    TextBox txtBox = collection[0] as TextBox;
                    if (txtBox != null)
                    {
                        if (ValidateTextBox(txtBox) == 0)
                        {
                            Globals.ThisAddIn.CO2EmissionFactors.Add(new KeyValuePair <string, string>(obj.ToString(), txtBox.Text));
                        }
                        else
                        {
                            itemSelected = false;
                        }
                    }
                }
            }


            if (parentCheckListBox.CheckedItems.Count == Globals.ThisAddIn.CO2EmissionFactors.Count)
            {
                Globals.ThisAddIn.fromCO2Emission = true;
            }
            if (itemSelected == true)
            {
                parentControl.runFunction(null, null);
            }
            else
            {
                if (Globals.ThisAddIn.CO2EmissionFactors.Count > 0)
                {
                    MessageBox.Show("Please enter a valid number");
                }
                else
                {
                    parentControl.runFunction(null, null);
                }
            }
        }