Пример #1
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, LaborprotectionEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Пример #2
0
        public ActionResult GetNameList()
        {
            //获取到已选数据
            List <LaborprotectionEntity> laborlist = laborprotectionbll.GetLaborList();

            DataItemDetailBLL dataItemDetailBLL = new DataItemDetailBLL();
            var data = dataItemDetailBLL.GetDataItemListByItemCode("'LaborName'").ToList();

            for (int i = 0; i < data.Count; i++)
            {
                //如果当前没有这个数据 则加入到集合中
                if (laborlist.Where(it => it.Name == data[i].ItemName).Count() == 0)
                {
                    LaborprotectionEntity lb = new LaborprotectionEntity();
                    lb.ID   = i.ToString();
                    lb.Name = data[i].ItemName;
                    laborlist.Add(lb);
                }
            }

            return(ToJsonResult(laborlist));;
        }
Пример #3
0
 public ActionResult SaveForm(string keyValue, LaborprotectionEntity entity)
 {
     laborprotectionbll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }
Пример #4
0
        public string ImportLabor()
        {
            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>();

                //先获取到原始的一个编号
                string no   = laborprotectionbll.GetNo();
                int    ysno = Convert.ToInt32(no);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    order = i;

                    string Name     = dt.Rows[i]["劳动防护用品名称"].ToString();
                    string Unit     = dt.Rows[i]["劳动防护用品单位"].ToString();
                    string Model    = dt.Rows[i]["型号"].ToString();
                    string Type     = dt.Rows[i]["类型"].ToString();
                    string TimeNum  = dt.Rows[i]["使用期限时间"].ToString();
                    string TimeType = dt.Rows[i]["使用期限单位"].ToString();
                    string Note     = dt.Rows[i]["使用说明"].ToString().Trim();



                    //---****值存在空验证*****--
                    if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Unit))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行值存在空,未能导入.";
                        error++;
                        continue;
                    }


                    LaborprotectionEntity ue = new LaborprotectionEntity();
                    ue.Name  = Name;
                    ue.Unit  = Unit;
                    ue.Model = Model;
                    ue.Type  = Type;
                    if (TimeNum != "")
                    {
                        ue.TimeNum = Convert.ToInt32(TimeNum);//工号
                    }
                    ue.TimeType = TimeType;
                    ue.Note     = Note;
                    ue.No       = ysno.ToString();
                    //下一条编号增加
                    ysno++;
                    ue.LaborOperationUserName = currUser.UserName;
                    ue.LaborOperationTime     = DateTime.Now;

                    try
                    {
                        laborprotectionbll.SaveForm("", ue);
                    }
                    catch
                    {
                        error++;
                    }
                }

                count    = dt.Rows.Count;
                message  = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }

            return(message);
        }
Пример #5
0
        /// <summary>
        /// 保存表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="entity">实体对象</param>
        /// <returns></returns>
        public void SaveForm(string keyValue, LaborinfoEntity entity, string json, string ID)
        {
            var res = DbFactory.Base().BeginTrans();

            try
            {
                //如果关联ID为空则为关联库新增一条数据
                if (entity.LId == null || entity.LId == "")
                {
                    LaborprotectionEntity labor = new LaborprotectionEntity();
                    labor.LaborOperationTime     = DateTime.Now;
                    labor.LaborOperationUserName = OperatorProvider.Provider.Current().UserName;
                    labor.Model    = entity.Model;
                    labor.Name     = entity.Name;
                    labor.No       = entity.No;
                    labor.Note     = entity.Note;
                    labor.TimeNum  = entity.TimeNum;
                    labor.TimeType = entity.TimeType;
                    labor.Type     = entity.Type;
                    labor.Unit     = entity.Unit;
                    labor.Create();
                    labor.ID   = ID;
                    entity.LId = labor.ID;
                    res.Insert <LaborprotectionEntity>(labor);
                }

                Repository <DepartmentEntity> inlogdb = new Repository <DepartmentEntity>(DbFactory.Base());
                DepartmentEntity dept = inlogdb.FindEntity(entity.DeptId);

                entity.DeptCode = dept.DeptCode;

                Repository <DepartmentEntity> orgdb = new Repository <DepartmentEntity>(DbFactory.Base());
                DepartmentEntity org = orgdb.FindEntity(dept.OrganizeId);

                if (org.Nature.Contains("省级"))
                {
                    entity.OrgCode = org.DeptCode;
                    entity.OrgId   = org.OrganizeId;
                    entity.OrgName = org.FullName;
                }
                else
                {
                    entity.OrgCode = org.EnCode;
                    entity.OrgId   = org.OrganizeId;
                    entity.OrgName = org.FullName;
                }


                if (!string.IsNullOrEmpty(keyValue))
                {
                    entity.Modify(keyValue);
                    res.Update <LaborinfoEntity>(entity);
                }
                else
                {
                    entity.Create();
                    res.Insert <LaborinfoEntity>(entity);
                }


                //先删除该危害因素下的所有人员
                string sql = string.Format("delete from BIS_LABOREQUIPMENTINFO where ASSID='{0}'", entity.ID);
                res.ExecuteBySql(sql);
                json = json.Replace("&nbsp;", "");
                List <LaborequipmentinfoEntity> list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <LaborequipmentinfoEntity> >(json);
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        list[i].Create();
                        list[i].AssId     = entity.ID;
                        list[i].LaborType = 0;
                    }
                    res.Insert <LaborequipmentinfoEntity>(list);
                }


                res.Commit();
            }
            catch (Exception e)
            {
                res.Rollback();
                throw e;
            }
        }
Пример #6
0
        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);
        }