public void LoadDepartmentDropDownList()
        {
            try
            {
                DepartmentTableBody.InnerHtml = "";
                string htmlContent = "";
                List<Department> departmentList = new List<Department>();
                Department aDepartment = new Department();
                departmentList = aDepartment.GetAllDepartment(_company.CompanyId);
                foreach (Department aDepo in departmentList)
                {
                    string CompanyName = "";
                    htmlContent += "<tr>";
                    foreach (Company acompany in companyList)
                    {
                        if (acompany.CompanyId == aDepo.CompanyId)
                        {
                            CompanyName += acompany.CompanyName;
                            break;
                        }
                    }

                    htmlContent += String.Format(@"<th>{0}</th><th>{1}</th><th>{2}</th><th>{3}</th><th>{4}</th></tr>", aDepo.DepartmentName, aDepo.ParentDepartmentId, aDepo.IsActive, aDepo.UpdateBy, aDepo.UpdateDate);
                }
                DepartmentTableBody.InnerHtml += htmlContent;

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
 public void LoadDepartmentDropDownList()
 {
     Department newDeg = new Department();
     List<Department> newDegList = newDeg.GetAllDepartment(_company.CompanyId);
     departmentDropDownList.DataSource = newDegList;
     departmentDropDownList.DataTextField = "DepartmentName";
     departmentDropDownList.DataValueField = "DepartmentId";
     departmentDropDownList.DataBind();
 }
        public void LoadDepartmentDropDownList()
        {
            List<Department> departmentList=new List<Department>();
            Department aDepartment=new Department();

            departmentList= aDepartment.GetAllDepartment(0);
            departmentIdRadDropDownList.DataSource = departmentList;
            departmentIdRadDropDownList.DataTextField = "DepartmentName";
            departmentIdRadDropDownList.DataValueField = "DepartmentId";
            departmentIdRadDropDownList.DataBind();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Department aDepartmnent = new Department();

                aDepartmnent.DepartmentName = txtDepartmentName.Value;

                aDepartmnent.UpdateDate = DateTime.Now;
                aDepartmnent.UpdateBy = _user.UserId;

                aDepartmnent.IsActive = true;
                aDepartmnent.CompanyId = _company.CompanyId;

                int sucess = 0;
                if (lblId.Text == "" || lblId.Text == "0")
                {
                    aDepartmnent.DepartmentId = new Department().GetMaxDepartmentId() + 1;
                    aDepartmnent.ParentDepartmentId = ParentDepartmentDropDownList.SelectedIndex > -1
                        ? int.Parse(ParentDepartmentDropDownList.SelectedIndex.ToString())
                        : aDepartmnent.DepartmentId;

                    sucess = aDepartmnent.InsertDepartment();

                    if (sucess > 0)
                    {
                        Alert.Show("Department info saved successfully");
                        this.Clear();
                    }
                }
                else
                {
                    aDepartmnent.DepartmentId = int.Parse(lblId.Text);
                    aDepartmnent.ParentDepartmentId = ParentDepartmentDropDownList.SelectedIndex > -1
                        ? int.Parse(ParentDepartmentDropDownList.SelectedIndex.ToString())
                        : aDepartmnent.DepartmentId;
                    sucess = aDepartmnent.UpdateDepartment();

                    if (sucess > 0)
                    {
                        Response.Redirect("DepartmentLists.aspx", true);
                    }
                }
                this.Clear();
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void RadGrid1_OnItemCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem item = (GridDataItem)e.Item;

            string id = item["colId"].Text;

            switch (e.CommandName)
            {
                case "btnSelect":
                    Response.Redirect("DepartmentInfo.aspx?id=" + id, true);
                    break;
                case "btnDelete":
                    int delete = new Department().DeleteDepartmentByDepartmentId(int.Parse(id));

                    if (delete == 0)
                    {
                        Alert.Show("Data was not delete..");
                    }
                    else
                        LoadDepartmentTable();
                    break;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Department aDepartmnent = new Department();
                List<Department> departmentList = aDepartmnent.GetAllDepartment(_company.CompanyId);
                Department tempDepartment = departmentList[departmentList.Count - 1];
                int id = tempDepartment.DepartmentId + 1;
                aDepartmnent.DepartmentId = id;
                aDepartmnent.ParentDepartmentId = id;

                aDepartmnent.DepartmentName = txtDepartmentName.Value;

                aDepartmnent.UpdateDate = DateTime.Now;
                aDepartmnent.UpdateBy = user.UserId;

                aDepartmnent.IsActive = true;
                aDepartmnent.CompanyId = _company.CompanyId;
                int success = aDepartmnent.InsertDepartment();
                if (success > 0)
                {
                    Session["savedDepartmentMessage"] = "Saved Department Information successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error Occured while inserting a new user");
                }
                this.Clear();
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        private void LoadDepartmentTable()
        {
            try
            {

                Department objDepartment = new Department();
                departmentsList = objDepartment.GetAllDepartment(_company.CompanyId);
                if (departmentsList.Count == 0)
                    departmentsList.Add(new Department());

                RadGrid1.DataSource = departmentsList;
                RadGrid1.Rebind();
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _company = (Company)Session["Company"];

            if (!isValidSession())
            {
                string str = Request.QueryString.ToString();
                if (str == string.Empty)
                    Response.Redirect("LogIn.aspx?refPage=index.aspx");
                else
                    Response.Redirect("LogIn.aspx?refPage=index.aspx?" + str);
            }
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string deptId = Request.QueryString["id"].ToString();

                    Department dept = new Department().GetDepartmentByDepartmentId(int.Parse(deptId), _company.CompanyId);
                    if (dept != null || dept.DepartmentId != 0)
                    {
                        lblId.Text = dept.DepartmentId.ToString();
                        txtDepartmentName.Value = dept.DepartmentName;

                    }
                }
            }
            LoadParentDepartmentIdDropDown();
        }
        void LoadParentDepartmentIdDropDown()
        {
            Department dep=new Department();
            List<Department> depList = dep.GetAllDepartment(_company.CompanyId);
            List<string> idList = new List<string>();

            foreach (Department depoo in depList)
            {

                idList.Add(depoo.DepartmentName);
            }
            ParentDepartmentDropDownList.DataSource = idList.Distinct();
            ParentDepartmentDropDownList.DataBind();
        }
        private void LoadDesignationTable()
        {
            try
            {
                Designation objDesignation =new Designation();
                List<Designation> objDesignationList = objDesignation.GetAllDesignation(_company.CompanyId);
                foreach (Designation aDesignation in objDesignationList)
                {
                    if (aDesignation.DepartmentId != 0)
                    {
                        Department aDepartment = new Department().GetDepartmentByDepartmentId(
                            aDesignation.DepartmentId, _company.CompanyId);
                        aDesignation.DepartmentName = aDepartment.DepartmentName;
                    }
                    else
                    {
                        aDesignation.DepartmentName = "None";
                    }
                }
                RadGrid1.DataSource = objDesignationList;
                RadGrid1.Rebind();

            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        private void LoadEmployeeListTable()
        {
            try
            {
                Addresses tempAddres = new Addresses();
                Designation tempDesignation = new Designation();
                Department tempDepartment = new Department();
                Employee objEmployee = new Employee();
                List<Employee> objEmployeeList = objEmployee.GetAllEmployee(_company.CompanyId);
                foreach (Employee employee in objEmployeeList)
                {

                    List<Addresses> objAddressList = tempAddres.GetAllAddresses(_company.CompanyId);
                    Designation aDesignation = tempDesignation.GetDesignationByDesignationId(employee.DesignationId,_company.CompanyId);
                    Department aDepartment = tempDepartment.GetDepartmentByDepartmentId(employee.DepartmentId,
                        _company.CompanyId);
                    employee.DepartmentName = aDepartment.DepartmentName;
                    employee.DesignationName = aDesignation.Designation;
                    employee.DOB = DateTime.Parse(employee.DOB).ToShortDateString();
                    employee.JoinDate = DateTime.Parse(employee.JoinDate).ToShortDateString();
                    List<string> countrList = Country.CountryList();

                    foreach (Addresses anAddresses in objAddressList)
                    {
                        if (anAddresses.SourceType == "Employee" && anAddresses.SourceId == employee.EmployeeId)
                        {
                            employee.AddressLine1 = anAddresses.AddressLine1;
                            employee.AddressLine2 = anAddresses.AddressLine2;
                            employee.City = anAddresses.City;
                            employee.ZipCode = anAddresses.ZipCode;
                            employee.Phone = anAddresses.Phone;
                            employee.Mobile = anAddresses.Mobile;
                            employee.Email = anAddresses.Email;
                            employee.CountryName = countrList[anAddresses.CountryId];
                            break;

                        }

                    }
                    RadGrid1.DataSource = objEmployeeList;
                    RadGrid1.Rebind();

                }
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _company = (Company)Session["Company"];
            user = (Users)Session["user"];

            this.LoadCountryDropDownList();
            this.LoadDepartmentDropDownList();

            if (!isValidSession())
            {
                string str = Request.QueryString.ToString();
                if (str == string.Empty)
                {
                    Response.Redirect("LogIn.aspx?refPage=index.aspx");
                }
                else
                {
                    Response.Redirect("LogIn.aspx?regPage=index.aspx"+str);
                }
            }
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string id = Request.QueryString["id"].ToString();
                    Employee tempEmployee= new Employee().GetEmployeeByEmployeeId(int.Parse(id),_company.CompanyId);
                    if (tempEmployee != null || tempEmployee.EmployeeId != 0)
                    {
                        List<string> countryList = Country.CountryList();
                        List<Addresses> addressList = new Addresses().GetAllAddresses(_company.CompanyId);
                        Designation designation =
                            new Designation().GetDesignationByDesignationId(tempEmployee.DesignationId,
                                _company.CompanyId);
                        Department department;
                        if (tempEmployee.DepartmentId != 0)
                        {
                            department = new Department().GetDepartmentByDepartmentId(tempEmployee.DepartmentId,
                                _company.CompanyId);
                            SetIndex(departmentDropDownList, department.DepartmentId.ToString());
                            LoadDesignationDropDownList(tempEmployee.DepartmentId);

                        }
                        else
                        {
                            department = new Department();
                            departmentDropDownList.SelectedIndex = -1;
                            LoadDesignationDropDownList(0);
                        }
                        SetIndex(designationDropDownList,tempEmployee.DesignationId.ToString());
                        lblId.Text = tempEmployee.EmployeeId.ToString();
                        txtEmployeeCode.Value = tempEmployee.EmployeeCode;
                        txtEmployeeName.Value = tempEmployee.EmployeeName;
                        JoinRadDatePicker.SelectedDate = DateTime.Parse(tempEmployee.JoinDate);
                        RadDatePicker1.SelectedDate = DateTime.Parse(tempEmployee.DOB);
                        chkIsActive.Checked = tempEmployee.IsActive;

                       //SetIndex(designationDropDownList,designation.DesignationId.ToString());
                        foreach (Addresses tAddress in addressList)
                        {
                            if (tAddress.SourceType == "Employee" && tAddress.SourceId == tempEmployee.EmployeeId)
                            {
                                addlblId.Text = tAddress.AddressId.ToString();
                                txtAddressLine1.Value = tAddress.AddressLine1;
                                txtAddressLine2.Value = tAddress.AddressLine2;
                                txtCity.Value = tAddress.City;
                                txtEmail.Value = tAddress.Email;
                                txtZipCode.Value = tAddress.ZipCode;
                                txtPhoneNo.Value = tAddress.Phone;
                                countryDropDownList.SelectedIndex = tAddress.CountryId;
                                break;

                            }

                        }
                    }

                }
            }
            if (Session["empMessage"] != null)
            {
                string message = Session["empMessage"].ToString();
                Session["empMessage"] = null;
                Alert.Show(message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                _company = (Company) Session["Company"];
                if (!isValidSession())
                {
                    string str = Request.QueryString.ToString();
                    if (str == string.Empty)
                        Response.Redirect("LogIn.aspx?refPage=index.aspx");
                    else
                        Response.Redirect("LogIn.aspx?refPage=index.aspx?" + str);
                }

                this.LoadDesignationTable();
                this.LoadDepartmentDropDownList();
                if (!IsPostBack)
                {
                    if (Request.QueryString["id"] != null)
                    {
                        string designationID = Request.QueryString["id"].ToString();
                        Designation objDesignation =
                            new Designation().GetDesignationByDesignationId(int.Parse(designationID), _company.CompanyId);
                        lblId.Text = objDesignation.DesignationId.ToString();
                        if (objDesignation != null || objDesignation.DepartmentId != 0)
                        {
                            Department aDepartment =
                                new Department().GetDepartmentByDepartmentId(objDesignation.DesignationId,
                                    _company.CompanyId);

                            txtDesignationName.Value = objDesignation.Designation;
                            SetIndex(departmentIdRadDropDownList, objDesignation.DepartmentId.ToString());
                            chkIsActive.Checked = objDesignation.IsActive;
                        }

                    }
                }
                if (Session["designationInfoMsg"] != null)
                {
                    string str = Session["designationInfoMsg"].ToString();
                    Alert.Show(str);
                    Session["designationInfoMsg"] = null;
                }
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }