public ActionResult GetLaborUser(string deptId, string postId, string type) { UserBLL userbll = new UserBLL(); List <LaborequipmentinfoEntity> LaborUlist = new List <LaborequipmentinfoEntity>(); if (postId != "") { List <UserEntity> userlist = userbll.GetListForCon(it => it.DepartmentId == deptId && it.DutyId == postId && it.IsPresence == "1").ToList(); foreach (var user in userlist) { LaborequipmentinfoEntity laboruser = new LaborequipmentinfoEntity(); laboruser.UserName = user.RealName; laboruser.LaborType = 0; laboruser.ShouldNum = 1; laboruser.UserId = user.UserId; if (type == "衣服") { laboruser.Size = "L"; } else if (type == "鞋子") { laboruser.Size = "40"; } else { laboruser.Size = ""; } laboruser.Create(); LaborUlist.Add(laboruser); } } return(ToJsonResult(LaborUlist)); }
public string ImportLabor() { LaborprotectionBLL laborprotectionbll = new LaborprotectionBLL(); PostCache postCache = new PostCache(); PostBLL postBLL = new PostBLL(); DepartmentBLL departmentBLL = new DepartmentBLL(); //获取到已选数据 List <LaborprotectionEntity> laborlist = laborprotectionbll.GetLaborList(); var currUser = OperatorProvider.Provider.Current(); string orgId = OperatorProvider.Provider.Current().OrganizeId;//所属公司 int error = 0; string message = "请选择格式正确的文件再导入!"; string falseMessage = ""; int count = HttpContext.Request.Files.Count; if (count > 0) { HttpPostedFileBase file = HttpContext.Request.Files[0]; if (string.IsNullOrEmpty(file.FileName)) { return(message); } if (!(file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xls") || file.FileName.Substring(file.FileName.IndexOf('.')).Contains("xlsx"))) { return(message); } string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName); file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName)); Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(); wb.Open(Server.MapPath("~/Resource/temp/" + fileName)); Aspose.Cells.Cells cells = wb.Worksheets[0].Cells; if (cells.MaxDataRow == 0) { message = "没有数据,请选择先填写模板在进行导入!"; return(message); } DataTable dt = cells.ExportDataTable(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, true); int order = 1; IList <LaborprotectionEntity> LaborList = new List <LaborprotectionEntity>(); IEnumerable <DepartmentEntity> deptlist = new DepartmentBLL().GetList(); OrganizeBLL orgbll = new OrganizeBLL(); //先获取到原始的一个编号 string no = laborprotectionbll.GetNo(); int ysno = Convert.ToInt32(no); DataItemDetailBLL dataItemDetailBLL = new DataItemDetailBLL(); var dataitem = dataItemDetailBLL.GetDataItemListByItemCode("'LaborName'").ToList(); List <LaborprotectionEntity> insertpro = new List <LaborprotectionEntity>(); List <LaborinfoEntity> insertinfo = new List <LaborinfoEntity>(); //先获取人员 List <UserEntity> userlist = new UserBLL().GetListForCon(it => it.IsPresence == "1" && it.Account != "System").ToList(); List <LaborequipmentinfoEntity> eqlist = new List <LaborequipmentinfoEntity>(); for (int i = 0; i < dt.Rows.Count; i++) { order = i; string Name = dt.Rows[i]["名称"].ToString(); string Model = dt.Rows[i]["型号"].ToString(); string Type = dt.Rows[i]["类型"].ToString(); string DeptName = dt.Rows[i]["使用部门"].ToString(); string OrgName = dt.Rows[i]["使用单位"].ToString(); string PostName = dt.Rows[i]["使用岗位"].ToString().Trim(); string Unit = dt.Rows[i]["劳动防护用品单位"].ToString().Trim(); string Time = dt.Rows[i]["使用期限"].ToString().Trim(); string TimeType = dt.Rows[i]["使用期限单位"].ToString().Trim(); string deptId = "", deptCode = "", PostId = ""; //---****值存在空验证*****-- if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Unit) || string.IsNullOrEmpty(DeptName) || string.IsNullOrEmpty(OrgName) || string.IsNullOrEmpty(PostName)) { falseMessage += "</br>" + "第" + (i + 2) + "行值存在空,未能导入."; error++; continue; } //验证机构是不是和自己一个机构 DepartmentEntity org = deptlist.Where(it => it.FullName == OrgName).FirstOrDefault(); if (org == null) { falseMessage += "</br>" + "第" + (i + 2) + "行使用单位名称不存在,未能导入."; error++; continue; } //如果导入的机构id和本人的机构id不一致 if (org.DepartmentId != currUser.OrganizeId) { falseMessage += "</br>" + "第" + (i + 2) + "行使用单位不是导入者的单位,未能导入."; error++; continue; } //验证所填部门是否存在 var deptFlag = false; var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.FullName == DeptName).FirstOrDefault(); if (entity1 == null) { falseMessage += "</br>" + "第" + (i + 2) + "行使用部门不存在,未能导入."; error++; deptFlag = true; break; } else { deptId = entity1.DepartmentId; deptCode = entity1.EnCode; } //var deptFlag = false; //var array = DeptName.Split('/'); //for (int j = 0; j < array.Length; j++) //{ // if (j == 0) // { // if (currUser.RoleName.Contains("省级")) // { // var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行部门不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } // else // { // var entity = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "厂级" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity == null) // { // entity = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "部门" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity == null) // { // entity = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "承包商" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行部门不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity.DepartmentId; // deptCode = entity.EnCode; // } // } // else // { // deptId = entity.DepartmentId; // deptCode = entity.EnCode; // } // } // else // { // deptId = entity.DepartmentId; // deptCode = entity.EnCode; // } // } // } // else if (j == 1) // { // var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "专业" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "班组" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行专业/班组不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } // else // { // var entity1 = deptlist.Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "班组" && x.FullName == array[j].ToString()).FirstOrDefault(); // if (entity1 == null) // { // falseMessage += "</br>" + "第" + (i + 2) + "行班组不存在,未能导入."; // error++; // deptFlag = true; // break; // } // else // { // deptId = entity1.DepartmentId; // deptCode = entity1.EnCode; // } // } //} if (deptFlag) { continue; } //检验所填岗位是否属于其公司或者部门 if (string.IsNullOrEmpty(deptId) || deptId == "undefined") { //所属公司 RoleEntity data = postCache.GetList(orgId, "true").OrderBy(x => x.SortCode).Where(a => a.FullName == PostName).FirstOrDefault(); if (data == null) { falseMessage += "</br>" + "第" + (i + 2) + "行岗位不属于该公司,未能导入."; error++; continue; } } else { //所属部门 //所属公司 RoleEntity data = postCache.GetList(orgId, deptId).OrderBy(x => x.SortCode).Where(a => a.FullName == PostName).FirstOrDefault(); if (data == null) { falseMessage += "</br>" + "第" + (i + 2) + "行岗位不属于该部门,未能导入."; error++; continue; } } //--**验证岗位是否存在**-- RoleEntity re = postBLL.GetList().Where(a => a.FullName == PostName && a.OrganizeId == orgId).FirstOrDefault(); if (!(string.IsNullOrEmpty(deptId) || deptId == "undefined")) { re = postBLL.GetList().Where(a => a.FullName == PostName && a.OrganizeId == orgId && a.DeptId == deptId).FirstOrDefault(); if (re == null) { re = postBLL.GetList().Where(a => a.FullName == PostName && a.OrganizeId == orgId && a.Nature == departmentBLL.GetEntity(deptId).Nature).FirstOrDefault(); } } if (re == null) { falseMessage += "</br>" + "第" + (i + 2) + "行岗位有误,未能导入."; error++; continue; } else { PostId = re.RoleId; } LaborinfoEntity linfo = new LaborinfoEntity(); linfo.PostId = PostId; linfo.DeptCode = deptCode; linfo.DeptId = deptId; linfo.DeptName = DeptName; linfo.LaboroPerationTime = DateTime.Now; linfo.LaboroPerationUserName = currUser.UserName; linfo.Model = Model; linfo.Name = Name; linfo.OrgCode = currUser.OrganizeCode; linfo.OrgId = currUser.OrganizeId; linfo.OrgName = currUser.OrganizeName; linfo.Type = Type; if (Time == "" || !isInt(Time)) { linfo.TimeNum = null; } else { linfo.TimeNum = Convert.ToInt32(Time); linfo.TimeType = TimeType; } linfo.PostName = PostName; linfo.Unit = Unit; linfo.Create(); //如果已存在物品库中 LaborprotectionEntity lp = laborlist.Where(it => it.Name == Name).FirstOrDefault(); if (lp != null) { linfo.No = lp.No; linfo.LId = lp.ID; //如果库里有值 则使用库里的值 linfo.Type = linfo.Type; linfo.TimeNum = lp.TimeNum; linfo.TimeType = lp.TimeType; } else { LaborprotectionEntity newlp = new LaborprotectionEntity(); newlp.Create(); newlp.Name = Name; newlp.No = ysno.ToString(); newlp.LaborOperationTime = DateTime.Now; newlp.LaborOperationUserName = currUser.UserName; newlp.Model = Model; newlp.Type = Type; newlp.Unit = Unit; newlp.TimeNum = linfo.TimeNum; newlp.TimeType = TimeType; linfo.No = ysno.ToString(); linfo.LId = newlp.ID; ysno++; insertpro.Add(newlp); } int num = 0; List <UserEntity> ulist = userlist.Where(it => it.DepartmentId == deptId && it.DutyId == PostId).ToList(); for (int j = 0; j < ulist.Count; j++) { //添加岗位关联人员 LaborequipmentinfoEntity eq = new LaborequipmentinfoEntity(); eq.UserName = ulist[j].RealName; eq.AssId = linfo.ID; eq.LaborType = 0; eq.ShouldNum = 1; num++; eq.UserId = ulist[j].UserId; if (linfo.Type == "衣服") { eq.Size = "L"; } else if (linfo.Type == "鞋子") { eq.Size = "40"; } else { eq.Size = ""; } eq.Create(); eqlist.Add(eq); } linfo.ShouldNum = num; insertinfo.Add(linfo); } laborinfobll.ImportSaveForm(insertinfo, insertpro, eqlist); count = dt.Rows.Count; message = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条"; message += "</br>" + falseMessage; } return(message); }
/// <summary> /// 保存表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="entity">实体对象</param> /// <returns></returns> public void SaveListForm(string json) { var res = DbFactory.Base().BeginTrans(); try { json = json.Replace(" ", ""); List <Laborff> list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Laborff> >(json); string ids = ""; foreach (Laborff item in list) { if (ids == "") { ids = "'" + item.ID + "'"; } else { ids += ",'" + item.ID + "'"; } } LaborissueEntity issue = new LaborissueEntity(); issue.Create(); issue.LaborOperationTime = DateTime.Now; issue.LaborOperationUserName = OperatorProvider.Provider.Current().UserName; issue.Type = 0;//表示发放记录 //新增记录母表 res.Insert <LaborissueEntity>(issue); Repository <LaborinfoEntity> labordb = new Repository <LaborinfoEntity>(DbFactory.Base()); string sql = string.Format(@"select * from bis_laborinfo where id in({0})", ids); List <LaborinfoEntity> laborlist = labordb.FindList(sql).ToList(); List <LaborissuedetailEntity> detaillist = new List <LaborissuedetailEntity>(); for (int i = 0; i < laborlist.Count; i++) { Laborff ff = list.Where(it => it.ID == laborlist[i].ID).FirstOrDefault(); LaborissuedetailEntity le = new LaborissuedetailEntity(); le.PostId = laborlist[i].PostId; le.DeptCode = laborlist[i].DeptCode; le.DeptId = laborlist[i].DeptId; le.DeptName = laborlist[i].DeptName; le.InfoId = laborlist[i].ID; le.IssueNum = ff.Count; le.LaborOperationTime = DateTime.Now; le.LaborOperationUserName = OperatorProvider.Provider.Current().UserName; le.Name = laborlist[i].Name; le.RecentTime = DateTime.Now; le.Model = laborlist[i].Model; le.Note = laborlist[i].Note; le.No = laborlist[i].No; le.OrgCode = laborlist[i].OrgCode; le.OrgId = laborlist[i].OrgId; le.OrgName = laborlist[i].OrgName; le.PostName = laborlist[i].PostName; le.ShouldNum = laborlist[i].ShouldNum; le.SueId = issue.ID; le.TimeNum = laborlist[i].TimeNum; le.TimeType = laborlist[i].TimeType; le.Type = laborlist[i].Type; le.Unit = laborlist[i].Unit; if (le.TimeType == "年") { le.NextTime = DateTime.Now.AddYears(Convert.ToInt32(le.TimeNum)); } else if (le.TimeType == "月") { le.NextTime = DateTime.Now.AddMonths(Convert.ToInt32(le.TimeNum)); } else if (le.TimeType == "日") { le.NextTime = DateTime.Now.AddDays(Convert.ToInt32(le.TimeNum)); } le.Create(); detaillist.Add(le); //修改原记录的发放数量与发放时间 if (laborlist[i].IssueNum != null) { laborlist[i].IssueNum += le.IssueNum; } else { laborlist[i].IssueNum = le.IssueNum; } laborlist[i].RecentTime = le.RecentTime; laborlist[i].NextTime = le.NextTime; //先获取当前用品标准下所有需发放人员 Repository <LaborequipmentinfoEntity> equdb = new Repository <LaborequipmentinfoEntity>(DbFactory.Base()); string equsql = string.Format("select * from bis_laborequipmentinfo where assid='{0}'", laborlist[i].ID); List <LaborequipmentinfoEntity> equlist = equdb.FindList(equsql).ToList(); List <LaborequipmentinfoEntity> laborque = new List <LaborequipmentinfoEntity>(); foreach (LaborequipmentinfoEntity equ in equlist) { LaborequipmentinfoEntity eq = new LaborequipmentinfoEntity(); eq.UserName = equ.UserName; eq.AssId = le.ID; eq.Brand = ""; eq.LaborType = 1; eq.Reson = ""; eq.ShouldNum = ff.PerCount; eq.Size = equ.Size; //eq.Size = ""; eq.UserId = equ.UserId; eq.Create(); laborque.Add(eq); } res.Insert <LaborequipmentinfoEntity>(laborque); } res.Insert <LaborissuedetailEntity>(detaillist); res.Update <LaborinfoEntity>(laborlist); res.Commit(); } catch (Exception e) { res.Rollback(); throw e; } }