using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
using System.Web.UI.WebControls;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Route Master                                Last Modified : 14-Aug-2007
* Programmer      : 
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Master_TA_UI_MasterTransportationRouteModify : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string strSetAlert;
    cls_Master_Transportation objTransportationRoute = new cls_Master_Transportation();
    cls_Master_Title objddlDetails = new cls_Master_Title();
    int Route_Id, Count, EmployeeID;
    cls_Common objCommon = new cls_Common();
    DataSet ds_TransRoute = new DataSet();
    #endregion
    #region PageLoad
    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 Function fills the Label from the Resource File
        LoadStrings(ci);
        //Set UserRights
        UserRights();
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"].ToString());
        Route_Id = Convert.ToInt32(Request.QueryString["RouteId"].ToString());
        if (!IsPostBack)
        {
            fillVehicleddl();
            loadTransPortationRouteDetails(Route_Id);
            btn_Modify.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            objCommon.menu("Transportation", "231");
        }
    }
    #endregion
    private void loadTransPortationRouteDetails(int id)
    {
        ds_TransRoute = objTransportationRoute.SelectTransportationRouteDetailsById(id);
        if (ds_TransRoute.Tables[0].Rows.Count > 0)
        {
            Session["parentLevelId_modify"] = ds_TransRoute.Tables[0].Rows[0]["Level_ID"].ToString();
            ddl_VehicleNo.SelectedValue = ds_TransRoute.Tables[0].Rows[0]["VehicleID"].ToString();
            txt_RouteName.Text = ds_TransRoute.Tables[0].Rows[0]["Route_Name"].ToString();
            txtRouteDesc.Text = ds_TransRoute.Tables[0].Rows[0]["Route_Description"].ToString();
        }
        ds_TransRoute.Dispose();
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_MasterTransportationRouteList.aspx");
    }
    protected void btn_Modify_Click(object sender, EventArgs e)
    {
        Count = objTransportationRoute.CheckRouteName_Update(txt_RouteName.Text.Trim().Replace("'", "''"), Route_Id);
        if (Convert.ToInt32(Session["parentLevelId"]) != 0)
        {
            int LevelID = Convert.ToInt32(Session["parentLevelId"]);
            Session["parentLevelId"] = null;
            if (Count == 0)
            {
                objTransportationRoute.UpdateTransportationRouteDetails(LevelID, Convert.ToInt32(ddl_VehicleNo.SelectedValue), txt_RouteName.Text.Trim().Replace("'", "''"), txtRouteDesc.Text.Trim().Replace("'", "''"), EmployeeID, Route_Id);
                string strRedirectPage = "TA_UI_MasterTransportationRouteList.aspx";
                base.MessageWithRedirect(rm.GetString("Alert_Routemodifiedsuccessfully", ci), strRedirectPage);
            }
            else
            {
                base.Message(rm.GetString("Validator_Route_RouteName_Already_Exists", ci));
            }
        }
        else
        {
            base.Message(rm.GetString("Alert_Selectallorganizationlevels", ci));
        }
    }
    //fill vehicle dropdown
    private void fillVehicleddl()
    {
        DataSet ds_Vehicles = new DataSet();
        string UserGroupName = string.Empty;
        ds_Vehicles = objTransportationRoute.SelectTransportationVehicleDetails(UserGroupName);
        if (ds_Vehicles.Tables[0].Rows.Count > 0)
        {
            ddl_VehicleNo.DataSource = ds_Vehicles;
            ddl_VehicleNo.DataTextField = "VehicleNo";
            ddl_VehicleNo.DataValueField = "VehicleId";
            ddl_VehicleNo.DataBind();
        }
        ds_Vehicles.Dispose();
        foreach (ListItem item in ddl_VehicleNo.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    //Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lbl_VehicleNo.Text = rm.GetString("Vehicle_Master_Vehicle_No", ci);
        lbl_RouteName.Text = rm.GetString("Transportation_Route_RouteName", ci);
        lbl_RouteDescription.Text = rm.GetString("Transportation_Route_RouteDesc", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Validator_Route_VehicleNo", ci);
        RequiredFieldValidator3.ErrorMessage = rm.GetString("Validator_Route_RouteName", ci);
        lbl_HeaderTransportationRoute.Text = rm.GetString("Masters_Transportation_Route_Master", ci);
        btn_Modify.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", ci);
        ddl_VehicleNo.Items[0].Text = rm.GetString("Select", ci);
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(12, Convert.ToInt32(Session["userGroup_Id"]), "modifyPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
}