コード例 #1
0
 public object getInstitutionDetail([FromBody] JObject json)
 {
     try
     {
         string  res    = json.Value <string>("json");
         dynamic dy     = JsonConvert.DeserializeObject <ExpandoObject>(res);
         string  fileid = dy.data.fileid;
         SafeInstitutionEntity entity = safeinstitutionbll.GetEntity(fileid);
         DataTable             cdt    = fileInfoBLL.GetFiles(entity.FilesId);
         IList <Photo>         cfiles = new List <Photo>(); //资料文件
         foreach (DataRow item in cdt.Rows)
         {
             Photo p = new Photo();
             p.id       = item[0].ToString();
             p.filename = item[1].ToString();
             p.fileurl  = dataitemdetailbll.GetItemValue("imgUrl") + item[2].ToString().Substring(1);
             cfiles.Add(p);
         }
         return(new
         {
             Code = 0,
             Count = -1,
             Info = "获取数据成功",
             data = new { fileid = entity.Id, filename = entity.FileName, issuedept = entity.IssueDept, filecode = entity.FileCode, lawtypecode = getName(entity.LawTypeCode, "InstitutionLaw"), carrydate = string.IsNullOrEmpty(entity.CarryDate.ToString()) ? "" : Convert.ToDateTime(entity.CarryDate).ToString("yyyy-MM-dd"), validversions = entity.ValidVersions, cfiles = cfiles }
         });
     }
     catch (Exception ex)
     {
         return(new { Code = -1, Count = 0, Info = ex.Message });
     }
 }
