using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SaveCars : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            Response.Redirect("LoginPage.aspx?ID=" + DateTime.Now.Ticks.ToString());
        }
    }
    private void UDF_ClaerTextBox()
    {
        Txt_Model.Text = String.Empty;
        Txt_MotorNum.Text = String.Empty;
        Txt_NameCar.Text = String.Empty;
        Txt_PelakNum.Text = String.Empty;
        Txt_ShasiNum.Text = String.Empty;
    }
    protected void Btn_Save_Click(object sender, EventArgs e)
    {
        Class_tblCar ClsCar = new Class_tblCar(Txt_NameCar.Text.Trim(), Txt_PelakNum.Text.Trim(), Txt_ShasiNum.Text.Trim(), Txt_MotorNum.Text.Trim(), Session["UserName"].ToString(), int.Parse(Txt_Model.Text.Trim()));
        if (ClsCar.UDF_CheckDuplicate() == 0)
        {
            ClsCar.UDF_Save();
            Lbl_Error.Visible = true;
            Lbl_Error.Text = "خودروی شماره با موفقیت ثبت شد";
            UDF_ClaerTextBox();
        }
        else
        {
            Lbl_Error.Visible = true;
            Lbl_Error.Text = " خودروی شما قبلا ثبت شده است";
           
        }
    }
    protected void Btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx?ID=" + DateTime.Now.Ticks.ToString());
    }
}