Beispiel #1
0
        public ActionResult AddOrgMap()
        {
            var files         = HttpContext.Request.Files;
            var requestParams = HttpContext.Request.Params;

            if (string.IsNullOrEmpty(requestParams.Get("DistributorID")))
            {
                return(this.HttpNotFound());
            }
            var distributorID = requestParams.Get("DistributorID");

            files["OrgMap"].SaveAs(Const.RealOrgMapPath(distributorID));
            files["Trains"].SaveAs(Const.RealTrainsPath(distributorID));
            var dto = new OrgMapAddDTO
            {
                DistributorID    = distributorID,
                OrgMap           = distributorID,
                OrgMapFile       = files["OrgMap"].FileName,
                Trains           = distributorID,
                Status           = 0,
                Domain1          = requestParams["Domain1"].TryBool(),
                Domain2          = requestParams["Domain2"].TryBool(),
                OrgMapUpdateTime = DateTime.Now,
                TrainsUpdateTime = DateTime.Now,
                OrgMapRealPath   = Const.RealOrgMapPath(distributorID),
                TrainsRealPath   = Const.RealTrainsPath(distributorID)
            };

            var result = FcpaProvider.AddOrgMap(dto);

            return(new JsonResult(result));
        }
Beispiel #2
0
 public OperateResultDTO AddOrgMap(OrgMapAddDTO dto)
 {
     try
     {
         var orgInfo = fcpa.fcpa_DistributorInfo.Find(dto.DistributorID);
         if (orgInfo == null)
         {
             return new OperateResultDTO {
                        success = false, message = "选择的经销商不存在"
             }
         }
         ;
         orgInfo.OrgMap           = dto.DistributorID;
         orgInfo.OrgMapFile       = dto.OrgMapFile;
         orgInfo.Trains           = dto.DistributorID;
         orgInfo.Status           = 0;
         orgInfo.Domain1          = dto.Domain1;
         orgInfo.Domain2          = dto.Domain2;
         orgInfo.OrgMapUpdateTime = DateTime.Now;
         orgInfo.TrainsUpdateTime = DateTime.Now;
         orgInfo.ShouldNum        = ReadExcel(dto.TrainsRealPath, orgInfo, dto);
         fcpa.SaveChanges();
         return(new OperateResultDTO {
             success = true
         });
     }
     catch (Exception e)
     {
         return(new OperateResultDTO {
             success = false, message = e.Message
         });
     }
 }
Beispiel #3
0
        public int ReadExcel(string path, fcpa_DistributorInfo distributor, OrgMapAddDTO dto)
        {
            //string path = @"C: \Users\XQL\Desktop\励志\须参加FCPA培训人员名单.xls";
            int num = 0;

            using (Stream steam = System.IO.File.OpenRead(path))
            {
                var workbook = new HSSFWorkbook(steam);
                var sheet    = workbook.GetSheetAt(0);
                if (sheet.GetRow(1).Cells.Count < 2)
                {
                    throw new ArgumentException("经销商公司名称不能为空");
                }
                string distributorName   = sheet.GetRow(1).GetCell(1).StringCellValue;
                var    distributorInFile = fcpa.fcpa_DistributorInfo.Where(p => p.DistributorName == distributorName).FirstOrDefault();
                if (distributorInFile == null)
                {
                    throw new ArgumentException("经销商公司名称不存在");
                }
                if (distributorInFile.DistributorID != distributor.DistributorID)
                {
                    throw new ArgumentException("选择的经销商与文件中的名称不一致");
                }
                for (int i = 7; i < sheet.LastRowNum; i++)
                {
                    var row        = sheet.GetRow(i);
                    var name       = row.GetCell(0).StringCellValue;
                    var department = row.GetCell(1).StringCellValue;
                    var title      = row.GetCell(2).StringCellValue;
                    if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(department) || string.IsNullOrWhiteSpace(title))
                    {
                        continue;
                    }
                    var caUser = fcpa.fcpa_CredentialInfo.Where(p => p.fcpa_DistributorInfo.DistributorID == distributor.DistributorID && p.Name == name).FirstOrDefault();
                    if (caUser != null)
                    {
                        throw new ArgumentException("培训名单中人员与现有人员重复");
                    }
                    fcpa.fcpa_CredentialInfo.Add(new fcpa_CredentialInfo
                    {
                        ID                   = Guid.NewGuid(),
                        Name                 = name.Trim(),
                        Department           = department.Trim(),
                        Title                = title.Trim(),
                        OffWork              = false,
                        Status               = 3,//未完成
                        Domain1              = dto.Domain1,
                        Domain2              = dto.Domain2,
                        UpdateDate           = DateTime.Now,
                        fcpa_DistributorInfo = distributor
                    });
                    num++;
                }
                if (num < 3)
                {
                    throw new ArgumentException("培训人员不得小于3,请重新上传");
                }
                fcpa.SaveChanges();
            }
            return(num);
        }
Beispiel #4
0
 public static OperateResultDTO AddOrgMap(OrgMapAddDTO dto)
 {
     return(PostAPI <OperateResultDTO>(WebConfiger.FcpaServicesUrl + "Credentials/AddOrgMap", dto));
 }
Beispiel #5
0
 public OperateResultDTO AddOrgMap(OrgMapAddDTO dto)
 {
     return(_FcpaService.AddOrgMap(dto));
 }