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_MasterTransportationRouteAdd : Base.BasePage
{
    #region VariableDeclaration
    ResourceManager rm;
    CultureInfo ci;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    cls_Common objCommon = new cls_Common();
    DataSet ds_Checkuser = new DataSet();
    string strSetAlert;
    cls_Master_Transportation objTransportationRoute = new cls_Master_Transportation();
    int Count, EmployeeID;
    #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();
        try
        {
            EmployeeID = Convert.ToInt32(Session["EmpAutoID"].ToString());
        }
        catch (Exception ex)
        {
            Response.Redirect("../Index.aspx");
            Response.Write(ex.ToString());
        }
        if (!IsPostBack)
        {
            fillVehicleddl();
            btn_save.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
    #region ButtonEvents
    protected void btn_save_Click(object sender, EventArgs e)
    {
        int intLevelID = 0;
        int intVehicleID = 0;
        string strRouteName = "";
        string strRouteDesc = "";
        if (Convert.ToInt32(Session["parentLevelId"]) != 0)
        {
            intLevelID = Convert.ToInt32(Session["parentLevelId"]);
            Session["parentLevelId"] = null;
            intVehicleID = Convert.ToInt32(ddl_VehicleNo.SelectedValue);
            strRouteName = txtRouteName.Text.Trim().Replace("'", "''");
            strRouteDesc = txtRouteDesc.Text.Trim().Replace("'", "''");
            Count = objTransportationRoute.CheckRouteName_Insert(intVehicleID, strRouteName);
            if (Count == 0)
            {
                objTransportationRoute.InsertTransportationRouteDetails(intLevelID, intVehicleID, strRouteName, strRouteDesc, EmployeeID);
                base.MessageWithRedirect(rm.GetString("Transportation_Routesavedsuccessfully", ci), "TA_UI_MasterTransportationRouteList.aspx");
            }
            else
            {
                base.Message(rm.GetString("Validator_Route_RouteName_Already_Exists", ci));
            }
        }
        else
        {
            base.Message(rm.GetString("Alert_Selectallorganizationlevels", ci));
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("TA_UI_MasterTransportationRouteList.aspx");
    }
    #endregion
    #region UserDefinedFunctions
    //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_save.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"]), "addPrv");
        if (ds_Checkuser.Tables[0].Rows.Count == 0)
        {
            Response.Redirect("MasterLandingPage.aspx");
        }
    }
    #endregion
}