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

namespace DAL
{
    public sealed class ChekMethods : Method
    {
        public bool Insert(string serial, string bank, string shobe, string date, string mablagh, int d, int p)
        {
            SqlParameter[] param = new SqlParameter[7];
            param[0] = new SqlParameter();
            param[0].ParameterName = "@serial";
            param[0].SqlDbType = System.Data.SqlDbType.NChar;
            param[0].Value = serial;
            //
            param[1] = new SqlParameter();
            param[1].ParameterName = "@bank";
            param[1].SqlDbType = System.Data.SqlDbType.NChar;
            param[1].Value = bank;
            //
            param[2] = new SqlParameter();
            param[2].ParameterName = "@shobe";
            param[2].SqlDbType = System.Data.SqlDbType.NChar;
            param[2].Value = shobe;
            //
            param[3] = new SqlParameter();
            param[3].ParameterName = "@date";
            param[3].SqlDbType = System.Data.SqlDbType.NChar;
            param[3].Value = date;
            //
            param[4] = new SqlParameter();
            param[4].ParameterName = "@mablagh";
            param[4].SqlDbType = System.Data.SqlDbType.Decimal;
            param[4].Value = mablagh;
            //
            param[5] = new SqlParameter();
            param[5].ParameterName = "@d";
            param[5].SqlDbType = System.Data.SqlDbType.TinyInt;
            param[5].Value = d;
            //
            param[6] = new SqlParameter();
            param[6].ParameterName = "@p";
            param[6].SqlDbType = System.Data.SqlDbType.TinyInt;
            param[6].Value = p;

            return this.ExecuteNonQuery("InsertChek", param, true);
        }

        public bool Update(string sname, string mojodi)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@sname";
            p[0].SqlDbType = System.Data.SqlDbType.NChar;
            p[0].Value = sname;
            //
            p[1] = new SqlParameter();
            p[1].ParameterName = "@mojodi";
            p[1].SqlDbType = System.Data.SqlDbType.Decimal;
            p[1].Value = mojodi;

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

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

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

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