Example #1
0
        public static void DeleteLocation(Location location)
        {
            using (SqlConnection conn = DbConfiguration.GetDBConnection())
            {
                conn.Open();
                var query = "DELETE FROM Locations where NAME = @name";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@name", location.Name);

                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException sqle)
                    {
                        Console.WriteLine("Delete Location thất bại");
                    }
                }
            }
        }
Example #2
0
        public static void UpdateLocation(Location location)
        {
            using (SqlConnection conn = DbConfiguration.GetDBConnection())
            {
                conn.Open();
                var query = "UPDATE Locations SET FULLPATH = @fullpath where NAME = @name";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@fullpath", location.Path);
                    cmd.Parameters.AddWithValue("@name", location.Name);

                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException sqle)
                    {
                        Console.WriteLine("Update Location thất bại");
                    }
                }
            }
        }
Example #3
0
 /**
  * Kiểm tra kết nối database
  */
 public static bool TestConnection()
 {
     using (SqlConnection conn = DbConfiguration.GetDBConnection())
     {
         try
         {
             conn.Open();
             Console.WriteLine("Kết nối database thành công");
             return(true);
         }
         catch (InvalidOperationException invalid)
         {
             Console.WriteLine("Kết nối database thất bại");
             return(false);
         }
         catch (SqlException sqle)
         {
             Console.WriteLine("Kết nối database thất bại");
             return(false);
         }
     }
 }
Example #4
0
        public static void SetLocation(Location location)
        {
            using (SqlConnection conn = DbConfiguration.GetDBConnection())
            {
                conn.Open();
                var query = "INSERT INTO Locations (NAME, FULLPATH) VALUES (@name, @fullpath)";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@name", location.Name);
                    cmd.Parameters.AddWithValue("@fullpath", location.Path);

                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException sqle)
                    {
                        Console.WriteLine("Thêm Location không thành công");
                    }
                }
            }
        }
Example #5
0
        public static void UpdateType(string type, bool isuse)
        {
            using (SqlConnection conn = DbConfiguration.GetDBConnection())
            {
                conn.Open();
                var query = "UPDATE FileType SET ISUSE = @isuse where TENTYPE = @tentype";
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@tentype", SqlDbType.VarChar);
                    cmd.Parameters.Add("@isuse", SqlDbType.Bit);

                    try
                    {
                        cmd.Parameters[0].Value = type;
                        cmd.Parameters[1].Value = isuse;
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException sqle)
                    {
                        Console.WriteLine("Update thất bại");
                    }
                }
            }
        }