示例#1
0
 /// <summary>
 /// 保存数据
 /// </summary>
 public void SaveImportData(IEnumerable <Spl_Person> personList)
 {
     try
     {
         DbContexts db = new DbContexts();
         foreach (var model in personList)
         {
             Spl_Person entity = new Spl_Person();
             entity.KEY_Id     = ResultHelper.NewId;
             entity.Name       = model.Name;
             entity.Sex        = model.Sex;
             entity.Age        = model.Age;
             entity.IDCard     = model.IDCard;
             entity.Phone      = model.Phone;
             entity.Email      = model.Email;
             entity.Address    = model.Address;
             entity.CreateTime = ResultHelper.NowTime.ToString("yyyy-MM-dd HH:mm:ss");
             entity.Region     = model.Region;
             entity.Category   = model.Category;
             db.Spl_Person.Add(entity);
         }
         db.SaveChanges();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
示例#2
0
 /// <summary>
 /// 保存数据
 /// </summary>
 public override void SaveImportData(IEnumerable <Spl_PersonModel> personList)
 {
     try
     {
         using (DBContainer db = new DBContainer())
         {
             foreach (var model in personList)
             {
                 Spl_Person entity = new Spl_Person();
                 entity.Id         = ResultHelper.NewId;
                 entity.Name       = model.Name;
                 entity.Sex        = model.Sex;
                 entity.Age        = model.Age;
                 entity.IDCard     = model.IDCard;
                 entity.Phone      = model.Phone;
                 entity.Email      = model.Email;
                 entity.Address    = model.Address;
                 entity.CreateTime = ResultHelper.NowTime;
                 entity.Region     = model.Region;
                 entity.Category   = model.Category;
                 db.Spl_Person.Add(entity);
             }
             db.SaveChanges();
         }
     }
     catch
     {
         throw;
     }
 }
示例#3
0
        public virtual Apps.Models.Spl.Spl_PersonModel GetById(string id)
        {
            Spl_Person entity = m_Rep.GetById(id);

            if (entity != null)
            {
                //Spl_Person entity = m_Rep.GetById(id);
                Apps.Models.Spl.Spl_PersonModel model = new Apps.Models.Spl.Spl_PersonModel();
                model.Id         = entity.Id;
                model.Name       = entity.Name;
                model.Sex        = entity.Sex;
                model.Age        = entity.Age;
                model.IDCard     = entity.IDCard;
                model.Phone      = entity.Phone;
                model.Email      = entity.Email;
                model.Address    = entity.Address;
                model.CreateTime = entity.CreateTime;
                model.Region     = entity.Region;
                model.Category   = entity.Category;

                return(model);
            }
            else
            {
                return(null);
            }
        }
示例#4
0
        public virtual async Task <Spl_PersonModel> GetByIdAsync(object id)
        {
            if (IsExists(id))
            {
                Spl_Person entity = await m_Rep.GetByIdAsync(id);

                Spl_PersonModel model = new Spl_PersonModel();
                model.Id         = entity.Id;
                model.Name       = entity.Name;
                model.Sex        = entity.Sex;
                model.Age        = entity.Age;
                model.IDCard     = entity.IDCard;
                model.Phone      = entity.Phone;
                model.Email      = entity.Email;
                model.Address    = entity.Address;
                model.CreateTime = entity.CreateTime;
                model.Region     = entity.Region;
                model.Category   = entity.Category;

                return(model);
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        /// <summary>
        /// 校验Excel数据
        /// </summary>
        public bool CheckImportBatchData(string fileName, List <Spl_Person> personList, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }
            int rowIndex  = 1;
            var excelFile = new ExcelQueryFactory(fileName);
            //获取所有的worksheet
            var sheetList = excelFile.GetWorksheetNames();

            //检查数据正确性
            foreach (var sheet in sheetList)
            {
                var errorMessage = new StringBuilder();

                //获得sheet对应的数据
                var data = excelFile.WorksheetNoHeader(sheet).ToList();

                //判断信息是否齐全
                if (data[1][2].Value.ToString() == "")
                {
                    errorMessage.Append("姓名不能为空");
                }


                var person = new Spl_Person();
                person.KEY_Id   = "";
                person.Name     = data[1][2].Value.ToString();
                person.Sex      = data[2][2].Value.ToString();
                person.Age      = Convert.ToInt32(data[3][2].Value).ToString();
                person.IDCard   = data[4][2].Value.ToString();
                person.Phone    = data[5][2].Value.ToString();
                person.Email    = data[6][2].Value.ToString();
                person.Address  = data[7][2].Value.ToString();
                person.Region   = data[8][2].Value.ToString();
                person.Category = data[9][2].Value.ToString();

                //集合错误
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "在Sheet {0} 发现错误:{1}{2}",
                                   sheet,
                                   errorMessage,
                                   "<br/>"));
                }
                personList.Add(person);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
示例#6
0
        public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_PersonModel model)
        {
            ValidationErrors errors = new ValidationErrors();

            try
            {
                Spl_Person entity = await m_Rep.GetByIdAsync(model.Id);

                if (entity != null)
                {
                    errors.Add(Resource.PrimaryRepeat);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
                entity            = new Spl_Person();
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.Sex        = model.Sex;
                entity.Age        = model.Age;
                entity.IDCard     = model.IDCard;
                entity.Phone      = model.Phone;
                entity.Email      = model.Email;
                entity.Address    = model.Address;
                entity.CreateTime = model.CreateTime;
                entity.Region     = model.Region;
                entity.Category   = model.Category;


                if (await m_Rep.CreateAsync(entity))
                {
                    return(new Tuple <ValidationErrors, bool>(errors, true));
                }
                else
                {
                    errors.Add(Resource.InsertFail);
                    return(new Tuple <ValidationErrors, bool>(errors, false));
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(new Tuple <ValidationErrors, bool>(errors, false));
            }
        }
示例#7
0
        public virtual bool Edit(ref ValidationErrors errors, Spl_PersonModel model)
        {
            try
            {
                Spl_Person entity = m_Rep.GetById(model.Id);
                if (entity == null)
                {
                    errors.Add(Resource.Disable);
                    return(false);
                }
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.Sex        = model.Sex;
                entity.Age        = model.Age;
                entity.IDCard     = model.IDCard;
                entity.Phone      = model.Phone;
                entity.Email      = model.Email;
                entity.Address    = model.Address;
                entity.CreateTime = model.CreateTime;
                entity.Region     = model.Region;
                entity.Category   = model.Category;



                if (m_Rep.Edit(entity))
                {
                    return(true);
                }
                else
                {
                    errors.Add(Resource.NoDataChange);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                errors.Add(ex.Message);
                ExceptionHander.WriteException(ex);
                return(false);
            }
        }
示例#8
0
 //[SupportFilter]
 public JsonResult Edit(Spl_Person model)
 {
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.m_Rep.Update(model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "修改", "Spl_Person");
             return(Json(JsonHandler.CreateMessage(1, Resource.EditSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "修改", "Spl_Person");
             return(Json(JsonHandler.CreateMessage(0, Resource.EditFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.EditFail)));
     }
 }
示例#9
0
 //[SupportFilter]
 public JsonResult Create(Spl_Person model)
 {
     model.CreateTime = ResultHelper.NowTime.ToString("yyyy-MM-dd HH:mm:ss");
     if (model != null && ModelState.IsValid)
     {
         if (m_BLL.m_Rep.Create(model))
         {
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name, "成功", "创建", "Spl_Person");
             return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed)));
         }
         else
         {
             string ErrorCol = errors.Error;
             LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",Name" + model.Name + "," + ErrorCol, "失败", "创建", "Spl_Person");
             return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol)));
         }
     }
     else
     {
         return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail)));
     }
 }
