protected void Page_Load(object sender, EventArgs e)
    {
        AssetBookFormUI assetBookFormUI = new AssetBookFormUI();

        if (!Page.IsPostBack)
        {
            if (Request.QueryString["AssetBookId"] != null)
            {
                assetBookFormUI.Tbl_AssetBookId = Request.QueryString["AssetBookId"];
                BindStatusDropDown();
                BindAveragingConventionDropDown();
                BindDepreciationMethodDropDown();
                FillForm(assetBookFormUI);
                btnSave.Visible   = false;
                btnClear.Visible  = false;
                btnUpdate.Visible = true;
                btnDelete.Visible = true;
                lblHeading.Text   = "Update Asset Book";
            }
            else
            {
                BindStatusDropDown();
                BindAveragingConventionDropDown();
                BindDepreciationMethodDropDown();
                btnSave.Visible   = true;
                btnClear.Visible  = true;
                btnUpdate.Visible = false;
                btnDelete.Visible = false;
                lblHeading.Text   = "Add New Asset Book";
            }
        }
    }
    public int UpdateAssetBook(AssetBookFormUI assetBookFormUI)
    {
        int resutl = 0;

        resutl = assetBookFormDAL.UpdateAssetBook(assetBookFormUI);
        return(resutl);
    }
    public int DeleteAssetBook(AssetBookFormUI assetBookFormUI)
    {
        int resutl = 0;

        resutl = assetBookFormDAL.DeleteAssetBook(assetBookFormUI);
        return(resutl);
    }
    public int AddAssetBook(AssetBookFormUI assetBookFormUI)
    {
        int resutl = 0;

        resutl = assetBookFormDAL.AddAssetBook(assetBookFormUI);
        return(resutl);
    }
    public DataTable GetAssetBookListById(AssetBookFormUI assetBookFormUI)
    {
        DataTable dtb = new DataTable();

        dtb = assetBookFormDAL.GetAssetBookListById(assetBookFormUI);
        return(dtb);
    }
    public DataTable GetAssetBookListById(AssetBookFormUI assetBookFormUI)
    {
        DataSet   ds   = new DataSet();
        DataTable dtbl = new DataTable();

        try
        {
            using (SqlConnection SupportCon = new SqlConnection(connectionString))
            {
                SqlCommand sqlCmd = new SqlCommand("SP_AssetBook_SelectById", SupportCon);
                sqlCmd.CommandType    = CommandType.StoredProcedure;
                sqlCmd.CommandTimeout = commandTimeout;

                sqlCmd.Parameters.Add("@tbl_AssetBookId", SqlDbType.NVarChar);
                sqlCmd.Parameters["@tbl_AssetBookId"].Value = assetBookFormUI.Tbl_AssetBookId;

                using (SqlDataAdapter adapter = new SqlDataAdapter(sqlCmd))
                {
                    adapter.Fill(ds);
                }
            }
            if (ds.Tables.Count > 0)
            {
                dtbl = ds.Tables[0];
            }
        }
        catch (Exception exp)
        {
            logExcpUIobj.MethodName       = "getAssetBookListById()";
            logExcpUIobj.ResourceName     = "AssetBookFormDAL.CS";
            logExcpUIobj.RecordId         = assetBookFormUI.Tbl_AssetBookId;
            logExcpUIobj.ExceptionDetails = "Error Occured. System Generated Error is: " + exp.ToString();
            logExcpDALobj.SaveExceptionToDB(logExcpUIobj);

            log.Error("[AssetBookFormDAL : getAssetBookListById] An error occured in the processing of Record Id : " + assetBookFormUI.Tbl_AssetBookId + ". Details : [" + exp.ToString() + "]");
        }
        finally
        {
            ds.Dispose();
        }

        return(dtbl);
    }
    private void FillForm(AssetBookFormUI assetBookFormUI)
    {
        try
        {
            DataTable dtb = assetBookFormBAL.GetAssetBookListById(assetBookFormUI);

            if (dtb.Rows.Count > 0)
            {
                txtAssetGuid.Text                        = dtb.Rows[0]["tbl_AssetId"].ToString();
                txtAsset.Text                            = dtb.Rows[0]["tbl_Asset"].ToString();
                txtAssetBookCode.Text                    = dtb.Rows[0]["AssetBookCode"].ToString();
                txtPlaceInServiceDate.Text               = dtb.Rows[0]["PlaceInServiceDate"].ToString();
                txtDepreciatedDueDate.Text               = dtb.Rows[0]["DepreciatedDueDate"].ToString();
                txtBeginYearCost.Text                    = dtb.Rows[0]["BeginYearCost"].ToString();
                txtCostBasis.Text                        = dtb.Rows[0]["CostBasis"].ToString();
                txtScrapValue.Text                       = dtb.Rows[0]["ScrapValue"].ToString();
                txtYearlyDepreciationRate.Text           = dtb.Rows[0]["YearlyDepreciationRate"].ToString();
                txtCurrentDepreciation.Text              = dtb.Rows[0]["CurrentDepreciation"].ToString();
                txtNetBookValue.Text                     = dtb.Rows[0]["NetBookValue"].ToString();
                ddlopt_DepreciationMethod.SelectedValue  = dtb.Rows[0]["opt_DepreciationMethod"].ToString();
                ddlopt_AveragingConvention.SelectedValue = dtb.Rows[0]["opt_AveragingConvention"].ToString();
                chkFullDepreciationFlag.Checked          = Convert.ToBoolean(dtb.Rows[0]["FullDepreciationFlag"].ToString());
                ddlopt_Status.SelectedValue              = dtb.Rows[0]["opt_Status"].ToString();
                txtOriginalLifeYear.Text                 = dtb.Rows[0]["OriginalLifeYear"].ToString();
                txtOriginalLifeDay.Text                  = dtb.Rows[0]["OriginalLifeDay"].ToString();
            }
        }
        catch (Exception exp)
        {
            logExcpUIobj.MethodName       = "FillForm()";
            logExcpUIobj.ResourceName     = "Asset_AssetBookForm.CS";
            logExcpUIobj.RecordId         = this.assetBookFormUI.Tbl_AssetBookId;
            logExcpUIobj.ExceptionDetails = "Error Occured. System Generated Error is: " + exp.ToString();
            logExcpDALobj.SaveExceptionToDB(logExcpUIobj);

            log.Error("[Asset_AssetBookForm : FillForm] An error occured in the processing of Record Details : [" + exp.ToString() + "]");
        }
    }
    public int DeleteAssetBook(AssetBookFormUI assetBookFormUI)
    {
        int result = 0;

        try
        {
            using (SqlConnection SupportCon = new SqlConnection(connectionString))
            {
                SupportCon.Open();
                SqlCommand sqlCmd = new SqlCommand("SP_AssetBook_Delete", SupportCon);

                sqlCmd.CommandType    = CommandType.StoredProcedure;
                sqlCmd.CommandTimeout = commandTimeout;

                sqlCmd.Parameters.Add("@tbl_AssetBookId", SqlDbType.NVarChar);
                sqlCmd.Parameters["@tbl_AssetBookId"].Value = assetBookFormUI.Tbl_AssetBookId;

                result = sqlCmd.ExecuteNonQuery();

                sqlCmd.Dispose();
                SupportCon.Close();
            }
        }
        catch (Exception exp)
        {
            logExcpUIobj.MethodName       = "DeleteAssetBook()";
            logExcpUIobj.ResourceName     = "AssetBookFormDAL.CS";
            logExcpUIobj.RecordId         = assetBookFormUI.Tbl_AssetBookId;
            logExcpUIobj.ExceptionDetails = "Error Occured. System Generated Error is: " + exp.ToString();
            logExcpDALobj.SaveExceptionToDB(logExcpUIobj);

            log.Error("[AssetBookFormDAL : DeleteAssetBook] An error occured in the processing of Record Id : " + assetBookFormUI.Tbl_AssetBookId + ". Details : [" + exp.ToString() + "]");
        }

        return(result);
    }
    public int AddAssetBook(AssetBookFormUI assetBookFormUI)
    {
        int result = 0;

        try
        {
            using (SqlConnection SupportCon = new SqlConnection(connectionString))
            {
                SupportCon.Open();
                SqlCommand sqlCmd = new SqlCommand("SP_AssetBook_Insert", SupportCon);
                sqlCmd.CommandType    = CommandType.StoredProcedure;
                sqlCmd.CommandTimeout = commandTimeout;

                sqlCmd.Parameters.Add("@CreatedBy", SqlDbType.NVarChar);
                sqlCmd.Parameters["@CreatedBy"].Value = assetBookFormUI.CreatedBy;

                sqlCmd.Parameters.Add("@tbl_OrganizationId", SqlDbType.NVarChar);
                sqlCmd.Parameters["@tbl_OrganizationId"].Value = assetBookFormUI.Tbl_OrganizationId;

                sqlCmd.Parameters.Add("@tbl_AssetId", SqlDbType.NVarChar);
                sqlCmd.Parameters["@tbl_AssetId"].Value = assetBookFormUI.Tbl_AssetId;

                sqlCmd.Parameters.Add("@AssetBookCode", SqlDbType.NVarChar);
                sqlCmd.Parameters["@AssetBookCode"].Value = assetBookFormUI.AssetBookCode;

                sqlCmd.Parameters.Add("@PlaceInServiceDate", SqlDbType.DateTime);
                sqlCmd.Parameters["@PlaceInServiceDate"].Value = assetBookFormUI.PlaceInServiceDate;

                sqlCmd.Parameters.Add("@DepreciatedDueDate", SqlDbType.DateTime);
                sqlCmd.Parameters["@DepreciatedDueDate"].Value = assetBookFormUI.DepreciatedDueDate;

                sqlCmd.Parameters.Add("@BeginYearCost", SqlDbType.Decimal);
                sqlCmd.Parameters["@BeginYearCost"].Value = assetBookFormUI.BeginYearCost;

                sqlCmd.Parameters.Add("@CostBasis", SqlDbType.Decimal);
                sqlCmd.Parameters["@CostBasis"].Value = assetBookFormUI.CostBasis;

                sqlCmd.Parameters.Add("@ScrapValue", SqlDbType.Decimal);
                sqlCmd.Parameters["@ScrapValue"].Value = assetBookFormUI.ScrapValue;

                sqlCmd.Parameters.Add("@YearlyDepreciationRate", SqlDbType.Decimal);
                sqlCmd.Parameters["@YearlyDepreciationRate"].Value = assetBookFormUI.YearlyDepreciationRate;

                sqlCmd.Parameters.Add("@CurrentDepreciation", SqlDbType.Decimal);
                sqlCmd.Parameters["@CurrentDepreciation"].Value = assetBookFormUI.CurrentDepreciation;

                sqlCmd.Parameters.Add("@NetBookValue", SqlDbType.Decimal);
                sqlCmd.Parameters["NetBookValue"].Value = assetBookFormUI.NetBookValue;

                sqlCmd.Parameters.Add("@opt_DepreciationMethod", SqlDbType.TinyInt);
                sqlCmd.Parameters["@opt_DepreciationMethod"].Value = assetBookFormUI.opt_DepreciationMethod;

                sqlCmd.Parameters.Add("@opt_AveragingConvention", SqlDbType.TinyInt);
                sqlCmd.Parameters["@opt_AveragingConvention"].Value = assetBookFormUI.opt_AveragingConvention;

                sqlCmd.Parameters.Add("@FullDepreciationFlag", SqlDbType.Bit);
                sqlCmd.Parameters["@FullDepreciationFlag"].Value = assetBookFormUI.FullDepreciationFlag;

                sqlCmd.Parameters.Add("@opt_Status", SqlDbType.TinyInt);
                sqlCmd.Parameters["@opt_Status"].Value = assetBookFormUI.opt_Status;

                sqlCmd.Parameters.Add("@OriginalLifeYear", SqlDbType.TinyInt);
                sqlCmd.Parameters["@OriginalLifeYear"].Value = assetBookFormUI.OriginalLifeYear;

                sqlCmd.Parameters.Add("@OriginalLifeDay", SqlDbType.TinyInt);
                sqlCmd.Parameters["@OriginalLifeDay"].Value = assetBookFormUI.OriginalLifeDay;


                result = sqlCmd.ExecuteNonQuery();

                sqlCmd.Dispose();
                SupportCon.Close();
            }
        }
        catch (Exception exp)
        {
            logExcpUIobj.MethodName       = "AddAssetBook()";
            logExcpUIobj.ResourceName     = "AssetBookFormDAL.CS";
            logExcpUIobj.RecordId         = "";
            logExcpUIobj.ExceptionDetails = "Error Occured. System Generated Error is: " + exp.ToString();
            logExcpDALobj.SaveExceptionToDB(logExcpUIobj);

            log.Error("[AssetBookFormDAL : AddAssetBook] An error occured in the processing of Record. Details : [" + exp.ToString() + "]");
        }

        return(result);
    }