コード例 #1
0
        public DataObject.Unit Get(int Id)
        {
            DataObject.Unit dataObjectUnit = null;

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = "Exec [Schedule].[GetActiveUnit] {0}";

                using (SqlCommand command = new SqlCommand(string.Format(query, Id), connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            dataObjectUnit           = new DataObject.Unit();
                            dataObjectUnit.Id        = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Name      = reader.GetValue(1).ToString();
                            dataObjectUnit.Address   = reader.GetValue(2).ToString();
                            dataObjectUnit.DateAdded = Convert.ToDateTime(reader.GetValue(3).ToString());
                        }
                    }
                }
            }

            return(dataObjectUnit);
        }
コード例 #2
0
ファイル: Unit.cs プロジェクト: s9703830/SmartVillage
        public DataObject.Unit Get(int Id)
        {
            DataObject.Unit dataObjectUnit = null;

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = "Exec [Schedule].[GetActiveUnit] {0}";

                using (SqlCommand command = new SqlCommand(string.Format(query, Id), connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            dataObjectUnit = new DataObject.Unit();
                            dataObjectUnit.Id = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Name = reader.GetValue(1).ToString();
                            dataObjectUnit.Address = reader.GetValue(2).ToString();
                            dataObjectUnit.DateAdded = Convert.ToDateTime(reader.GetValue(3).ToString());
                        }
                    }
                }
            }

            return dataObjectUnit;
        }
コード例 #3
0
        public List <DataObject.Unit> ListConfigurationUnits()
        {
            List <DataObject.Unit> unitList = new List <DataObject.Unit>();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = "Exec [Schedule].[ListConfigurationUnit]";

                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            DataObject.Unit dataObjectUnit = new DataObject.Unit();
                            dataObjectUnit.Id = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Id_ScheduleUnit = 0;
                            dataObjectUnit.Name            = reader.GetValue(1).ToString();
                            dataObjectUnit.Address         = string.Empty;
                            dataObjectUnit.DateAdded       = DateTime.Now;

                            unitList.Add(dataObjectUnit);
                        }
                    }
                }
            }

            return(unitList);
        }
コード例 #4
0
        public List <DataObject.Unit> List(int Id_Schedule)
        {
            List <DataObject.Unit> unitList = new List <DataObject.Unit>();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = "Exec [Schedule].[ListActiveUnit] {0}";

                using (SqlCommand command = new SqlCommand(string.Format(query, Id_Schedule), connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            DataObject.Unit dataObjectUnit = new DataObject.Unit();
                            dataObjectUnit.Id = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Id_ScheduleUnit = int.Parse(reader.GetValue(1).ToString());
                            dataObjectUnit.Name            = reader.GetValue(2).ToString();
                            dataObjectUnit.Address         = reader.GetValue(3).ToString();
                            dataObjectUnit.DateAdded       = Convert.ToDateTime(reader.GetValue(4).ToString());
                            dataObjectUnit.IsActive        = Convert.ToBoolean(reader.GetValue(5).ToString());

                            unitList.Add(dataObjectUnit);
                        }
                    }
                }
            }

            return(unitList);
        }
コード例 #5
0
        public List <DataObject.Unit> ListWithZone(int Id_Schedule)
        {
            List <DataObject.Unit> unitList = new List <DataObject.Unit>();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = @"SELECT cfunit.Id, unit.Id as 'Id_ScheduleUnit', cfunit.Name, cfunit.[Address], 
                                        cfunit.DateAdded, cfunit.IsActive, cfunit.Id_Zone
	                            FROM [Schedule].[Unit] unit
	                            INNER JOIN [Configuration].[Unit] cfunit on cfunit.Id = unit.Id_Unit
	                            WHERE unit.Id_Schedule = {0}"    ;

                using (SqlCommand command = new SqlCommand(string.Format(query, Id_Schedule), connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            DataObject.Unit dataObjectUnit = new DataObject.Unit();
                            dataObjectUnit.Id = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Id_ScheduleUnit = int.Parse(reader.GetValue(1).ToString());
                            dataObjectUnit.Name            = reader.GetValue(2).ToString();
                            dataObjectUnit.Address         = reader.GetValue(3).ToString();
                            dataObjectUnit.DateAdded       = Convert.ToDateTime(reader.GetValue(4).ToString());
                            dataObjectUnit.IsActive        = Convert.ToBoolean(reader.GetValue(5).ToString());
                            dataObjectUnit.Id_Zone         = int.Parse(reader.GetValue(6).ToString());

                            unitList.Add(dataObjectUnit);
                        }
                    }
                }
            }

            return(unitList);
        }
