protected void btnAdd_Click(object sender, EventArgs e)
        {
            Attendance.Entities.UserInfo objInfo = new UserInfo();
            Attendance.Entities.EmergencyContactInfo objContactInfo = new EmergencyContactInfo();
            try
            {
                Attendance.BAL.Report obj = new Report();

                objInfo.Firstname = txtAddFirstName.Text == "" ? "" : GeneralFunction.ToProper(txtAddFirstName.Text.Trim()).Trim();
                objInfo.Lastname = txtAddLastName.Text == "" ? "" : GeneralFunction.ToProper(txtAddLastName.Text.Trim()).Trim();
                string PhotoLink = "defaultUSer.jpg";

                try
                {
                    if (photoUpload.HasFile)
                    {
                        string filePhotoName = photoUpload.FileName;
                        string Photoextension = System.IO.Path.GetExtension(filePhotoName);
                        if (Photoextension == ".jpg" || Photoextension == ".png" || Photoextension == ".jpeg" || Photoextension == ".JPG" || Photoextension == ".PNG" || Photoextension == ".JPEG")
                        {

                            string SaveFileLoc = Server.MapPath("~/Photos/");
                            if (System.IO.Directory.Exists(SaveFileLoc) == false)
                            {
                                System.IO.Directory.CreateDirectory(SaveFileLoc);
                            }

                            string FileNameSaveData = SaveFileLoc + (objInfo.Firstname.Trim() + objInfo.Lastname.Trim()).Trim() + ".jpeg";
                            PhotoLink = (objInfo.Firstname.Trim() + objInfo.Lastname.Trim()).Trim() + ".jpeg";

                            photoUpload.SaveAs(FileNameSaveData);
                            Bitmap oBitmap = default(Bitmap);
                            oBitmap = new Bitmap(FileNameSaveData);
                            Graphics oGraphic = default(Graphics);

                            int newwidthimg = 140;
                            // Here create a new bitmap object of the same height and width of the image.
                            //float AspectRatio = (float)oBitmap.Size.Width / (float)oBitmap.Size.Height;
                            //int newHeight = Convert.ToInt32(newwidthimg / AspectRatio);
                            int newHeight = 140;

                            Bitmap bmpNew = new Bitmap(newwidthimg, newHeight);
                            oGraphic = Graphics.FromImage(bmpNew);

                            oGraphic.CompositingQuality = CompositingQuality.HighQuality;
                            oGraphic.SmoothingMode = SmoothingMode.HighQuality;
                            oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;


                            oGraphic.DrawImage(oBitmap, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), 0, 0, oBitmap.Width, oBitmap.Height, GraphicsUnit.Pixel);
                            // Release the lock on the image file. Of course,
                            // image from the image file is existing in Graphics object
                            oBitmap.Dispose();
                            oBitmap = bmpNew;

                            //SolidBrush oBrush = new SolidBrush(Color.Black);
                            //Font ofont = new Font("Arial", 8);
                            //oGraphic.DrawString("Some text to write", ofont, oBrush, 10, 10);
                            //oGraphic.Dispose();
                            //ofont.Dispose();
                            //oBrush.Dispose();
                            oBitmap.Save(FileNameSaveData, ImageFormat.Jpeg);

                            oBitmap.Dispose();

                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "alert('File access denied');", true);
                }

                int UserID = Convert.ToInt32(Session["UserID"]);
                //objInfo.EmpID = txtAddEmpID.Text.Trim();
                objInfo.Deptname = ddlDeptment.SelectedItem.Text.ToString();
                objInfo.Designation = txtDesignation.Text == "" ? "" : GeneralFunction.ToProper(txtDesignation.Text.Trim());
                objInfo.ScheduleID = Convert.ToInt32(ddlSchedule.SelectedItem.Value);
                objInfo.StartDt = txtStartDt.Text == "" ? Convert.ToDateTime("01/01/1900") : Convert.ToDateTime(txtStartDt.Text);
                if (rdActiveFalse.Checked == true)
                {
                    objInfo.IsActive = false;
                }
                else
                {
                    objInfo.IsActive = true;
                }



                if (rdGenderMale.Checked == true)
                {
                    objInfo.Gender = "Male";
                }
                else
                {
                    objInfo.Gender = "Female";
                }

                if (rdMarriedSingle.Checked == true)
                {
                    objInfo.MaritalID = 1;
                }
                else
                {
                    objInfo.MaritalID = 2;
                }


                objInfo.DateOfBirth = txtDateOfBirth.Text.ToString() == "" ? Convert.ToDateTime("01/01/1900") : Convert.ToDateTime(txtDateOfBirth.Text);
                objInfo.Phone = txtEmpPhone.Text;
                objInfo.Mobile = txtEmpMobile.Text;
                objInfo.BusinessEmail = txtBusinessEmail.Text;
                objInfo.PersonalEmail = txtPersonalEmail.Text;
                objInfo.WageID = Convert.ToInt32(ddlWagetype.SelectedItem.Value);
                objInfo.Salary = txtsalary.Text.Trim();
                objInfo.Deductions = Convert.ToInt32(ddlDeductions.SelectedItem.Value);
                objInfo.County = txtCounty.Text.Trim();

                objContactInfo.Person1 = txtCn1Name.Text.ToString() == "" ? "" : GeneralFunction.ToProper(txtCn1Name.Text.ToString().Trim());
                objContactInfo.P1Address1 = GeneralFunction.ToProperNotes(txtCn1Address1.Text.ToString().Trim());
                objContactInfo.P1Address2 = GeneralFunction.ToProperNotes(txtCn1Address2.Text.ToString().Trim());
                objContactInfo.Phone1 = txtCn1Phone.Text.ToString().Trim();
                objContactInfo.Relation1 = GeneralFunction.ToProperNotes(txtCn1Relation.Text.ToString().Trim());
                objContactInfo.Email1 = txtCn1Email.Text.ToString().Trim();
                objContactInfo.StateID1 = Convert.ToInt32(ddlCn1State.SelectedItem.Value);
                // objContactInfo.Zip1 = txtCn1Zip.Text.Trim();

                if (txtCn1Zip.Text != "" && txtCn1Zip.Text.Trim().Length == 4)
                {
                    objContactInfo.Zip1 = "0" + txtCn1Zip.Text.Trim();
                }
                else
                {
                    objContactInfo.Zip1 = txtCn1Zip.Text.Trim();
                }


                objContactInfo.Person2 = txtCn2Name.Text.ToString() == "" ? "" : GeneralFunction.ToProper(txtCn2Name.Text.ToString().Trim());
                objContactInfo.P2Address1 = GeneralFunction.ToProperNotes((txtCn2Address1.Text.ToString().Trim()));
                objContactInfo.P2Address2 = GeneralFunction.ToProperNotes(txtCn2Address2.Text.ToString().Trim());
                objContactInfo.Phone2 = txtCn2Phone.Text.ToString().Trim();
                objContactInfo.Relation2 = GeneralFunction.ToProperNotes(txtCn2Relation.Text.ToString().Trim());
                objContactInfo.Email2 = txtCn2Email.Text.ToString().Trim();
                objContactInfo.StateID2 = Convert.ToInt32(ddlCn2State.SelectedItem.Value);
                if (txtCn2Zip.Text != "" && txtCn2Zip.Text.Trim().Length == 4)
                {
                    objContactInfo.Zip2 = "0" + txtCn2Zip.Text.Trim();
                }
                else
                {
                    objContactInfo.Zip2 = txtCn2Zip.Text.Trim();
                }


                objContactInfo.Person3 = txtCn3Name.Text.ToString() == "" ? "" : GeneralFunction.ToProper(txtCn3Name.Text.ToString().Trim());
                objContactInfo.P3Address1 = GeneralFunction.ToProperNotes(txtCn3Address1.Text.ToString().Trim());
                objContactInfo.P3Address2 = GeneralFunction.ToProperNotes(txtCn3Address2.Text.ToString().Trim());
                objContactInfo.Phone3 = txtCn3Phone.Text.ToString().Trim();
                objContactInfo.Relation3 = GeneralFunction.ToProperNotes(txtCn3Relation.Text.ToString().Trim());
                objContactInfo.Email3 = txtCn3Email.Text.ToString().Trim();
                objContactInfo.StateID3 = Convert.ToInt32(ddlCn3State.SelectedItem.Value);
                if (txtCn3Zip.Text != "" && txtCn3Zip.Text.Trim().Length == 4)
                {
                    objContactInfo.Zip3 = "0" + txtCn3Zip.Text.Trim();
                }
                else
                {
                    objContactInfo.Zip3 = txtCn3Zip.Text.Trim();
                }


                string LocationName = ddlLocation.SelectedItem.Text.ToString().Trim();
                if (LocationName.Trim().ToUpper() == "INBH" || LocationName.Trim().ToUpper() == "INDG")
                {
                    objInfo.SSN = "";
                }
                else
                {
                    objInfo.SSN = txtEmpSSN.Text.Trim();
                }
                objInfo.Address1 = GeneralFunction.ToProperNotes(txtEmpAddress1.Text.ToString().Trim());
                objInfo.Address2 = GeneralFunction.ToProperNotes(txtEmpAddress2.Text.ToString().Trim());
                objInfo.StateID = Convert.ToInt32(ddlEmpState.SelectedItem.Value);
                if (txtEmpZip.Text != "" && txtEmpZip.Text.Trim().Length == 4)
                {
                    objInfo.Zip = "0" + txtEmpZip.Text.Trim();
                }
                else
                {
                    objInfo.Zip = txtEmpZip.Text.Trim();
                }
                objInfo.DriverLicense = txtEmpDriveLicense.Text.Trim();
                objInfo.EmpTypeID = Convert.ToInt32(ddlEmpType.SelectedItem.Value);

                if (objInfo.SSN != "")
                {
                    if (obj.CheckUniqueSSN(objInfo.SSN.Trim()))
                    {

                        bool bnew = obj.AddUser(objInfo, objContactInfo, UserID, LocationName, PhotoLink);
                        if (bnew)
                        {
                            txtAddFirstName.Text = "";
                            txtAddLastName.Text = "";
                            txtBusinessEmail.Text = "";
                            txtDateOfBirth.Text = "";
                            txtDesignation.Text = "";
                            txtEmpAddress1.Text = "";
                            txtEmpAddress2.Text = "";
                            txtEmpDriveLicense.Text = "";
                            txtEmpMobile.Text = "";
                            txtEmpPhone.Text = "";
                            txtEmpSSN.Text = "";
                            txtEmpZip.Text = "";

                            txtCn1Address1.Text = "";
                            txtCn1Address2.Text = "";
                            txtCn1Email.Text = "";
                            txtCn1Name.Text = "";
                            txtCn1Phone.Text = "";
                            txtCn1Relation.Text = "";

                            txtCn2Address1.Text = "";
                            txtCn2Address2.Text = "";
                            txtCn2Email.Text = "";
                            txtCn2Name.Text = "";
                            txtCn2Phone.Text = "";
                            txtCn2Relation.Text = "";

                            txtCn3Address1.Text = "";
                            txtCn3Address2.Text = "";
                            txtCn3Email.Text = "";
                            txtCn3Name.Text = "";
                            txtCn3Phone.Text = "";
                            txtCn3Relation.Text = "";

                            ddlDeptment.SelectedIndex = 0;
                            ddlEmpState.SelectedIndex = 0;
                            ddlEmpType.SelectedIndex = 0;
                            ddlSchedule.SelectedIndex = 0;

                            mdlAddPopUp.Hide();
                            GetUserDetails(Convert.ToInt32(Session["SortBy"]),ddlLocation.SelectedItem.Text.ToString().Trim());
                        }
                    }
                    else
                    {
                        lblError.Visible = true;
                        lblError.Text = "Employee details are not added. SSN is already existed";
                        txtEmpSSN.Text = "";
                        txtEmpSSN.Focus();
                        mdlAddPopUp.Show();
                    }
                }
                else
                {
                    bool bnew = obj.AddUser(objInfo, objContactInfo, UserID, LocationName, PhotoLink);
                    if (bnew)
                    {
                        txtAddFirstName.Text = "";
                        txtAddLastName.Text = "";
                        txtBusinessEmail.Text = "";
                        txtDateOfBirth.Text = "";
                        txtDesignation.Text = "";
                        txtEmpAddress1.Text = "";
                        txtEmpAddress2.Text = "";
                        txtEmpDriveLicense.Text = "";
                        txtEmpMobile.Text = "";
                        txtEmpPhone.Text = "";
                        txtEmpSSN.Text = "";
                        txtEmpZip.Text = "";

                        txtCn1Address1.Text = "";
                        txtCn1Address2.Text = "";
                        txtCn1Email.Text = "";
                        txtCn1Name.Text = "";
                        txtCn1Phone.Text = "";
                        txtCn1Relation.Text = "";

                        txtCn2Address1.Text = "";
                        txtCn2Address2.Text = "";
                        txtCn2Email.Text = "";
                        txtCn2Name.Text = "";
                        txtCn2Phone.Text = "";
                        txtCn2Relation.Text = "";

                        txtCn3Address1.Text = "";
                        txtCn3Address2.Text = "";
                        txtCn3Email.Text = "";
                        txtCn3Name.Text = "";
                        txtCn3Phone.Text = "";
                        txtCn3Relation.Text = "";

                        ddlDeptment.SelectedIndex = 0;
                        ddlEmpState.SelectedIndex = 0;
                        ddlEmpType.SelectedIndex = 0;
                        ddlSchedule.SelectedIndex = 0;

                        mdlAddPopUp.Hide();
                        GetUserDetails(Convert.ToInt32(Session["SortBy"]),ddlLocation.SelectedItem.Text.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                //System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "Script", "alert('"+ex.ToString()+"');", true);
            }
        }
        protected void btnUpdateEmergency_Click(object sender, EventArgs e)
        {
            try
            {
                Attendance.Entities.EmergencyContactInfo objContactInfo = new EmergencyContactInfo();
                int UserID = Convert.ToInt32(Session["UserID"]);
                int EmployeeID = Convert.ToInt32(hdnUserID.Value);
                String strHostName = Request.UserHostAddress.ToString();
                string strIp = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

                objContactInfo.Person1 = txtCn1Name.Text.ToString() == "" ? "" : GeneralFunction.ToProper(txtCn1Name.Text.ToString().Trim());
                objContactInfo.P1Address1 = GeneralFunction.ToProperNotes(txtCn1Address1.Text.ToString().Trim());
                objContactInfo.P1Address2 = GeneralFunction.ToProperNotes(txtCn1Address2.Text.ToString().Trim());
                objContactInfo.Phone1 = txtCn1Phone.Text.ToString().Trim();
                objContactInfo.Relation1 = GeneralFunction.ToProperNotes(txtCn1Relation.Text.ToString().Trim());
                objContactInfo.Email1 = txtCn1Email.Text.ToString().Trim();
                objContactInfo.StateID1 = Convert.ToInt32(ddlCn1State.SelectedItem.Value);
                // objContactInfo.Zip1 = txtCn1Zip.Text.Trim();

                if (txtCn1Zip.Text != "" && txtCn1Zip.Text.Trim().Length == 4)
                {
                    objContactInfo.Zip1 = "0" + txtCn1Zip.Text.Trim();
                }
                else
                {
                    objContactInfo.Zip1 = txtCn1Zip.Text.Trim();
                }


                objContactInfo.Person2 = txtCn2Name.Text.ToString() == "" ? "" : GeneralFunction.ToProper(txtCn2Name.Text.ToString().Trim());
                objContactInfo.P2Address1 = GeneralFunction.ToProperNotes((txtCn2Address1.Text.ToString().Trim()));
                objContactInfo.P2Address2 = GeneralFunction.ToProperNotes(txtCn2Address2.Text.ToString().Trim());
                objContactInfo.Phone2 = txtCn2Phone.Text.ToString().Trim();
                objContactInfo.Relation2 = GeneralFunction.ToProperNotes(txtCn2Relation.Text.ToString().Trim());
                objContactInfo.Email2 = txtCn2Email.Text.ToString().Trim();
                objContactInfo.StateID2 = Convert.ToInt32(ddlCn2State.SelectedItem.Value);
                if (txtCn2Zip.Text != "" && txtCn2Zip.Text.Trim().Length == 4)
                {
                    objContactInfo.Zip2 = "0" + txtCn2Zip.Text.Trim();
                }
                else
                {
                    objContactInfo.Zip2 = txtCn2Zip.Text.Trim();
                }


                objContactInfo.Person3 = txtCn3Name.Text.ToString() == "" ? "" : GeneralFunction.ToProper(txtCn3Name.Text.ToString().Trim());
                objContactInfo.P3Address1 = GeneralFunction.ToProperNotes(txtCn3Address1.Text.ToString().Trim());
                objContactInfo.P3Address2 = GeneralFunction.ToProperNotes(txtCn3Address2.Text.ToString().Trim());
                objContactInfo.Phone3 = txtCn3Phone.Text.ToString().Trim();
                objContactInfo.Relation3 = GeneralFunction.ToProperNotes(txtCn3Relation.Text.ToString().Trim());
                objContactInfo.Email3 = txtCn3Email.Text.ToString().Trim();
                objContactInfo.StateID3 = Convert.ToInt32(ddlCn3State.SelectedItem.Value);
                if (txtCn3Zip.Text != "" && txtCn3Zip.Text.Trim().Length == 4)
                {
                    objContactInfo.Zip3 = "0" + txtCn3Zip.Text.Trim();
                }
                else
                {
                    objContactInfo.Zip3 = txtCn3Zip.Text.Trim();
                }

                Attendance.BAL.Report obj = new Report();
                obj.UpdateEmergencyDetails(objContactInfo, UserID, EmployeeID, strIp);
                //Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
                GetEmpDet(EmployeeID);
                mdlEditEmergContactDet.Hide();


            }
            catch (Exception ex)
            {

            }
        }