Ejemplo n.º 1
0
 private void btnAddSeminar_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         using (var db = new LetranIntegratedSystemEntities())
         {
             if (txtSeminar.Text != "" && txtVenue.Text != "" && txtSeminarInclusiveDate.Text != "")
             {
                 EmployeeSeminar es = new EmployeeSeminar();
                 es.EmployeeID    = EmpID;
                 es.Title         = txtSeminar.Text;
                 es.Venue         = txtVenue.Text;
                 es.InclusiveDate = txtSeminarInclusiveDate.Text;
                 db.EmployeeSeminars.Add(es);
                 db.SaveChanges();
                 MessageBox.Show("Add Successfully.", "System Success", MessageBoxButton.OK, MessageBoxImage.Information);
                 ClearSeminar();
                 GetEmployeeSeminar();
             }
             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
        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);
            }
        }