示例#1
0
 public string Delete(ContextDB db)
 {
     if (AuthorsID != 0)
     {
         Engine.cmd = new SqlCommand("delete Authors where AuthorsID=@id", Engine.con);
         Engine.con.Open();
         Engine.cmd.Parameters.AddWithValue("@id", AuthorsID);
         Engine.cmd.ExecuteNonQuery();
         Engine.con.Close();
         db.SaveChanges();
         Console.WriteLine(Utilities.Messages.OutputMessages.Successful);
     }
     return(Utilities.Messages.ExceptionMessages.IncorrectInputMessege);
 }
示例#2
0
 public string Create(ContextDB db)
 {
     if (AuthorsID != null && AuthorsName != string.Empty)
     {
         Engine.cmd = new SqlCommand($"insert into Authors(AuthorsID,AuthorsName) values(@id,@name)", Engine.con);
         Engine.con.Open();
         Engine.cmd.Parameters.AddWithValue("@id", AuthorsID);
         Engine.cmd.Parameters.AddWithValue("@name", AuthorsName);
         Engine.cmd.ExecuteNonQuery();
         Engine.con.Close();
         Console.WriteLine(Utilities.Messages.OutputMessages.Successful);
         db.SaveChanges();
     }
     return(Utilities.Messages.ExceptionMessages.IncorrectInputMessege);
 }
示例#3
0
 public string Update(ContextDB db)
 {
     if (GenresID != null && GenresName != string.Empty)
     {
         Engine.cmd = new SqlCommand("update Genres set GenresName=@name where GenresID=@id", Engine.con);
         Engine.con.Open();
         Engine.cmd.Parameters.AddWithValue("@id", GenresID);
         Engine.cmd.Parameters.AddWithValue("@name", GenresName);
         Engine.cmd.ExecuteNonQuery();
         Engine.con.Close();
         db.SaveChanges();
         Console.WriteLine(Utilities.Messages.OutputMessages.Successful);
     }
     return(Utilities.Messages.ExceptionMessages.IncorrectInputMessege);
 }
示例#4
0
 public string Create(ContextDB db)
 {
     if (BooksID != null && BooksName != string.Empty && BooksISBN != null && GenresID != null)
     {
         Engine.cmd = new SqlCommand($"insert into Books(BooksID,BooksName,BooksISBN,GenresID) values(@id,@name,@isbn, @genreId)", Engine.con);
         Engine.con.Open();
         Engine.cmd.Parameters.AddWithValue("@id", BooksID);
         Engine.cmd.Parameters.AddWithValue("@name", BooksName);
         Engine.cmd.Parameters.AddWithValue("@isbn", BooksISBN);
         Engine.cmd.Parameters.AddWithValue("@genreId", GenresID);
         Engine.cmd.ExecuteNonQuery();
         Engine.con.Close();
         db.SaveChanges();
         Console.WriteLine(Utilities.Messages.OutputMessages.Successful);
     }
     return(Utilities.Messages.ExceptionMessages.IncorrectInputMessege);
 }
示例#5
0
        public static void Read(ContextDB db)
        {
            Console.Clear();
            Engine.con.Open();
            DataTable dt    = new DataTable();
            var       adapt = new SqlDataAdapter("select * from Authors", Engine.con);

            adapt.Fill(dt);
            foreach (DataRow dataRow in dt.Rows)
            {
                foreach (var item in dataRow.ItemArray)
                {
                    Console.Write(item + "  ");
                }
                Console.WriteLine();
            }
            Engine.con.Close();
            db.SaveChanges();
            Console.WriteLine(Utilities.Messages.OutputMessages.Successful);
        }
示例#6
0
        public void Filter(ContextDB db)
        {
            Engine.con.Open();
            DataTable  dt      = new DataTable();
            SqlCommand command = new SqlCommand("Select * from Authors where AuthorsName=@name", Engine.con);

            command.Parameters.AddWithValue("@name", AuthorsName);
            SqlDataAdapter data = new SqlDataAdapter(command);

            data.Fill(dt);
            foreach (DataRow dataRow in dt.Rows)
            {
                foreach (var item in dataRow.ItemArray)
                {
                    Console.Write(item + "  ");
                }
                Console.WriteLine();
            }
            Engine.con.Close();
            db.SaveChanges();
            Console.WriteLine(Utilities.Messages.OutputMessages.Successful);
        }