Example #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtZoneName.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a new device name!");
                HandleException(ex);
            }
            else if (string.IsNullOrEmpty(textBox1.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a new version!");
                HandleException(ex);
            }
            else
            {
                try
                {
                    lfa.pmgmt.data.DAO.BusinessRule.RuleSet DAO = new data.DAO.BusinessRule.RuleSet();
                    DAO.ConnectionString = _connectionString;
                    DAO.Insert(txtZoneName.Text, textBox1.Text, DateTime.Now);

                    HandleInformationMesssage("Data successfully saved! Please refresh the form data!");

                    this.Close();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
Example #2
0
        private void BindLoadShedRules()
        {
            lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
            ruleSetDAO.ConnectionString = _connectionString;

            List <lfa.pmgmt.data.DTO.BusinessRule.RuleSet> ruleSets = ruleSetDAO.List();

            grdMain.DataSource = ruleSets;

            btnGrdMainHeader.Text     = "Rulesets";
            btnGrdChildOneHeader.Text = string.Empty;
            btnGrdChildTwoHeader.Text = string.Empty;
        }
Example #3
0
        private void DeleteRuleset()
        {
            int selectedId = 0;

            foreach (DataGridViewRow dataRow in grdMain.Rows)
            {
                if (dataRow.Selected)
                {
                    selectedId = int.Parse(dataRow.Cells[0].Value.ToString());

                    lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
                    ruleSetDAO.ConnectionString = _connectionString;

                    ruleSetDAO.Delete(selectedId);

                    HandleInformationMesssage("Data successfully deleted! Please refresh the data!");
                }
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            int status = 2;

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a load value!");
                HandleException(ex);
            }
            else
            {
                ComboItem zone = comboBox1.SelectedItem as ComboItem;

                string comparer = comboBox4.SelectedItem.ToString();
                string deviceOnOff = comboBox5.SelectedItem.ToString();

                switch (comparer)
                {
                    case "Smaller Then Equal":
                        comparer = "<";
                        break;
                    case "Bigger Then Equal":
                        comparer = ">=";
                        break;
                    case "Smaller Then":
                        comparer = "<";
                        break;
                    case "Bigger Then":
                        comparer = ">";
                        break;
                    case "Equal":
                        comparer = "==";
                        break;
                }

                if (deviceOnOff == "Switch On")
                {
                    status = 1;
                }

                string condition = zone.Id + ".1." + comparer + "." + textBox1.Text;

                string result = zone.Id + ".1." + status.ToString();

                lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                ruleDAO.ConnectionString = _connectionString;
                ruleDAO.Insert(_ruleId, condition, result);

                int ruleId = ruleDAO.GetLastInsertedRuleId();

                //if (!comboBox2.SelectedItem.ToString().ToLower().Equals("none"))
                //{
                    lfa.pmgmt.data.DAO.BusinessRule.RuleSet rulesetDAO = new data.DAO.BusinessRule.RuleSet();
                    rulesetDAO.ConnectionString = _connectionString;
                    rulesetDAO.InsertPriority(_ruleId, ruleId, comboBox2.SelectedItem.ToString());
                //}

                List<lfa.pmgmt.data.DTO.BusinessRule.Rule> rules = new List<data.DTO.BusinessRule.Rule>();
                rules = ruleDAO.List(_ruleId);

                dataGridView1.DataSource = null;

                dataGridView1.DataSource = rules;

                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    string sdeviceOnOff = "Off";
                    string rule = row.Cells[1].Value.ToString();
                    string sresult = row.Cells[2].Value.ToString();

                    string[] ruleArray = rule.Split(".".ToCharArray());
                    int unitId = int.Parse(ruleArray[0].ToString());
                    string scomparer = ruleArray[2].ToString();
                    string value = ruleArray[3].ToString();

                    string[] resultArray = sresult.Split(".".ToCharArray());
                    int deviceId = int.Parse(resultArray[1].ToString());
                    int sstatus = int.Parse(resultArray[2].ToString());

                    if (sstatus == 1)
                    {
                        sdeviceOnOff = "On";
                    }

                    lfa.pmgmt.data.DAO.Configuration.Zone zoneDAO = new data.DAO.Configuration.Zone();
                    zoneDAO.ConnectionString = _connectionString;

                    lfa.pmgmt.data.DTO.Configuration.Zone zoneItem = zoneDAO.Get(unitId);

                    string zoneName = zoneItem.Name;

                    row.Cells[1].Value = "If " + zoneName + " load is " + scomparer + " " + value + " Then";
                    row.Cells[2].Value = "Switch " + sdeviceOnOff;
                }

                dataGridView1.Columns[1].Width = 180;
                dataGridView1.Columns[2].Width = 150;
            }
        }
Example #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            int status = 2;

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a load value!");
                HandleException(ex);
            }
            else
            {
                ComboItem zone = comboBox1.SelectedItem as ComboItem;

                string comparer    = comboBox4.SelectedItem.ToString();
                string deviceOnOff = comboBox5.SelectedItem.ToString();

                switch (comparer)
                {
                case "Smaller Then Equal":
                    comparer = "<";
                    break;

                case "Bigger Then Equal":
                    comparer = ">=";
                    break;

                case "Smaller Then":
                    comparer = "<";
                    break;

                case "Bigger Then":
                    comparer = ">";
                    break;

                case "Equal":
                    comparer = "==";
                    break;
                }

                if (deviceOnOff == "Switch On")
                {
                    status = 1;
                }

                string condition = zone.Id + ".1." + comparer + "." + textBox1.Text;

                string result = zone.Id + ".1." + status.ToString();

                lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                ruleDAO.ConnectionString = _connectionString;
                ruleDAO.Insert(_ruleId, condition, result);

                int ruleId = ruleDAO.GetLastInsertedRuleId();

                //if (!comboBox2.SelectedItem.ToString().ToLower().Equals("none"))
                //{
                lfa.pmgmt.data.DAO.BusinessRule.RuleSet rulesetDAO = new data.DAO.BusinessRule.RuleSet();
                rulesetDAO.ConnectionString = _connectionString;
                rulesetDAO.InsertPriority(_ruleId, ruleId, comboBox2.SelectedItem.ToString());
                //}

                List <lfa.pmgmt.data.DTO.BusinessRule.Rule> rules = new List <data.DTO.BusinessRule.Rule>();
                rules = ruleDAO.List(_ruleId);

                dataGridView1.DataSource = null;

                dataGridView1.DataSource = rules;

                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    string sdeviceOnOff = "Off";
                    string rule         = row.Cells[1].Value.ToString();
                    string sresult      = row.Cells[2].Value.ToString();

                    string[] ruleArray = rule.Split(".".ToCharArray());
                    int      unitId    = int.Parse(ruleArray[0].ToString());
                    string   scomparer = ruleArray[2].ToString();
                    string   value     = ruleArray[3].ToString();

                    string[] resultArray = sresult.Split(".".ToCharArray());
                    int      deviceId    = int.Parse(resultArray[1].ToString());
                    int      sstatus     = int.Parse(resultArray[2].ToString());

                    if (sstatus == 1)
                    {
                        sdeviceOnOff = "On";
                    }

                    lfa.pmgmt.data.DAO.Configuration.Zone zoneDAO = new data.DAO.Configuration.Zone();
                    zoneDAO.ConnectionString = _connectionString;

                    lfa.pmgmt.data.DTO.Configuration.Zone zoneItem = zoneDAO.Get(unitId);

                    string zoneName = zoneItem.Name;

                    row.Cells[1].Value = "If " + zoneName + " load is " + scomparer + " " + value + " Then";
                    row.Cells[2].Value = "Switch " + sdeviceOnOff;
                }

                dataGridView1.Columns[1].Width = 180;
                dataGridView1.Columns[2].Width = 150;
            }
        }
