using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Masters_TA_UI_Master_LoanEntryView : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DataSet dsLoanEntry;
    Int64 getLoanID,EmpID;
    PayrollConfigurationEventData objLoanEntry = new PayrollConfigurationEventData();
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        getLoanID= Convert.ToInt64(Request.QueryString["Loan_ID"]);
        EmpID= Int32.Parse(Session["EmpAutoID"].ToString());
        btn_Modify.Focus();
        loadcss();
        LoadStrings(ci);
        if (!Page.IsPostBack)
        {
            UserRights();
            LoadStrings(ci);
            GetLoanEntryDetails();
        }
        int intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
        if (intIndividualUser >= 1)
        {
            btn_Modify.Enabled = false;
            btn_Delete.Enabled = false;
        }
       
    }
    private void GetLoanEntryDetails()
    {
        dsLoanEntry = new DataSet();
        DataTable dtLoanEntry = new DataTable();
        Hashtable htable = new Hashtable();
        htable.Add("@tag", "S");
        htable.Add("@loanId", getLoanID);
        dsLoanEntry = objLoanEntry.InsertLoanDetails(htable);
        dtLoanEntry = dsLoanEntry.Tables[0];
        if (dtLoanEntry.Rows.Count > 0)
        {
            if (dtLoanEntry.Rows[0]["Employee_Code_Id"] != DBNull.Value)
            {
                if (dtLoanEntry.Rows[0]["Employee_Code_Id"].ToString() != string.Empty)
                {
                    txt_EmployeeId.Text = Convert.ToString(dtLoanEntry.Rows[0]["Employee_Code_Id"]);
                }
            }
            if (dtLoanEntry.Rows[0]["Employee_FirstName"] != DBNull.Value)
            {
                if (dtLoanEntry.Rows[0]["Employee_FirstName"].ToString() != string.Empty)
                {
                    txt_EmployeeName.Text = Convert.ToString(dtLoanEntry.Rows[0]["Employee_FirstName"]);
                }
            }
            if (dtLoanEntry.Rows[0]["Loan_Amount"] != DBNull.Value)
            {
                if (dtLoanEntry.Rows[0]["Loan_Amount"].ToString() != string.Empty)
                {
                    txt_loanAmount.Text = Convert.ToString(dtLoanEntry.Rows[0]["Loan_Amount"]);
                }
            }
            if (dtLoanEntry.Rows[0]["Total_DeductionMonth"] != DBNull.Value)
            {
                if (dtLoanEntry.Rows[0]["Total_DeductionMonth"].ToString() != string.Empty)
                {
                    txt_DeductionMonth.Text = Convert.ToString(dtLoanEntry.Rows[0]["Total_DeductionMonth"]);
                }
            }
            if (dtLoanEntry.Rows[0]["Deduction_StartMonth"] != DBNull.Value)
            {
                if (dtLoanEntry.Rows[0]["Deduction_StartMonth"].ToString() != string.Empty)
                {
                    txt_DeductionStartMonth.Text = Convert.ToString(dtLoanEntry.Rows[0]["Deduction_StartMonth"]);
                }
            }
            if (dtLoanEntry.Rows[0]["Monthly_DeductAmount"] != DBNull.Value)
            {
                if (dtLoanEntry.Rows[0]["Monthly_DeductAmount"].ToString() != string.Empty)
                {
                    txt_MonthDueAmount.Text = Convert.ToString(dtLoanEntry.Rows[0]["Monthly_DeductAmount"]);
                }
            }
            if (dtLoanEntry.Rows[0]["Loan_BalanceAmount"] != DBNull.Value)
            {
                if (dtLoanEntry.Rows[0]["Loan_BalanceAmount"].ToString() != string.Empty)
                {
                    txt_BalanceAmount.Text = Convert.ToString(dtLoanEntry.Rows[0]["Loan_BalanceAmount"]);
                }
            }
            //if (dtLoanEntry.Rows[0]["ManualTimeEntry_OutTime"] != DBNull.Value)
            //{
            //    if (dtLoanEntry.Rows[0]["ManualTimeEntry_OutTime"].ToString() != string.Empty)
            //    {
            //        lbl_OutTime.Text = Convert.ToString(dtLoanEntry.Rows[0]["ManualTimeEntry_OutTime"]);
            //    }
            //}
            //if (dtLoanEntry.Rows[0]["ManualTimeEntry_OutPunchType"] != DBNull.Value)
            //{
            //    if (dtLoanEntry.Rows[0]["ManualTimeEntry_OutPunchType"].ToString() != string.Empty)
            //    {
            //        lbl_OutPunchType.Text = Convert.ToString(dtLoanEntry.Rows[0]["ManualTimeEntry_OutPunchType"]);
            //    }
            //}
            //if (dtLoanEntry.Rows[0]["ManualTimeEntry_Reason"] != DBNull.Value)
            //{
            //    if (dtLoanEntry.Rows[0]["ManualTimeEntry_Reason"].ToString() != string.Empty)
            //    {
            //        lbl_Reason.Text = Convert.ToString(dtLoanEntry.Rows[0]["ManualTimeEntry_Reason"]);
            //        lbl_Reason.ToolTip = Convert.ToString(dtLoanEntry.Rows[0]["ManualTimeEntry_Reason"]);
            //    }
            //}
            //if (dtLoanEntry.Rows[0]["Entrance_Name"] != DBNull.Value)
            //{
            //    if (dtLoanEntry.Rows[0]["Entrance_Name"].ToString() != string.Empty)
            //    {
            //        lbl_EntranceName.Text = Convert.ToString(dtLoanEntry.Rows[0]["Entrance_Name"]);
            //    }
            //}
            //if (dtLoanEntry.Rows[0]["ManualTimeEntry_Status"] != DBNull.Value)
            //{
            //    if (dtLoanEntry.Rows[0]["ManualTimeEntry_Status"].ToString() != string.Empty)
            //    {
            //        lbl_Status.Text = Convert.ToString(dtLoanEntry.Rows[0]["ManualTimeEntry_Status"]);
            //    }
            //}
            //if (dtLoanEntry.Rows[0]["IsOnDuty"].ToString() == "True")
            //{
            //    lbl_EntryType.Text = "On Duty";
            //}
            //else
            //{
            //    lbl_EntryType.Text = "Manual Entry";
            //}
        }
    }
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        //if (lbl_Status.Text == "Approved")
        //{
        //    base.Message(rm.GetString("Msg_ApprovedManualTimeEntryCannotbemodified", ci));
        //    return;
        //}
        Response.Redirect("../Transactions/TA_UI_Transactions_ManualTimeEntryModify.aspx?MID=" + getLoanID);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Transactions/TA_UI_Transactions_ManualTimeEntry.aspx");
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        //string strScript = string.Empty;
        //if (lbl_Status.Text == "Approved")
        //{
        //    base.Message(rm.GetString("Alert_ApprovedManualTimeEntryCannotbedeleted", ci));
        //    return;
        //}
        //else
        //{
        //    objManualTimeEntry.DeleteManualTimeEntry(gintManualTimeEntryId, gintUserId);
        //    strScript = strScript + "<script language='javascript'>";
        //    strScript = strScript + "alert('" + rm.GetString("Alert_ManualTimeEntryhasbeendeletedsucessfully", ci) + "');";
        //    strScript = strScript + "location.replace('TA_UI_Transactions_ManualTimeEntry.aspx')";
        //    strScript = strScript + "</script>";
        //    Page.RegisterStartupScript("Alert", strScript);
        //}
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(26, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["viewPrv"] == DBNull.Value || Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["viewPrv"]) != 1)
            {
                Response.Redirect("TA_UI_Master_LoanAddDetails.aspx");
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.btn_Modify.Visible = true;
            }
            else
            {
                this.btn_Modify.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_Delete.Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
            }
        }
        else
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    private void loadcss()
    {
        CultureInfo ci;
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        //if Standard Demo
        htmlmanualView.Attributes.Add("dir", rm.GetString("Direction", ci));

        if (source_Language == "Resources.Resource_AR")
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap-rtl.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome-rtl.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min-rtl.css";
            stylecustom.Href = "../dist/css/custom-rtl.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
        else
        {
            stylebootstrap.Href = "../bootstrap/css/bootstrap.min.css";
            stylefontawesome.Href = "../bootstrap/font-awesome/css/font-awesome.css";
            styleAdminLTE.Href = "../dist/css/AdminLTE.min.css";
            stylecustom.Href = "../dist/css/custom.css";
            stylefonts.Href = "../dist/css/fonts.css";
        }
    }

    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_LoanEntry", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_loanAmount.Text = rm.GetString("loan_Amount", ci);
        lbl_DeductionMonth.Text = rm.GetString("loanDeductionMonth", ci);
        lbl_MonthDueAmount.Text = rm.GetString("Loan_DurationMonths", ci);
        lbl_DeductionStartMonth.Text = rm.GetString("loan_DeductStart_Month", ci);
        lbl_loanDescribtion.Text = rm.GetString("loanDescription", ci);
        lbl_BalanceAmount.Text = rm.GetString("loan_BalanceAmount", ci);
        btn_Modify.Text = rm.GetString("btn_Modify", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
    }
}