using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Masters_TA_UI_Master_AttandanceCodeAdd : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objcommon = new cls_Common();
    string strSetAlert;
    protected override void Page_Load(object sender, EventArgs e)
    {        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language
        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;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        LoadStrings(ci);
        //Set UserRights
        UserRights();
        ddlCompany.Focus();
        if (!IsPostBack)
        {
            CompanyBinding();
            btn_add.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave") + "');return false;";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objcommon.menu("Others", "99");
        }
    }
    protected void btn_add_Click(object sender, EventArgs e)
    {
        int iAttandanceID = 0;
        string strAttandanceCode = "";
        string strAttandanceValue = "";
        string strOpr = "";
        int iCompanyID = 0;
        strAttandanceCode = txt_AttandanceCode.Text.Trim().Replace("'", "''");
        strAttandanceValue = Convert.ToString(ddlAttandance.SelectedValue).Trim();
        iCompanyID = Convert.ToInt32(ddlCompany.SelectedValue);
        strOpr = "I";
        string strScript = "";
        DataSet dsCheck = new DataSet();
        AttandanceCodeEventData objClass = new AttandanceCodeEventData();
        dsCheck = objClass.CheckAttandance(iAttandanceID, strAttandanceCode, strAttandanceValue, iCompanyID, strOpr);
        if (dsCheck != null && dsCheck.Tables.Count > 0 && dsCheck.Tables[0].Rows.Count > 0)
        {
            if (dsCheck.Tables[0].Rows[0]["RecCount"] != DBNull.Value)
            {
                if (Convert.ToInt16(dsCheck.Tables[0].Rows[0]["RecCount"]) > 0)
                {
                    strScript = "alert('" + rm.GetString("Alert_AttandanceCodealreadyexists", ci) + "');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", strScript, true);
                    return;
                }
            }
        }
        int EmpID = Convert.ToInt32(Session["EmpAutoID"].ToString());
        objClass.InsertAttandance(strAttandanceCode, strAttandanceValue, iCompanyID, EmpID);
        strScript = "alert('" + rm.GetString("Alert_AttandanceCodesavedsuccessfully", ci) + "');location.replace('TA_UI_Master_AttandanceCode.aspx');";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", strScript, true);
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_Master_AttandanceCode.aspx");
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Attandance.Text = rm.GetString("Attandance", ci);
        lbl_AttandanceCode.Text = rm.GetString("AttandanceCode", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_Header.Text = rm.GetString("AttandanceCode", ci);
        btn_add.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        ddlAttandance.Items[0].Text = rm.GetString("Select", ci);
        ddlAttandance.Items[1].Text = rm.GetString("Dash_Absent", ci);
        ddlAttandance.Items[2].Text = rm.GetString("AttendanceCode_Present", ci);
        ddlAttandance.Items[3].Text = rm.GetString("LeaveApplication_Leave", ci);
        RequiredFieldValidator2.ErrorMessage = rm.GetString("Alert_Select_Company", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Alert_SelectAttandance", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Alert_EnterAttandanceCode", ci);
        ddlCompany.Items[0].Text = rm.GetString("Select", ci);
    }
    private void UserRights()
    {
        Cls_CheckUser objCheckUser = new Cls_CheckUser();
        DataSet ds_Checkuser = new DataSet();
        ds_Checkuser = objCheckUser.checkRights(99, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
        else
        {
            //   
        }
    }
    private void CompanyBinding()
    {
        ShiftEvenData objShift = new ShiftEvenData();
        string gstrUserGroupName = string.Empty;
        DataSet dsCompany = new DataSet();
        gstrUserGroupName = Convert.ToString(Session["UserGroupName"]);
        dsCompany = objShift.SelectCompany(gstrUserGroupName, Convert.ToString(Session["LevelRights"]), 0);
        if (dsCompany != null)
        {
            if (dsCompany.Tables[0].Rows.Count > 0)
            {
                ddlCompany.DataSource = dsCompany;
                ddlCompany.DataTextField = "CompanyName";
                ddlCompany.DataValueField = "CompanyId";
                ddlCompany.DataBind();
            }
        }
        foreach (ListItem item in ddlCompany.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
}