Example #6
0
        private static bool ExecutePriority(string connectionString, string priorityValue, out int status, out int ruleCount)
        {
            int  tempStatus  = 0;
            bool executeRule = false;

            List <lfa.pmgmt.data.DTO.BusinessRule.Load> loadList = new List <data.DTO.BusinessRule.Load>();

            lfa.pmgmt.data.DAO.BusinessRule.Load loadDAO = new data.DAO.BusinessRule.Load();
            loadDAO.ConnectionString = connectionString;

            loadList = loadDAO.List();

            int currentUnitLoad = 0;

            if (loadList[0].ManualLoad > 0)
            {
                currentUnitLoad = loadList[0].ManualLoad;
            }
            else
            {
                currentUnitLoad = loadList[0].CurrentLoad;
            }

            lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
            ruleSetDAO.ConnectionString = connectionString;

            List <lfa.pmgmt.data.DTO.BusinessRule.Priority> priorityRules = ruleSetDAO.ListPriority(priorityValue);

            int tmpRuleCount = 0;

            foreach (lfa.pmgmt.data.DTO.BusinessRule.Priority priorityRule in priorityRules)
            {
                if (priorityRule.PriorityType.ToLower().Equals(priorityValue.ToLower()))
                {
                    lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                    ruleDAO.ConnectionString = connectionString;

                    List <lfa.pmgmt.data.DTO.BusinessRule.Rule> ruleDTOList = ruleDAO.GetFromRuleSet(priorityRule.Id_RuleSet);

                    tmpRuleCount = ruleDTOList.Count;

                    foreach (lfa.pmgmt.data.DTO.BusinessRule.Rule ruleDTO in ruleDTOList)
                    {
                        if (executeRule)
                        {
                            break;
                        }

                        string[] ruleArray  = ruleDTO.Condition.Split(".".ToCharArray());
                        int      unitId     = int.Parse(ruleArray[0].ToString());
                        int      deviceId   = int.Parse(ruleArray[1].ToString());
                        string   mathMetric = ruleArray[2].ToString();
                        int      loadValue  = int.Parse(ruleArray[3].ToString());

                        string[] resultArray = ruleDTO.Result.Split(".".ToCharArray());
                        tempStatus = int.Parse(resultArray[2].ToString());

                        switch (mathMetric)
                        {
                        case "<=":
                            executeRule = CurrentLoadSmallerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                            break;

                        case ">=":
                            executeRule = CurrentLoadBiggerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                            break;

                        case "<":
                            executeRule = CurrentLoadSmallerThenValue(executeRule, loadValue, currentUnitLoad);
                            break;

                        case ">":
                            executeRule = CurrentLoadBiggerThenValue(executeRule, loadValue, currentUnitLoad);
                            break;

                        case "==":
                            executeRule = CurrentLoadEqualsValue(executeRule, loadValue, currentUnitLoad);
                            break;
                        }
                    }

                    if (executeRule)
                    {
                        break;
                    }
                }

                if (executeRule)
                {
                    break;
                }
            }

            status    = tempStatus;
            ruleCount = tmpRuleCount;

            return(executeRule);
        }
