コード例 #1
0
        public IActionResult oCreate(dynamic model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var entity = new HaikanSmartTownCockpit.Api.Entities.OrganPeoInfo();
                entity.OrganPeoInfoUuid = Guid.NewGuid();
                entity.OrganName        = model.organName;
                entity.Sex              = model.sex;
                entity.Birth            = model.birth;
                entity.IdentityCard     = model.identityCard;
                entity.Phone            = model.phone;
                entity.Education        = model.education;
                entity.ZjWork           = model.zjWork;
                entity.Duty             = model.duty;
                entity.HouseAddress     = model.houseAddress;
                entity.OrganizationUuid = model.organizationUuid;
                entity.AddTime          = DateTime.Now.ToString("yyyy-MM-dd");
                entity.AddPeople        = AuthContextService.CurrentUser.DisplayName;
                entity.IsDeleted        = 0;
                _dbContext.OrganPeoInfo.Add(entity);
                int res = _dbContext.SaveChanges();
                if (res > 0)
                {
                    ToLog.AddLog("添加", "成功:添加:工会人员信息一条数据", _dbContext);
                }
                response.SetSuccess("添加成功");
                return(Ok(response));
            }
        }
コード例 #2
0
        public IActionResult Create(dynamic model)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                var query  = _dbContext.Organization.FirstOrDefault(x => x.OrganizationName == "妇联");
                var entity = new HaikanSmartTownCockpit.Api.Entities.OrganPeoInfo();
                entity.OrganPeoInfoUuid = Guid.NewGuid();
                entity.OrganName        = model.organName;
                entity.Sex              = model.sex;
                entity.Birth            = model.birth;
                entity.IdentityCard     = model.identityCard;
                entity.Phone            = model.phone;
                entity.Education        = model.education;
                entity.ZjWork           = model.zjWork;
                entity.Duty             = model.duty;
                entity.HouseAddress     = model.houseAddress;
                entity.ManType          = "适龄妇女";
                entity.AddTime          = DateTime.Now.ToString("yyyy-MM-dd");
                entity.AddPeople        = AuthContextService.CurrentUser.DisplayName;
                entity.OrganizationUuid = query.OrganizationUuid;
                entity.IsDeleted        = 0;
                _dbContext.OrganPeoInfo.Add(entity);
                _dbContext.SaveChanges();
                response.SetSuccess("添加成功");
                return(Ok(response));
            }
        }
コード例 #3
0
        public IActionResult oImport(IFormFile excelfile, [FromForm] string guid)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                DateTime beginTime = DateTime.Now;

                string sWebRootFolder = _hostingEnvironment.WebRootPath + "\\UploadFiles\\ImportBuidingExcel";


                //var schoolinfo = _dbContext.SchoolInforManagement.AsQueryable();
                string   uploadtitle = "工会人员信息导入" + DateTime.Now.ToString("yyyyMMddHHmmss");
                string   sFileName   = $"{uploadtitle}.xlsx";
                FileInfo file        = new FileInfo(Path.Combine(sWebRootFolder, sFileName));
                //string conStr = ConnectionStrings.DefaultConnection;
                string responsemsgsuccess = "";
                string responsemsgrepeat  = "";
                string responsemsgdefault = "";
                int    successcount       = 0;
                int    repeatcount        = 0;
                int    defaultcount       = 0;
                string today = DateTime.Now.ToString("yyyy-MM-dd");
                try
                {
                    //把excelfile中的数据复制到file中
                    using (FileStream fs = new FileStream(file.ToString(), FileMode.Create)) //初始化一个指定路径和创建模式的FileStream
                    {
                        excelfile.CopyTo(fs);
                        fs.Flush();  //清空stream的缓存,并且把缓存中的数据输出到file
                    }
                    DataTable dt = Haikan3.Utils.ExcelTools.ExcelToDataTable(file.ToString(), "Sheet1", true);

                    if (dt == null || dt.Rows.Count == 0)
                    {
                        response.SetFailed("表格无数据");
                        return(Ok(response));
                    }
                    else
                    {
                        if (!dt.Columns.Contains("姓名"))
                        {
                            response.SetFailed("无‘姓名’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("性别"))
                        {
                            response.SetFailed("无‘性别’列");
                            return(Ok(response));
                        }
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            var entity = new HaikanSmartTownCockpit.Api.Entities.OrganPeoInfo();
                            entity.OrganPeoInfoUuid = Guid.NewGuid();
                            if (!string.IsNullOrEmpty(dt.Rows[i]["姓名"].ToString()))
                            {
                                entity.OrganName = dt.Rows[i]["姓名"].ToString();
                            }
                            else
                            {
                                responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行姓名为空" + "</p></br>";
                                defaultcount++;
                                continue;
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["性别"].ToString()))
                            {
                                if (dt.Rows[i]["性别"].ToString() != "男" && dt.Rows[i]["性别"].ToString() != "女")
                                {
                                    responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行性别不正确" + "</p></br>";
                                    defaultcount++;
                                    continue;
                                }
                                else
                                {
                                    entity.Sex = dt.Rows[i]["性别"].ToString();
                                }
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["出生日期"].ToString()))
                            {
                                entity.Birth = dt.Rows[i]["出生日期"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["学历"].ToString()))
                            {
                                entity.Education = dt.Rows[i]["学历"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["身份证号"].ToString()))
                            {
                                entity.IdentityCard = dt.Rows[i]["身份证号"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["手机号"].ToString()))
                            {
                                entity.Phone = dt.Rows[i]["手机号"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["工作"].ToString()))
                            {
                                entity.ZjWork = dt.Rows[i]["工作"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["职位"].ToString()))
                            {
                                entity.Duty = dt.Rows[i]["职位"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["地址"].ToString()))
                            {
                                entity.HouseAddress = dt.Rows[i]["地址"].ToString();
                            }
                            entity.OrganizationUuid = Guid.Parse(guid);
                            entity.AddTime          = DateTime.Now.ToString("yyyy-MM-dd");
                            entity.AddPeople        = AuthContextService.CurrentUser.DisplayName;
                            entity.IsDeleted        = 0;
                            _dbContext.OrganPeoInfo.Add(entity);
                            _dbContext.SaveChanges();
                            successcount++;
                        }
                    }
                    responsemsgsuccess = "<p style='color:green'>导入成功:" + successcount + "条</p></br>" + responsemsgsuccess;
                    responsemsgrepeat  = "<p style='color:orange'>重复需手动修改数据:" + repeatcount + "条</p></br>" + responsemsgrepeat;
                    responsemsgdefault = "<p style='color:red'>导入失败:" + defaultcount + "条</p></br>" + responsemsgdefault;

                    ToLog.AddLog("导入", "成功:导入:工会人员信息数据", _dbContext);
                    DateTime endTime  = DateTime.Now;
                    TimeSpan useTime  = endTime - beginTime;
                    string   taketime = "导入时间" + useTime.TotalSeconds.ToString() + "秒  ";
                    response.SetData(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(new
                    {
                        time       = taketime,
                        successmsg = responsemsgsuccess
                        ,
                        repeatmsg  = responsemsgrepeat,
                        defaultmsg = responsemsgdefault
                    })));
                    return(Ok(response));
                }
                catch (Exception ex)
                {
                    response.SetFailed(ex.Message);
                    return(Ok(response));
                }
            }
        }
