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_tblWhAssets
{
    String Str_AssetName = String.Empty;
    int int_AssetUnitID = 0;
    int int_AssetCategoryID = 0;
    int int_AssetProviderID = 0;
    int int_AssetOrderPoint = 0;

    public Class_tblWhAssets(String Str_AssetName, int int_AssetUnitID, int int_AssetCategoryID, int int_AssetProviderID, int int_AssetOrderPoint)
	{
        this.Str_AssetName = Str_AssetName;
        this.int_AssetUnitID = int_AssetUnitID;
        this.int_AssetCategoryID = int_AssetCategoryID;
        this.int_AssetProviderID = int_AssetProviderID;
        this.int_AssetOrderPoint = int_AssetOrderPoint;
	}

    /// <summary>
    /// از این متد برای ایجاد کالا می توان استفاده نمود
    /// </summary>
    public void UDF_SaveWhAsset()
    {
        LSC_WareHouseDataContext db = new LSC_WareHouseDataContext();
        tblWhAsset tblAs = new tblWhAsset();
        tblAs.AssetName = Str_AssetName.Trim();
        tblAs.AssetUnitID = int_AssetUnitID;
        tblAs.AssetCategoryID = int_AssetCategoryID;
        tblAs.AssetProviderID = int_AssetProviderID;
        tblAs.AssetOrderPoint = int_AssetOrderPoint;
        db.tblWhAssets.InsertOnSubmit(tblAs);
        db.SubmitChanges();
    }

    /// <summary>
    /// از این متد برای بررسی اینکه آیا رکورد قبلا وارد شده است یا خیر استفاده می شود
    /// </summary>
    /// <returns></returns>
    public int UDF_CheckDuplicate()
    {
        int int_Duplicated = 0;
        LSC_WareHouseDataContext db = new LSC_WareHouseDataContext();
        try
        {
            tblWhAsset tblAs = db.tblWhAssets.Single(n => n.AssetName == Str_AssetName.Trim());
            if (tblAs.AssetName.Trim() == "")
            {
                int_Duplicated = 0;
            }
            else
            {
                int_Duplicated = 1;
            }
        }
        catch
        {
            int_Duplicated = 0;
        }
        return int_Duplicated;
    }
}
