Exemplo n.º 1
0
        public string GenerateAttachment()
        {
            var    records      = RenewalLLNegotiationRecord.GetRecords(Id);
            var    templateName = HttpContext.Current.Server.MapPath("~/Template/Renewal_LLNegotiationRecord_Template.xlsx");
            string fileName     = string.Concat(HttpContext.Current.Server.MapPath("~/UploadFiles/"), Guid.NewGuid(), ".xlsx");

            File.Copy(templateName, fileName);
            FileInfo file = new FileInfo(fileName);
            ExcelDataInputDirector excelDirector = new ExcelDataInputDirector(file, ExcelDataInputType.RenewalLLNegotiationRecord);
            List <ExcelInputDTO>   datas         = records.Select(r => new ExcelInputDTO
            {
                McdParticipants = r.McdParticipants,
                Content         = r.Content,
                LLParticipants  = r.LLParticipants,
                Topic           = r.Topic,
                Location        = r.Location,
                MeetingDate     = r.Date.Value.ToString("yyyy-MM-dd"),
                CreateDate      = r.CreateTime.ToString("yyyy-MM-dd")
            }).ToList();

            excelDirector.ListInput(datas);
            Guid       reqId = new Guid("f314bf06-f557-4893-ae78-af3b0b561885");
            Attachment att   = Attachment.Get(Id.ToString(), reqId);

            if (att == null)
            {
                att = new Attachment();
                att.InternalName    = Path.GetFileName(fileName);
                att.RefTableName    = this.TableName;
                att.RefTableID      = Id.ToString();
                att.RelativePath    = "//";
                att.Name            = "Negotiation Record List";
                att.Extension       = ".xlsx";
                att.Length          = (int)file.Length;
                att.CreateTime      = DateTime.Now;
                att.CreatorNameZHCN = ClientCookie.UserNameZHCN;
                att.CreatorNameENUS = ClientCookie.UserNameENUS;
                att.CreatorID       = ClientCookie.UserCode;
                att.ID            = Guid.NewGuid();
                att.RequirementId = reqId;
                att.TypeCode      = "";
                Attachment.Add(att);
            }
            else
            {
                att.InternalName    = Path.GetFileName(fileName);
                att.RefTableName    = this.TableName;
                att.RefTableID      = Id.ToString();
                att.RelativePath    = "//";
                att.Name            = "Negotiation Record List";
                att.Extension       = ".xlsx";
                att.Length          = (int)file.Length;
                att.CreateTime      = DateTime.Now;
                att.CreatorNameZHCN = ClientCookie.UserNameZHCN;
                att.CreatorNameENUS = ClientCookie.UserNameENUS;
                att.CreatorID       = ClientCookie.UserCode;
                Attachment.Update(att);
            }
            return(fileName);
        }