private void CollectEmployeeDetailInfo() { _TheEmployeeToComplete.EmployeeDetails.EnglishName = _ItsView.EnglishName; _TheEmployeeToComplete.EmployeeDetails.Gender = Gender.GetById(int.Parse(_ItsView.Gender)); _TheEmployeeToComplete.EmployeeDetails.MaritalStatus = MaritalStatus.GetById(int.Parse(_ItsView.MaritalStatus)); decimal height; if (decimal.TryParse(_ItsView.Height, out height)) { _TheEmployeeToComplete.EmployeeDetails.Height = height; } else { _TheEmployeeToComplete.EmployeeDetails.Height = 0; } decimal weight; if (decimal.TryParse(_ItsView.Weight, out weight)) { _TheEmployeeToComplete.EmployeeDetails.Weight = weight; } else { _TheEmployeeToComplete.EmployeeDetails.Weight = 0; } DateTime birthday; if (DateTime.TryParse(_ItsView.BirthDay, out birthday)) { _TheEmployeeToComplete.EmployeeDetails.Birthday = birthday; } else { _TheEmployeeToComplete.EmployeeDetails.Birthday = Convert.ToDateTime("1900-1-1"); } _TheEmployeeToComplete.EmployeeDetails.NativePlace = _ItsView.NativePlace; _TheEmployeeToComplete.Account.MobileNum = _ItsView.Phone; _TheEmployeeToComplete.EmployeeDetails.PhysicalConditions = _ItsView.PhysicalCondition; //_TheEmployeeToComplete.EmployeeDetails.Birthday = DateTime.Parse(_ItsView.BirthDay); _TheEmployeeToComplete.EmployeeDetails.PoliticalAffiliation = PoliticalAffiliation.GetById(int.Parse(_ItsView.PoliticalAffiliation)); _TheEmployeeToComplete.EmployeeDetails.Nationality = _ItsView.Nationality; //_TheEmployeeToComplete.EmployeeDetails.Birthday = DateTime.Parse(_ItsView.BirthDay); _TheEmployeeToComplete.EmployeeDetails.Photo = _ItsView.Photo; HandleEducationInfo(); HandleIDCardInfo(); HandleCountryNationalityInfo(); }
/// <summary> /// 除了image以外的所有数据绑定 /// </summary> /// <param name="sdr"></param> /// <param name="employee"></param> private static void GetEmployeeNotImageFieldFromParm(SqlDataReader sdr, Employee employee) { for (int i = 0; i < sdr.FieldCount; i++) { DateTime tryDateTimeParse; int tryIntParse; bool tryBoolParse; switch (sdr.GetName(i)) { case _DBAccountID: if (sdr[_DBAccountID] != null && int.TryParse(sdr[_DBAccountID].ToString(), out tryIntParse)) { employee.Account = employee.Account ?? new Account(); employee.Account.Id = (int)sdr[_DBAccountID]; employee.Account.Position = new Position(); employee.Account.Position.Grade = new PositionGrade(); employee.Account.Position.Grade.Id = (int)sdr[_DBPositionGradeID]; } break; case _DBCompanyID: if (sdr[_DBCompanyID] != null && int.TryParse(sdr[_DBCompanyID].ToString(), out tryIntParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.Company = employee.EmployeeDetails.Work.Company ?? new Department(); employee.EmployeeDetails.Work.Company.DepartmentID = (int)sdr[_DBCompanyID]; } break; case _DBEmployeeType: if (sdr[_DBEmployeeType] != null && int.TryParse(sdr[_DBEmployeeType].ToString(), out tryIntParse)) { employee.EmployeeType = (EmployeeTypeEnum)sdr[_DBEmployeeType]; } break; case _DBComeDate: if (sdr[_DBComeDate] != null && DateTime.TryParse(sdr[_DBComeDate].ToString(), out tryDateTimeParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.ComeDate = (DateTime)sdr[_DBComeDate]; } break; case _DBLeaveDate: if (sdr[_DBLeaveDate] != null && DateTime.TryParse(sdr[_DBLeaveDate].ToString(), out tryDateTimeParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.DimissionInfo = employee.EmployeeDetails.Work.DimissionInfo ?? new DimissionInfo(); employee.EmployeeDetails.Work.DimissionInfo.DimissionDate = (DateTime)sdr[_DBLeaveDate]; } break; case _DBBirthday: if (sdr[_DBBirthday] != null && DateTime.TryParse(sdr[_DBBirthday].ToString(), out tryDateTimeParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Birthday = (DateTime)sdr[_DBBirthday]; } break; case _DBResidencePermit: if (sdr[_DBResidencePermit] != null && DateTime.TryParse(sdr[_DBResidencePermit].ToString(), out tryDateTimeParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.ResidencePermits = employee.EmployeeDetails.ResidencePermits ?? new ResidencePermit(); employee.EmployeeDetails.ResidencePermits.DueDate = (DateTime)sdr[_DBResidencePermit]; } break; case _DBEnglishName: if (sdr[_DBEnglishName] != null) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.EnglishName = sdr[_DBEnglishName].ToString(); } break; case _DBGender: if (sdr[_DBGender] != null && int.TryParse(sdr[_DBGender].ToString(), out tryIntParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Gender = Gender.GetById((int)sdr[_DBGender]); } break; case _DBPoliticalAffiliation: if (sdr[_DBPoliticalAffiliation] != null && int.TryParse(sdr[_DBPoliticalAffiliation].ToString(), out tryIntParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.PoliticalAffiliation = PoliticalAffiliation.GetById((int)sdr[_DBPoliticalAffiliation]); } break; case _DBMaritalStatus: if (sdr[_DBMaritalStatus] != null && int.TryParse(sdr[_DBMaritalStatus].ToString(), out tryIntParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.MaritalStatus = MaritalStatus.GetById((int)sdr[_DBMaritalStatus]); } break; case _DBEducationalBackground: if (sdr[_DBEducationalBackground] != null && int.TryParse(sdr[_DBEducationalBackground].ToString(), out tryIntParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Education = employee.EmployeeDetails.Education ?? new Education(); employee.EmployeeDetails.Education.EducationalBackground = EducationalBackground.GetById((int)sdr[_DBEducationalBackground]); } break; case _DBWorkType: if (sdr[_DBWorkType] != null && int.TryParse(sdr[_DBWorkType].ToString(), out tryIntParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.WorkType = WorkType.GetById((int)sdr[_DBWorkType]); } break; case _DBHasChild: if (sdr[_DBHasChild] != null && bool.TryParse(sdr[_DBHasChild].ToString(), out tryBoolParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Family = employee.EmployeeDetails.Family ?? new Family(); employee.EmployeeDetails.Family.HasChild = (bool)sdr[_DBHasChild]; } break; case _DBCertificates: if (sdr[_DBCertificates] != null) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.Education = employee.EmployeeDetails.Education ?? new Education(); employee.EmployeeDetails.Education.Certificates = sdr[_DBCertificates].ToString(); } break; case _DBPRPArea: if (sdr[_DBPRPArea] != null) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.RegisteredPermanentResidence = employee.EmployeeDetails.RegisteredPermanentResidence ?? new RegisteredPermanentResidence(); employee.EmployeeDetails.RegisteredPermanentResidence.PRPArea = sdr[_DBPRPArea].ToString(); } break; case _DBProbationTime: if (sdr[_DBProbationTime] != null && DateTime.TryParse(sdr[_DBProbationTime].ToString(), out tryDateTimeParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.ProbationTime = (DateTime)sdr[_DBProbationTime]; } break; case _DBProbationStartTime: if (sdr[_DBProbationStartTime] != null && DateTime.TryParse(sdr[_DBProbationStartTime].ToString(), out tryDateTimeParse)) { employee.EmployeeDetails = employee.EmployeeDetails ?? new EmployeeDetails(); employee.EmployeeDetails.ProbationStartTime = (DateTime)sdr[_DBProbationStartTime]; } break; case _DBDoorCardNo: if (sdr[_DBDoorCardNo] != null) { employee.EmployeeAttendance = employee.EmployeeAttendance ?? new EmployeeAttendance(); employee.EmployeeAttendance.DoorCardNo = sdr[_DBDoorCardNo].ToString(); } break; case _DBSocietyWorkAge: if (sdr[_DBSocietyWorkAge] != null && int.TryParse(sdr[_DBSocietyWorkAge].ToString(), out tryIntParse)) { employee.SocWorkAgeAndVacationList = employee.SocWorkAgeAndVacationList ?? new SocWorkAgeAndVacationList(); employee.SocWorkAgeAndVacationList.SocietyWorkAge = (int)sdr[_DBSocietyWorkAge]; } break; case _DBCountryNationalityID: if (sdr[_DBCountryNationalityID] != null && int.TryParse(sdr[_DBCountryNationalityID].ToString(), out tryIntParse)) { employee.EmployeeDetails.CountryNationality = new Nationality((int)sdr[_DBCountryNationalityID], "", ""); } break; case _DBWorkPlace: employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.WorkPlace = sdr[_DBWorkPlace].ToString(); break; case _DBPrincipalShipID: if (sdr[_DBPrincipalShipID] != null && int.TryParse(sdr[_DBPrincipalShipID].ToString(), out tryIntParse)) { employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.Principalship = PrincipalShip.GetById(( int) sdr[_DBPrincipalShipID]); } break; case _DBSalaryCardNo: employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.SalaryCardNo = sdr[_DBSalaryCardNo].ToString(); break; case _DBSalaryCardBank: employee.EmployeeDetails.Work = employee.EmployeeDetails.Work ?? new Work(); employee.EmployeeDetails.Work.SalaryCardBank = sdr[_DBSalaryCardBank].ToString(); break; default: break; } } }