using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Globalization;
using System.Threading;
using System.Reflection;
using System.Resources;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                                          Started Date  : 18-July-2007
* Module          : Manual Time Entry                                                  Last Modified : 29-Aug-2007
* Programmer      : Kumuthini.L
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          : \\windev\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
****************************************************************************************************************************/
public partial class Transactions_Transaction_ManualTimeEntryView : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    CultureInfo ci;
    ManualEntryEventData objManualTimeEntry = new ManualEntryEventData();
    Int64 gintManualTimeEntryId, gintUserId;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    DataSet dsManualTimeEntry;
    string NewTimeFormat = string.Empty;
    #endregion
    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;
        
        gintManualTimeEntryId = Convert.ToInt64(Request.QueryString["MID"]);
        gintUserId = Int32.Parse(Session["EmpAutoID"].ToString());
        btn_Modify.Focus();
        loadcss();
        if (Session["ITimeFormat"].ToString() == "%H:%M")
        {
            NewTimeFormat = "HH:mm:ss";
        }
        else
        {
            NewTimeFormat = "hh:mm:ss tt";
        }
        if (!Page.IsPostBack)
        {
            UserRights();
            LoadStrings(ci);            
            GetManualEntryDetails();
        }
        int intIndividualUser = objCheckUser.CheckIndividualUser(Convert.ToString(Session["UserGroupName"]));
        if (intIndividualUser >= 1)
        {
            btn_Modify.Enabled = false;
            btn_Delete.Enabled = false;
        }
    }
    // **********************************************************************************************************************
    // Function Name : GetManualEntryDetails
    // Purpose :
    //     The GetManualEntryDetails Method is used to get the Details of the Manual Time Entry for a particular 
    //     Manual Time Entry ID and the details are assigned to the appropriate Labels for Viewing
    // **********************************************************************************************************************
    private void GetManualEntryDetails()
    {
        dsManualTimeEntry = new DataSet();
        DataTable dtManualTimeEntry = new DataTable();
        dsManualTimeEntry = objManualTimeEntry.SelectManualEntryById(gintManualTimeEntryId);
        dtManualTimeEntry = dsManualTimeEntry.Tables[0];
        if (dtManualTimeEntry.Rows.Count > 0)
        {
            if (dtManualTimeEntry.Rows[0]["Employee_Code_Id"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Employee_Code_Id"].ToString() != string.Empty)
                {
                    lbl_EmpId.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Code_Id"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Employee_Name"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Employee_Name"].ToString() != string.Empty)
                {
                    lbl_EmpName.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Employee_Name"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Mdate"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Mdate"].ToString() != string.Empty)
                {
                    lbl_EntryDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Mdate"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["InDate"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["InDate"].ToString() != string.Empty)
                {
                    lbl_InDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["InDate"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_InTime"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_InTime"].ToString() != string.Empty)
                {
                    lbl_InTime.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["ManualTimeEntry_InTime"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_InPunchType"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_InPunchType"].ToString() != string.Empty)
                {
                    lbl_InPunchType.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["ManualTimeEntry_InPunchType"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["OutDate"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["OutDate"].ToString() != string.Empty)
                {
                    lbl_OutDate.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["OutDate"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_OutTime"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_OutTime"].ToString() != string.Empty)
                {
                    lbl_OutTime.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["ManualTimeEntry_OutTime"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_OutPunchType"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_OutPunchType"].ToString() != string.Empty)
                {
                    lbl_OutPunchType.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["ManualTimeEntry_OutPunchType"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_Reason"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_Reason"].ToString() != string.Empty)
                {
                    lbl_Reason.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["ManualTimeEntry_Reason"]);
                    lbl_Reason.ToolTip = Convert.ToString(dtManualTimeEntry.Rows[0]["ManualTimeEntry_Reason"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["Entrance_Name"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["Entrance_Name"].ToString() != string.Empty)
                {
                    lbl_EntranceName.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["Entrance_Name"]);
                }
            }
            if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_Status"] != DBNull.Value)
            {
                if (dtManualTimeEntry.Rows[0]["ManualTimeEntry_Status"].ToString() != string.Empty)
                {
                    lbl_Status.Text = Convert.ToString(dtManualTimeEntry.Rows[0]["ManualTimeEntry_Status"]);
                }
            }
            if (dtManualTimeEntry.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=" + gintManualTimeEntryId);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Transactions/TA_UI_Transactions_ManualTimeEntry.aspx");
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = rm.GetString("UserGroups_ManualTimeEntry", ci);
        lbl_EmployeeId.Text = rm.GetString("email_EmployeeId", ci);
        lbl_EmployeeName.Text = rm.GetString("email_EmployeeName", ci);
        lbl_EntranceName1.Text = rm.GetString("EntranceMaster_Entrance_Name", ci);
        lbl_InDate1.Text = rm.GetString("ManualTimeEntry_InDate", ci);
        lbl_InTime1.Text = rm.GetString("ManualTimeEntry_InTime", ci);
        lbl_InPunchType1.Text = rm.GetString("ManualTimeEntry_InPunchType", ci);
        lbl_ManualTimeEntryDate.Text = rm.GetString("ManualTimeEntry_ManualTimeEntryDate", ci);
        lbl_OutDate1.Text = rm.GetString("ManualTimeEntry_OutDate", ci);
        lbl_OutTime1.Text = rm.GetString("ManualTimeEntry_OutTime", ci);
        lbl_OutPunchType1.Text = rm.GetString("ManualTimeEntry_OutPunchType", ci);
        lbl_Reason1.Text = rm.GetString("email_Reason", ci);
        lbl_Status1.Text = rm.GetString("email_Status", ci);
        lblEntryType.Text = rm.GetString("ManualTimeEntryType", 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);
    }
    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_Transactions_ManualTimeEntry.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("TransactionLandingPage.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 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";
        }
    }
}