Example #7
0
        private void DeleteRuleset()
        {
            int selectedId = 0;

            foreach (DataGridViewRow dataRow in grdMain.Rows)
            {
                if (dataRow.Selected)
                {
                    selectedId = int.Parse(dataRow.Cells[0].Value.ToString());

                    lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
                    ruleSetDAO.ConnectionString = _connectionString;

                    ruleSetDAO.Delete(selectedId);

                    HandleInformationMesssage("Data successfully deleted! Please refresh the data!");
                }
            }
        }
Example #8
0
        private void BindLoadShedRules()
        {
            lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
            ruleSetDAO.ConnectionString = _connectionString;

            List<lfa.pmgmt.data.DTO.BusinessRule.RuleSet> ruleSets = ruleSetDAO.List();

            grdMain.DataSource = ruleSets;

            btnGrdMainHeader.Text = "Rulesets";
            btnGrdChildOneHeader.Text = string.Empty;
            btnGrdChildTwoHeader.Text = string.Empty;
        }
Example #9
0
        private static bool ExecutePriority(string connectionString, string priorityValue)
        {
            bool executeRule = false;

            List <lfa.pmgmt.data.DTO.BusinessRule.Load> loadList = new List <data.DTO.BusinessRule.Load>();

            lfa.pmgmt.data.DAO.BusinessRule.Load loadDAO = new data.DAO.BusinessRule.Load();
            loadDAO.ConnectionString = connectionString;

            loadList = loadDAO.List();

            int currentUnitLoad = loadList[0].CurrentLoad;

            lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
            ruleSetDAO.ConnectionString = connectionString;

            List <lfa.pmgmt.data.DTO.BusinessRule.Priority> priorityRules = ruleSetDAO.ListPriority();

            foreach (lfa.pmgmt.data.DTO.BusinessRule.Priority priorityRule in priorityRules)
            {
                if (priorityRule.PriorityType.ToLower().Equals(priorityValue.ToLower()))
                {
                    lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                    ruleDAO.ConnectionString = connectionString;

                    lfa.pmgmt.data.DTO.BusinessRule.Rule ruleDTO = ruleDAO.GetFromRuleSet(priorityRule.Id_RuleSet);

                    string[] ruleArray  = ruleDTO.Condition.Split(".".ToCharArray());
                    int      unitId     = int.Parse(ruleArray[0].ToString());
                    int      deviceId   = int.Parse(ruleArray[1].ToString());
                    string   mathMetric = ruleArray[2].ToString();
                    int      loadValue  = int.Parse(ruleArray[3].ToString());

                    switch (mathMetric)
                    {
                    case "<=":
                        executeRule = CurrentLoadSmallerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                        break;

                    case ">=":
                        executeRule = CurrentLoadBiggerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                        break;

                    case "<":
                        executeRule = CurrentLoadSmallerThenValue(executeRule, loadValue, currentUnitLoad);
                        break;

                    case ">":
                        executeRule = CurrentLoadBiggerThenValue(executeRule, loadValue, currentUnitLoad);
                        break;

                    case "==":
                        executeRule = CurrentLoadEqualsValue(executeRule, loadValue, currentUnitLoad);
                        break;
                    }
                }
            }

            #region OBSOLETE
            //int currentUnitLoad = loadList[0].CurrentLoad;
            //int maxLoad = loadList[0].MaximumLoad;

            //if (currentUnitLoad >= maxLoad)
            //{
            //    executePriority = true;
            //}
            #endregion

            return(executeRule);
        }