示例#10
0
        public virtual void Modify(ref ValidationErrors errors, Apps.Models.Spl.Spl_PersonModel model, params string[] updateProperties)
        {
            Spl_Person entity = m_Rep.GetById(model.Id);

            if (entity == null)
            {
                errors.Add(Resource.Disable);
                return;
            }
            if (updateProperties.Count() <= 0)
            {
                entity.Id         = model.Id;
                entity.Name       = model.Name;
                entity.Sex        = model.Sex;
                entity.Age        = model.Age;
                entity.IDCard     = model.IDCard;
                entity.Phone      = model.Phone;
                entity.Email      = model.Email;
                entity.Address    = model.Address;
                entity.CreateTime = model.CreateTime;
                entity.Region     = model.Region;
                entity.Category   = model.Category;
            }
            else
            {
                Type type  = typeof(Apps.Models.Spl.Spl_PersonModel);
                Type typeE = typeof(Apps.Models.Spl_Person);
                foreach (var item in updateProperties)
                {
                    System.Reflection.PropertyInfo pi  = type.GetProperty(item);
                    System.Reflection.PropertyInfo piE = typeE.GetProperty(item);
                    piE.SetValue(entity, pi.GetValue(model), null);
                }
            }


            m_Rep.Modify(entity, updateProperties);
        }
