Ejemplo n.º 1
0
        private void BindRuleData()
        {
            dataGridView1.DataSource = null;

            lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
            ruleDAO.ConnectionString = _connectionString;

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

            rules = ruleDAO.List(_ruleId);

            dataGridView1.Rows.Clear();
            dataGridView1.DataSource = null;

            dataGridView1.DataSource = rules;

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

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

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

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

                lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string unitName   = unitDAO.GetName(unitId);
                string deviceName = deviceDAO.GetDeviceName(deviceId);

                row.Cells[1].Value = "If " + unitName + " load is " + comparer + " " + value + " Then";
                row.Cells[2].Value = "Switch " + deviceName + " " + deviceOnOff;
            }

            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 150;
        }
Ejemplo n.º 2
0
        private void BindRuleData()
        {
            dataGridView1.DataSource = null;

            lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
            ruleDAO.ConnectionString = _connectionString;

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

            dataGridView1.Rows.Clear();
            dataGridView1.DataSource = null;

            dataGridView1.DataSource = rules;

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

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

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

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

                lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string unitName = unitDAO.GetName(unitId);
                string deviceName = deviceDAO.GetDeviceName(deviceId);

                row.Cells[1].Value = "If " + unitName + " load is " + comparer + " " + value + " Then";
                row.Cells[2].Value = "Switch " + deviceName + " " + deviceOnOff;
            }

            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 150;
        }
Ejemplo n.º 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                DataGridViewRow selectedRow    = dataGridView1.SelectedRows[0];
                int             selectedItemId = int.Parse(selectedRow.Cells[0].Value.ToString());

                lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                ruleDAO.ConnectionString = _connectionString;
                ruleDAO.Delete(selectedItemId);

                HandleInformationMesssage("Rule successfully deleted!");

                BindRuleData();
            }
            else
            {
                Exception ex = new Exception("No rule selected to delete!");
                HandleException(ex);
            }
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
                int selectedItemId = int.Parse(selectedRow.Cells[0].Value.ToString());

                lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
                ruleDAO.ConnectionString = _connectionString;
                ruleDAO.Delete(selectedItemId);

                HandleInformationMesssage("Rule successfully deleted!");

                BindRuleData();
            }
            else
            {
                Exception ex = new Exception("No rule selected to delete!");
                HandleException(ex);
            }
        }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            int status = 2;

            ComboItem zone   = comboBox1.SelectedItem as ComboItem;
            ComboItem unit   = comboBox2.SelectedItem as ComboItem;
            ComboItem device = comboBox3.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 = unit.Id + "." + device.Id + "." + comparer + "." + textBox1.Text;

            string result = unit.Id + "." + device.Id + "." + status.ToString();

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

            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 = result.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.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string unitName   = unitDAO.GetName(unitId);
                string deviceName = deviceDAO.GetDeviceName(deviceId);

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

            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 150;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            int status = 2;

            ComboItem zone = comboBox1.SelectedItem as ComboItem;
            ComboItem unit = comboBox2.SelectedItem as ComboItem;
            ComboItem device = comboBox3.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 = unit.Id + "." + device.Id + "." + comparer + "." + textBox1.Text;

            string result = unit.Id + "." + device.Id + "." + status.ToString();

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

            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 = result.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.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string unitName = unitDAO.GetName(unitId);
                string deviceName = deviceDAO.GetDeviceName(deviceId);

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

            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 150;
        }