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

namespace BLL
{
    public class Chek
    {
        string _serial;
        string _bank;
        string _shobe;
        string _date;
        string _mablagh;
        int _d;
        int _p;

        public string Serial
        {
            get { return _serial; }
            set { _serial = value; }
        }
        public string Bank
        {
            get { return _bank; }
            set { _bank = value; }
        }
        public string Shobe
        {
            get { return _shobe; }
            set { _shobe = value; }
        }
        public string Date
        {
            get { return _date; }
            set { _date = value; }
        }
        public string Mablagh
        {
            get { return _mablagh; }
            set { _mablagh = value; }
        }
        public int Daryafti
        {
            get { return _d; }
            set { _d = value; }
        }
        public int PasShode
        {
            get { return _p; }
            set { _p = value; }
        }

        public Chek() { }
        public Chek(string serial, string bank, string shobe, string date, string mablagh, int d, int p)
        {
            Serial = serial;
            Bank = bank;
            Shobe = shobe;
            Date = date;
            Mablagh = mablagh;
            Daryafti = d;
            PasShode = p;
        }

        public void Insert()
        {
            ChekMethods method = new ChekMethods();
            method.Insert(this.Serial, this.Bank, this.Shobe, this.Date, this.Mablagh, this.Daryafti, this.PasShode);
        }

        public void Delete()
        {
            ChekMethods method = new ChekMethods();
            method.Delete(this.Serial);
        }

        public static List<Chek> GetAllCheks(IDataReader reader)
        {
            List<Chek> tempList = new List<Chek>();
            while (reader.Read())
            {
                try
                {
                    Chek temp = new Chek
                    {
                        Serial = reader["serial"].ToString(),
                        Bank= reader["bank"].ToString(),
                        Shobe=reader["shobe"].ToString(),
                        Date=reader["date"].ToString(),
                        Mablagh=reader["mablagh"].ToString(),
                        Daryafti=Convert.ToInt32(reader["d"]),
                        PasShode = Convert.ToInt32(reader["p"])
                    };
                    tempList.Add(temp);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
            }
            return tempList;
        }

        public static List<Chek> GetAllCheks()
        {
            ChekMethods methods = new ChekMethods();
            return GetAllCheks((IDataReader)methods.SelectAll());
        }

        public static List<Chek> GetChek(string serial)
        {
            ChekMethods methods = new ChekMethods();
            return GetAllCheks((IDataReader)methods.Select(serial));
        }
    }
}
