Exemple #1
0
        /// <summary>
        /// 随机生成一条雇员信息
        /// </summary>
        /// <returns></returns>
        public static IEmployee GetRandomEmployee()
        {
            int index_first  = random.Next(0, firstNames.Length);
            int index_second = random.Next(0, lastNames.Length);
            int index_post   = random.Next(0, posts.Length);

            IFactory  factory = FactoryService.GetFactory(posts[index_post].Post_name);
            IEmployee emp     = factory.Get();

            emp.Id   = int.Parse(CreateEmployeeID());
            emp.Sex  = (random.Next(0, 6) < 3 ? "男" : "女");
            emp.Name = (firstNames[index_first] + " " + lastNames[index_second]);
            emp.Age  = random.Next(18, 40);
            return(emp);
        }
Exemple #2
0
        /// <summary>
        /// 根据ID查询雇员信息
        /// </summary>
        /// <param name="key">查询ID</param>
        /// <returns></returns>
        dynamic IModelService.Get(dynamic key)
        {
            string id = key;

            try
            {
                using (SqlConnection conn = sqlHelper.GetConnection())
                {
                    conn.Open();
                    string     sql = "SELECT * FROM [dbo].[EmployeeInfo] WHERE Id = @Id;";
                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.Add("@Id", SqlDbType.NVarChar);
                    cmd.Parameters["@Id"].Value = id;
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            System.Data.IDataRecord record = reader;

                            IFactory  factory = FactoryService.GetFactory(record.GetString(4));
                            IEmployee emp     = factory.Get();
                            emp.Id   = int.Parse(record.GetString(0));
                            emp.Name = record.GetString(1);
                            emp.Age  = record.GetInt32(2);
                            emp.Sex  = record.GetString(6);

                            return(emp);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
            }
            catch (SqlException sqle)
            {
                throw sqle;
            }
            catch (Exception e)
            {
                throw e;
            }
        }