Beispiel #1
0
        public static bool InsertProcessInfo(PTProcessInfo info, PTDate date)
        {
            bool            inserted        = false;
            SqlCeConnection connection      = null;
            int             noOfRowAffected = 0;

            try
            {
                connection = Connection();
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = "INSERT INTO ProcessInfos (Name, ActiveTime, DateIdx) VALUES (@name, @active, @dateIdx)";
                command.Parameters.Add("@name", SqlDbType.NVarChar).Value = info.name;
                command.Parameters.Add("@active", SqlDbType.Int).Value    = info.activeTime.TotalMinutes;
                command.Parameters.Add("@dateIdx", SqlDbType.Int).Value   = date.index;
                noOfRowAffected = command.ExecuteNonQuery();
                if (noOfRowAffected > 0)
                {
                    inserted = true;
                }
            }
            finally
            {
                connection.Close();
            }
            return(inserted);
        }
Beispiel #2
0
        public static bool DeleteProcessInfo(PTProcessInfo info, PTDate date)
        {
            bool            deleted         = false;
            SqlCeConnection connection      = null;
            int             noOfRowAffected = 0;

            try
            {
                connection = Connection();
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = "DELETE FROM ProcessInfos WHERE Name=@name AND DateIdx=@dateIdx";
                command.Parameters.Add("@name", SqlDbType.NVarChar).Value = info.name;
                command.Parameters.Add("@dateIdx", SqlDbType.Int).Value   = date.index;
                noOfRowAffected = command.ExecuteNonQuery();
                if (noOfRowAffected > 0)
                {
                    deleted = true;
                }
            }
            finally
            {
                connection.Close();
            }
            return(deleted);
        }
Beispiel #3
0
        public static PTProcessInfo GetInfoForProcessOnDate(string processName, PTDate date)
        {
            PTProcessInfo   info       = new PTProcessInfo(0, string.Empty, default(TimeSpan));
            SqlCeConnection connection = null;

            try
            {
                connection = Connection();
                connection.Open();
                var command = connection.CreateCommand();
                command.CommandText = "SELECT * FROM ProcessInfos WHERE Name=@name AND DateIdx=@dateIdx";
                command.Parameters.Add("@dateIdx", SqlDbType.Int).Value   = date.index;
                command.Parameters.Add("@name", SqlDbType.NVarChar).Value = processName;
                SqlCeDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    info.index      = reader.GetInt32(0);
                    info.name       = reader.GetString(1);
                    info.activeTime = new TimeSpan(0, reader.GetInt32(2), 0);
                }
            }
            finally
            {
                connection.Close();
            }
            return(info);
        }