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

namespace DAL
{
    public sealed class KalaMethods:Method
    {
        public bool Insert(string kalaid, string kalaname, string price,string groupname,string vahed)
        {
            SqlParameter[] p = new SqlParameter[5];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@kalaid";
            p[0].SqlDbType = System.Data.SqlDbType.NChar;
            p[0].Value = kalaid;
            //
            p[1] = new SqlParameter();
            p[1].ParameterName = "@kalaname";
            p[1].SqlDbType = System.Data.SqlDbType.NChar;
            p[1].Value = kalaname;
            //
            p[2] = new SqlParameter();
            p[2].ParameterName = "@price";
            p[2].SqlDbType = System.Data.SqlDbType.Decimal;
            p[2].Value = price;
            //
            p[3] = new SqlParameter();
            p[3].ParameterName = "@groupname";
            p[3].SqlDbType = System.Data.SqlDbType.NChar;
            p[3].Value = groupname;
            //
            p[4] = new SqlParameter();
            p[4].ParameterName = "@vahed";
            p[4].SqlDbType = System.Data.SqlDbType.NChar;
            p[4].Value = vahed;

            return this.ExecuteNonQuery("InsertKala", p, true);
        }

        public bool Update(string kalaid, string kalaname, string price,string groupname,string vahed)
        {
            SqlParameter[] p = new SqlParameter[5];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@kalaid";
            p[0].SqlDbType = System.Data.SqlDbType.BigInt;
            p[0].Value = kalaid;
            //
            p[1] = new SqlParameter();
            p[1].ParameterName = "@kalaname";
            p[1].SqlDbType = System.Data.SqlDbType.NChar;
            p[1].Value = kalaname;
            //
            p[2] = new SqlParameter();
            p[2].ParameterName = "@price";
            p[2].SqlDbType = System.Data.SqlDbType.Decimal;
            p[2].Value = price;
            //
            p[3] = new SqlParameter();
            p[3].ParameterName = "@groupname";
            p[3].SqlDbType = System.Data.SqlDbType.NChar;
            p[3].Value = groupname;
            //
            p[4] = new SqlParameter();
            p[4].ParameterName = "@vahed";
            p[4].SqlDbType = System.Data.SqlDbType.NChar;
            p[4].Value = vahed;

            return this.ExecuteNonQuery("UpdateKala", p, true);
        }

        public bool Delete(string kalaid)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@kalaid";
            p[0].SqlDbType = System.Data.SqlDbType.BigInt;
            p[0].Value = kalaid;
            return this.ExecuteNonQuery("DELETE FROM Kala WHERE kalaid=@kalaid", p, false);
        }

        public object SelectAll()
        {
            return this.ExecuteReader("SELECT * FROM Kala", null, false);
        }

        public object Select(long kalaid)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@kalaid";
            p[0].SqlDbType = System.Data.SqlDbType.BigInt;
            p[0].Value = kalaid;
            return this.ExecuteReader("SELECT * FROM Kala WHERE kalaid=@kalaid", p, false);
        }

        public object SelectAllKalaGroups()
        {
            return this.ExecuteReader("SELECT * FROM Kalagroup", null, false);
        }
    }
}
