using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Self_Project
{
    public partial class EditStudentType : Form
    {
        public EditStudentType()
        {
            InitializeComponent();
        }
        StudentType objStdType = new StudentType();

        private void EditStudentType_Load(object sender, EventArgs e)
        {
            objStdType.ShowModels(cmb_Student_Type);
            cmb_Student_Type.SelectedIndex = -1;
            cmb_Student_Type.SelectedIndex = 0;
        }

        private void cmb_Student_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            txt_Type.TEXT = cmb_Student_Type.Text;
            try
            {
                objStdType.Name = txt_Type.TEXT;
                objStdType.ID = Convert.ToSByte(cmb_Student_Type.SelectedValue);
            }
            catch { }
        }

        private void btn_OK_Click(object sender, EventArgs e)
        {
            if (txt_Type.TEXT == objStdType.Name)
            {
                MessageBox.Show("نوع دانشجو تغییر نیافته است", "نوع دانشجو", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txt_Type.Focus();
                return;
            }
            //-------------------------------------------------
            try
            {
                objStdType.Name = txt_Type.TEXT;
                objStdType.Update();
                MessageBox.Show("اطلاعات با موفقیت ثبت شد", "نوع دانشجو", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            catch (StudentType_Exceptions_Name ex)
            {
                MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Type.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txt_Type.Focus();
            }
            
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}