예제 #1
0
        public void Show()
        {
            try
            {
                CompanyTableBody.InnerHtml = "";
                string htmlContent = "";
                List<Employee> departmentList = new List<Employee>();
                Employee aDepartment = new Employee();
                departmentList = aDepartment.GetAllEmployee(_company.CompanyId);
                foreach (Employee aDepo in departmentList)
                {

                    htmlContent += "<tr>";

                    htmlContent += String.Format(@"<th>{0}</th><th>{1}</th><th>{2}</th><th>{3}</th><th>{4}</th><th>{5}</th></tr>", aDepo.EmployeeCode, aDepo.EmployeeName, aDepo.Address, aDepo.DOB, aDepo.JoinDate, aDepo.IsActive);
                    htmlContent += "</tr>";
                }
                CompanyTableBody.InnerHtml += htmlContent;

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
        protected void RadGrid1_OnItemCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
                GridDataItem item = (GridDataItem) e.Item;
                string id = item["colId"].Text;
                switch (e.CommandName)
                {
                    case "btnSelect":
                        Response.Redirect("EmployeeInfo.aspx?id="+id,true);
                        break;
                    case "btnDelete":
                        int success = new Employee().DeleteEmployeeByEmployeeId(int.Parse(id));
                        long addId = GetAddressID(int.Parse(id));
                        int chk1 = new Addresses().DeleteAddressesByAddressId(addId);
                        if (success == 0 || chk1==0)
                            Alert.Show("Data is not deleted");
                        else
                        {
                            this.LoadEmployeeListTable();
                        }

                        break;
                }

            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {

                Users user = new Users().GetUserByUserName(txtUserName.Value);
                if (user.UserId != 0)
                {
                    if (user.UserPassword != txtPassword.Value)
                    {
                        Alert.Show("User and password didn't match. Please re-enter the correct password.");
                        txtPassword.Focus();
                        return;
                    }

                    int companyId = int.Parse(ddlCompany.SelectedValue);

                    Session["user"] = user;
                    UserRoleMapping userRole = new UserRoleMapping().GetUserRoleMappingByUserId(user.UserId);
                    UserRole role = new UserRole().GetUserRoleById(userRole.RoleId, companyId);
                    Session["Role"] = role;

                    //Get host and port from the url;
                    string host = HttpContext.Current.Request.Url.Host;
                    string port = HttpContext.Current.Request.Url.Port.ToString();

                    string path = "http://" + host + ":" + port + "/";
                    this.GenerateMenu(user, path, Int32.Parse("0"));

                    Company company= new Company().GetCompanyByCompanyId(companyId);
                    Session["company"] = company;

                    if (user.EmployeeId != 0)
                    {
                        Employee employee = new Employee().GetEmployeeByEmployeeId(user.EmployeeId,
                            user.CompanyId);
                        Session["Employee"] = employee;

                        //Department objDepartment = new Department().GetEmployeeDepartment(user.EmployeeId);
                        //Session["Department"] = objDepartment.DepartmentName;
                    }
                    else
                        Session["Department"] = "All";

                    string refPage = (Request.QueryString["refPage"] == null) ? string.Empty : Request.QueryString["refPage"].ToString();
                    Response.Redirect(((refPage == string.Empty || refPage.ToLower() == "logout") ? "index.aspx" : refPage), false);
                }
                else
                {
                    Alert.Show("The user is not exist in the database. Please check the username.");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                Alert.Show("Error during process user authentication. Error: " + ex.Message);
            }
        }
예제 #4
0
 public void LoadSalesPersonDropDown()
 {
     Employee newEmp = new Employee();
     List<Employee> empList = newEmp.GetAllEmployee(_company.CompanyId);
     salesPersonDropDownList.DataSource = empList;
     salesPersonDropDownList.DataTextField = "EmployeeName";
     salesPersonDropDownList.DataValueField = "EmployeeId";
     salesPersonDropDownList.DataBind();
 }
예제 #5
0
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            try
            {
                Users user = new Users().GetUserByUserName(txtUserName.Value);
                if (user.UserId != 0)
                {
                    if (user.UserPassword != txtPassword.Value)
                    {
                        Alert.Show("User and password didn't match. Please re-enter the correct password.");
                        txtPassword.Focus();
                        return;
                    }

                    //string IP = Request.UserHostName;
                    //string compName = DetermineCompName(IP);

                    //UserLoginLog log = new UserLoginLog().GetUserLastLogin(user.UserId);
                    //if (log.Id != 0)
                    //{
                    //    if (log.IpAddress != IP && log.Status == "Logged In")
                    //    {
                    //        Alert.Show("Sorry! This is user is already logged in from another PC.");
                    //        return;
                    //    }
                    //}

                    Session["user"] = user;
                    UserRoleMapping userRole = new UserRoleMapping().GetUserRoleMappingByUserId(user.UserId);
                    UserRole role = new UserRole().GetUserRoleById(userRole.RoleId, user.CompanyId);
                    Session["Role"] = role;

                    //Get host and port from the url;
                    string host = HttpContext.Current.Request.Url.Host;
                    string port = HttpContext.Current.Request.Url.Port.ToString();

                    string path = "http://" + host + ":" + port + "/";
                    this.GenerateMenu(user, path);

                    //log = new UserLoginLog();
                    //log.UserId = user.UserId;
                    //log.SessionId = Session.SessionID;

                    //log.IpAddress = IP;
                    //log.LoginPCName = compName;
                    //log.LoginTime = DateTime.Now;
                    //log.Status = "Logged In";
                    //log.LogOutTime = PublicVariables.minDate;

                    //log.InsertUserLoginLog();
                    Company company;
                    UserRoleMapping userRoles = new UserRoleMapping().GetUserRoleMappingByUserId(user.UserId);
                    if (userRoles.RoleId != 0 && user.UserId == 1)
                    {
                        user.IsSuperUser = true;
                        company = new Company().GetCompanyByCompanyId(1);
                    }
                    else
                    {
                        user.IsSuperUser = false;
                        company = new Company().GetCompanyByCompanyId(user.CompanyId);
                    }

                    Session["company"] = company;

                    if (user.CompanyId == 0 && !user.IsSuperUser)
                    {
                        Alert.Show("Sorry this user is not associated with any company. Contact your system administrator to fix this issue.");
                        return;
                    }

                    if (user.EmployeeId != 0)
                    {
                        Employee employee = new Employee().GetEmployeeByEmployeeId(user.EmployeeId,
                            user.CompanyId);
                        Session["Employee"] = employee;

                        //Department objDepartment = new Department().GetEmployeeDepartment(user.EmployeeId);
                        //Session["Department"] = objDepartment.DepartmentName;
                    }
                    else
                        Session["Department"] = "All";

                    string refPage = (Request.QueryString["refPage"] == null) ? string.Empty : Request.QueryString["refPage"].ToString();
                    Response.Redirect(((refPage == string.Empty || refPage.ToLower() == "logout") ? "index.aspx" : refPage), false);
                }
                else
                {
                    Alert.Show("The user is not exist in the database. Please check the username.");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                Alert.Show("Error during process user authentication. Error: " + 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 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 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);
            }
        }
예제 #9
0
        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);
            }
        }