Ejemplo n.º 1
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, FireTroopsEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        //[AjaxOnly]
        //[HandlerAuthorize(PermissionMode.Ignore)]
        // [ValidateAntiForgeryToken]
        public string ExcelImport()
        {
            if (OperatorProvider.Provider.Current().IsSystem)
            {
                return("超级管理员无此操作权限");
            }
            string orgId        = OperatorProvider.Provider.Current().OrganizeId;//所属公司
            var    currUser     = OperatorProvider.Provider.Current();
            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));
                DataTable dt    = ExcelHelper.ExcelImport(Server.MapPath("~/Resource/temp/" + fileName));
                int       order = 2;
                string    orgid = OperatorProvider.Provider.Current().OrganizeId;
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    FireTroopsEntity item = new FireTroopsEntity();
                    order = i + 1;
                    #region 序号
                    string sortcode = dt.Rows[i][0].ToString();
                    int    tempSortCode;
                    if (!string.IsNullOrEmpty(sortcode))
                    {
                        if (Int32.TryParse(sortcode, out tempSortCode))
                        {
                            item.SortCode = tempSortCode;
                        }
                        else
                        {
                            falseMessage += string.Format(@"第{0}行导入失败,序号必须为整数!</br>", order);
                            error++;
                            continue;
                        }
                    }
                    else
                    {
                        falseMessage += string.Format(@"第{0}行导入失败,序号不能为空!</br>", order);
                        error++;
                        continue;
                    }
                    #endregion

                    #region 责任部门
                    string deptlist = dt.Rows[i][1].ToString();
                    if (string.IsNullOrEmpty(deptlist))
                    {
                        falseMessage += string.Format(@"第{0}行导入失败,单位(部门)不能为空!</br>", order);
                        error++;
                        continue;
                    }
                    var p1 = string.Empty; var p2 = string.Empty;
                    var array    = deptlist.Split('/');
                    var deptFlag = false;
                    for (int j = 0; j < array.Length; j++)
                    {
                        if (j == 0)
                        {
                            if (currUser.RoleName.Contains("省级") || currUser.RoleName.Contains("集团"))
                            {
                                var entity1 = departmentBLL.GetList().Where(x => x.OrganizeId == currUser.OrganizeId && x.FullName == array[j].ToString()).FirstOrDefault();
                                if (entity1 == null)
                                {
                                    //falseMessage += "</br>" + "第" + (i + 3) + "行部门不存在,未能导入.";
                                    //error++;
                                    //deptFlag = true;
                                    //break;
                                    item.Dept = deptlist;
                                    break;
                                }
                                else
                                {
                                    item.Dept     = entity1.FullName;
                                    item.DeptCode = entity1.EnCode;
                                    p1            = entity1.DepartmentId;
                                }
                            }
                            else
                            {
                                var entity = departmentBLL.GetList().Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "厂级" && x.FullName == array[j].ToString()).FirstOrDefault();
                                if (entity == null)
                                {
                                    entity = departmentBLL.GetList().Where(x => x.OrganizeId == currUser.OrganizeId && (x.Nature == "部门" || x.Nature == "承包商" || x.Nature == "分包商") && x.FullName == array[j].ToString()).FirstOrDefault();
                                    if (entity == null)
                                    {
                                        entity = departmentBLL.GetList().Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "承包商" && x.FullName == array[j].ToString()).FirstOrDefault();
                                        if (entity == null)
                                        {
                                            //falseMessage += "</br>" + "第" + (i + 3) + "行部门不存在,未能导入.";
                                            //error++;
                                            //deptFlag = true;
                                            //break;
                                            item.Dept = deptlist;
                                            break;
                                        }
                                        else
                                        {
                                            item.Dept     = entity.FullName;
                                            item.DeptCode = entity.EnCode;
                                            p1            = entity.DepartmentId;
                                        }
                                    }
                                    else
                                    {
                                        item.Dept     = entity.FullName;
                                        item.DeptCode = entity.EnCode;
                                        p1            = entity.DepartmentId;
                                    }
                                }
                                else
                                {
                                    p1 = entity.DepartmentId;
                                }
                            }
                        }
                        else if (j == 1)
                        {
                            var entity1 = departmentBLL.GetList().Where(x => x.OrganizeId == currUser.OrganizeId && (x.Nature == "专业" || x.Nature == "承包商" || x.Nature == "分包商") && x.FullName == array[j].ToString() && x.ParentId == p1).FirstOrDefault();
                            if (entity1 == null)
                            {
                                entity1 = departmentBLL.GetList().Where(x => x.OrganizeId == currUser.OrganizeId && x.Nature == "班组" && x.FullName == array[j].ToString() && x.ParentId == p1).FirstOrDefault();
                                if (entity1 == null)
                                {
                                    //falseMessage += "</br>" + "第" + (i + 3) + "行专业/班组不存在,未能导入.";
                                    //error++;
                                    //deptFlag = true;
                                    //break;
                                    item.Dept = deptlist;
                                    break;
                                }
                                else
                                {
                                    item.Dept     = entity1.FullName;
                                    item.DeptCode = entity1.EnCode;
                                    p2            = entity1.DepartmentId;
                                }
                            }
                            else
                            {
                                item.Dept     = entity1.FullName;
                                item.DeptCode = entity1.EnCode;
                                p2            = entity1.DepartmentId;
                            }
                        }
                        else
                        {
                            var entity1 = departmentBLL.GetList().Where(x => x.OrganizeId == currUser.OrganizeId && (x.Nature == "班组" || x.Nature == "承包商" || x.Nature == "分包商") && x.FullName == array[j].ToString() && x.ParentId == p2).FirstOrDefault();
                            if (entity1 == null)
                            {
                                //falseMessage += "</br>" + "第" + (i + 3) + "行班组不存在,未能导入.";
                                //error++;
                                //deptFlag = true;
                                //break;
                                item.Dept = deptlist;
                                break;
                            }
                            else
                            {
                                item.Dept     = entity1.FullName;
                                item.DeptCode = entity1.EnCode;
                            }
                        }
                    }
                    if (deptFlag)
                    {
                        continue;
                    }
                    #endregion

                    #region  称
                    string username = dt.Rows[i][2].ToString().Trim();
                    if (string.IsNullOrEmpty(username))
                    {
                        falseMessage += string.Format(@"第{0}行导入失败,姓名不能为空!</br>", order);
                        error++;
                        continue;
                    }
                    if (username != "")
                    {
                        if (item.DeptCode != "" && item.DeptCode != null)
                        {
                            UserInfoEntity userEntity = userbll.GetUserInfoByName(item.Dept, username);
                            if (userEntity == null)
                            {
                                falseMessage += string.Format(@"第{0}行,姓名在【{1}】不存在!</br>", order, item.Dept);
                                error++;
                                continue;
                            }
                            else
                            {
                                item.UserId   = userEntity.UserId;
                                item.UserName = userEntity.RealName;
                            }
                        }
                        else
                        {
                            item.UserName = username;
                        }
                    }
                    #endregion


                    #region 职务
                    string quarters = dt.Rows[i][3].ToString();
                    if (!string.IsNullOrEmpty(quarters))
                    {
                        var data = new DataItemCache().ToItemValue("Quarters", quarters);
                        if (data != null && !string.IsNullOrEmpty(data))
                        {
                            item.Quarters = quarters;
                        }
                        else
                        {
                            falseMessage += string.Format(@"第{0}行导入失败,职务不存在!</br>", order);
                            error++;
                            continue;
                        }
                    }
                    else
                    {
                        falseMessage += string.Format(@"第{0}行导入失败,职务不能为空!</br>", order);
                        error++;
                        continue;
                    }
                    #endregion

                    #region 性别
                    item.Sex = dt.Rows[i][4].ToString().Trim();
                    #endregion

                    #region 身份证号
                    //身份证号
                    string identity = dt.Rows[i][5].ToString().Trim();
                    if (!string.IsNullOrEmpty(identity))
                    {
                        if (!Regex.IsMatch(identity, @"^(^d{15}$|^\d{18}$|^\d{17}(\d|X|x))$", RegexOptions.IgnoreCase))
                        {
                            falseMessage += string.Format(@"第{0}行身份证号格式有误!</br>", order);
                            error++;
                            continue;
                        }
                        else
                        {
                            item.IdentityCard = identity;
                        }
                    }
                    #endregion

                    #region 学历
                    string degrees = dt.Rows[i][6].ToString().Trim();
                    if (!string.IsNullOrEmpty(degrees))
                    {
                        var data = new DataItemCache().ToItemValue("Degrees", degrees);
                        if (data != null && !string.IsNullOrEmpty(data))
                        {
                            item.DegreesId = degrees;
                        }
                        else
                        {
                            falseMessage += string.Format(@"第{0}行导入失败,学历不存在!</br>", order);
                            error++;
                            continue;
                        }
                    }
                    #endregion

                    #region 持证情况
                    string certificates = dt.Rows[i][7].ToString().Trim();
                    if (!string.IsNullOrEmpty(certificates))
                    {
                        if (certificates.Length > 100)
                        {
                            falseMessage += string.Format(@"第{0}行持证情况字符过长!</br>", order);
                            error++;
                            continue;
                        }
                        else
                        {
                            item.Certificates = certificates;
                        }
                    }
                    #endregion

                    #region 户籍所在地
                    string placedomicile = dt.Rows[i][8].ToString().Trim();
                    if (!string.IsNullOrEmpty(placedomicile))
                    {
                        item.PlaceDomicile = placedomicile;
                    }
                    #endregion

                    #region 手机号
                    string phone = dt.Rows[i][9].ToString().Trim();
                    if (!string.IsNullOrEmpty(phone))
                    {
                        if (!Regex.IsMatch(phone, @"^(\+\d{2,3}\-)?\d{11}$", RegexOptions.IgnoreCase))
                        {
                            falseMessage += string.Format(@"第{0}行手机号格式不正确!</br>", order);
                            error++;
                            continue;
                        }
                        else
                        {
                            item.Certificates = certificates;
                        }
                    }
                    #endregion


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

            return(message);
        }
Ejemplo n.º 3
0
 public ActionResult SaveForm(string keyValue, FireTroopsEntity entity)
 {
     FireTroopsbll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }