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

namespace Self_Project
{
    public class StudentType : IControlable
    {
        //---------------------------------
        private string _name = "";
        public string Name
        {
            get { return _name; }
            set 
            {
                if (value == "")
                    throw new StudentType_Exceptions_Name();
                else
                    _name = value;
            }
        }
        //---------------------------------
        private SByte _iD = -1;

        public SByte ID
        {
            get { return _iD; }
            set 
            {
                if (value < 0)
                    throw new StudentType_Exceptions_ID();
                else
                    _iD = value;
            }
        }
        //---------------------------------
        public void ControlInfo()
        {
            if (_name == "")
                throw new StudentType_Exceptions_Name();
            if (_iD < 0)
                throw new StudentType_Exceptions_ID();
        }
        //---------------------------------
        public void ShowModels(System.Windows.Forms.ComboBox CMB)
        {
            CMB.DataSource = DataBase_SQL.Action(DBOperation.Select, null, "Model", "Esm,Model", "Esm");
            CMB.DisplayMember = "Esm";
            CMB.ValueMember = "Model";
        }
        //---------------------------------
        public void Create()
        {
            if (_name == "")
                throw new StudentType_Exceptions("نام وارد شده، معتبر نیست");
            Condition Cond1 = new Condition(1);
            Condition Cond2 = new Condition(1);
            DataTable DT = new DataTable();
            Cond1.AddCondition("Esm", Operatotrs.مساوی, _name, Concat_Type.None);
            if (DataBase_SQL.Action(DBOperation.Select, Cond1, "Model", "Model").Rows.Count > 0)
                throw new StudentType_Exceptions("نام وارد شده ، تکراری است");
            else
                DataBase_SQL.Action(DBOperation.Insert, null, "Model", "Esm", _name);
            //--------------------------------------
            Cond2.AddCondition("Esm", Operatotrs.مساوی, _name, Concat_Type.None);
            DT = DataBase_SQL.Action(DBOperation.Select, Cond2, "Model", "Model");
            DataBase_SQL.Bank_Action("Insert Into Limit Values (" + DT.Rows[0][0].ToString() + ",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)");
            DataBase_SQL.Bank_Action("Insert Into Prices Values (" + DT.Rows[0][0].ToString() + ",1000,2000,3000)");
        }
        //---------------------------------
        public void Update()
        {
            Condition Cond = new Condition(1);
            Cond.AddCondition("Esm", Operatotrs.مساوی, _name, Concat_Type.None);
            if (DataBase_SQL.Action(DBOperation.Select, Cond, "Model", "Esm").Rows.Count > 0)
                throw new StudentType_Exceptions("نوع وارد شده، تکراری است");
            else
            {
                Condition Cond2 = new Condition(1);
                Cond2.AddCondition("Model", Operatotrs.مساوی, _iD.ToString(), Concat_Type.None);
                DataBase_SQL.Action(DBOperation.Update, Cond2, "Model", "Esm", _name);
            }
        }
        //---------------------------------
    }
}
