using System;
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_PenaltyConfiguration : Base.BasePage
{
    PayrollConfiguration_Angler objpayroll = new PayrollConfiguration_Angler();
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objClassCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    ShiftEvenData objShift = new ShiftEvenData();
    CategoryEventData objcat = new CategoryEventData();
    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;        
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);        
        if (!Page.IsPostBack)
        {
            LoadStrings(ci);
            UserRights();
            objClassCommon.menu("Configuration", "266");
            CompanyBinding();
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        lbl_Header.Text = "Penalty Percentage Configuration";
        lblCompany.Text = rm.GetString("EntranceMaster_Company", ci);
        lblLateConfig.Text = "Disruptive - Late Fine Percentage";
        lblHeader2.Text = "Non-Disruptive - Late Fine Percentage";
        lblHeader3.Text = "Disruptive & Non-Disruptive Early Exit Fine Percentage";
        lblNonStartTime.Text = lblStartEarlyExit.Text = lblStartTime.Text = "Start Time (HH:mm)";
        lblNonEndTime.Text = lblEndEarlyExit.Text = lblEndTime.Text = "End Time (HH:mm)";
        lblfirstNonlate.Text = lblFirstEarly.Text = lblfirstlate.Text = "First Time (%)";
        lblSecondNonlate.Text = lblSecondEarly.Text = lblsecondlate.Text = "Second Time (%)";
        lblThirdNonlate.Text = lblThirdEarly.Text = lblThirdlate.Text = "Third Time (%)";
        lblfourthNonlate.Text = lblFourthEarly.Text = lblFourthlate.Text = "Fourth Time (%)";
        btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
    }
    private void CompanyBinding()
    {
        DataSet dsCompany = new DataSet();
        dsCompany = objShift.SelectCompany(Convert.ToString(Session["UserGroupName"]), 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);
        }
    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            try
            {
                int intCompanyId = 0;
                if (ddlCompany.SelectedValue != "0")
                    intCompanyId = Convert.ToInt32(ddlCompany.SelectedValue);
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Alert_Select_Company", ci) + "');", true);
                    return;
                }
                if (Convert.ToString(txtfirstLateStart.Text) == string.Empty || Convert.ToString(txtfirstLateEnd.Text) == string.Empty || Convert.ToString(txtsecondLateStart.Text) == string.Empty || Convert.ToString(txtsecondLateEnd.Text) == string.Empty || Convert.ToString(txtThirdLateStart.Text) == string.Empty || Convert.ToString(txtThirdLateEnd.Text) == string.Empty || Convert.ToString(TxtLateInValue11.Text) == string.Empty || Convert.ToString(TxtLateInValue12.Text) == string.Empty || Convert.ToString(TxtLateInValue13.Text) == string.Empty || Convert.ToString(TxtLateInValue14.Text) == string.Empty || Convert.ToString(TxtLateInValue21.Text) == string.Empty || Convert.ToString(TxtLateInValue22.Text) == string.Empty || Convert.ToString(TxtLateInValue23.Text) == string.Empty || Convert.ToString(TxtLateInValue24.Text) == string.Empty || Convert.ToString(TxtLateInValue31.Text) == string.Empty || Convert.ToString(TxtLateInValue32.Text) == string.Empty || Convert.ToString(TxtLateInValue33.Text) == string.Empty || Convert.ToString(TxtLateInValue34.Text) == string.Empty)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Fill all field value of disruptive late fine percentage');", true);
                    return;
                }
                if (Convert.ToString(txtnonfirstLateStart.Text) == string.Empty || Convert.ToString(txtnonfirstLateEnd.Text) == string.Empty || Convert.ToString(txtnonsecondLateStart.Text) == string.Empty || Convert.ToString(txtnonsecondLateEnd.Text) == string.Empty || Convert.ToString(txtnonthirdLateStart.Text) == string.Empty || Convert.ToString(txtnonthirdLateEnd.Text) == string.Empty || Convert.ToString(TxtnonLateInValue11.Text) == string.Empty || Convert.ToString(TxtnonLateInValue12.Text) == string.Empty || Convert.ToString(TxtnonLateInValue13.Text) == string.Empty || Convert.ToString(TxtnonLateInValue14.Text) == string.Empty || Convert.ToString(TxtnonLateInValue21.Text) == string.Empty || Convert.ToString(TxtnonLateInValue22.Text) == string.Empty || Convert.ToString(TxtnonLateInValue23.Text) == string.Empty || Convert.ToString(TxtnonLateInValue24.Text) == string.Empty || Convert.ToString(TxtnonLateInValue31.Text) == string.Empty || Convert.ToString(TxtnonLateInValue32.Text) == string.Empty || Convert.ToString(TxtnonLateInValue33.Text) == string.Empty || Convert.ToString(TxtnonLateInValue34.Text) == string.Empty)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Fill all field values of Non-disruptive late fine percentage');", true);
                    return;
                }
                if (Convert.ToString(TxtearlyStart.Text) == string.Empty || Convert.ToString(TxtearlyEnd.Text) == string.Empty || Convert.ToString(Txtearly11.Text) == string.Empty || Convert.ToString(Txtearly12.Text) == string.Empty || Convert.ToString(Txtearly12.Text) == string.Empty || Convert.ToString(Txtearly13.Text) == string.Empty || Convert.ToString(Txtearly14.Text) == string.Empty)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Fill all field values of Disruptive and Non-disruptive early exit fine percentage');", true);
                    return;
                }
                else
                {
                    objcat.InsertUpdatePenalty
                        (
                       intCompanyId,
                        1,
                        Convert.ToString(txtfirstLateStart.Text),
                        Convert.ToString(txtfirstLateEnd.Text),
                        Convert.ToString(txtsecondLateStart.Text),
                        Convert.ToString(txtsecondLateEnd.Text),
                        Convert.ToString(txtThirdLateStart.Text),
                        Convert.ToString(txtThirdLateEnd.Text),
                        Convert.ToDecimal(TxtLateInValue11.Text),
                        Convert.ToDecimal(TxtLateInValue12.Text),
                        Convert.ToDecimal(TxtLateInValue13.Text),
                        Convert.ToDecimal(TxtLateInValue14.Text),
                        Convert.ToDecimal(TxtLateInValue21.Text),
                        Convert.ToDecimal(TxtLateInValue22.Text),
                        Convert.ToDecimal(TxtLateInValue23.Text),
                        Convert.ToDecimal(TxtLateInValue24.Text),
                        Convert.ToDecimal(TxtLateInValue31.Text),
                        Convert.ToDecimal(TxtLateInValue32.Text),
                        Convert.ToDecimal(TxtLateInValue33.Text),
                        Convert.ToDecimal(TxtLateInValue34.Text)
                        );

                    objcat.InsertUpdatePenalty
                    (
                        intCompanyId,
                        2,
                    Convert.ToString(txtnonfirstLateStart.Text),
                    Convert.ToString(txtnonfirstLateEnd.Text),
                    Convert.ToString(txtnonsecondLateStart.Text),
                    Convert.ToString(txtnonsecondLateEnd.Text),
                    Convert.ToString(txtnonthirdLateStart.Text),
                    Convert.ToString(txtnonthirdLateEnd.Text),
                    Convert.ToDecimal(TxtnonLateInValue11.Text),
                    Convert.ToDecimal(TxtnonLateInValue12.Text),
                    Convert.ToDecimal(TxtnonLateInValue13.Text),
                    Convert.ToDecimal(TxtnonLateInValue14.Text),
                    Convert.ToDecimal(TxtnonLateInValue21.Text),
                    Convert.ToDecimal(TxtnonLateInValue22.Text),
                    Convert.ToDecimal(TxtnonLateInValue23.Text),
                    Convert.ToDecimal(TxtnonLateInValue24.Text),
                    Convert.ToDecimal(TxtnonLateInValue31.Text),
                    Convert.ToDecimal(TxtnonLateInValue32.Text),
                    Convert.ToDecimal(TxtnonLateInValue33.Text),
                    Convert.ToDecimal(TxtnonLateInValue34.Text)
                    );

                    objcat.InsertUpdatePenalty
                        (
                       intCompanyId,
                        3,
                        Convert.ToString(TxtearlyStart.Text),
                        Convert.ToString(TxtearlyEnd.Text),
                        Convert.ToString(""),
                        Convert.ToString(""),
                        Convert.ToString(""),
                        Convert.ToString(""),
                        Convert.ToDecimal(Txtearly11.Text),
                        Convert.ToDecimal(Txtearly12.Text),
                        Convert.ToDecimal(Txtearly13.Text),
                        Convert.ToDecimal(Txtearly14.Text),
                        Convert.ToDecimal(0),
                        Convert.ToDecimal(0),
                        Convert.ToDecimal(0),
                        Convert.ToDecimal(0),
                        Convert.ToDecimal(0),
                        Convert.ToDecimal(0),
                        Convert.ToDecimal(0),
                        Convert.ToDecimal(0)
                        );
                }
                clearControls();
                string str = "alert('Penalty Percentage configuration saved successfully.');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
            }
            catch (Exception ex)
            {
                Message(ex.ToString());
            }
        }
    }
    private void UserRights()
    {
        if (ViewState["vw_ds_Checkuser"] == null)
        {
            ds_Checkuser = objCheckUser.checkRights(267, Convert.ToInt32(Session["userGroup_Id"]), "addPrv");
            ViewState["vw_ds_Checkuser"] = ds_Checkuser;
        }
        else
            ds_Checkuser = (DataSet)ViewState["vw_ds_Checkuser"];
        if (ds_Checkuser.Tables[0].Rows.Count != 0)
            Response.Redirect("MasterLandingPage.aspx");
    }
    private void clearControls()
    {
        ddlCompany.SelectedIndex = -1;
        txtfirstLateStart.Text = "";
        txtfirstLateEnd.Text = "";
        txtsecondLateEnd.Text = "";
        txtsecondLateStart.Text = "";
        txtThirdLateEnd.Text = "";
        txtThirdLateStart.Text = "";
        TxtLateInValue11.Text = "";
        TxtLateInValue12.Text = "";
        TxtLateInValue13.Text = "";
        TxtLateInValue14.Text = "";
        TxtLateInValue21.Text = "";
        TxtLateInValue22.Text = "";
        TxtLateInValue23.Text = "";
        TxtLateInValue24.Text = "";
        TxtLateInValue31.Text = "";
        TxtLateInValue32.Text = "";
        TxtLateInValue33.Text = "";
        TxtLateInValue34.Text = "";

        txtnonfirstLateEnd.Text = "";
        txtnonfirstLateStart.Text = "";
        txtnonsecondLateEnd.Text = "";
        txtnonsecondLateStart.Text = "";
        txtnonthirdLateEnd.Text = "";
        txtnonthirdLateStart.Text = "";
        txtThirdLateEnd.Text = "";
        txtThirdLateStart.Text = "";
        TxtnonLateInValue11.Text = "";
        TxtnonLateInValue12.Text = "";
        TxtnonLateInValue13.Text = "";
        TxtnonLateInValue14.Text = "";
        TxtnonLateInValue21.Text = "";
        TxtnonLateInValue22.Text = "";
        TxtnonLateInValue23.Text = "";
        TxtnonLateInValue24.Text = "";
        TxtnonLateInValue31.Text = "";
        TxtnonLateInValue32.Text = "";
        TxtnonLateInValue33.Text = "";
        TxtnonLateInValue34.Text = "";

        Txtearly11.Text = "";
        Txtearly12.Text = "";
        Txtearly13.Text = "";
        Txtearly14.Text = "";
        TxtearlyStart.Text = "";
        TxtearlyEnd.Text = "";
    }
}