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>
public class Class_tblWareHouse
{
    private String Str_WareHouseName = String.Empty;

	public Class_tblWareHouse(String Str_WareHouseName)
	{
        this.Str_WareHouseName = Str_WareHouseName;
	}

    public void UDF_CreateNewWareHouse()
    {
        LSC_WareHouseDataContext db = new LSC_WareHouseDataContext();
        tblWareHouseName tblWarH = new tblWareHouseName();
        tblWarH.WarHouseDescription = Str_WareHouseName;
        db.tblWareHouseNames.InsertOnSubmit(tblWarH);
        db.SubmitChanges();
    }
     
     
/// <summary>
/// از این متد برای بررسی عدم تکرار نام انبار استفاده می شود
///    0 = No Duplicated   1 = Duplicated
/// </summary>
/// <returns></returns>
    public int UDF_CheckDuplicate()
    {
        int int_Duplicated = 0;
        LSC_WareHouseDataContext db = new LSC_WareHouseDataContext();
        try
        {
            tblWareHouseName tblWarH = db.tblWareHouseNames.Single(n => n.WarHouseDescription == Str_WareHouseName.Trim());
            if (tblWarH.WarHouseDescription.Trim() == "")
            {
                int_Duplicated = 0;
            }
            else
            {
                int_Duplicated = 1;
            }
        }
        catch
        {
            int_Duplicated = 0;
        }
        return int_Duplicated;
    }
}