示例#11
0
        public virtual void Create(ref ValidationErrors errors, Apps.Models.Spl.Spl_PersonModel model)
        {
            Spl_Person entity = m_Rep.GetById(model.Id);

            if (entity != null)
            {
                errors.Add(Resource.PrimaryRepeat);
                return;
            }
            entity            = new Spl_Person();
            entity.Id         = model.Id;
            entity.Name       = model.Name;
            entity.Sex        = model.Sex;
            entity.Age        = model.Age;
            entity.IDCard     = model.IDCard;
            entity.Phone      = model.Phone;
            entity.Email      = model.Email;
            entity.Address    = model.Address;
            entity.CreateTime = model.CreateTime;
            entity.Region     = model.Region;
            entity.Category   = model.Category;

            m_Rep.Create(entity);
        }
示例#12
0
        /// <summary>
        /// 校验Excel数据
        /// </summary>
        public bool CheckImportData(string fileName, List <Spl_Person> personList, ref ValidationErrors errors)
        {
            var targetFile = new FileInfo(fileName);

            if (!targetFile.Exists)
            {
                errors.Add("导入的数据文件不存在");
                return(false);
            }

            var excelFile = new ExcelQueryFactory(fileName);

            //对应列头
            excelFile.AddMapping <Spl_Person>(x => x.Name, "Name");
            excelFile.AddMapping <Spl_Person>(x => x.Sex, "Sex");
            excelFile.AddMapping <Spl_Person>(x => x.Age, "Age");
            excelFile.AddMapping <Spl_Person>(x => x.IDCard, "IDCard");
            excelFile.AddMapping <Spl_Person>(x => x.Phone, "Phone");
            excelFile.AddMapping <Spl_Person>(x => x.Email, "Email");
            excelFile.AddMapping <Spl_Person>(x => x.Address, "Address");
            excelFile.AddMapping <Spl_Person>(x => x.Region, "Region");
            excelFile.AddMapping <Spl_Person>(x => x.Category, "Category");
            //SheetName
            var excelContent = excelFile.Worksheet <Spl_Person>(0);

            int rowIndex = 1;

            //检查数据正确性
            foreach (var row in excelContent)
            {
                var errorMessage = new StringBuilder();
                var person       = new Spl_Person();

                person.KEY_Id   = "";
                person.Name     = row.Name;
                person.Sex      = row.Sex;
                person.Age      = row.Age;
                person.IDCard   = row.IDCard;
                person.Phone    = row.Phone;
                person.Email    = row.Email;
                person.Address  = row.Address;
                person.Region   = row.Region;
                person.Category = row.Category;

                if (string.IsNullOrWhiteSpace(row.Name))
                {
                    errorMessage.Append("Name - 不能为空. ");
                }

                if (string.IsNullOrWhiteSpace(row.IDCard))
                {
                    errorMessage.Append("IDCard - 不能为空. ");
                }

                //=============================================================================
                if (errorMessage.Length > 0)
                {
                    errors.Add(string.Format(
                                   "第 {0} 列发现错误:{1}{2}",
                                   rowIndex,
                                   errorMessage,
                                   "<br/>"));
                }
                personList.Add(person);
                rowIndex += 1;
            }
            if (errors.Count > 0)
            {
                return(false);
            }
            return(true);
        }
示例#13
0
        //[SupportFilter]
        public ActionResult Edit(string id)
        {
            Spl_Person entity = m_BLL.m_Rep.Find(Convert.ToInt32(id));

            return(View(entity));
        }