public ActionResult GetTemplate(string projectGuid)
        {
            return(ActionUtils.Json(() =>
            {
                CommUtils.AssertHasContent(projectGuid, "projectGuid不能为空");

                var authoritiedProjectIds = m_dbAdapter.Authority.GetAuthorizedProjectIds();
                var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid);
                CommUtils.Assert(authoritiedProjectIds.Any(x => x == project.ProjectId), "用户[{0}]没有上传文件模板到产品[{1}]的权限", CurrentUserName, project.Name);

                var docPatternTypes = GetDocPatternTypes(project);
                var result = docPatternTypes.ConvertAll(x =>
                {
                    var path = DocumentPattern.GetPath(project, x);
                    var fileName = DocumentPattern.GetFileName(x);
                    var exist = System.IO.File.Exists(path);
                    return new
                    {
                        templateFileName = fileName.Remove(fileName.LastIndexOf(".")),
                        docPatternType = x.ToString(),
                        status = exist ? "Exist" : "NotExist",
                        createTime = exist ? System.IO.File.GetCreationTime(path).ToString("yyyy-MM-dd HH:mm") : "",
                    };
                });

                return ActionUtils.Success(result);
            }));
        }
Example #2
0
        public ActionResult DownloadTemplateTimeFile(string templateGuid)
        {
            string err = "未知的错误";

            try
            {
                if (string.IsNullOrEmpty(templateGuid))
                {
                    return(RedirectToAction("CreateProjet", "MyProjects"));
                }

                var template  = m_dbAdapter.Template.GetTemplate(templateGuid);
                var timeLists = m_dbAdapter.Template.GetTemplateTimeLists(templateGuid);

                TemplateTimePattern patternObj = new TemplateTimePattern();
                patternObj.TemplateTimeList = timeLists.ConvertAll(x => new TemplateTimeItem
                {
                    TemplateName      = template.TemplateName,
                    TemplateTimeName  = x.TemplateTimeName,
                    BeginTime         = x.BeginTime,
                    EndTime           = x.EndTime,
                    TimeSpan          = x.TimeSpan,
                    TimeSpanUnit      = x.TimeSpanUnit,
                    TemplateTimeType  = x.TemplateTimeType,
                    SearchDirection   = x.SearchDirection,
                    HandleReduplicate = x.HandleReduplicate
                }).ToList();

                var excelPattern    = new ExcelPattern();
                var patternFilePath = DocumentPattern.GetPath(DocPatternType.TemplateTime);

                MemoryStream ms = new MemoryStream();
                if (!excelPattern.Generate(patternFilePath, patternObj, ms))
                {
                    throw new ApplicationException("Generate file failed.");
                }
                string fileFullName = template.TemplateName + "_时间模板" + ".xlsx";
                string mimeType     = "application/xlsx";

                ms.Seek(0, SeekOrigin.Begin);
                return(File(ms, mimeType, fileFullName));
            }
            catch (ApplicationException ae)
            {
                err = ae.Message;
                return(RedirectToAction("NotFound", "Error"));
            }
            catch (Exception e)
            {
                err = "服务器错误:" + e.Message;
                return(RedirectToAction("NotFound", "Error"));
            }
        }
        public ActionResult DownloadTemplate(string projectGuid, string templateFileName)
        {
            CommUtils.AssertHasContent(projectGuid, "projectGuid不能为空");
            CommUtils.AssertHasContent(templateFileName, "templateFileName不能为空");

            var authoritiedProjectIds = m_dbAdapter.Authority.GetAuthorizedProjectIds();
            var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid);

            CommUtils.Assert(authoritiedProjectIds.Any(x => x == project.ProjectId), "用户[{0}]没有修改产品[{1}]的权限", CurrentUserName, project.Name);

            templateFileName += ".docx";
            string sourcePath = Path.Combine(DocumentPattern.GetFolder(project), templateFileName);

            return(File(sourcePath, "application/octet-stream", templateFileName));
        }
        public ActionResult UploadTemplate(string projectGuid, string templateFileName)
        {
            return(ActionUtils.Json(() =>
            {
                CommUtils.Assert(Request.Files.Count > 0, "请选择文件");

                var file = Request.Files[0];
                CommUtils.Assert(file.ContentLength > 0, "文件内容不能为空");

                CommUtils.AssertHasContent(projectGuid, "projectGuid不能为空");
                CommUtils.AssertHasContent(templateFileName, "templateFileName不能为空");

                //   var authoritiedProjectIds = m_dbAdapter.Authority.GetAuthorizedProjectIds(AuthorityType.ModifyTask);
                var authoritiedProjectIds = m_dbAdapter.Authority.GetAuthorizedProjectIds();

                var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid);
                CommUtils.Assert(authoritiedProjectIds.Any(x => x == project.ProjectId), "用户[{0}]没有修改产品[{1}]的权限", CurrentUserName, project.Name);

                templateFileName += ".docx";
                CommUtils.Assert(file.FileName.EndsWith(".docx", StringComparison.CurrentCultureIgnoreCase),
                                 "文件[{0}]格式错误,请选择.docx格式的文件", file.FileName);

                CommUtils.Assert(!CommUtils.IsWPS(file.InputStream), "不支持wps编辑过的.docx格式文件,仅支持office编辑的.docx文件");
                CommUtils.Assert(IsValidDocPatternName(project, templateFileName), "上传参数有误:templateFileName={0}", templateFileName);

                string sourcePath = Path.Combine(DocumentPattern.GetFolder(project), templateFileName);
                string backupPath = Path.Combine(DocumentPattern.GetFolder(project), "backup");
                if (!Directory.Exists(backupPath))
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(backupPath);
                    directoryInfo.Create();
                }

                string backupFilePath = Path.Combine(backupPath, templateFileName);

                if (System.IO.File.Exists(sourcePath))
                {
                    backupFilePath = FileUtils.InsertTimeStamp(backupFilePath);
                    System.IO.File.Copy(sourcePath, backupFilePath, true);
                }

                file.SaveAs(sourcePath);

                return ActionUtils.Success(1);
            }));
        }
 private bool IsValidDocPatternName(ABSManagement.Models.Project project, string docPatternName)
 {
     return(GetDocPatternTypes(project).ConvertAll(x => DocumentPattern.GetFileName(x))
            .Any(x => x.Equals(docPatternName, StringComparison.CurrentCultureIgnoreCase)));
 }
