using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                   Started Date  : 12-Aug-2007
* Module          : Vehicle Master                              Last Modified : 14-Aug-2007
* Programmer      : 
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Master_TA_UI_MasterTransportationVehicleModify : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    string strSetAlert;
    cls_Master_Transportation objTransportationVehicle = new cls_Master_Transportation();
    int VehId, Count, EmployeeID;
    DataSet ds_TransVehicle = new DataSet();
    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();
        txtVehicleNo.Focus();
        VehId = Convert.ToInt32(Request.QueryString["VehicleId"].ToString());
        EmployeeID = Convert.ToInt32(Session["EmpAutoID"].ToString());
        if (!IsPostBack)
        {
            loadTransPortationVehicleDetails(VehId);
            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", "230");
        }
    }
    private void loadTransPortationVehicleDetails(int id)
    {
        ds_TransVehicle = objTransportationVehicle.SelectTransportationVehicleDetailsById(id);
        if (ds_TransVehicle.Tables[0].Rows.Count > 0)
        {
            txtVehicleNo.Text = ds_TransVehicle.Tables[0].Rows[0]["VehicleNo"].ToString();
            txtVehicleDesc.Text = ds_TransVehicle.Tables[0].Rows[0]["VehicleDescription"].ToString();
        }
    }
    protected void btn_save_Click(object sender, EventArgs e)
    {
        Count = objTransportationVehicle.CheckVehicleNO_Update(txtVehicleNo.Text.Trim().Replace("'", "''"), VehId);
        if (Count == 0)
        {
            objTransportationVehicle.UpdateTransportationVehicleDetails(txtVehicleNo.Text.Trim().Replace("'", "''"), txtVehicleDesc.Text.Trim().Replace("'", "''"), VehId, EmployeeID);
            //Response.Redirect("TA_UI_MasterTransportationVehicleView.aspx?VehicleId=" + VehId);
            string strRedirectPage = "TA_UI_MasterTransportationVehicleList.aspx";
            // base.MessageWithRedirect("Vehicle modified successfully", strRedirectPage);
            base.MessageWithRedirect(rm.GetString("Alert_Vehiclemodifiedsuccessfully", ci), strRedirectPage);
        }
        else
        {
            //lblerror.Text = rm.GetString("Vehicle_Master_Vehicle_No_Already_Exits", ci);
            base.Message(rm.GetString("Vehicle_Master_Vehicle_No_Already_Exits", ci));
        }
    }
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        //Response.Redirect("TA_UI_MasterTransportationVehicleList.aspx");
        Response.Redirect("TA_UI_MasterTransportationVehicleList.aspx");
    }
    //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_VehicleDescription.Text = rm.GetString("Vehicle_Master_Vehicle_Desc", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        ReqVehNo.ErrorMessage = rm.GetString("Validator_Vehicle_VehicleNo", ci);
        lbl_TransportationVehicle.Text = rm.GetString("Masters_Transportation_Vehicle_Master", ci);
        btn_save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Cancel.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Back", 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");
        }
        else
        {
            //   
        }
    }
}