コード例 #2
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, SafeInstitutionEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #3
0
        public string ImportStandard(string treeId, string treeName, string treeCode)
        {
            try
            {
                if (OperatorProvider.Provider.Current().IsSystem)
                {
                    return("超级管理员无此操作权限");
                }
                string orgId        = OperatorProvider.Provider.Current().OrganizeId;//所属公司
                int    error        = 0;
                int    success      = 0;
                string message      = "请选择文件格式正确的文件再导入!";
                string falseMessage = "";
                int    count        = HttpContext.Request.Files.Count;
                if (count > 0)
                {
                    if (HttpContext.Request.Files.Count != 2)
                    {
                        return("请按正确的方式导入两个文件.");
                    }
                    HttpPostedFileBase file  = HttpContext.Request.Files[0];
                    HttpPostedFileBase file2 = HttpContext.Request.Files[1];
                    if (string.IsNullOrEmpty(file.FileName) || string.IsNullOrEmpty(file2.FileName))
                    {
                        return(message);
                    }
                    Boolean isZip1 = file.FileName.Substring(file.FileName.IndexOf('.')).Contains("zip");   //第一个文件是否为Zip格式
                    Boolean isZip2 = file2.FileName.Substring(file2.FileName.IndexOf('.')).Contains("zip"); //第二个文件是否为Zip格式
                    if ((isZip1 || isZip2) == false || (isZip1 && isZip2) == true)
                    {
                        return(message);
                    }
                    string fileName1 = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file.FileName);
                    file.SaveAs(Server.MapPath("~/Resource/temp/" + fileName1));
                    string fileName2 = DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(file2.FileName);
                    file2.SaveAs(Server.MapPath("~/Resource/temp/" + fileName2));
                    string decompressionDirectory = Server.MapPath("~/Resource/decompression/") + DateTime.Now.ToString("yyyyMMddhhmmssfff") + "\\";
                    Aspose.Cells.Workbook wb      = new Aspose.Cells.Workbook();
                    if (isZip1)
                    {
                        UnZip(Server.MapPath("~/Resource/temp/" + fileName1), decompressionDirectory, "", true);
                        wb.Open(Server.MapPath("~/Resource/temp/" + fileName2));
                    }
                    else
                    {
                        UnZip(Server.MapPath("~/Resource/temp/" + fileName2), decompressionDirectory, "", true);
                        wb.Open(Server.MapPath("~/Resource/temp/" + fileName1));
                    }

                    Aspose.Cells.Cells cells = wb.Worksheets[0].Cells;
                    DataTable          dt    = cells.ExportDataTable(1, 0, cells.MaxDataRow, cells.MaxColumn, false);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        SafeInstitutionEntity entity = new SafeInstitutionEntity();
                        entity.Id      = Guid.NewGuid().ToString();
                        entity.FilesId = Guid.NewGuid().ToString();

                        //文件名称
                        string filename = dt.Rows[i][0].ToString();
                        //文件编号
                        string filecode = dt.Rows[i][1].ToString();
                        //发布单位
                        string issuedept = dt.Rows[i][4].ToString();
                        //发布时间
                        string releasedate = dt.Rows[i][5].ToString();
                        //修订时间
                        string revisedate = dt.Rows[i][6].ToString();
                        //实施时间
                        string carrydate = dt.Rows[i][7].ToString();
                        //备注
                        string Remark = dt.Rows[i][8].ToString();



                        //---****值存在空验证*****--
                        if (string.IsNullOrEmpty(filename) || string.IsNullOrEmpty(filecode))
                        {
                            falseMessage += "</br>" + "第" + (i + 1) + "行值存在空,未能导入.";
                            error++;
                            continue;
                        }

                        bool conbool = false;


                        //正文附件路径
                        string[] filepaths = dt.Rows[i][2].ToString().Split(';');

                        var filepath = "";
                        for (int j = 0; j < filepaths.Length; j++)
                        {
                            filepath = filepaths[j];

                            if (string.IsNullOrEmpty(filepath))
                            {
                                continue;
                            }
                            string strPath = filepath.Substring(filepath.IndexOf('.'));
                            //---****文件格式验证*****--
                            if (!(strPath.Contains("doc") || strPath.Contains("docx") || strPath.Contains("pdf")))
                            {
                                falseMessage += "</br>" + "第" + (i + 1) + "行指定正文附件格式不正确,未能导入.";
                                error++;
                                conbool = true;
                                continue;
                            }

                            //---****文件是否存在验证*****--
                            if (!System.IO.File.Exists(decompressionDirectory + filepath))
                            {
                                falseMessage += "</br>" + "第" + (i + 1) + "行指定正文附件不存在,未能导入.";
                                error++;
                                conbool = true;
                                continue;
                            }
                            var            fileinfo       = new FileInfo(decompressionDirectory + filepath);
                            FileInfoEntity fileInfoEntity = new FileInfoEntity();
                            string         fileguid       = Guid.NewGuid().ToString();
                            fileInfoEntity.Create();
                            fileInfoEntity.RecId          = entity.FilesId; //关联ID
                            fileInfoEntity.FileName       = filepath;
                            fileInfoEntity.FilePath       = "~/Resource/InstitutionSystem/" + fileguid + fileinfo.Extension;
                            fileInfoEntity.FileSize       = (Math.Round(decimal.Parse(fileinfo.Length.ToString()) / decimal.Parse("1024"), 2)).ToString();//文件大小(kb)
                            fileInfoEntity.FileExtensions = fileinfo.Extension;
                            fileInfoEntity.FileType       = fileinfo.Extension.Replace(".", "");
                            TransportRemoteToServer(Server.MapPath("~/Resource/InstitutionSystem/"), decompressionDirectory + filepath, fileguid + fileinfo.Extension);
                            fileinfobll.SaveForm("", fileInfoEntity);
                        }

                        if (conbool)
                        {
                            continue;
                        }
                        //正文附件路径
                        filepaths = dt.Rows[i][3].ToString().Split(';');

                        filepath = "";
                        for (int j = 0; j < filepaths.Length; j++)
                        {
                            filepath = filepaths[j];

                            if (string.IsNullOrEmpty(filepath))
                            {
                                continue;
                            }
                            string strPath = filepath.Substring(filepath.IndexOf('.'));
                            //---****文件格式验证*****--
                            if (!(strPath.Contains("doc") || strPath.Contains("docx") || strPath.Contains("pdf") || strPath.Contains("ppt") || strPath.Contains("xlsx") || strPath.Contains("xls") || strPath.Contains("png") || strPath.Contains("jpg") || strPath.Contains("jpeg")))
                            {
                                falseMessage += "</br>" + "第" + (i + 1) + "行指定附件格式不正确,未能导入.";
                                error++;
                                conbool = true;
                                continue;
                            }

                            //---****文件是否存在验证*****--
                            if (!System.IO.File.Exists(decompressionDirectory + filepath))
                            {
                                falseMessage += "</br>" + "第" + (i + 1) + "行指定附件不存在,未能导入.";
                                error++;
                                conbool = true;
                                continue;
                            }
                            var            fileinfo       = new FileInfo(decompressionDirectory + filepath);
                            FileInfoEntity fileInfoEntity = new FileInfoEntity();
                            string         fileguid       = Guid.NewGuid().ToString();
                            fileInfoEntity.Create();
                            fileInfoEntity.RecId          = entity.Id; //关联ID
                            fileInfoEntity.FileName       = filepath;
                            fileInfoEntity.FilePath       = "~/Resource/InstitutionSystem/" + fileguid + fileinfo.Extension;
                            fileInfoEntity.FileSize       = (Math.Round(decimal.Parse(fileinfo.Length.ToString()) / decimal.Parse("1024"), 2)).ToString();//文件大小(kb)
                            fileInfoEntity.FileExtensions = fileinfo.Extension;
                            fileInfoEntity.FileType       = fileinfo.Extension.Replace(".", "");
                            TransportRemoteToServer(Server.MapPath("~/Resource/InstitutionSystem/"), decompressionDirectory + filepath, fileguid + fileinfo.Extension);
                            fileinfobll.SaveForm("", fileInfoEntity);
                        }

                        entity.FileName    = filename;
                        entity.FileCode    = filecode;
                        entity.IssueDept   = issuedept;
                        entity.LawTypeId   = treeId;
                        entity.LawTypeName = treeName;
                        entity.LawTypeCode = treeCode;
                        if (!string.IsNullOrEmpty(releasedate))
                        {
                            entity.ReleaseDate = Convert.ToDateTime(releasedate);
                        }
                        if (!string.IsNullOrEmpty(revisedate))
                        {
                            entity.ReviseDate = Convert.ToDateTime(revisedate);
                        }
                        if (!string.IsNullOrEmpty(carrydate))
                        {
                            entity.CarryDate = Convert.ToDateTime(carrydate);
                        }

                        entity.Remark = !string.IsNullOrEmpty(Remark) ? Remark : "";

                        try
                        {
                            safeinstitutionbll.SaveForm(entity.Id, entity);
                            success++;
                        }
                        catch
                        {
                            error++;
                        }
                    }
                    message  = "共有" + dt.Rows.Count + "条记录,成功导入" + success + "条,失败" + error + "条";
                    message += "</br>" + falseMessage;
                }
                return(message);
            }
            catch (Exception e)
            {
                return("导入的Excel数据格式不正确,请下载标准模板重新填写!");
            }
        }
