Exemple #1
0
        /// <summary>
        /// Generate release note report
        /// </summary>
        /// <param name="release">Model</param>
        /// <param name="templatePath">Path of template</param>
        /// <param name="errorValidation">Returns errors</param>
        /// <returns></returns>
        public static MemoryStream GenerateReleaseNoteReport(ReleaseNote release, string templatePath, out string errorValidation)
        {
            //Put in memory the template file
            byte[] byteArray = File.ReadAllBytes(templatePath);
            errorValidation = string.Empty;

            MemoryStream ms = new MemoryStream();
            ms.Write(byteArray, 0, (int)byteArray.Length);

            using (WordprocessingDocument theDoc = WordprocessingDocument.Open(ms, true))
            {
                MainDocumentPart mainPart = theDoc.MainDocumentPart;

                List<string> logs = ValidateReleaseNoteReport(release, mainPart);
                if (logs.Count > 0)
                {
                    errorValidation = "The release template has an incorrect format: \r\n\t";
                    errorValidation += string.Join("\r\n\t", logs);
                    return null;
                }

                var sdtElements = mainPart.Document.Body.Descendants<SdtElement>(); //includes runs, blocks, cells
                string certificateNumber = release.Certificate.Sequential;
                InsertInBlock(sdtElements, "EntryPoint", release.Certificate.EntryPoint.Name);
                InsertInBlock(sdtElements, "ImporterName", release.ImporterName);
                InsertInBlock(sdtElements, "CertificateNumber", certificateNumber);
                var checks = mainPart.Document.Body.Descendants<FieldChar>().Where(x => x.FieldCharType == FieldCharValues.Begin);
                bool visuallyCheck = release.VisuallyCheck.HasValue ? release.VisuallyCheck.Value : false;
                bool isClosed = release.Certificate.WorkflowStatusId == WorkflowStatusEnum.Closed ? true : false;
                bool isPartial = release.PartialComplete.GetValueOrDefault();
                bool isCompleted = !isPartial;
                foreach (var item in checks)
                {
                    if (((FormFieldName)item.FormFieldData.FirstChild).Val == "VisuallyCheck" || ((FormFieldName)item.FormFieldData.FirstChild).Val == "VisuallyCheckArabic")
                    {
                        ((DefaultCheckBoxFormFieldState)item.FormFieldData.GetFirstChild<CheckBox>().LastChild).Val = visuallyCheck == true ? new OnOffValue(true) : new OnOffValue(false);
                    }
                    else
                    {
                        if (((FormFieldName)item.FormFieldData.FirstChild).Val == "Complete")
                        {
                            ((DefaultCheckBoxFormFieldState)item.FormFieldData.GetFirstChild<CheckBox>().LastChild).Val = isCompleted == true ? new OnOffValue(true) : new OnOffValue(false);
                        }
                        else if (((FormFieldName)item.FormFieldData.FirstChild).Val == "Partial")
                        {
                            ((DefaultCheckBoxFormFieldState)item.FormFieldData.GetFirstChild<CheckBox>().LastChild).Val = isPartial == true ? new OnOffValue(true) : new OnOffValue(false);
                        }
                    }
                }
                InsertInBlock(sdtElements, "ContainersDetails", release.ContainersDetails);
                InsertInBlock(sdtElements, "ImportDocumentDetails", release.ImportDocumentDetails);
                InsertInBlock(sdtElements, "NumberLineItems", release.NumberLineItems.GetValueOrDefault().ToString());

                InsertInBlock(sdtElements, "ShipmentType", release.ShipmentType.GetValueOrDefault().ToString());
                InsertInBlock(sdtElements, "ShipmentTypeArabic", release.ShipmentType.GetValueOrDefault().ToString());

                InsertInBlock(sdtElements, "Unit", release.Unit);
                InsertInBlock(sdtElements, "ReceivedQty", release.ReceivedQuantity.GetValueOrDefault().ToString());
                InsertInBlock(sdtElements, "RemanQty", release.RemainingQuantity.GetValueOrDefault().ToString());

                decimal totalqty = release.ReceivedQuantity.GetValueOrDefault() + release.RemainingQuantity.GetValueOrDefault();
                InsertInBlock(sdtElements, "TotalQty", totalqty.ToString());

                InsertInBlock(sdtElements, "Comments", release.Comments);
                InsertInBlock(sdtElements, "CertificateNumberPartial", string.Format("{0}/{1:000}", certificateNumber, release.PartialNumber));
                InsertInBlock(sdtElements, "IssuanceDate", release.IssuanceDate.ToString("dd/MM/yyyy"));

                // Save the changes to the table back into the document.
                mainPart.Document.Save();

            }

            return ms;
        }