Example #10
0
        private static bool ExecutePriority(string connectionString, string priorityValue, out int status, out int ruleCount)
        {
            int tempStatus = 0;
            bool executeRule = false;

            List<lfa.pmgmt.data.DTO.BusinessRule.Load> loadList = new List<data.DTO.BusinessRule.Load>();

            lfa.pmgmt.data.DAO.BusinessRule.Load loadDAO = new data.DAO.BusinessRule.Load();
            loadDAO.ConnectionString = connectionString;

            loadList = loadDAO.List();

            int currentUnitLoad = 0;

            if (loadList[0].ManualLoad > 0)
            {
                currentUnitLoad = loadList[0].ManualLoad;
            }
            else
            {
                currentUnitLoad = loadList[0].CurrentLoad;
            }

            //System.Diagnostics.EventLog.WriteEntry("BUGGER", currentUnitLoad.ToString(), System.Diagnostics.EventLogEntryType.Warning);

            lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
            ruleSetDAO.ConnectionString = connectionString;

            List<lfa.pmgmt.data.DTO.BusinessRule.Priority> priorityRules = ruleSetDAO.ListPriority(priorityValue);

            int tmpRuleCount = 0;

            foreach (lfa.pmgmt.data.DTO.BusinessRule.Priority priorityRule in priorityRules)
            {
                if (priorityRule.PriorityType.ToLower().Equals(priorityValue.ToLower()))
                {
                    lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                    ruleDAO.ConnectionString = connectionString;

                    List<lfa.pmgmt.data.DTO.BusinessRule.Rule> ruleDTOList = ruleDAO.GetFromRuleSet(priorityRule.Id_RuleSet);

                    tmpRuleCount = ruleDTOList.Count;

                    foreach (lfa.pmgmt.data.DTO.BusinessRule.Rule ruleDTO in ruleDTOList)
                    {
                        if (executeRule)
                        {
                            break;
                        }

                        string[] ruleArray = ruleDTO.Condition.Split(".".ToCharArray());
                        int unitId = int.Parse(ruleArray[0].ToString());
                        int deviceId = int.Parse(ruleArray[1].ToString());
                        string mathMetric = ruleArray[2].ToString();
                        int loadValue = int.Parse(ruleArray[3].ToString());

                        string[] resultArray = ruleDTO.Result.Split(".".ToCharArray());
                        tempStatus = int.Parse(resultArray[2].ToString());

                        switch (mathMetric)
                        {
                            case "<=":
                                executeRule = CurrentLoadSmallerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                                break;
                            case ">=":
                                executeRule = CurrentLoadBiggerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                                break;
                            case "<":
                                executeRule = CurrentLoadSmallerThenValue(executeRule, loadValue, currentUnitLoad);
                                break;
                            case ">":
                                executeRule = CurrentLoadBiggerThenValue(executeRule, loadValue, currentUnitLoad);
                                break;
                            case "==":
                                executeRule = CurrentLoadEqualsValue(executeRule, loadValue, currentUnitLoad);
                                break;
                        }

                    }

                    if (executeRule)
                    {
                        break;
                    }
                }

                if (executeRule)
                {
                    break;
                }
            }

            status = tempStatus;
            ruleCount = tmpRuleCount;

            return executeRule;
        }