コード例 #4
0
 public ActionResult SaveForm(string keyValue, SafeInstitutionEntity entity)
 {
     safeinstitutionbll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }
コード例 #5
0
        public string ImportInstitution()
        {
            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 = 1;
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    order = i;
                    //文件名称(必填)
                    string filename = dt.Rows[i][0].ToString();
                    //发布单位
                    string iuusedept = dt.Rows[i][1].ToString();
                    //文件编号
                    string filecode = dt.Rows[i][2].ToString();
                    //管理制度类别(必填)
                    string lawtype = dt.Rows[i][3].ToString();
                    //施行日期(必填)
                    string carrydate = dt.Rows[i][4].ToString();
                    //有效版本号(必填)
                    string validversions = dt.Rows[i][5].ToString();
                    //---****值存在空验证*****--
                    if (string.IsNullOrEmpty(filename) || string.IsNullOrEmpty(lawtype) || string.IsNullOrEmpty(carrydate) || string.IsNullOrEmpty(validversions))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行值存在空,未能导入.";
                        error++;
                        continue;
                    }
                    SafeInstitutionEntity sl = new SafeInstitutionEntity();
                    sl.FileName  = filename;
                    sl.IssueDept = iuusedept;
                    sl.FileCode  = filecode;
                    string itemvalue = dataitemdetailbll.GetItemValue(lawtype, "InstitutionLaw");
                    sl.LawTypeCode   = itemvalue;
                    sl.ValidVersions = validversions;
                    try
                    {
                        sl.CarryDate = DateTime.Parse(DateTime.Parse(carrydate).ToString("yyyy-MM-dd"));
                    }
                    catch
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行时间有误,未能导入.";
                        error++;
                        continue;
                    }
                    try
                    {
                        safeinstitutionbll.SaveForm("", sl);
                    }
                    catch
                    {
                        error++;
                    }
                }
                count    = dt.Rows.Count - 1;
                message  = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }
            return(message);
        }