using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for Class_tblCompanyUnits
/// </summary>
public class Class_tblCompanyUnits
{
    private String Str_CompanyUnitName = String.Empty;

    public Class_tblCompanyUnits(String Str_CompanyUnitName)
	{
        this.Str_CompanyUnitName = Str_CompanyUnitName.Trim();
	}

    /// <summary>
    /// از این متد برای ایجاد واحد شرکت می توان استفاده نمود
    /// </summary>
    public void UDF_CreateNewCompanyUnit()
    {
        LSC_WareHouseDataContext db = new LSC_WareHouseDataContext();
        tblCompanyUnit tblCmpUnit = new tblCompanyUnit();
        tblCmpUnit.CompanyUnitName = Str_CompanyUnitName;
        db.tblCompanyUnits.InsertOnSubmit(tblCmpUnit);
        db.SubmitChanges();
    }

    public int UDF_CheckDuplicate()
    {
        int int_Duplicated = 0;
        LSC_WareHouseDataContext db = new LSC_WareHouseDataContext();
        try
        {
            tblCompanyUnit tblCmpUnit = db.tblCompanyUnits.Single(n => n.CompanyUnitName == Str_CompanyUnitName.Trim());
            if (tblCmpUnit.CompanyUnitName.Trim() == "")
            {
                int_Duplicated = 0;
            }
            else
            {
                int_Duplicated = 1;
            }
        }
        catch
        {
            int_Duplicated = 0;
        }
        return int_Duplicated;
    }

}
