Example #1
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, WrittenWorkEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #2
0
        public string ImportSWP(string belongtypecode)
        {
            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;
                if (Directory.Exists(Server.MapPath("~/Resource/ht/images/swp")) == false)//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(Server.MapPath("~/Resource/ht/images/swp"));
                }
                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    order = i;
                    //文件名称
                    string filename = dt.Rows[i][0].ToString();
                    //文件编号
                    string filecode = dt.Rows[i][1].ToString();
                    //颁发部门
                    string iuusedept = dt.Rows[i][2].ToString();
                    //发布日期
                    string publishdate = dt.Rows[i][3].ToString();
                    //实施日期
                    string carrydate = dt.Rows[i][4].ToString();
                    //---****值存在空验证*****--
                    if (string.IsNullOrEmpty(filename) || string.IsNullOrEmpty(filecode) || string.IsNullOrEmpty(iuusedept) || string.IsNullOrEmpty(carrydate) || string.IsNullOrEmpty(publishdate))
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行值存在空,未能导入.";
                        error++;
                        continue;
                    }
                    WrittenWorkEntity sl = new WrittenWorkEntity();
                    sl.FileName       = filename;
                    sl.FileCode       = filecode;
                    sl.IssueDept      = iuusedept;
                    sl.BelongTypeCode = belongtypecode;//所属单位
                    sl.FilesId        = Guid.NewGuid().ToString();

                    FileInfoEntity fileEntity = new FileInfoEntity();
                    fileEntity.RecId       = sl.FilesId;
                    fileEntity.EnabledMark = 1;
                    fileEntity.DeleteMark  = 0;
                    fileEntity.FilePath    = "~/Resource/ht/images/swp/" + filename;
                    fileEntity.FileName    = sl.FileName;
                    fileEntity.FolderId    = "ht/images";
                    try
                    {
                        sl.CarryDate   = DateTime.Parse(DateTime.Parse(carrydate).ToString("yyyy-MM-dd"));
                        sl.PublishDate = DateTime.Parse(DateTime.Parse(publishdate).ToString("yyyy-MM-dd"));
                    }
                    catch
                    {
                        falseMessage += "</br>" + "第" + (i + 2) + "行时间有误,未能导入.";
                        error++;
                        continue;
                    }
                    try
                    {
                        writtenworkbll.SaveForm("", sl);
                        fileInfoBLL.SaveForm("", fileEntity);
                    }
                    catch
                    {
                        error++;
                    }
                }
                count    = dt.Rows.Count - 1;
                message  = "共有" + count + "条记录,成功导入" + (count - error) + "条,失败" + error + "条";
                message += "</br>" + falseMessage;
            }
            return(message);
        }
Example #3
0
 public ActionResult SaveForm(string keyValue, WrittenWorkEntity entity)
 {
     writtenworkbll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }