//public void btnSearchLocationAdd_Click(object sender, EventArgs e)
        //{
        //    AddNewLocationRequest objAddLocationRequest = new AddNewLocationRequest();
        //    location objlocation = new location();
        //    objlocation.loc = txtAddLocationName.Text;

        //        AdminBLL ws=new AdminBLL();
        //        ws.AddLocation(objlocation);
        //        HttpContext.Current.Items.Add("COMPLETE", "INSERT");
        //        Server.Transfer("..//SMSADMIN//AddNewUserComplete.aspx");

        //}

        protected void Add_AdminLocation(object sender, EventArgs e)
        {
            AddNewLocationRequest objAddLocationRequest = new AddNewLocationRequest();
            LocationData          objlocation           = new LocationData();

            objlocation.locid = "12";
            objlocation.loc   = txtAddLocationName.Text;

            AdminBLL ws = new AdminBLL();

            ws.AddLocation(objlocation);
            HttpContext.Current.Items.Add("COMPLETE", "INSERT");
            Server.Transfer("..//SMSADMIN//AddNewUserComplete.aspx");
        }
        protected void btnSearchLocationAdd_Click(object sender, EventArgs e)
        {
            log4net.ILog logger = log4net.LogManager.GetLogger("File");
            try
            {
                AddNewLocationRequest objAddLocationRequest = new AddNewLocationRequest();
                LocationData          objlocation           = new LocationData();
                //-------------------------------------------------------------------------------
                DBConnectionHandler1 db = new DBConnectionHandler1();
                SqlConnection        cn = db.getconnection();
                cn.Open();
                if (cn.State == ConnectionState.Open)
                {
                }
                else
                {
                    cn.Open();
                }
                SqlCommand    cmd = new SqlCommand("select max(Location_id) from location", cn);
                SqlDataReader dr  = cmd.ExecuteReader();
                if (dr.Read())
                {
                    int maxid  = dr.GetInt32(0);
                    int maxid1 = maxid + 1;
                    if (maxid1.ToString().Length == 1)
                    {
                        Session["Assigncode"] = "ASS1000" + maxid1.ToString();
                    }
                    else if (maxid1.ToString().Length == 2)
                    {
                        Session["Assigncode"] = "ASS100" + maxid1.ToString();
                    }
                    else if (maxid1.ToString().Length == 3)
                    {
                        Session["Assigncode"] = "ASS10" + maxid1.ToString();
                    }
                    else
                    {
                    }
                }
                cmd.Dispose();
                dr.Close(); cn.Close();

                //--------------------------------------------------------------------------------


                if (txtAddLocation.Text.Trim() != "")
                {
                    if (txtClientUserID.Text != "" && txtClientPassword.Text != "")
                    {
                        if (Regex.IsMatch(txtAddLocation.Text, ZipRegexboth))
                        {
                            int k = chkloc(txtAddLocation.Text.Trim().ToString(), txtsiteaddres.Text.Trim().ToString());
                            if (k > 0)
                            {
                                lblerror.Visible = true;
                                lblerror.Text    = "Site Name Already Exist ..!";
                                throw new Exception();
                            }
                        }


                        objlocation.Location_name = txtAddLocation.Text.Trim();
                        objlocation.code          = Session["Assigncode"].ToString();
                        Session["Location_name"]  = txtAddLocation.Text.Trim();
                        objlocation.Loc_Address   = txtsiteaddres.Text.Trim();

                        objlocation.F_cont  = txtFinanceContactTel.Text.Trim();
                        objlocation.F_Mob   = txtFinanceContactMob.Text.Trim();
                        objlocation.F_Email = txtFinanceContactEmail.Text.Trim();
                        objlocation.F_Fax   = txtFinanceContactFax.Text.Trim();

                        objlocation.O_cont  = txtOperationsContactTelephone.Text.Trim();
                        objlocation.O_Mob   = txtOperationsContactMobile.Text.Trim();
                        objlocation.O_Email = txtOperationsContactEmail.Text.Trim();
                        objlocation.O_Fax   = txtOperationsContactFax.Text.Trim();

                        objlocation.M_cont  = txtlblManagementContactTelephone.Text.Trim();
                        objlocation.F_Mob   = txtManagementContactMobile.Text.Trim();
                        objlocation.F_Email = txtManagementContactEmail.Text.Trim();
                        objlocation.F_Fax   = txtManagementContactFax.Text.Trim();

                        objlocation.Emergency_email    = txtEmergencyContactEmail.Text.Trim();
                        objlocation.Chift_Security_day = txtChiefSecurityRequiredDay1.Text.Trim();
                        objlocation.Chift_Security_nig = txtChiefSecurityRequiredEvening.Text.Trim();

                        objlocation.Security_Off_day = txtSODay.Text.Trim();
                        objlocation.Security_Off_nig = txtSONight.Text.Trim();

                        objlocation.Senior_Secu_Off_day = TxtSSODay.Text.Trim();
                        objlocation.Senior_Secu_Off_nig = txtSSONight.Text.Trim();

                        objlocation.Supervisor_day = txtsupervisorrequiredDay.Text.Trim();
                        objlocation.Supervisor_nig = txtSupervisorRequireNight.Text.Trim();

                        objlocation.Contract_value = txtContractValue.Text.Trim();
                        //  string sdate = txtdatefrom.Text.Trim() != "" ? txtdatefrom.Text : "NULL";
                        if (txtdatefrom.Text.Trim() != "")
                        {
                            objlocation.Contract_start_date = Convert.ToDateTime(txtdatefrom.Text);
                        }

                        if (txtdateto.Text.Trim() != "")
                        {
                            objlocation.Contract_expire_date = Convert.ToDateTime(txtdateto.Text);
                        }

                        objlocation.Date_From = Convert.ToDateTime(DateTime.Now);

                        objlocation.Finance_Name    = txtFinaceName.Text.Trim();
                        objlocation.Operation_Name  = txtOperationName.Text.Trim();
                        objlocation.Management_Name = txtManagementName.Text.Trim();

                        objlocation.OtherPerson1     = txtOther1.Text.Trim();
                        objlocation.OtherPerson1_day = txtOther1_day.Text.Trim();
                        objlocation.OtherPerson1_nig = txtOther1_nig.Text.Trim();

                        objlocation.OtherPerson2     = txtOther2.Text.Trim();
                        objlocation.OtherPerson2_day = txtOther2_day.Text.Trim();
                        objlocation.OtherPerson2_nig = txtOther2_nig.Text.Trim();

                        objlocation.OtherPerson3     = txtOther3.Text.Trim();
                        objlocation.OtherPerson3_day = txtOther3_day.Text.Trim();
                        objlocation.OtherPerson3_nig = txtOther3_nig.Text.Trim();

                        objlocation.ClientUserID   = txtClientUserID.Text;
                        objlocation.ClientPassword = txtClientPassword.Text;

                        objlocation.Current_Status = "Present";

                        AdminBLL ws = new AdminBLL();
                        ws.AddLocation(objlocation);

                        getStaffID();
                        getLocationID();
                        Dal.executesql("Insert into UserInformation(UserID,UserPassword,NRICno,Role,Staff_ID) values('" + txtClientUserID.Text + "','" + txtClientPassword.Text + "','1111','Client','" + Staff_ID + "')");
                        Dal.executesql("Insert into StaffLocationMap(StaffID,LocationID) values('" + Staff_ID + "','" + Location_ID + "')");
                        btnNextLocationAdd.Enabled  = true;
                        btnClearLocationAdd.Enabled = true;
                        HttpContext.Current.Items.Add("COMPLETE", "INSERT");
                        lblerror.Visible = true;
                        lblerror.Text    = "Add Record Successfully";
                        //Response.Redirect("CompleteForm.aspx");
                        // Server.Transfer("..//SMSAdmin//AlertUpdateComplete.aspx");
                    }
                    else
                    {
                        lblerror.Visible = true;
                        lblerror.Text    = "Please Fill UserID & Password ..!";
                    }
                }
                else
                {
                    lblerror.Visible = true;
                    lblerror.Text    = "Fill Site Name ..!";
                    lblerr.Visible   = true;
                }
            }
            catch (Exception ex)
            {
                logger.Info(ex.Message);
            }



            //TabContainer1.ActiveTabIndex = 1;
        }
        protected void Add_Location(object sender, EventArgs e)
        {
            log4net.ILog logger = log4net.LogManager.GetLogger("File");
            try
            {
                AddNewLocationRequest objAddLocationRequest = new AddNewLocationRequest();
                LocationData          objlocation           = new LocationData();
                String zipreg       = "^[a-z A-Z]+$";
                String ZipRegex     = "^[0-9]+$";
                String ZipRegexboth = "^[a-z A-Z 0-9]+$";

                // if (Regex.IsMatch(txtAddLocationName.Text, ZipRegexboth))
                // {
                if (Regex.IsMatch(txtAddLocationName1.Text, zipreg))
                {
                    column = "locid";
                    table  = "location";
                    where  = "where locid='" + txtAddLocationName.Text + "'";
                    if (b.isexistBLL(column, table, where))
                    {
                        lblerror.Visible = true;
                        lblerror.Text    = "Location Code Already Exist ..!";
                        lblerr.Visible   = true;
                        throw new Exception();
                    }

                    column = "loc";
                    table  = "location";
                    where  = "where loc='" + txtAddLocationName1.Text + "'";
                    if (b.isexistBLL(column, table, where))
                    {
                        lblerror.Visible = true;
                        lblerror.Text    = "Location Name Already Exist ..!";
                        lblerr2.Visible  = true;
                        throw new Exception();
                    }



                    objlocation.locid     = txtAddLocationName.Text;
                    objlocation.loc       = txtAddLocationName1.Text;
                    objlocation.Date_From = Convert.ToDateTime(DateTime.Now);

                    AdminBLL ws = new AdminBLL();
                    ws.AddLocation(objlocation);
                    UpdateAutogenCode();
                    HttpContext.Current.Items.Add("COMPLETE", "INSERT");
                    Server.Transfer("..//SMSADMIN//AlertUpdateComplete.aspx");
                }
                else
                {
                    lblerror.Visible = true;
                    lblerror.Text    = "Invalid Location Name ..!";
                    lblerr2.Visible  = true;
                }
                //}
                //else
                //{
                //    lblerror.Visible = true;
                //    lblerror.Text = "Invalid Location Code ..!";
                //    lblerr.Visible = true;
                //}
            }
            catch (Exception ex)
            {
                logger.Info(ex.Message);
            }
        }