Beispiel #1
0
        private void btnImportEmployee_Click(object sender, EventArgs e)
        {
            string txt = "";
            try
            {
                StreamReader sr = new StreamReader(txbEmployeeListFile.Text);
                txt = sr.ReadToEnd();
                sr.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            string[] empList = txt.Split(new string[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
            foreach (string empstr in empList)
            {
                string[] empinfo = empstr.Split(',');
                Employee emp = new Employee() {EmployeeNumber = empinfo[0], Name = empinfo[1], Dept = empinfo[2]};
                string shortpy = "";
                emp.Pinyin = GetPinyin(emp.Name, out shortpy);
                emp.ShortPinyin = shortpy;
                AnnualPartySqlHelper.Instance.InitEmployee(emp);
            }
            MessageBox.Show("成功导入员工" + empList.Length + "个");

        }
Beispiel #2
0
        //public MyEmployee(IDataReader reader)
        //{
        //    LoadBasic(reader);
      

      public void LoadBasic(Employee reader)
      {
          this.EmployeeNumber = reader.EmployeeNumber;
          this.Name = reader.Name;
          this.Dept = reader.Dept;
          this.Checkin = reader.CheckIn;
          this.Pinyin = reader.PinyinFull;
          this.ShortPinyin = reader.PinyinShort;
          //this.EmployeeNumber = (string)reader["EmployeeNumber"];
          //this.Name = (string)reader["Name"];
          //this.Dept = (string)reader["Dept"];
          //this.Checkin = (bool)reader["CheckIn"];
          //if (!Convert.IsDBNull(reader["PinyinFull"]))
          //{
          //    this.Pinyin = (string)reader["PinyinFull"];
          //}
          //if (!Convert.IsDBNull(reader["PinyinShort"]))
          //{
          //    this.ShortPinyin = (string)reader["PinyinShort"];
          //}
      }
 /// <summary>
 /// 获得所有的员工,不管是否签到的
 /// </summary>
 /// <returns></returns>
 public Dictionary<string,Employee> GetAllEmployee(bool withPhoto)
 {
     string sql = "select * from " + (withPhoto ? "vEmployeeFull" : "Employee");
     var reader = SqlHelper.ExecuteReader(conn, System.Data.CommandType.Text, sql);
     Dictionary<string, Employee> employees = new Dictionary<string, Employee>();
     while (reader.Read())
     {
         Employee emp = new Employee();
         if (withPhoto)
         {
             emp.LoadWithPhoto(reader);
         }
         else
         {
             emp.LoadBasic(reader);
         }
         employees.Add(emp.EmployeeNumber, emp);
     }
     reader.Close();
     return employees;
 }
 /// <summary>
 /// 插入一个员工信息
 /// </summary>
 /// <param name="e"></param>
 public void InitEmployee(Employee e)
 {
     string sql =
         "insert into Employee(EmployeeNumber,Name,Dept,Alias,PinyinFull,PinyinShort) values(@num,@name,@dept,@alias,@pinyin,@pinyinshort)";
     SqlParameter p1 = new SqlParameter("@num", e.EmployeeNumber);
     SqlParameter p2 = new SqlParameter("@name", e.Name);
     SqlParameter p3 = new SqlParameter("@dept", e.Dept);
     SqlParameter p4 = new SqlParameter("@alias", e.Alias);
     SqlParameter p5 = new SqlParameter("@pinyin", e.Pinyin);
     SqlParameter p6 = new SqlParameter("@pinyinshort", e.ShortPinyin);
     SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, p1, p2, p3, p4, p5, p6);
 }
 /// <summary>
 /// 从HR系统中获取员工信息和照片信息
 /// </summary>
 /// <param name="conn"></param>
 /// <param name="sql"></param>
 /// <returns></returns>
 public List<Employee> GetAllEmployeeFromHrDB(string conn,string sql)
 {
     SqlDataReader reader = SqlHelper.ExecuteReader(conn, CommandType.Text, sql);
     List<Employee> empList = new List<Employee>();
     while (reader.Read())
     {
         Employee e = new Employee();
         e.EmployeeNumber = (string)reader["EmployeeID"];
         e.Name = (string) reader["ChineseName"];
         e.Dept = (string) reader["Department"];
         if (!Convert.IsDBNull(reader["alias"]))
         {
             e.Alias = (string) reader["alias"];
         }
         string py = "";
         if (!Convert.IsDBNull(reader["lastname"]))
         {
            py += (string)reader["lastname"];
         }
         if (!Convert.IsDBNull(reader["firstname"]))
         {
             py += (string)reader["firstname"];
         }
         e.Pinyin = py;
         if (!Convert.IsDBNull(reader["Photo"]))
         {
             byte[] bImg = (byte[])reader["Photo"];
             e.Photo = GetImage(bImg);
         }
         else
         {
             e.Photo = null;
         }
         empList.Add(e);
     }
     return empList;
 }
 /// <summary>
 /// 插入一个员工信息
 /// </summary>
 /// <param name="e"></param>
 public void InitEmployee(MyEmployee e)
 {
      AnnualPartyEntities entities = new AnnualPartyEntities();
      Employee employee=new Employee();
     employee.EmployeeNumber = e.EmployeeNumber;
     employee.Dept = e.Dept;
     employee.Name = e.Name;
     employee.PinyinFull = e.Pinyin;
     employee.PinyinShort = e.ShortPinyin;
     employee.Alias = e.Alias;
     entities.Employee.Add(employee);
     entities.SaveChanges();
     // string sql =
     //    "insert into Employee(EmployeeNumber,Name,Dept,Alias,PinyinFull,PinyinShort) values(@num,@name,@dept,@alias,@pinyin,@pinyinshort)";
     //SqlParameter p1 = new SqlParameter("@num", e.EmployeeNumber);
     //SqlParameter p2 = new SqlParameter("@name", e.Name);
     //SqlParameter p3 = new SqlParameter("@dept", e.Dept);
     //SqlParameter p4 = new SqlParameter("@alias", e.Alias);
     //SqlParameter p5 = new SqlParameter("@pinyin", e.Pinyin);
     //SqlParameter p6 = new SqlParameter("@pinyinshort", e.ShortPinyin);
     //SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql, p1, p2, p3, p4, p5, p6);
 }