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

/// <summary>
/// Summary description for Class_tblCar
/// </summary>
public class Class_tblCar
{
    private String Str_CarName = String.Empty;
    private String Str_PelakNumber = String.Empty;
    private String Str_ShasiName = String.Empty;
    private String Str_MotorNumber = String.Empty;
    private String Str_UserName = String.Empty;
    private int int_Model = 0;

    public Class_tblCar(String _CarName, String _PelakNumber, String _ShasiName, String _MotorNumber, String _UserName, int _Model)
	{
        this.Str_CarName = _CarName;
        this.Str_PelakNumber = _PelakNumber;
        this.Str_ShasiName = _ShasiName;
        this.Str_MotorNumber = _MotorNumber;
        this.Str_UserName = _UserName;
        this.int_Model = _Model;
	}

    public int UDF_CheckDuplicate()
    {
        int int_Duplicated = 0;
        LSCTamiratDataContext db = new LSCTamiratDataContext();
        try
        {
            tblCar car = db.tblCars.Single(n => n.PelakNumber.Trim() == Str_PelakNumber.Trim());
            if (car.PelakNumber.Trim() == "")
            {
                int_Duplicated = 0;
            }
            else
            {
                int_Duplicated = 1;
            }
        }
        catch
        {
            int_Duplicated = 0;
        }
        return int_Duplicated;
    }

    public void UDF_Save()
    {
        LSCTamiratDataContext db = new LSCTamiratDataContext();
        tblCar car = new tblCar();
        car.CarName = Str_CarName;
        car.PelakNumber = Str_PelakNumber;
        car.ShasiNumber = Str_ShasiName;
        car.MotorNumber = Str_MotorNumber;
        car.DriverUserName = Str_UserName;
        car.CarModel = int_Model;

        db.tblCars.InsertOnSubmit(car);
        db.SubmitChanges();
    }
}