Exemple #2
0
        /// <summary>
        /// Validate if the document is ok before fill all fields
        /// </summary>
        /// <param name="model">Model</param>
        /// <param name="mainPart">Document</param>
        /// <returns>List of errors</returns>
        public static List<string> ValidateReleaseNoteReport(ReleaseNote model, MainDocumentPart mainPart)
        {
            List<string> logs = new List<string>();

            var sdtBodyElements = mainPart.Document.Body.Descendants<SdtElement>();
            ValidateInBlock(sdtBodyElements, "EntryPoint", logs);
            ValidateInBlock(sdtBodyElements, "ImporterName", logs);
            ValidateInBlock(sdtBodyElements, "CertificateNumber", logs);
            ValidateInBlock(sdtBodyElements, "ContainersDetails", logs);
            ValidateInBlock(sdtBodyElements, "ImportDocumentDetails", logs);
            ValidateInBlock(sdtBodyElements, "ShipmentType", logs);
            ValidateInBlock(sdtBodyElements, "ShipmentTypeArabic", logs);
            ValidateInBlock(sdtBodyElements, "Unit", logs);
            ValidateInBlock(sdtBodyElements, "ReceivedQty", logs);
            ValidateInBlock(sdtBodyElements, "RemanQty", logs);
            ValidateInBlock(sdtBodyElements, "TotalQty", logs);
            ValidateInBlock(sdtBodyElements, "Comments", logs);
            ValidateInBlock(sdtBodyElements, "CertificateNumberPartial", logs);
            ValidateInBlock(sdtBodyElements, "IssuanceDate", logs);

            return logs;
        }
 /// <summary>
 /// Execute the click event of the button new
 /// </summary>
 private void ExecuteNewReleaseNoteCommand()
 {
     ReleaseNote newReleaseNote = new ReleaseNote { CertificateId = _certificate.CertificateId, Certificate = _certificate, IssuanceDate = DateTime.Now };
     ReleaseNoteViewModel model = new ReleaseNoteViewModel(newReleaseNote);
     model.SavedItem += OnReleaseNoteSaved;
     model.ReloadDocuments += ReleaseDocumentReloadDocuments;
     ReleaseNoteEditionRequested(this, new ContextEditionEventArgs<ReleaseNoteViewModel>(model));
 }
 /// <summary>
 /// Command to view the document associated with the ReleaseNote
 /// </summary>
 /// <param name="item">ReleaseNote item parameter</param>
 private void ViewReleaseNote(ReleaseNote item)
 {
     IsBusy = true;
     _context.GetDocumentByReleaseNoteId(item.ReleaseNoteId, CompletedViewReleaseNote, null);
 }
 /// <summary>
 /// Command to edit ReleaseNote
 /// </summary>
 /// <param name="item">ReleaseNote item parameter</param>
 private void EditReleaseNote(ReleaseNote item)
 {
     if (ReleaseNoteEditionRequested != null)
     {
         item.Certificate = _certificate;
         ReleaseNoteViewModel model = new ReleaseNoteViewModel(item);
         model.SavedItem += OnReleaseNoteSaved;
         model.ReloadDocuments += ReleaseDocumentReloadDocuments;
         ReleaseNoteEditionRequested(this, new ContextEditionEventArgs<ReleaseNoteViewModel>(model));
     }
 }