示例#1
0
        public static Publisher AddPublisher(Publisher publisher)
        {
            string sql =
                "INSERT Publishers (Name)" +
                "VALUES (@Name)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Name", publisher.Name)
                };

                int newId = DBHelper.GetScalar(sql, para);
                return GetPublisherById(newId);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
示例#2
0
        public static Publisher GetPublisherById(int id)
        {
            string sql = "SELECT * FROM Publishers WHERE Id = @Id";

            try
            {
                SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Id", id));
                if (reader.Read())
                {
                    Publisher publisher = new Publisher();

                    publisher.Id = (int)reader["Id"];
                    publisher.Name = (string)reader["Name"];

                    reader.Close();

                    return publisher;
                }
                else
                {
                    reader.Close();
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
示例#3
0
 public static void DeletePublisher(Publisher publisher)
 {
     DeletePublisherById( publisher.Id );
 }
示例#4
0
        private static IList<Publisher> GetPublishersBySql( string sql, params SqlParameter[] values )
        {
            List<Publisher> list = new List<Publisher>();

            try
            {
                DataTable table = DBHelper.GetDataSet( sql, values );

                foreach (DataRow row in table.Rows)
                {
                    Publisher publisher = new Publisher();

                    publisher.Id = (int)row["Id"];
                    publisher.Name = (string)row["Name"];

                    list.Add(publisher);
                }

                return list;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
示例#5
0
        public static void ModifyPublisher(Publisher publisher)
        {
            string sql =
                "UPDATE Publishers " +
                "SET " +
                    "Name = @Name " +
                "WHERE Id = @Id";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Id", publisher.Id),
                    new SqlParameter("@Name", publisher.Name)
                };

                DBHelper.ExecuteCommand(sql, para);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
示例#6
0
 public static void ModifyPublisher(Publisher publisher)
 {
     PublisherService.ModifyPublisher(publisher);
 }
示例#7
0
 public static void DeletePublisher(Publisher publisher)
 {
     PublisherService.DeletePublisher(publisher);
 }
示例#8
0
 public static Publisher AddPublisher(Publisher publisher)
 {
     return PublisherService.AddPublisher(publisher);
 }