protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Designation newDesignation = new Designation();

                bool chk = false;
                Employee aEmployee = new Employee();
                Addresses aAddresses=new Addresses();
                List<Employee> employeeListC =aEmployee.GetAllEmployee(_company.CompanyId);
                if (lblId.Text == "" || lblId.Text == "0")
                foreach (Employee anEmployee in employeeListC)
                {
                    if (anEmployee.EmployeeCode == txtEmployeeCode.Value)
                    {
                        Session["empMessage"] = "Employee Code is exist! Try Again";
                        chk = true;
                        break;
                    }
                }
                 if (chk == true)
                {
                    Response.Redirect(Request.RawUrl);
                }
                Employee tempEmployee = new Employee();

                aEmployee.EmployeeCode = txtEmployeeCode.Value;
                aEmployee.EmployeeName = txtEmployeeName.Value;
                aEmployee.DOB = RadDatePicker1.SelectedDate.ToString();
                aEmployee.JoinDate = JoinRadDatePicker.SelectedDate.ToString();

                aEmployee.DepartmentId = int.Parse(departmentDropDownList.SelectedIndex>-1?departmentDropDownList.SelectedItem.Value:"0");
                aEmployee.DesignationId = int.Parse(designationDropDownList.SelectedItem.Value);
                aEmployee.Address = "Main Address";
                aAddresses.SourceType = "Employee";
                aAddresses.AddressLine1 = txtAddressLine1.Value;
                aAddresses.AddressLine2 = txtAddressLine2.Value;
                aAddresses.AddressType = "Main Address";
                aAddresses.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                aAddresses.City = txtCity.Value;
                aAddresses.ZipCode = txtZipCode.Value;
                aAddresses.Email = txtEmail.Value;
                aAddresses.Web = "";
                aAddresses.Phone = txtPhoneNo.Value;
                aAddresses.Mobile = txtMobile.Value;
                aAddresses.CompanyId = _company.CompanyId;
                aEmployee.CompanyId = _company.CompanyId;
                aEmployee.IsActive = true;
                aEmployee.UpdateBy = user.UserId;
                aEmployee.UpdateDate = DateTime.Now;
                if (lblId.Text == "" || lblId.Text == "0")
                {
                    aEmployee.EmployeeId = new Employee().GetMaxEmployeeId() + 1;
                    aAddresses.SourceId = aEmployee.EmployeeId;
                    aAddresses.AddressId = new Addresses().GetMaxAddressId() + 1;

                    int chkEmployee = aEmployee.InsertEmployee();
                    int chkAddress = aAddresses.InsertAddresses();
                    if (chkAddress > 0 && chkEmployee > 0)
                    {
                        Session["empMessage"] = "Saved Successfully";
                        Response.Redirect(Request.RawUrl);

                    }
                    else
                    {
                        Alert.Show("Error occured while inserting employee information");
                    }
                }
                else
                {
                    aEmployee.EmployeeId = int.Parse(lblId.Text);
                    aAddresses.SourceId = aEmployee.EmployeeId;
                    aAddresses.AddressId = long.Parse(addlblId.Text);
                   int chk3= aEmployee.UpdateEmployee();
                    int chk1=aAddresses.UpdateAddresses();
                    if(chk3>0&&chk1>0)
                        Response.Redirect("EmployeeList.aspx",true);

                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool chk = false;
                Employee aEmployee = new Employee();
                Addresses aAddresses=new Addresses();
                List<Employee> employeeListC =aEmployee.GetAllEmployee(_company.CompanyId);

                foreach (Employee anEmployee in employeeListC)
                {
                    if (anEmployee.EmployeeCode == txtEmployeeCode.Value)
                    {
                        Session["empMessage"] = "Employee Code is exist! Try Again";
                        chk = true;
                        break;
                    }
                }
                 if (chk == true)
                {
                    Response.Redirect(Request.RawUrl);
                }
                Employee tempEmployee = new Employee();
                int id;
                if (employeeListC.Count > 0)
                {
                    tempEmployee = (employeeListC[employeeListC.Count - 1]);
                      id= tempEmployee.EmployeeId + 1;
                }
                else
                {
                    id = 0;
                }

                aEmployee.EmployeeId = id;
                aEmployee.EmployeeCode = txtEmployeeCode.Value;
                aEmployee.EmployeeName = txtEmployeeName.Value;
                aEmployee.DOB = RadDatePicker1.SelectedDate.ToString();
                aEmployee.JoinDate = JoinRadDatePicker.SelectedDate.ToString();
                aEmployee.DesignationId = int.Parse(designationDropDownList.SelectedItem.ToString());
                aEmployee.DepartmentId = int.Parse(departmentDropDownList.SelectedItem.ToString());
                aAddresses.SourceId = id;
                aEmployee.Address = "Main Address";
                aAddresses.SourceType = "Employee";
                aAddresses.AddressLine1 = txtAddressLine1.Value;
                aAddresses.AddressLine2 = txtAddressLine2.Value;
                aAddresses.AddressType = "Main Address";
                aAddresses.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                aAddresses.City = txtCity.Value;
                aAddresses.ZipCode = txtZipCode.Value;
                aAddresses.Email = txtEmail.Value;
                aAddresses.CompanyId = _company.CompanyId;
                aEmployee.CompanyId = _company.CompanyId;
                aEmployee.IsActive = true;
                aEmployee.UpdateBy = user.UserId;
                aEmployee.UpdateDate = DateTime.Now;
                int chkEmployee = aEmployee.InsertEmployee();
                int chkAddress = aAddresses.InsertAddresses();
                if (chkAddress > 0 && chkEmployee > 0)
                {
                    Session["empMessage"] = "Saved Successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error occured while inserting employee information");
                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }