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

namespace DAL
{
    public sealed class FroshMethods:Method
    {
        public bool Insert(string sanadid, string fakid, string kalaid, string number, string price, string date,string cid)
        {
            SqlParameter[] p = new SqlParameter[7];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@sanadid";
            p[0].SqlDbType = System.Data.SqlDbType.Decimal;
            p[0].Value = sanadid;
            //
            p[1] = new SqlParameter();
            p[1].ParameterName = "@fakid";
            p[1].SqlDbType = System.Data.SqlDbType.Decimal;
            p[1].Value = fakid;
            //
            p[2] = new SqlParameter();
            p[2].ParameterName = "@kalaid";
            p[2].SqlDbType = System.Data.SqlDbType.NChar;
            p[2].Value = kalaid;
            //
            p[3] = new SqlParameter();
            p[3].ParameterName = "@number";
            p[3].SqlDbType = System.Data.SqlDbType.Int;
            p[3].Value = number;
            //
            p[4] = new SqlParameter();
            p[4].ParameterName = "@price";
            p[4].SqlDbType = System.Data.SqlDbType.Decimal;
            p[4].Value = price;
            //
            p[5] = new SqlParameter();
            p[5].ParameterName = "@date";
            p[5].SqlDbType = System.Data.SqlDbType.NChar;
            p[5].Value = date;
            //
            p[6] = new SqlParameter();
            p[6].ParameterName = "@cid";
            p[6].SqlDbType = System.Data.SqlDbType.NChar;
            p[6].Value = cid;

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

        public object GetNewFroshSanadId()
        {
            return this.ExecuteScalar("GetNewFroshSanadId", null, true);
        }

        public bool Delete(string sanadid)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@sanadid";
            p[0].SqlDbType = System.Data.SqlDbType.Decimal;
            p[0].Value = sanadid;
            return this.ExecuteNonQuery("DELETE FROM SarfaslFrosh WHERE sanadid=@sanadid", 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);
        }

        public bool InsertUnkhownName(string sanadid, int faktor, string name)
        {
            SqlParameter[] p = new SqlParameter[3];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@sanadid";
            p[0].SqlDbType = System.Data.SqlDbType.Decimal;
            p[0].Value = sanadid;
            //
            p[1] = new SqlParameter();
            p[1].ParameterName = "@faktor";
            p[1].SqlDbType = System.Data.SqlDbType.Int;
            p[1].Value = faktor;
            //
            p[2] = new SqlParameter();
            p[2].ParameterName = "@name";
            p[2].SqlDbType = System.Data.SqlDbType.NChar;
            p[2].Value = name;
            return this.ExecuteNonQuery("INSERT UnkhownFaktor VALUES(@sanadid,@faktor,@name)", p, false);
        }

        public object GetUnkhownName(string sanadid, int faktor)
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter();
            p[0].ParameterName = "@sanadid";
            p[0].SqlDbType = System.Data.SqlDbType.Decimal;
            p[0].Value = sanadid;
            //
            p[1] = new SqlParameter();
            p[1].ParameterName = "@faktor";
            p[1].SqlDbType = System.Data.SqlDbType.Int;
            p[1].Value = faktor;
            //
            return this.ExecuteScalar("SELECT name FROM UnkhownFaktor WHERE sanadid=@sanadid AND faktor=@faktor", p, false);
        }
    }
}
