예제 #1
0
        public void AddDevice(Device d)
        {
            string cmd = "INSERT INTO " + TABLE_NAME + " (" +
                         COLUMN_DEVICE_ID + ", " +
                         COLUMN_LASTUPDATE + ", " +
                         COLUMN_DEVICE_TYPE + ", " +
                         COLUMN_PARENT_ID + ") VALUES (" +
                         PARAM_DEVICE_ID + ", " +
                         PARAM_LASTUPDATE + ", " +
                         PARAM_DEVICE_TYPE + ", " +
                         PARAM_PARENT_ID + ")";

            using (DbConnection conn = di.getDbConnection(Config.Instance.ConnectString))
            {
                try
                {
                    DbCommand comm = di.getDbCommand(cmd);
                    comm.Parameters.Add(Utility.GetDbParameter(comm, PARAM_DEVICE_ID, DbType.String, 16, d.DeviceID, ParameterDirection.Input));
                    comm.Parameters.Add(Utility.GetDbParameter(comm, PARAM_LASTUPDATE, DbType.String, 16, d.LastUpdate, ParameterDirection.Input));
                    comm.Parameters.Add(Utility.GetDbParameter(comm, PARAM_DEVICE_TYPE, DbType.Int32, 4, d.DeviceType, ParameterDirection.Input));
                    comm.Parameters.Add(Utility.GetDbParameter(comm, PARAM_PARENT_ID, DbType.String, 16, d.ParentId, ParameterDirection.Input));

                    comm.Connection = conn;
                    conn.Open();
                    comm.ExecuteNonQuery();
                }
                finally
                {
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
            }
        }
예제 #2
0
        public void UpdateDeviceSwitch(Device_Switch ds)
        {
            string cmd = "UPDATE " + TABLE_NAME + " SET " +
                         COLUMN_DEVICE_ID + "=" + PARAM_DEVICE_ID + "," +
                         COLUMN_ON_OFF_CONFIG + "=" + PARAM_ON_OFF_CONFIG + " WHERE " +
                         COLUMN_DEVICE_ID + "=" + PARAM_DEVICE_ID;// DT SET deviceid=@DeviceId, lastupdate=@LastUpdate Where deviceid=@DeviceId";

            using (DbConnection conn = di.getDbConnection(Config.Instance.ConnectString))
            {
                try
                {
                    DbCommand comm = di.getDbCommand(cmd);
                    comm.Parameters.Add(Utility.GetDbParameter(comm, PARAM_DEVICE_ID, DbType.String, 16, ds.DeviceID, ParameterDirection.Input));
                    comm.Parameters.Add(Utility.GetDbParameter(comm, PARAM_ON_OFF_CONFIG, DbType.String, 60, ds.OnOffConfig, ParameterDirection.Input));

                    comm.Connection = conn;
                    conn.Open();
                    comm.ExecuteNonQuery();
                }
                finally
                {
                    if (conn != null)
                    {
                        conn.Close();
                    }
                }
            }
        }