Example #6
0
 protected override string GetPatternFilePath()
 {
     return(DocumentPattern.GetPath(m_project, DocPatternType.IncomeDistributionReport));
 }
Example #7
0
 protected override string GetPatternFilePath()
 {
     return DocumentPattern.GetPath(m_project, DocPatternType.CashInterestRateConfirmForm);
 }
        public SaveDocumentPatternWindow(DocumentPattern dp)
        {
            this._documentToSave = dp;

            InitializeComponent();
        }
 public DocumentPatternLoadedEventArgs(DocumentPattern documentPattern)
 {
     this.DocumentPattern = documentPattern;
 }
        public DocumentView(DocumentPattern documentPattern)
        {
            this.DocumentPattern = documentPattern;

            InitializeComponent();
        }
Example #11
0
 protected override string GetPatternFilePath()
 {
     return(DocumentPattern.GetPath(m_project, DocPatternType.DemoJianYuanReport));
 }
Example #12
0
 public static void LoadRegions(DocumentView document, DocumentPattern documentPattern)
 {
 }
Example #13
0
        public ActionResult ExportTasks(string projectGuid, string paymentDay, string timeRange,
                                        string taskStatusList)
        {
            return(ActionUtils.Json(() =>
            {
                var projectId = -1;
                var authorizedProjectIds = m_dbAdapter.Authority.GetAuthorizedProjectIds();
                var projects = m_dbAdapter.Project.GetProjects(authorizedProjectIds);
                var dictProjects = projects.ToDictionary(x => x.ProjectId);
                var upperLimitDate = DateTime.Parse("9999-12-31");
                var lowerLimitDate = DateTime.Parse("1753-01-02");

                if (!string.IsNullOrWhiteSpace(projectGuid))
                {
                    var project = m_dbAdapter.Project.GetProjectByGuid(projectGuid);
                    projectId = project.ProjectId;

                    CommUtils.Assert(authorizedProjectIds.Contains(projectId), "当前用户没有读取产品[{0}]偿付期列表的权限", project.Name);
                    if (!string.IsNullOrWhiteSpace(paymentDay))
                    {
                        GetLimitDates(projectGuid, paymentDay, ref upperLimitDate, ref lowerLimitDate);
                    }
                }

                var taskStatusValues = new List <TaskStatus>();
                if (taskStatusList != null)
                {
                    taskStatusValues = CommUtils.ParseEnumList <TaskStatus>(taskStatusList);
                }
                else
                {
                    taskStatusValues = new List <TaskStatus>()
                    {
                        TaskStatus.Waitting,
                        TaskStatus.Running,
                        TaskStatus.Finished,
                        TaskStatus.Skipped,
                        TaskStatus.Overdue,
                        TaskStatus.Error
                    };
                }

                DateTime?endTime = null;
                if (!string.IsNullOrWhiteSpace(timeRange))
                {
                    var enumTime = CommUtils.ParseEnum <TaskFilterTime>(timeRange);
                    if (enumTime != TaskFilterTime.All)
                    {
                        endTime = ParseFilterTime(enumTime);
                    }
                }

                var tasks = m_dbAdapter.Task.GetTasks(1, 1000000, endTime, projectId,
                                                      taskStatusValues, authorizedProjectIds, Toolkit.DateToString(upperLimitDate),
                                                      Toolkit.DateToString(lowerLimitDate), paymentDay ?? "1753-01-02");

                TaskPattern patternObj = new TaskPattern();

                patternObj.Tasks = tasks.Items.ConvertAll(x => new TaskItem
                {
                    ProjectName = dictProjects[x.ProjectId].Name,
                    TaskName = x.Description,
                    BeginTime = Toolkit.DateToString(x.StartTime),
                    EndTime = Toolkit.DateToString(x.EndTime),
                    TaskDetail = x.TaskDetail,
                    TaskTarget = x.TaskTarget,
                    TaskExtensionName = (x.TaskExtension != null &&
                                         !string.IsNullOrWhiteSpace(x.TaskExtension.TaskExtensionName)
                        ? x.TaskExtension.TaskExtensionName : string.Empty)
                }).ToList();

                var excelPattern = new ExcelPattern();
                string patternFilePath = DocumentPattern.GetPath(DocPatternType.TaskList);

                MemoryStream ms = new MemoryStream();
                if (!excelPattern.Generate(patternFilePath, patternObj, ms))
                {
                    CommUtils.Assert(false, "Generate file failed.");
                }
                ms.Seek(0, SeekOrigin.Begin);

                string fileFullName = projectId == -1 ? "工作列表.xlsx"
                    : dictProjects[projectId].Name + "_工作列表.xlsx";
                var resource = ResourcePool.RegisterMemoryStream(CurrentUserName, fileFullName, ms);
                return ActionUtils.Success(resource.Guid.ToString());
            }));
        }