Example #11
0
        private static bool ExecutePriority(string connectionString, string priorityValue)
        {
            bool executeRule = false;

            List<lfa.pmgmt.data.DTO.BusinessRule.Load> loadList = new List<data.DTO.BusinessRule.Load>();

            lfa.pmgmt.data.DAO.BusinessRule.Load loadDAO = new data.DAO.BusinessRule.Load();
            loadDAO.ConnectionString = connectionString;

            loadList = loadDAO.List();

            int currentUnitLoad = loadList[0].CurrentLoad;

            lfa.pmgmt.data.DAO.BusinessRule.RuleSet ruleSetDAO = new data.DAO.BusinessRule.RuleSet();
            ruleSetDAO.ConnectionString = connectionString;

            List<lfa.pmgmt.data.DTO.BusinessRule.Priority> priorityRules = ruleSetDAO.ListPriority();

            foreach (lfa.pmgmt.data.DTO.BusinessRule.Priority priorityRule in priorityRules)
            {
                if(priorityRule.PriorityType.ToLower().Equals(priorityValue.ToLower()))
                {
                    lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                    ruleDAO.ConnectionString = connectionString;

                    lfa.pmgmt.data.DTO.BusinessRule.Rule ruleDTO = ruleDAO.GetFromRuleSet(priorityRule.Id_RuleSet);

                    string[] ruleArray = ruleDTO.Condition.Split(".".ToCharArray());
                    int unitId = int.Parse(ruleArray[0].ToString());
                    int deviceId = int.Parse(ruleArray[1].ToString());
                    string mathMetric = ruleArray[2].ToString();
                    int loadValue = int.Parse(ruleArray[3].ToString());

                    switch (mathMetric)
                    {
                        case "<=":
                            executeRule = CurrentLoadSmallerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                            break;
                        case ">=":
                            executeRule = CurrentLoadBiggerThenEqualsValue(executeRule, loadValue, currentUnitLoad);
                            break;
                        case "<":
                            executeRule = CurrentLoadSmallerThenValue(executeRule, loadValue, currentUnitLoad);
                            break;
                        case ">":
                            executeRule = CurrentLoadBiggerThenValue(executeRule, loadValue, currentUnitLoad);
                            break;
                        case "==":
                            executeRule = CurrentLoadEqualsValue(executeRule, loadValue, currentUnitLoad);
                            break;
                    }
                }
            }

            #region OBSOLETE
            //int currentUnitLoad = loadList[0].CurrentLoad;
            //int maxLoad = loadList[0].MaximumLoad;

            //if (currentUnitLoad >= maxLoad)
            //{
            //    executePriority = true;
            //}
            #endregion

            return executeRule;
        }