Ejemplo n.º 1
0
 private void btnAddWorkExp_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (var db = new LetranIntegratedSystemEntities())
         {
             if (txtCompany.Text != "" && txtPosition.Text != "")
             {
                 EmployeeWork ew = new EmployeeWork();
                 ew.EmployeeID    = EmpID;
                 ew.Company       = txtCompany.Text;
                 ew.WorkPosition  = txtPosition.Text;
                 ew.InclusiveDate = txtWorkExpInclusivedate.Text;
                 ew.Salary        = txtSalary.Text;
                 ew.ReasonLeaving = txtReasonForLeaving.Text;
                 db.EmployeeWorks.Add(ew);
                 db.SaveChanges();
                 MessageBox.Show("Add Successfully.", "System Success", MessageBoxButton.OK, MessageBoxImage.Information);
                 ClearWorkExp();
                 GetEmployeeWorkExp();
             }
             else
             {
                 MessageBox.Show("Fill the required fields.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Something went wrong!", "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
Ejemplo n.º 2
0
        public JsonResult Post([FromBody] EmployeeWork _staff) // add staff to database
        {
            db.insertStaff(_staff);
            Staff addedStaff = db.getAllStaff()[0];

            return(new JsonResult(addedStaff));
        }
        //This is a method that is parsing the data coming from file and set it to the EmployeeWork model and returns a list of EmployeeWork models
        public List <EmployeeWork> ParseDataFromFile(List <string[]> rowsInFile)
        {
            List <EmployeeWork> employeesModels = new List <EmployeeWork>();

            //Looping through all of the rows of the text file and  parse the values
            foreach (var row in rowsInFile)
            {
                EmployeeWork employeeWorkModel = new EmployeeWork();

                //Trimming the whitespace in the file
                employeeWorkModel.EmpID     = Convert.ToInt32(row[0].Trim());
                employeeWorkModel.ProjectID = Convert.ToInt32(row[1].Trim());
                //Setting the DateFrom property with any DateTime formats
                employeeWorkModel.DateFrom = DateTime.ParseExact(row[2].Trim(), GetAllDateTimeFormats(), CultureInfo.InvariantCulture, DateTimeStyles.None);

                if (row[3].Trim() == "NULL")
                {
                    //If there is a "NULL" value in the text file, set the DateTo value to DateTime.Now
                    employeeWorkModel.DateTo = DateTime.Now.Date;
                }
                else
                {
                    //Setting the DateTo property with any DateTime formats
                    employeeWorkModel.DateTo = DateTime.ParseExact(row[3].Trim(), GetAllDateTimeFormats(), CultureInfo.InvariantCulture, DateTimeStyles.None);
                }

                employeesModels.Add(employeeWorkModel);
            }
            return(employeesModels);
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeWork employeeWork = db.EmployeeWorks.Find(id);

            db.EmployeeWorks.Remove(employeeWork);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
        public ActionResult delEmployeeWork()
        {
            string workNumber = Session["workNumber"].ToString();
            var    query      = from o in db.EmployeeWork
                                where o.employee_workNumber == workNumber
                                select o.Id;
            int          id   = query.First();
            EmployeeWork data = db.EmployeeWork.Find(id);

            data.workId_isDisable = "Y";
            db.SaveChanges();

            return(RedirectToAction("employeeMain", "basicData"));
        }
Ejemplo n.º 6
0
        // GET: EmployeeWorks/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeWork employeeWork = db.EmployeeWorks.Find(id);

            if (employeeWork == null)
            {
                return(HttpNotFound());
            }
            return(View(employeeWork));
        }
Ejemplo n.º 7
0
        public void insertStaff(EmployeeWork _staff)
        {
            SqlConnection _connect = new SqlConnection(_connectionString);

            using (SqlCommand cmd = new SqlCommand("insertStaff", _connect))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                _connect.Open();

                cmd.Parameters.AddWithValue("@name", SqlDbType.NVarChar).Value    = _staff.staffName;
                cmd.Parameters.AddWithValue("@surname", SqlDbType.NVarChar).Value = _staff.staffSurname;
                cmd.Parameters.AddWithValue("@companyid", SqlDbType.Int).Value    = _staff.companyID;
                cmd.Parameters.AddWithValue("@departmentid", SqlDbType.Int).Value = _staff.departmentID;

                cmd.ExecuteNonQuery();
            }
            _connect.Close();
        }
Ejemplo n.º 8
0
        public ActionResult Edit(EmployeeWork employeeWork, HttpPostedFileBase upimage = null)
        {
            if (!ModelState.IsValid)
            {
                return(View(employeeWork));
            }

            if (upimage != null)
            {
                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(upimage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(upimage.ContentLength);
                }

                employeeWork.Image = imageData;
            }

            db.Entry(employeeWork).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
        public ActionResult editEmployeeWork(string work_name)
        {
            //將工種名稱轉換成id
            var query = from o in db.WorkInfo
                        where o.work_name == work_name
                        select o.work_id;
            int workID = query.First();

            //將工號轉換成EmployeeWork表對應的ID
            string workNumber = Session["workNumber"].ToString();
            var    query1     = from o in db.EmployeeWork
                                where o.employee_workNumber == workNumber
                                select o.Id;
            int EmployeeWorkID = query1.First();

            //修改資料並儲存
            EmployeeWork data = db.EmployeeWork.Find(EmployeeWorkID);

            data.employee_Workid = workID;
            db.SaveChanges();

            return(RedirectToAction("employeeMain", "basicData"));
        }
Ejemplo n.º 10
0
        private void btnADD_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                db = new LetranIntegratedSystemEntities();
                Employee       emp         = new Employee();
                AspNetUser     aspuser     = new AspNetUser();
                AspNetUserRole asproleuser = new AspNetUserRole();
                string         roleid      = "";


                int deptid      = Convert.ToInt32(cbDepartment.SelectedValue);
                int facareaid   = Convert.ToInt32(cbFacultyArea.SelectedValue);
                int statid      = Convert.ToInt32(cbStatus.SelectedValue);
                int desigid     = Convert.ToInt32(cbDesignation.SelectedValue);
                int posid       = Convert.ToInt32(cbEmployeePosition.SelectedValue);
                int lvlid       = Convert.ToInt32(cbLevel.SelectedValue);
                int resareaid   = Convert.ToInt32(cbArea.SelectedValue);
                int reszipcode  = Convert.ToInt32(cbZipcode.SelectedValue);
                int provareaid  = Convert.ToInt32(cbProvArea.SelectedValue);
                int provzipcode = Convert.ToInt32(cbProvZipcode.SelectedValue);
                int emptypeid   = Convert.ToInt32(cbEmpType.SelectedValue);

                if (String.IsNullOrEmpty(txtEmpNumber.Text) || String.IsNullOrEmpty(cbDepartment.Text) || String.IsNullOrEmpty(cbStatus.Text) ||
                    String.IsNullOrEmpty(cbDesignation.Text) || String.IsNullOrEmpty(cbEmployeePosition.Text) || String.IsNullOrEmpty(dpHired.Text) ||
                    String.IsNullOrEmpty(cbSalutation.Text) || String.IsNullOrEmpty(txtLastName.Text) || String.IsNullOrEmpty(txtFirstName.Text) ||
                    String.IsNullOrEmpty(txtCitizenship.Text) || String.IsNullOrEmpty(cbStatus.Text) || String.IsNullOrEmpty(txtReligion.Text) || String.IsNullOrEmpty(txtCity.Text))
                {
                    MessageBox.Show("Please fill up necessary fields.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    Mouse.OverrideCursor = null;
                    return;
                }
                if (db.Employees.Where(m => m.EmployeeNo == txtEmpNumber.Text).FirstOrDefault() != null)
                {
                    MessageBox.Show("Employee number already exists!", "System Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Mouse.OverrideCursor = null;
                    return;
                }
                if (db.Employees.Where(m => m.FirstName.Trim().ToUpper() == txtFirstName.Text.Trim().ToUpper() && m.LastName.Trim().ToUpper() == txtLastName.Text.Trim().ToUpper() && m.MiddleName.Trim().ToUpper() == (String.IsNullOrEmpty(txtMiddleName.Text) ? " " : txtMiddleName.Text.Trim().ToUpper())).FirstOrDefault() != null)
                {
                    MessageBox.Show("Employee already exists!!", "System Warning", MessageBoxButton.OK, MessageBoxImage.Error);
                    Mouse.OverrideCursor = null;
                    return;
                }
                emp.EmployeeNo = txtEmpNumber.Text;
                emp.Title      = cbSalutation.Text;
                emp.LastName   = txtLastName.Text;
                emp.FirstName  = txtFirstName.Text;
                emp.MiddleName = String.IsNullOrEmpty(txtMiddleName.Text) ? " " : txtMiddleName.Text;
                emp.Nickname   = txtNickName.Text;
                if (emptypeid != 0)
                {
                    emp.EmploymentTypeID = emptypeid;
                }
                if (deptid != 0)
                {
                    emp.EmployeeDepartmentID = deptid;
                }
                if (facareaid != 0)
                {
                    emp.FacultyAreaID = facareaid;
                }
                if (statid != 0)
                {
                    emp.EmployeeStatusID = statid;
                }
                if (desigid != 0)
                {
                    emp.EmployeeDesignation = desigid;
                }
                if (posid != 0)
                {
                    emp.EmployeePositionID = posid;
                }
                if (lvlid != 0)
                {
                    emp.EmployeeLevelID = lvlid;
                }
                if (!String.IsNullOrEmpty(dpHired.Text))
                {
                    emp.DateHired = Convert.ToDateTime(dpHired.SelectedDate);
                }
                if (!String.IsNullOrEmpty(dpPermanency.Text))
                {
                    emp.DatePermanency = Convert.ToDateTime(dpPermanency.SelectedDate);
                }
                if (!String.IsNullOrEmpty(dpEndo.Text))
                {
                    emp.DateEndContract = Convert.ToDateTime(dpEndo.SelectedDate);
                }
                emp.ReasonForLeaving      = txtReason.Text;
                emp.OtherReasonForLeaving = txtReason.Text;
                if (!String.IsNullOrEmpty(dpResigned.Text))
                {
                    emp.DateResigned = Convert.ToDateTime(dpResigned.SelectedDate);
                }
                if (!String.IsNullOrEmpty(dpRetirement.Text))
                {
                    emp.DateRetired = Convert.ToDateTime(dpRetirement.SelectedDate);
                }
                emp.ResidentialAddress = txtCity.Text;
                if (resareaid != 0)
                {
                    emp.ResidentialAreaID = resareaid;
                }
                if (reszipcode != 0)
                {
                    emp.ResidentialZipCodeID = reszipcode;
                }
                emp.ProvincialAddress = txtProvAddress.Text;
                if (provareaid != 0)
                {
                    emp.ProvincialAreaID = provareaid;
                }
                if (provzipcode != 0)
                {
                    emp.ProvincialZipCodeID = provzipcode;
                }
                emp.TelephoneNo           = txtTelno.Text;
                emp.ProvincialTelephoneNo = txtProvTelno.Text;
                emp.MobileNo       = txtMobileno.Text;
                emp.PrimaryEmail   = txtLetranEmail.Text;
                emp.SecondaryEmail = txtAlternateEmail.Text;
                emp.Sex            = rbMale.IsChecked == true ? "M" : "F";
                if (!String.IsNullOrEmpty(dpBirthday.Text))
                {
                    emp.Birthday = Convert.ToDateTime(dpBirthday.SelectedDate);
                }
                emp.Birthplace  = txtPlaceBirth.Text;
                emp.CivilStatus = cbCivilStatus.Text.Substring(0, 1);
                emp.Nationality = txtCitizenship.Text;
                emp.Religion    = txtReligion.Text;
                emp.TaxStatus   = cbTax.Text;
                emp.TIN         = txtTIN.Text;
                emp.SSS         = txtSSS.Text;
                emp.PAG_IBIG    = txtPagibig.Text;
                emp.PhilHealth  = txtPhilhealth.Text;
                emp.CedulaNo    = txtCertificateNumber.Text;
                if (!String.IsNullOrEmpty(dpRC.Text))
                {
                    emp.CedulaDate = Convert.ToDateTime(dpRC.SelectedDate).ToLongDateString();
                }
                emp.CedulaPlace = txtRCPlace.Text;
                emp.DateEncoded = DateTime.Now;
                emp.Archive     = chkActive.IsChecked == true ? false : true;
                if (!String.IsNullOrEmpty(txtPic.Text))
                {
                    emp.Photo = File.ReadAllBytes(txtPic.Text);
                }
                var newemp = db.Employees.Add(emp);
                db.SaveChanges();

                if (newemp.EmployeeDesignation == 1 || newemp.EmployeeDepartmentID == 19)
                {
                    roleid = "2";
                }
                if (newemp.EmployeeDesignation == 2)
                {
                    roleid = "5";
                }
                if (newemp.EmployeeDepartmentID == 34)
                {
                    roleid = "9";
                }
                else if (newemp.EmployeeDepartmentID == 35)
                {
                    roleid = "10";
                }
                else if (newemp.EmployeeDepartmentID == 18)
                {
                    roleid = "8";
                }
                else
                {
                    roleid = "4";
                }

                if (db.AspNetUsers.Where(m => m.UserName == newemp.EmployeeNo).FirstOrDefault() != null)
                {
                    MessageBox.Show("User account for this person already exists!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else if (db.AspNetUsers.Where(m => m.Email == newemp.PrimaryEmail && m.Email != "").FirstOrDefault() != null)
                {
                    MessageBox.Show("Email already exists!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
                else
                {
                    if (String.IsNullOrEmpty(roleid))
                    {
                        MessageBox.Show("Role is not specified", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        return;
                    }
                    else
                    {
                        aspuser.Id                   = Guid.NewGuid().ToString();
                        aspuser.UserName             = newemp.EmployeeNo;
                        aspuser.Email                = newemp.PrimaryEmail;
                        aspuser.EmailConfirmed       = true;
                        aspuser.PhoneNumberConfirmed = false;
                        aspuser.TwoFactorEnabled     = false;
                        aspuser.LockoutEnabled       = true;
                        aspuser.AccessFailedCount    = 0;
                        aspuser.SecurityStamp        = Guid.NewGuid().ToString();
                        var passwordHasher = new Microsoft.AspNet.Identity.PasswordHasher();
                        aspuser.PasswordHash = passwordHasher.HashPassword("letran1620");
                        var adduser = db.AspNetUsers.Add(aspuser);
                        asproleuser.UserId = adduser.Id;
                        asproleuser.RoleId = roleid;
                        db.AspNetUserRoles.Add(asproleuser);
                    }
                }

                if (dgEmpEduc.Items.Count > 0)
                {
                    foreach (HRiSClass.EmployeeAddEducationList x in dgEmpEduc.ItemsSource)
                    {
                        EmployeeEducation ee = new EmployeeEducation();
                        ee.EmployeeID     = newemp.EmployeeID;
                        ee.EducationType  = x.EducationType;
                        ee.Institution    = x.Institution;
                        ee.Degree         = x.Degree;
                        ee.GraduationDate = x.Graduation;
                        ee.Awards         = x.Award;
                        db.EmployeeEducations.Add(ee);
                    }
                }

                //Work Experience
                if (dgWorkExp.Items.Count > 0)
                {
                    foreach (HRiSClass.EmployeeAddWorkList x in dgWorkExp.ItemsSource)
                    {
                        EmployeeWork ew = new EmployeeWork();
                        ew.EmployeeID    = newemp.EmployeeID;
                        ew.Company       = x.Company;
                        ew.WorkPosition  = x.Position;
                        ew.InclusiveDate = x.InclusiveDate;
                        ew.Salary        = x.LastSalary;
                        ew.ReasonLeaving = x.Reason;
                        db.EmployeeWorks.Add(ew);
                    }
                }

                //Semniars
                if (dgSeminars.Items.Count > 0)
                {
                    foreach (HRiSClass.EmployeeAddSeminarList x in dgSeminars.ItemsSource)
                    {
                        EmployeeSeminar es = new EmployeeSeminar();
                        es.EmployeeID    = newemp.EmployeeID;
                        es.Title         = x.Seminar;
                        es.InclusiveDate = x.InclusiveDate;
                        es.Venue         = x.Venue;
                        db.EmployeeSeminars.Add(es);
                    }
                }

                db.SaveChanges();
                TextClear();
                MessageBox.Show("Successfully Addedd.", "System Success", MessageBoxButton.OK, MessageBoxImage.Information);
                Mouse.OverrideCursor = null;
            }
            catch (Exception)
            {
                MessageBox.Show("Something went wrong.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }