using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Library
{
    class category
    {
        public int ID;
        public string Name;

        DataAccess da = new DataAccess();

        public void Add()
        {
            string sql = "Insert into category(catname)values(N'{0}')";
            sql = string.Format(sql, this.Name);
            da.connect();
            da.docommand(sql);
            da.Disconnect();
        }
        public void delete()
        {
            da.connect();
            string sql = "delete from category where catid={0}";
            sql = string.Format(sql, this.ID);
            da.docommand(sql);
            da.Disconnect();

        }

        public DataTable GetList()
        {
            DataTable dt = new DataTable();
            da.connect();
            dt = da.select("Select * from Category");
            da.Disconnect();
            return dt;
        }
        public void GetOne()
        {
            DataTable dt = new DataTable();
            da.connect();
            dt = da.select("Select * from Category Where catid="+this.ID);
            da.Disconnect();
            this.Name = dt.Rows[0]["catname"].ToString();
        }

        public void Update()
        {
            da.connect();
            string sql = "Update category Set catname=N'{0}' where catid={1}";
            sql = string.Format(sql, this.Name, this.ID);
            da.docommand(sql);
            da.Disconnect();
        }
    }
}