Example #14
0
        public ActionResult DownloadTemplateTaskFile(string templateGuid)
        {
            string err = "未知的错误";

            try
            {
                if (string.IsNullOrEmpty(templateGuid))
                {
                    return(RedirectToAction("CreateProjet", "MyProjects"));
                }

                var template      = m_dbAdapter.Template.GetTemplate(templateGuid);
                var templateTasks = m_dbAdapter.Template.GetTemplateTasks(templateGuid);

                //使用1 2 3~N替代掉TemplateTaskId
                var templateTaskIdDict = new Dictionary <int, int>();
                var templateTaskId     = 1;
                templateTasks.ForEach(x =>
                {
                    templateTaskIdDict[x.TemplateTaskId] = templateTaskId;
                    x.TemplateTaskId = templateTaskId;
                    ++templateTaskId;
                });

                //CommUtils.Assert(tasks.Count == 0,"当前模板");
                TemplateTaskPattern patternObj = new TemplateTaskPattern();
                patternObj.TemplateTaskList = templateTasks.ConvertAll(x => new TemplateTaskItem
                {
                    TemplateName        = template.TemplateName,
                    TemplateTaskId      = x.TemplateTaskId,
                    TemplateTaskName    = x.TemplateTaskName,
                    BeginTime           = x.BeginDate,
                    EndTime             = x.TriggerDate,
                    PrevTemplateTaskIds = string.Join("|",
                                                      x.PrevIds.Where(prevId => templateTaskIdDict.ContainsKey(prevId)).ToList()
                                                      .ConvertAll(prevId => templateTaskIdDict[prevId].ToString()).ToArray()),
                    TemplateTaskDetail        = x.TemplateTaskDetail,
                    TemplateTaskTarget        = x.TemplateTaskTarget,
                    TemplateTaskExtensionName = (x.TemplateTaskExtensionName == null ? "" : x.TemplateTaskExtensionName)
                }).ToList();

                var          excelPattern    = new ExcelPattern();
                var          patternFilePath = DocumentPattern.GetPath(DocPatternType.TemplateTask);
                MemoryStream ms = new MemoryStream();
                if (!excelPattern.Generate(patternFilePath, patternObj, ms))
                {
                    throw new ApplicationException("Generate file failed.");
                }

                string fileFullName = template.TemplateName + ".xlsx";
                string mimeType     = "application/xlsx";

                ms.Seek(0, SeekOrigin.Begin);
                return(File(ms, mimeType, fileFullName));
            }
            catch (ApplicationException ae)
            {
                err = ae.Message;
                return(RedirectToAction("NotFound", "Error"));
            }
            catch (Exception e)
            {
                err = "服务器错误:" + e.Message;
                return(RedirectToAction("NotFound", "Error"));
            }
        }
Example #15
0
 protected override string GetPatternFilePath()
 {
     return(DocumentPattern.GetPath(m_project, DocPatternType.InterestPaymentPlanApplication));
 }
Example #16
0
 protected override string GetPatternFilePath()
 {
     return(DocumentPattern.GetPath(m_project, DocPatternType.SpecialPlanTransferInstruction));
 }