using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using ajans.class_ajans;

namespace ajans.forms
{
    public partial class frm_darj_ranande : Telerik.WinControls.UI.RadForm
    {
        public frm_darj_ranande()
        {
            InitializeComponent();
        }

        public Boolean Editmode = false;
        public int id_ran;

        private void btn_insert_Click(object sender, EventArgs e)
        {
            ranande r1 = new ranande();
            r1.id_ran = id_ran;
            r1.coderanande = txt_coderanande.Text;
            r1.n_ranande = txt_nranande.Text;
            r1.l_ranande = txt_lranande.Text;
            r1.t_estekhdam = txt_testekhdam.Text;
            r1.codemeli = txt_codemeli.Text;
            r1.mob = txt_mob.Text;
            r1.tel_home = txt_telhome.Text;
            r1.moteahel = ch_moteahel.Checked;
            r1.address = txt_add.Text;

            if (Editmode)
            {
                r1.update();
                this.Close();
                return;
            }
            car c = new car();
            c.id_ran = id_ran;
            c.n_car = txt_ncar.Text;
            c.sh_plak = txt_shplak.Text;
            c.model = txt_modelcar.Text;
            c.clascar = comboBox1.Text;
            //c.clascar = ch
            //if (Editmode1)
            //{
            //    c.update();
            //    this.Close();
            //    return;

            //}
            if (r1.Exist())
            {
                MessageBox.Show("کد ملی وارد شده تکرار ی است", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (c.Exist())
            {
                MessageBox.Show("شماره پلاک وارد شده تکراری است ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            r1.insert();
            c.insert();
           
         

         
            DialogResult dr;
            dr = MessageBox.Show("عملیات با موفقیت انجام شد آیا می خواهید راننده جدیدی ثبت کنید","پیام",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                txt_nranande.Text = "";
                txt_lranande.Text = "";
                txt_testekhdam.Text = "";
                txt_codemeli.Text = "";
                txt_mob.Text = "";
                txt_add.Text = "";
                txt_telhome.Text = "";
                txt_ncar.Text = "";
                txt_shplak.Text = "";
                txt_modelcar.Text = "";
            }
           else this.Close();




        }

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

       
        }
    }