コード例 #6
0
ファイル: Scheduling.cs プロジェクト: ttgzs/SmartVillage
        private void LoadShedUnit(List <lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort,
                                  lfa.pmgmt.data.DTO.Schedule.Unit unit, int status)
        {
            if (unit.IsActive)
            {
                string deviceAddress = string.Empty;

                SwitchbankUpdate mySwitchbankUpdate = null;

                BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

                for (int x = 0; x <= 7; x++)
                {
                    mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;
                }

                foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                {
                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    string deviceName     = unitDevice.Name;
                    int    deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                    deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                    string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                    bool switchOn = unitDevice.DeviceOn;

                    if (switchOn)
                    {
                        status = 1;
                    }
                    else
                    {
                        status = 2;
                    }

                    SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                }

                try
                {
                    mySwitchbankUpdate = new SwitchbankUpdate(
                        mySwitchStates[0],
                        mySwitchStates[1],
                        mySwitchStates[2],
                        mySwitchStates[3],
                        mySwitchStates[4],
                        mySwitchStates[5],
                        mySwitchStates[6],
                        mySwitchStates[7]);

                    SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch (System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(200);

                    try
                    {
                        mySwitchbankUpdate = new SwitchbankUpdate(
                            mySwitchStates[0],
                            mySwitchStates[1],
                            mySwitchStates[2],
                            mySwitchStates[3],
                            mySwitchStates[4],
                            mySwitchStates[5],
                            mySwitchStates[6],
                            mySwitchStates[7]);

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException ex)
                    {
                        lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                        logDAO.ConnectionString = _connectionString;
                        logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "ERR");
                    }
                }
            }
        }
コード例 #7
0
ファイル: Unit.cs プロジェクト: s9703830/SmartVillage
        public List<DataObject.Unit> List(int Id_Schedule)
        {
            List<DataObject.Unit> unitList = new List<DataObject.Unit>();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = "Exec [Schedule].[ListActiveUnit] {0}";

                using (SqlCommand command = new SqlCommand(string.Format(query, Id_Schedule), connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            DataObject.Unit dataObjectUnit = new DataObject.Unit();
                            dataObjectUnit.Id = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Id_ScheduleUnit = int.Parse(reader.GetValue(1).ToString());
                            dataObjectUnit.Name = reader.GetValue(2).ToString();
                            dataObjectUnit.Address = reader.GetValue(3).ToString();
                            dataObjectUnit.DateAdded = Convert.ToDateTime(reader.GetValue(4).ToString());
                            dataObjectUnit.IsActive = Convert.ToBoolean(reader.GetValue(5).ToString());

                            unitList.Add(dataObjectUnit);
                        }
                    }
                }
            }

            return unitList;
        }
コード例 #8
0
ファイル: Unit.cs プロジェクト: s9703830/SmartVillage
        public List<DataObject.Unit> ListWithZone(int Id_Schedule)
        {
            List<DataObject.Unit> unitList = new List<DataObject.Unit>();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = @"SELECT cfunit.Id, unit.Id as 'Id_ScheduleUnit', cfunit.Name, cfunit.[Address],
                                        cfunit.DateAdded, cfunit.IsActive, cfunit.Id_Zone
                                FROM [Schedule].[Unit] unit
                                INNER JOIN [Configuration].[Unit] cfunit on cfunit.Id = unit.Id_Unit
                                WHERE unit.Id_Schedule = {0}";

                using (SqlCommand command = new SqlCommand(string.Format(query, Id_Schedule), connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            DataObject.Unit dataObjectUnit = new DataObject.Unit();
                            dataObjectUnit.Id = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Id_ScheduleUnit = int.Parse(reader.GetValue(1).ToString());
                            dataObjectUnit.Name = reader.GetValue(2).ToString();
                            dataObjectUnit.Address = reader.GetValue(3).ToString();
                            dataObjectUnit.DateAdded = Convert.ToDateTime(reader.GetValue(4).ToString());
                            dataObjectUnit.IsActive = Convert.ToBoolean(reader.GetValue(5).ToString());
                            dataObjectUnit.Id_Zone = int.Parse(reader.GetValue(6).ToString());

                            unitList.Add(dataObjectUnit);
                        }
                    }
                }
            }

            return unitList;
        }
