Exemple #1
0
 //public string AddChangePersons(AddChangePersons requset)
 //{
 //    using (var db = DbFactory.Open())
 //    {
 //        var builder = requset.information;
 //        //第一版更改批量导入暂时不用
 //        //var requestAddChangePersonList = JsonTools.Deserialize<List<RequestAddChangePerson>>(builder);
 //        //var countryPersonList = new List<CountryPerson>();
 //        //foreach (var info in requestAddChangePersonList)
 //        //{
 //        //    var countryPerson = new CountryPerson();
 //        //    countryPerson.UserName = info.Name;
 //        //    countryPerson.Phone =info.Phone;
 //        //    countryPerson.CountryName = RealName;
 //        //    countryPerson.PostionId = info.Id;
 //        //    countryPerson.AllowChanges = null;
 //        //    countryPersonList.Add(countryPerson);
 //        //}
 //        //db.InsertAll(countryPersonList);
 //        return "yes";
 //    }
 //}
 #endregion
 #region 执行批量插入数据的方法
 public ReturnInsertStatus InsertExeclCountryPerson(CountryImportExcel request)
 {
     using (var db = DbFactory.Open())
     {
         var postList = db.Select <Model.Post.Post>(x => x.PostType == GrassrootsFloodCtrlEnums.ZZTXEnums.县级防汛防台责任人.ToString());
         //获取数据
         var newpath = System.Web.HttpContext.Current.Server.MapPath(request.filePath);
         //将数据转化table
         //var dt = Common.ExcelHelper.GetDataTable(newpath);
         //dt.Rows.RemoveAt(0);
         Workbook workbook = new Workbook();
         workbook.Open(newpath);
         Cells cells = workbook.Worksheets[0].Cells;
         var   dt    = cells.ExportDataTable(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, true);
         dt.Rows.RemoveAt(0);
         //table传list
         var insertExeclCountryPersonList = DtChangeList(dt);
         //核对数据有没有重复和手机号是否正确
         var returnCheckInsert = CheckInsertData(insertExeclCountryPersonList, postList);
         if (returnCheckInsert.Status)
         {
             int checkCount;
             var auditing = db.Select <AuditCounty>("select * from dbo.AuditCounty where CountyADCD='" + adcd + "'");
             if (auditing.Count == 0)
             {
                 checkCount = 1;
             }
             else
             {
                 checkCount = Convert.ToInt32(auditing[0].AuditNums) + 1;
             }
             //插入数据库的List
             var countryPersonList = GetCountryPerson(insertExeclCountryPersonList, request, checkCount);
             if (countryPersonList != null)
             {
                 db.InsertAll(countryPersonList);
                 logHelper.WriteLog(logMsgName + countryPersonList.Count, OperationTypeEnums.新增);
                 List <AdcdItems> _list = new List <AdcdItems>();
                 var adcdinfo           = db.Single <ADCDInfo>(w => w.adcd == countryPersonList.FirstOrDefault().adcd);
                 countryPersonList.ForEach(w => {
                     AdcdItems _model = new AdcdItems()
                     {
                         adcdId   = adcdinfo.Id,
                         phone    = w.Phone,
                         username = w.UserName
                     };
                     _list.Add(_model);
                 });
                 //_IAppRegPersonUpdate.AppRegPersonSaveMore( new AppRegPersonSaveMore() { AdcdIds=_list });
                 //if (logHelper.WriteLog(logMsgName + countryPersonList.Count, OperationTypeEnums.新增))
                 //{ throw new Exception("插入日志"); }
             }
         }
         return(returnCheckInsert);
     }
 }
 //public string AddChangePersons(AddChangePersons requset)
 //{
 //    using (var db = DbFactory.Open())
 //    {
 //        var builder = requset.information;
 //        //第一版更改批量导入暂时不用
 //        //var requestAddChangePersonList = JsonTools.Deserialize<List<RequestAddChangePerson>>(builder);
 //        //var countryPersonList = new List<CountryPerson>();
 //        //foreach (var info in requestAddChangePersonList)
 //        //{
 //        //    var countryPerson = new CountryPerson();
 //        //    countryPerson.UserName = info.Name;
 //        //    countryPerson.Phone =info.Phone;
 //        //    countryPerson.CountryName = RealName;
 //        //    countryPerson.PostionId = info.Id;
 //        //    countryPerson.AllowChanges = null;
 //        //    countryPersonList.Add(countryPerson);
 //        //}
 //        //db.InsertAll(countryPersonList);
 //        return "yes";
 //    }
 //}
 #endregion
 #region 执行批量插入数据的方法
 public ReturnInsertStatus InsertExeclCountryPerson(CountryImportExcel request)
 {
     using (var db = DbFactory.Open())
     {
         var postList = db.Select <Model.Post.Post>(x => x.PostType == GrassrootsFloodCtrlEnums.ZZTXEnums.县级防汛防台责任人.ToString());
         //获取数据
         var newpath = System.Web.HttpContext.Current.Server.MapPath(request.filePath);
         //将数据转化table
         //var dt = Common.ExcelHelper.GetDataTable(newpath);
         //dt.Rows.RemoveAt(0);
         Workbook workbook = new Workbook();
         workbook.Open(newpath);
         Cells cells = workbook.Worksheets[0].Cells;
         var   dt    = cells.ExportDataTable(0, 0, cells.MaxDataRow + 1, cells.MaxColumn + 1, true);
         dt.Rows.RemoveAt(0);
         //table传list
         var insertExeclCountryPersonList = DtChangeList(dt);
         //核对数据有没有重复和手机号是否正确
         var returnCheckInsert = CheckInsertData(insertExeclCountryPersonList, postList);
         if (returnCheckInsert.Status)
         {
             int checkCount;
             var auditing = db.Select <AuditCounty>("select * from dbo.AuditCounty where CountyADCD='" + adcd + "'");
             if (auditing.Count == 0)
             {
                 checkCount = 1;
             }
             else
             {
                 checkCount = Convert.ToInt32(auditing[0].AuditNums) + 1;
             }
             //插入数据库的List
             var countryPersonList = GetCountryPerson(insertExeclCountryPersonList, request, checkCount);
             if (countryPersonList != null)
             {
                 db.InsertAll(countryPersonList);
                 logHelper.WriteLog(logMsgName + countryPersonList.Count, OperationTypeEnums.新增);
                 //if (logHelper.WriteLog(logMsgName + countryPersonList.Count, OperationTypeEnums.新增))
                 //{ throw new Exception("插入日志"); }
             }
         }
         return(returnCheckInsert);
     }
 }
        private List <CountryPerson> GetCountryPerson(List <InsertExeclCountryPerson> insertExeclCountryPersonList, CountryImportExcel request, int checkCount)
        {
            var countryPersonList = new List <CountryPerson>();

            if (!CheckInserExecl(insertExeclCountryPersonList))
            {
                return(null);
            }
            else
            {
                foreach (var insertExecl in insertExeclCountryPersonList)
                {
                    var countryPerson = new CountryPerson();
                    if (!string.IsNullOrEmpty(insertExecl.UserName) && !string.IsNullOrEmpty(insertExecl.Phone) && !string.IsNullOrEmpty(insertExecl.Postion))
                    {
                        countryPerson.UserName   = insertExecl.UserName;
                        countryPerson.Position   = insertExecl.Postion;
                        countryPerson.Post       = insertExecl.Post;
                        countryPerson.Remark     = insertExecl.Remark;
                        countryPerson.CreateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        countryPerson.CreateName = insertExecl.UserName;
                        countryPerson.Phone      = insertExecl.Phone;
                        countryPerson.UpdateName = insertExecl.UserName;
                        countryPerson.Year       = request.year;
                        countryPerson.Country    = RealName;
                        countryPerson.adcd       = adcd;
                        countryPerson.AuditNums  = checkCount;
                        countryPerson.UpdateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        countryPersonList.Add(countryPerson);
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(countryPersonList);
            }
        }
        //public string Post(AddChangePersons requset)
        //{
        //    return CountryPerson.AddChangePersons(requset);
        //}

        public ReturnInsertStatus Post(CountryImportExcel requset)
        {
            return(CountryPerson.InsertExeclCountryPerson(requset));
        }