62,046
社区成员
发帖
与我相关
我的任务
分享
//导入员工信息
public void SubmitEmployeeExcel()
{
string result = "";
HttpPostedFile postedFile = System.Web.HttpContext.Current.Request.Files["EmployeeExcel"];
string name = postedFile.FileName;
string _tp = System.IO.Path.GetExtension(name);
#region 查询关联数据
List<string> liststr = new List<string>();
liststr.Add("1");//工作地点
liststr.Add("18");//隶属公司
liststr.Add("19");//业务单元
liststr.Add("20");//成本中心
liststr.Add("21");//员工职能
liststr.Add("22");//员工职位/层级
liststr.Add("24");//员工类别1
liststr.Add("25");//员工类别2
liststr.Add("26");//员工类别3
liststr.Add("27");//员工雇佣类型
liststr.Add("28");//员工变动类型
liststr.Add("29");//员工工作制度
liststr.Add("30");//特殊工作证件类型
liststr.Add("31");//高薪技术职位类型
liststr.Add("32");//员工合同类型
liststr.Add("33");//员工合同签署方
liststr.Add("34");//政治面貌类别
liststr.Add("35");//学历类别
liststr.Add("36");//员工户口类型
liststr.Add("37");//员工紧急联系人与本人关系
liststr.Add("43");//国籍
liststr.Add("44");//证件类型
liststr.Add("45");//婚姻状态
liststr.Add("46");//个税类型
liststr.Add("47");//雇佣类型
SearchCommonCategory searchcommencategory = new SearchCommonCategory
{
SearchType = SearchTypeEnum.Total,
CategoryTypeIDs = string.Join(",", liststr)
};
IList<CommonCategoryInfo> commonList = icommonCategory.SearchCommonCategory(searchcommencategory);
SearchDepDetail searchdep=new SearchDepDetail ()
{
SearchType = SearchTypeEnum.Total,
};
IList<DepDetailInfo> deplist = idepdetail.SearchDepDetail(searchdep);
#endregion
if (_tp == ".xlsx")
{
string saveName = DateTime.Now.ToString("yyyyMMddHHmmss") + _tp;
string path = Server.MapPath("../fileupload/EmployeeInfoExcel/") + saveName;
postedFile.SaveAs(path);
DataSet ds = ReadExcel(path);
if (ds.Tables.Count > 0)
{
result += "ds.Tables.Count=" + ds.Tables.Count;
result +="Rows.Count="+ ds.Tables[0].Rows.Count;
EmployeeInfo info = null;
if (ds.Tables[0].Rows.Count > 0)
{
result += "ds.Tables[0].Rows.RemoveAt(0)=" + ds.Tables[0].Rows[0][0];
if (ds.Tables[0].Rows[0][1].ToString() == "员工工号")
ds.Tables[0].Rows.RemoveAt(0);
}
foreach (DataRow dr in ds.Tables[0].Rows)
{
result += "dr[1]=" + dr[1].ToString();
if (!string.IsNullOrEmpty(dr[1].ToString()))
{
info = iemployee.GetEmployee(dr[1].ToString());
info = info ?? new EmployeeInfo();
#region Info赋值
info.Age = dr[52].ToString();
//info.ApplicationDate = "";
info.ArchivesAddress = dr[83].ToString();
info.AreaCode = dr[10].ToString();
info.AreaID = commonList.Where(w => w.CategoryTypeID == 1 && w.CategoryName == dr[12].ToString() && w.CLevel == 3).Select(s => s.CategoryID).FirstOrDefault();
...
info.EmployeeRelationship = commonList.Where(w => w.CategoryTypeID == 47 && w.CategoryName == dr[101].ToString()).Select(s => s.CategoryID).FirstOrDefault();
string email = dr[30].ToString();
string username = dr[102].ToString();
if (!string.IsNullOrEmpty(username) && username != "0" && username != "#N/A")
{
if (info.UserID > 0)
{
UserInfo userinfo = new UserInfo();
userinfo = iuser.GetUser(info.UserID);
//userinfo.UserName = username;
userinfo.Profile.Email = email;
iuser.UpdateUser(userinfo);
}
else
{
//if (iuser.ExsitUsername("branson#" + username))
//{
// info.UserID = iuser.GetUser("branson#" + username).UserID;
//}
//else
if (!iuser.ExsitUsername("branson#" + username))
info.UserID = iuser.CreateADUser(username, email, info.EmployeeNameCh,info.Tel,info.Phone,info.CensusRegisterAddress,info.EmployeeCode,info.ZipCode,info.Birthday);
}
}
if (info.EmployeeID > 0)
iemployee.UpdateEmployee(info);
else
iemployee.CreateEmployee(info);
#endregion
}
else
continue;
}
Response.Write("{'result':" + result + "}");
}
}
}