コード例 #9
0
ファイル: Unit.cs プロジェクト: s9703830/SmartVillage
        public List<DataObject.Unit> ListConfigurationUnits()
        {
            List<DataObject.Unit> unitList = new List<DataObject.Unit>();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string query = "Exec [Schedule].[ListConfigurationUnit]";

                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    SqlDataReader reader = command.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            DataObject.Unit dataObjectUnit = new DataObject.Unit();
                            dataObjectUnit.Id = int.Parse(reader.GetValue(0).ToString());
                            dataObjectUnit.Id_ScheduleUnit = 0;
                            dataObjectUnit.Name = reader.GetValue(1).ToString();
                            dataObjectUnit.Address = string.Empty;
                            dataObjectUnit.DateAdded = DateTime.Now;

                            unitList.Add(dataObjectUnit);
                        }
                    }
                }
            }

            return unitList;
        }
コード例 #10
0
        private void AsyncLoadShedUnit(object parameters)
        {
            try
            {
                ArrayList parms = parameters as ArrayList;

                List <lfa.pmgmt.data.DTO.Schedule.Device> unitDevices = parms[0] as List <lfa.pmgmt.data.DTO.Schedule.Device>;

                int defaultPort = (int)parms[1];

                lfa.pmgmt.data.DTO.Schedule.Unit unit = parms[2] as lfa.pmgmt.data.DTO.Schedule.Unit;

                int status = (int)parms[3];

                if (unit.IsActive)
                {
                    string deviceAddress = string.Empty;

                    SwitchbankUpdate mySwitchbankUpdate = null;

                    BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

                    for (int x = 0; x <= 7; x++)
                    {
                        mySwitchStates[x] = BravaCodes.SwitchState.NoChange;
                    }

                    foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                    {
                        lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                        deviceDAO.ConnectionString = _connectionString;

                        string deviceName     = unitDevice.Name;
                        int    deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                        deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                        string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                        //if (status == 0)
                        //{
                        bool switchOn = unitDevice.DeviceOn;

                        if (switchOn)
                        {
                            status = 1;
                        }
                        else
                        {
                            status = 2;
                        }
                        //}

                        SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                    }

                    mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                              mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                              mySwitchStates[6], mySwitchStates[7]);

                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 1", System.Diagnostics.EventLogEntryType.Warning);

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

                        try
                        {
                            mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                                      mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                                      mySwitchStates[6], mySwitchStates[7]);


                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 1", System.Diagnostics.EventLogEntryType.Warning);

                            SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        catch (System.Net.Sockets.SocketException soex)
                        {
                            lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                            logDAO.ConnectionString = _connectionString;
                            logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + soex.ToString(), DateTime.Now);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "ERR");
                        }
                    }
                }
                else
                {
                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 2", System.Diagnostics.EventLogEntryType.Warning);

                        SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

                        try
                        {
                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 2", System.Diagnostics.EventLogEntryType.Warning);

                            SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        catch (System.Net.Sockets.SocketException ex)
                        {
                            lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                            logDAO.ConnectionString = _connectionString;
                            logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "ERR");
                        }
                    }
                }
            }
            catch (Exception)
            {
                //File.AppendAllText(@"c:\smartpower\logerr.txt", er.ToString());
            }
        }
コード例 #11
0
        private void LoadShedUnit(List <lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort, lfa.pmgmt.data.DTO.Schedule.Unit unit)
        {
            int status = 0;

            foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
            {
                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;


                string deviceName     = unitDevice.Name;
                int    deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                string deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                string deviceSwitch  = deviceDAO.GetDeviceSwitch(deviceConfigId);

                bool switchOn = unitDevice.DeviceOn;

                if (switchOn)
                {
                    status = 1;
                }
                else
                {
                    status = 2;
                }

                SendSwitchState(deviceAddress, defaultPort, deviceSwitch, status);
            }
        }