Exemplo n.º 1
0
        /*
         * /// <summary>
         * /// 创建雇员信息
         * /// </summary>
         * /// <returns></returns>
         * public ActionResult Create()
         * {
         *  IModelService helper = new EmployeeService();
         *
         *  Employee emp = EmployeeService.GetRandomEmployee();
         *  emp.Post = Request["Post"];
         *  emp.Salary = EmployeeService.GetSalaryAboutPost(Request["Post"]);
         *  emp.Sex = Request["Sex"];
         *  emp.Name = Request["Name"];
         *  emp.Age = Int32.Parse(Request["Age"]);
         *  emp.Experience = float.Parse(Request["Experience"]);
         *
         *  if (helper.Create(emp))
         *      Response.Write("<script>alert('添加成功!')</script>");
         *  else
         *      Response.Write("<script>alert('添加失败!')</script>");
         *
         *  return RedirectToAction("GetEmployeeInfo", "MainSystem");
         * }/*/

        /// <summary>
        /// 创建雇员信息
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            IModelService helper = new EmployeeService();

            IFactory  factory = FactoryService.GetFactory(Request["Post"]);
            IEmployee emp     = factory.Get();

            emp.Sex  = Request["Sex"];
            emp.Name = Request["Name"];
            emp.Age  = Int32.Parse(Request["Age"]);

            if (helper.Create(emp))
            {
                Response.Write("<script>alert('添加成功!')</script>");
            }
            else
            {
                Response.Write("<script>alert('添加失败!')</script>");
            }

            return(RedirectToAction("GetEmployeeInfo", "MainSystem"));
        }//*/
Exemplo n.º 2
0
        /// <summary>
        /// 验证输入,通过后更新雇员信息,反之显示错误提示
        /// </summary>
        /// <returns></returns>
        public ActionResult UpdateEmployee()
        {
            IFactory  factory = FactoryService.GetFactory(Request["Emp_Post.Post_Name"]);
            IEmployee emp     = factory.Get();

            emp.Id   = int.Parse(Request["Id"].ToString());
            emp.Name = Request["Name"];
            emp.Age  = int.Parse(Request["Age"].ToString());
            emp.Sex  = Request["Sex"];

            EmployeeService.IsEffective(emp);
            modelService.Update(emp);
            ViewBag.list = EmployeeService.GetEmployeeInfo();
            Response.Write("<script>alert('更新完成')</script>");


            try
            {
                return(View("EmployeeInfo", emp));
            }
            catch (FormatException e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                Response.Write("<script>alert('年龄必须是数字!')</script>"); /*/
                                                                       * Response.Write("<script>alert('" + e.Message + "')</script>"); //*/
                ViewBag.list = EmployeeService.GetEmployeeInfo();
                return(View("EmployeeInfo"));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                Response.Write("<script>alert('输入数据有误!请重新输入')</script>"); /*/
                                                                           * Response.Write("<script>alert('" + e.Message + "')</script>"); //*/
                ViewBag.list = EmployeeService.GetEmployeeInfo();
                return(View("EmployeeInfo"));
            }
        }