コード例 #4
0
        public IActionResult Import(IFormFile excelfile)
        {
            var response = ResponseModelFactory.CreateInstance;

            using (_dbContext)
            {
                DateTime beginTime = DateTime.Now;

                string sWebRootFolder = _hostingEnvironment.WebRootPath + "\\UploadFiles\\ImportBuidingExcel";


                //var schoolinfo = _dbContext.SchoolInforManagement.AsQueryable();
                string   uploadtitle = "共青团组织信息导入" + DateTime.Now.ToString("yyyyMMddHHmmss");
                string   sFileName   = $"{uploadtitle}.xlsx";
                FileInfo file        = new FileInfo(Path.Combine(sWebRootFolder, sFileName));
                //string conStr = ConnectionStrings.DefaultConnection;
                string responsemsgsuccess = "";
                string responsemsgrepeat  = "";
                string responsemsgdefault = "";
                int    successcount       = 0;
                int    repeatcount        = 0;
                int    defaultcount       = 0;
                string today = DateTime.Now.ToString("yyyy-MM-dd");
                var    query = _dbContext.Organization.FirstOrDefault(x => x.OrganizationName == "共青团");
                try
                {
                    //把excelfile中的数据复制到file中
                    using (FileStream fs = new FileStream(file.ToString(), FileMode.Create)) //初始化一个指定路径和创建模式的FileStream
                    {
                        excelfile.CopyTo(fs);
                        fs.Flush();  //清空stream的缓存,并且把缓存中的数据输出到file
                    }
                    DataTable dt = Haikan3.Utils.ExcelTools.ExcelToDataTable(file.ToString(), "Sheet1", true);

                    if (dt == null || dt.Rows.Count == 0)
                    {
                        response.SetFailed("表格无数据");
                        return(Ok(response));
                    }
                    else
                    {
                        if (!dt.Columns.Contains("姓名"))
                        {
                            response.SetFailed("无‘姓名’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("性别"))
                        {
                            response.SetFailed("无‘性别’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("出生日期"))
                        {
                            response.SetFailed("无‘出生日期’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("学历"))
                        {
                            response.SetFailed("无‘学历’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("身份证号"))
                        {
                            response.SetFailed("无‘身份证号’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("手机号"))
                        {
                            response.SetFailed("无‘手机号’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("工作"))
                        {
                            response.SetFailed("无‘工作’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("职位"))
                        {
                            response.SetFailed("无‘职位’列");
                            return(Ok(response));
                        }
                        if (!dt.Columns.Contains("地址"))
                        {
                            response.SetFailed("无‘地址’列");
                            return(Ok(response));
                        }
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            var entity = new HaikanSmartTownCockpit.Api.Entities.OrganPeoInfo();
                            entity.OrganPeoInfoUuid = Guid.NewGuid();
                            if (!string.IsNullOrEmpty(dt.Rows[i]["姓名"].ToString()))
                            {
                                Regex reg = new Regex("^([\\u4e00-\\u9fa5]){2,7}$");
                                if (reg.IsMatch(dt.Rows[i]["姓名"].ToString()))
                                {
                                    entity.OrganName = dt.Rows[i]["姓名"].ToString();
                                }
                                else
                                {
                                    responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行姓名格式不正确" + "</p></br>";
                                    defaultcount++;
                                    continue;
                                }
                            }
                            else
                            {
                                responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行姓名为空" + "</p></br>";
                                defaultcount++;
                                continue;
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["性别"].ToString()))
                            {
                                if (dt.Rows[i]["性别"].ToString() != "男" && dt.Rows[i]["性别"].ToString() != "女")
                                {
                                    responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行性别不正确" + "</p></br>";
                                    defaultcount++;
                                    continue;
                                }
                                else
                                {
                                    entity.Sex = dt.Rows[i]["性别"].ToString();
                                }
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["出生日期"].ToString()))
                            {
                                Regex reg = new Regex("^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
                                if (reg.IsMatch(dt.Rows[i]["出生日期"].ToString()))
                                {
                                    entity.Birth = dt.Rows[i]["出生日期"].ToString();
                                }
                                else
                                {
                                    responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行出生日期不正确" + "</p></br>";
                                    defaultcount++;
                                    continue;
                                }
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["学历"].ToString()))
                            {
                                Regex reg = new Regex("^(小学|初中|中专|大专|本科|硕士|博士)$");
                                if (reg.IsMatch(dt.Rows[i]["学历"].ToString()))
                                {
                                    entity.Education = dt.Rows[i]["学历"].ToString();
                                }
                                else
                                {
                                    responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行学历类别不正确" + "</p></br>";
                                    defaultcount++;
                                    continue;
                                }
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["身份证号"].ToString()))
                            {
                                Regex reg = new Regex("^(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)$");
                                if (reg.IsMatch(dt.Rows[i]["身份证号"].ToString()))
                                {
                                    entity.IdentityCard = dt.Rows[i]["身份证号"].ToString();
                                }
                                else
                                {
                                    responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行身份证号格式不正确" + "</p></br>";
                                    defaultcount++;
                                    continue;
                                }
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["手机号"].ToString()))
                            {
                                Regex reg = new Regex("^[1][3,4,5,7,8][0-9]{9}$");
                                if (reg.IsMatch(dt.Rows[i]["手机号"].ToString()))
                                {
                                    entity.Phone = dt.Rows[i]["手机号"].ToString();
                                }
                                else
                                {
                                    responsemsgdefault += "<p style='color:red'>" + "第" + (i + 2) + "行手机号格式不正确" + "</p></br>";
                                    defaultcount++;
                                    continue;
                                }
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["工作"].ToString()))
                            {
                                entity.ZjWork = dt.Rows[i]["工作"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["职位"].ToString()))
                            {
                                entity.Duty = dt.Rows[i]["职位"].ToString();
                            }
                            if (!string.IsNullOrEmpty(dt.Rows[i]["地址"].ToString()))
                            {
                                entity.HouseAddress = dt.Rows[i]["地址"].ToString();
                            }
                            entity.OrganizationUuid = query.OrganizationUuid;
                            entity.AddTime          = DateTime.Now.ToString("yyyy-MM-dd");
                            entity.AddPeople        = AuthContextService.CurrentUser.DisplayName;
                            entity.IsDeleted        = 0;
                            _dbContext.OrganPeoInfo.Add(entity);
                            _dbContext.SaveChanges();
                            successcount++;
                        }
                    }
                    responsemsgsuccess = "<p style='color:green'>导入成功:" + successcount + "条</p></br>" + responsemsgsuccess;
                    responsemsgrepeat  = "<p style='color:orange'>重复需手动修改数据:" + repeatcount + "条</p></br>" + responsemsgrepeat;
                    responsemsgdefault = "<p style='color:red'>导入失败:" + defaultcount + "条</p></br>" + responsemsgdefault;


                    DateTime endTime  = DateTime.Now;
                    TimeSpan useTime  = endTime - beginTime;
                    string   taketime = "导入时间" + useTime.TotalSeconds.ToString() + "秒  ";
                    response.SetData(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(new
                    {
                        time       = taketime,
                        successmsg = responsemsgsuccess
                        ,
                        repeatmsg  = responsemsgrepeat,
                        defaultmsg = responsemsgdefault
                    })));
                    return(Ok(response));
                }
                catch (Exception ex)
                {
                    response.SetFailed(ex.Message);
                    return(Ok(response));
                }
            }
        }