/// <summary> /// 新增职员。 /// </summary> /// <param name="dto">待新增职员的信息。</param> /// <returns>新增是否成功的标示。(1:成功;-2:登录Id重复)</returns> public static string InsertStaff(StaffDTO dto) { //判断登录Id是否重复。 string hql = "select count(*) from Staff s where s.LoginId = :loginId"; IQuery q = Db.Session.CreateQuery(hql); q.SetString("loginId", dto.LoginId); object o = q.UniqueResult(); if (int.Parse(o.ToString()) > 0) { return("-2"); } //职员基本信息。 Staff s = new Staff(); s.LoginId = dto.LoginId; s.Password = StringSecurity.StringToSHA1Hash(dto.Password); s.Name = dto.Name; s.Disabled = dto.Disabled; s.OrderId = dto.OrderId; s.IdCard = dto.IdCard; s.Code = dto.Code; s.OfficePhone = dto.OfficePhone; s.ExtNumber = dto.ExtNumber; s.CellPhone = dto.CellPhone; s.FamilyPhone = dto.FamilyPhone; s.Email = dto.Email; s.ZipCode = dto.ZipCode; s.Remark = dto.Remark; s.Address = dto.Address; s.DegreeTag = dto.DegreeTag; s.Sex = dto.Sex; s.PoliticalAppearanceTag = dto.PoliticalAppearanceTag; s.Married = dto.Married; s.Birthday = dto.Birthday; s.CountryTag = dto.CountryTag; s.EntersDay = dto.EntersDay; s.NationTag = dto.NationTag; s.LeavesDay = dto.LeavesDay; s.PositionTag = dto.PositionTag; s.TitleTag = dto.TitleTag; //所有通过程序加入的职员都不是内部用户。 s.IsInnerUser = 0; //所属部门。 Department d = Db.Session.Load(typeof(Department), dto.DepartmentId) as Department; d.AddStaff(s); Db.TransInsert(s); return("1"); }
public void SaveBtnClick() { if (viewCompany.EmployeeSelected == null) { return; } viewCompany.EmployeeSelected.EmployeeName = viewEmployee.EmplName; viewCompany.EmployeeSelected.Position = viewEmployee.PositionSelected; if (double.TryParse(viewEmployee.Salary, out double result)) { viewCompany.EmployeeSelected.Salary = result; } Department depTemp = viewEmployee.DepartmentSelected; depTemp.AddStaff(viewCompany.EmployeeSelected); DelEmployee(); }
static void Main(string[] args) { //first create the four new departments. Department MthDepartment = new Department(); Department EngDepartment = new Department(); Department GeoDepartment = new Department(); Department CSDepartment = new Department(); //add people to them MthDepartment.AddStaff("James", 70000, "Administrator"); MthDepartment.AddStaff("Matt", 80000, "dean"); MthDepartment.AddStaff("Clark", 75000, "Researcher"); MthDepartment.AddStaff("Jill", 75000, "Professor"); EngDepartment.AddStaff("Mark", 70000, "Administrator"); EngDepartment.AddStaff("Kaitlyn", 80000, "dean"); EngDepartment.AddStaff("John", 75000, "Researcher"); EngDepartment.AddStaff("Bob", 75000, "Professor"); GeoDepartment.AddStaff("Joe", 70000, "Administrator"); GeoDepartment.AddStaff("Cathy", 80000, "dean"); GeoDepartment.AddStaff("Annette", 75000, "Researcher"); GeoDepartment.AddStaff("Chester", 75000, "Professor"); //should have used a database... CSDepartment.AddStaff("Cortney", 70000, "Administrator"); CSDepartment.AddStaff("Joesph", 80000, "dean"); CSDepartment.AddStaff("Jackelyn", 75000, "Researcher"); CSDepartment.AddStaff("Gregg", 75000, "Professor"); //now add all the departments to the university. University newUni = new University(new List <Department> { MthDepartment, EngDepartment, GeoDepartment, CSDepartment }); //for each department for (int z = 0; z < newUni.DepartmentList.Count(); z++) { //and each staff member in that department. for (int i = 0; i < newUni.DepartmentList[0].departmentStaff.Count(); i++) { //print out the staff list. Console.WriteLine("{0} Makes ${1}", newUni.DepartmentList[z].departmentStaff[i].Name, newUni.DepartmentList[0].departmentStaff[i].Salary); //if the specific person can teach or research, cast the object to the specific type (interface or class type) and execute their unique method. if (newUni.DepartmentList[z].departmentStaff[i] is Researcher) { ((Researcher)(newUni.DepartmentList[z].departmentStaff[i])).conductReaserch(); } if (newUni.DepartmentList[z].departmentStaff[i] is ITeachable) { ((ITeachable)(newUni.DepartmentList[z].departmentStaff[i])).Teach(); } if (newUni.DepartmentList[z].departmentStaff[i] is IAdmin) { ((IAdmin)(newUni.DepartmentList[z].departmentStaff[i])).Administrate(); } } Console.WriteLine(); } Console.ReadLine(); }