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

namespace DAL
{
    public sealed class AnbarMethods : Method
    {
        public object SelectAll()
        {
            return this.ExecuteReader("GetAllMojodiKala", null, true);
        }
        public void DeleteZeroMojodi()
        {
            this.ExecuteNonQuery("Delete From Anbar WHERE mojodi=0", null, false);
        }

        public bool Insert(string kalaid, string kharid, string number)
        {
            SqlParameter[] p = new SqlParameter[3];            

            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 = "@kharid";
            p[1].SqlDbType = System.Data.SqlDbType.Decimal;
            p[1].Value = kharid;

            p[2] = new SqlParameter();
            p[2].ParameterName = "@number";
            p[2].SqlDbType = System.Data.SqlDbType.Int;
            p[2].Value = number;

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

        public bool Update(string acode,string kalaid,string kharid,string mojodi)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@acode";
            p[0].SqlDbType = System.Data.SqlDbType.Decimal;
            p[0].Value = acode;

            p[1] = new SqlParameter();
            p[1].ParameterName = "@kalaid";
            p[1].SqlDbType = System.Data.SqlDbType.NChar;
            p[1].Value = kalaid;

            p[2] = new SqlParameter();
            p[2].ParameterName = "@kharid";
            p[2].SqlDbType = System.Data.SqlDbType.Decimal;
            p[2].Value = kharid;

            p[3] = new SqlParameter();
            p[3].ParameterName = "@mojodi";
            p[3].SqlDbType = System.Data.SqlDbType.Int;
            p[3].Value = mojodi;

            return this.ExecuteNonQuery("UPDATE Anbar SET mojodi=@mojodi,kharid=@kharid,kalaid=@kalaid WHERE acode=@acode", p, false);
        }

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

        public  object GetMojodiKala(string kalaid)
        {

            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@kalaid";
            p[0].SqlDbType = System.Data.SqlDbType.NChar;
            p[0].Value = kalaid;
            return this.ExecuteScalar("GetMojodiKala", p, true);
        }
    }
}
