Пример #1
0
 public void SetValue(OpenXmlElement element, T value) => _accessor.Set(element, value);
Пример #2
0
        //internal override void Load(XmlReader xmlReader)
        //{
        //    LoadAttributes(xmlReader);
        //    this.Text = xmlReader.ReadElementString();
        //}
        internal override void Populate(XmlReader xmlReader, OpenXmlLoadMode loadMode)
        {
            LoadAttributes(xmlReader);

            if (!xmlReader.IsEmptyElement)
            {                     // only when element is not empty (not  <element />).
                xmlReader.Read(); // read this element

                this.RawInnerText = string.Empty;

                int         unwanted         = 0;
                int         textNodePosition = -1; // the position of the text in the ShadowElement's children when there are other unexpected node.
                XmlNodeType textNodeType     = XmlNodeType.Text;

                if (xmlReader.NodeType == XmlNodeType.EndElement)
                {
                    Debug.Assert(xmlReader.LocalName.Equals(this.LocalName));
                }
                else
                {
                    while (!xmlReader.EOF)
                    {
                        if (xmlReader.NodeType == XmlNodeType.EndElement)
                        {
                            Debug.Assert(xmlReader.LocalName.Equals(this.LocalName));
                            break;
                        }
                        else if (string.IsNullOrEmpty(this.RawInnerText) &&
                                 (xmlReader.NodeType == XmlNodeType.Text ||
                                  xmlReader.NodeType == XmlNodeType.CDATA ||
                                  xmlReader.NodeType == XmlNodeType.SignificantWhitespace ||
                                  xmlReader.NodeType == XmlNodeType.Whitespace /* O15:#3024890 */))
                        {
                            // text or CDATA
                            // scenario: normal text element <Application>Microsoft Office Word</Application>
                            // scenario: <w:t>This is <![CDATA[Xml Example <tag>text</tag>.]]> 1</w:t>

                            // only load text when no text is loaded,
                            // for case "<foo/>Text1<bar/>Text2", only load "Text1", very rare case

                            this.RawInnerText = xmlReader.Value;
                            textNodePosition  = unwanted;
                            textNodeType      = xmlReader.NodeType;

                            xmlReader.Read();
                        }
                        else
                        {
                            Debug.Assert(xmlReader.NodeType != XmlNodeType.EntityReference);

                            // Load unexpected children if there are any.

                            OpenXmlElement child = this.ElementFactory(xmlReader);
                            child.Load(xmlReader, OpenXmlLoadMode.Full);
                            unwanted++;

                            if (this.ShadowElement == null)
                            {
                                this.ShadowElement = new OpenXmlUnknownElement(this.Prefix, this.LocalName, this.NamespaceUri);
                            }

                            this.ShadowElement.AppendChild(child);
                        }
                    }
                }

                if (unwanted == 0)
                {
                    // only text node, no unwanted children
                    Debug.Assert(this.ShadowElement == null);
                }
                else if (textNodePosition > -1)
                {
                    // place an OpenXmlMiscNode for the loaded text in the ShadowElement so that we can write out correct content in serialization.
                    OpenXmlMiscNode textNode = null;
                    switch (textNodeType)
                    {
                    case XmlNodeType.Text:
                        textNode = OpenXmlMiscNode.CreateFromText(this.RawInnerText);
                        break;

                    case XmlNodeType.CDATA:
                        textNode = OpenXmlMiscNode.CreateFromCdata(this.RawInnerText);
                        break;

                    case XmlNodeType.SignificantWhitespace:
                    case XmlNodeType.Whitespace:     /* O15:#3024890 */
                        textNode = OpenXmlMiscNode.CreateFromSignificantWhitespace(this.RawInnerText);
                        break;
                    }
                    this.ShadowElement.InsertAt(textNode, textNodePosition);
                }
                else
                {
                    // textNodePosition == -1, no text loaded.
                }
            }

            xmlReader.Skip(); // skip the end tag

            // set raw outer xml to empty to indicate that it is passed
            this.RawOuterXml = string.Empty;
        }
        private protected void SetElement <T>(int sequenceNumber, T newChild)
            where T : OpenXmlElement
        {
            switch (OpenXmlCompositeType)
            {
            case OpenXmlCompositeType.Other:
                throw new InvalidOperationException();

            case OpenXmlCompositeType.OneAll:
            {
                T child = GetElement <T>(sequenceNumber);
                if (child != null)
                {
                    // remove the old one
                    RemoveChild(child);
                }

                if (newChild != null)
                {
                    AppendChild(newChild);
                }
            }

                // TODO: should we handle error case?
                //  1: there are more than 1 elements for a type?
                //  2: there are more than 2 elements?
                //  3. there are other elements other than allowed children?
                break;

            case OpenXmlCompositeType.OneChoice:
            {
                OpenXmlElement child         = FirstChild;
                OpenXmlElement previousChild = null;

                // skip unknown element and MiscNode
                while (child != null && !IsKnownElement(child))
                {
                    previousChild = child;
                    child         = child.NextSibling();
                }

                OpenXmlElement next = null;
                while (child != null)
                {
                    next = child.NextSibling();

                    // remove all exist elements
                    if (IsKnownElement(child))
                    {
                        RemoveChild(child);
                    }

                    child = next;
                }

                if (newChild != null)
                {
                    InsertAfter(newChild, previousChild);
                }
            }

                // TODO: should we handle error case?
                //  1: there are more than 1 elements for a type?
                //  2: there are more than 2 elements?
                //  3. there are other elements other than allowed children?
                break;

            case OpenXmlCompositeType.OneSequence:
            {
                OpenXmlElement child = FirstChild;
                OpenXmlElement prev  = null;

                while (child != null)
                {
                    if (IsKnownElement(child))
                    {
                        int childSequenceNumber = GetSequenceNumber(child);

                        if (childSequenceNumber == sequenceNumber)
                        {
                            // remove the old one
                            if (child is T)
                            {
                                // insert the new element after the previous.
                                prev = child.PreviousSibling();
                                RemoveChild(child);
                                break;
                            }
                            else
                            {
                                // same tag name, but wrong type, see bug 448241
                                prev = child;
                            }
                        }
                        else if (childSequenceNumber > sequenceNumber)
                        {
                            break;
                        }
                        else
                        {
                            // always insert after the first known element
                            prev = child;

                            // continue search
                        }
                    }

                    // continue search
                    child = child.NextSibling();
                }

                if (newChild != null)
                {
                    InsertAfter(newChild, prev);
                }
            }

                // TODO: should we handle error case?
                //  1: there are more than 1 elements for a type?
                //  2: there are more than 2 elements?
                //  3. there are other elements other than allowed children?
                break;
            }
        }
Пример #4
0
 private static bool IsOpenXmlLeafTextElement(OpenXmlElement element)
 {
     return(element is OpenXmlLeafTextElement);
 }
Пример #5
0
 /// <summary>
 /// Creates an OpenXmlReader from the OpenXmlElement (travel the DOM tree).
 /// </summary>
 /// <param name="openXmlElement">The OpenXmlElement to read.</param>
 /// <returns>The newly created OpenXmlReader.</returns>
 public static OpenXmlReader Create(OpenXmlElement openXmlElement)
 {
     return(new OpenXmlDomReader(openXmlElement));
 }
Пример #6
0
 /// <summary>
 /// Writes out a start tag of the element. And write the attributes in attributes. The attributes of the element will be omitted.
 /// </summary>
 /// <param name="elementObject">The OpenXmlElement object to be writen.</param>
 /// <param name="attributes">The attributes to be writtern.</param>
 /// <param name="namespaceDeclarations">The namespace declarations to be written, can be null if no namespace declarations.</param>
 public abstract void WriteStartElement(OpenXmlElement elementObject, IEnumerable <OpenXmlAttribute> attributes, IEnumerable <KeyValuePair <string, string> > namespaceDeclarations);
Пример #7
0
 /// <summary>
 /// Writes out a start tag of the element. And write the attributes in attributes. The attributes of the element will be omitted.
 /// </summary>
 /// <param name="elementObject">The OpenXmlElement object to be writen.</param>
 /// <param name="attributes">The attributes to be writtern.</param>
 public override void WriteStartElement(OpenXmlElement elementObject, IEnumerable <OpenXmlAttribute> attributes)
 {
     WriteStartElement(elementObject, attributes, elementObject.NamespaceDeclarations);
 }
Пример #8
0
 private void Init(OpenXmlElement openXmlElement)
 {
     _rootElement  = openXmlElement;
     _elementState = ElementState.Null;
 }
Пример #9
0
        public static MemoryStream GetTemplate2(int id, string path, out string code, string _userID)
        {
            var             memoryStream = new MemoryStream();
            AuditDetailInfo item         = AuditService.GetInstance().getAuditInfo(id, _userID);

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            code = item.AuditCode;
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date        = DateTime.Now;
                string   currentDate = "Ngày " + date.ToString("dd/MM/yyyy");
                var      body        = document.MainDocumentPart.Document.Body;
                var      paras       = body.Elements <Paragraph>();

                Table tableData     = CreateTable2(item);
                var   startTimeText = "Vào lúc " + item.StartTime.Hour + " giờ " + item.StartTime.Minute + " phút ngày " + item.StartTime.Day + " tháng " + item.StartTime.Month + " năm " + item.StartTime.Year;
                var   endTimeText   = "Vào lúc " + item.EndTime.Hour + " giờ " + item.EndTime.Minute + " phút ngày " + item.EndTime.Day + " tháng " + item.EndTime.Month + " năm " + item.EndTime.Year;
                var   intime        = "ngày " + item.InTime.Day + " tháng " + item.InTime.Month + " năm " + item.InTime.Year;
                foreach (var text in body.Descendants <Text>())
                {
                    string auditCode = WordUtils.checkNull(item.AuditCode);
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("code", auditCode.Contains("/BB-BKG") ? auditCode : "Số: ......./BB-BKG");
                    text.Text = text.Text.Replace("starttime", startTimeText);
                    text.Text = text.Text.Replace("endtime", endTimeText);
                    text.Text = text.Text.Replace("location", WordUtils.checkNull(HardData.location[Int32.Parse(item.Location) - 1]));
                    text.Text = text.Text.Replace("preside", WordUtils.checkNull(item.PresideTitle + " " + item.PresideName + " - " + item.PresideRoleName));
                    text.Text = text.Text.Replace("secretary", WordUtils.checkNull(item.SecretaryTitle + " " + item.SecretaryName + " - " + item.SecretaryRoleName));

                    /*        text.Text = text.Text.Replace("curDepart", item.CurDepartmentName);
                     *      text.Text = text.Text.Replace("depart", item.DepartmentName);*/
                    text.Text = text.Text.Replace("preName", item.PresideName);
                    text.Text = text.Text.Replace("secName", item.SecretaryName);
                    text.Text = text.Text.Replace("datein", intime);
                    if (text.Text == "lstItem")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData, textP2);
                        textP1.Remove();
                    }

                    if (text.Text == "firstelist")
                    {
                        text.Text = text.Text.Replace("firstelist", "");
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        foreach (AuditEmployeeInfo employ in item.Employees)
                        {
                            textP1.AppendChild(new Tabs());
                            textP1.AppendChild(new Tabs());
                            textP1.AppendChild(new Tabs());
                            textP1.AppendChild(new Tabs());

                            textP1.AppendChild(new Text("- " + employ.Title + " " + employ.Name + " - " + employ.RoleName));
                            textP1.AppendChild(new Break());
                        }
                    }


                    if (text.Text == "endelist")
                    {
                        text.Text = text.Text.Replace("endelist", "");
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        foreach (AuditEmployeeInfo employ in item.Employees)
                        {
                            int    tempLen = 50 - employ.Name.Length;
                            string dot     = " :";
                            for (var i = 0; i < tempLen; i++)
                            {
                                dot += ".";
                            }
                            textP1.AppendChild(new Text(" * " + employ.Name + dot));
                            textP1.AppendChild(new Break());
                            textP1.AppendChild(new Break());
                            textP1.AppendChild(new Break());
                        }
                    }
                }

                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
Пример #10
0
        public static MemoryStream GetTemplate(int id, string path, out string code, string _userID)
        {
            double      Totalcost    = 0;
            var         memoryStream = new MemoryStream();
            BidPlanInfo item         = BidPlanService.GetInstance().getBidPlan(id, _userID);


            SearchAuditInfo audit = AuditService.GetInstance().GetAuditWordByQuoteID(item.QuoteID);

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            code = item.BidPlanCode;
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date        = DateTime.Now;
                string   currentDate = "Ngày " + date.ToString("dd/MM/yyyy");
                var      body        = document.MainDocumentPart.Document.Body;
                var      paras       = body.Elements <Paragraph>();

                List <string>         headers = new List <string>();
                List <List <string> > items   = new List <List <string> >();
                headers.Add("STT");
                headers.Add("Tên gói thầu");
                headers.Add("Giá gói thầu");
                headers.Add("Nguồn vốn");
                headers.Add("Hình thức phương thức lựa chọn nhà thầu");
                headers.Add("Thời gian tổ chức lựa chọn nhà thầu");
                headers.Add("Loại hợp đồng");
                headers.Add("Thời gian thực hiện hợp đồng");

                foreach (ItemInfo record in item.Items)
                {
                    Totalcost += record.ItemPrice * record.Amount;
                }
                if (item.IsVAT)
                {
                    Totalcost = Totalcost * (item.VATNumber + 100) / 100;
                }
                string auditCodeEmpty = "         /BB-BKG";
                if (audit.AuditCode == null || audit.AuditCode == "")
                {
                    audit.AuditCode = auditCodeEmpty;
                }
                List <string> row = new List <string>();
                row.Add("1");
                row.Add(item.BidName);

                row.Add(string.Format("{0:0,0}", Totalcost).Replace(",", ".") + " VNĐ");

                row.Add(WordUtils.checkNull(item.CapitalName));
                row.Add((HardData.bidMethod[item.BidMethod - 1]));
                row.Add(item.BidTime);
                row.Add(item.BidType);
                row.Add(item.BidExpirated + " " + item.BidExpiratedUnit);
                items.Add(row);

                Table tableData1 = CreateBidplan1(headers, items, string.Format("{0:0,0}", Totalcost).Replace(",", ".") + " VNĐ");
                Table tableData2 = CreateBidplan2(item, Totalcost);

                string dateInStr      = "";
                string auditDateInStr = "";
                dateInStr      = "ngày " + item.DateIn.Day + " tháng " + item.DateIn.Month + " năm " + item.DateIn.Year;
                auditDateInStr = "ngày " + audit.InTime.Day + " tháng " + audit.InTime.Month + " năm " + audit.InTime.Year;
                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("bidcompany", WordUtils.checkNull(item.Bid));
                    text.Text = text.Text.Replace("bidplandatein", WordUtils.checkNull(dateInStr));
                    text.Text = text.Text.Replace("currentYear ", DateTime.Now.Year.ToString());
                    text.Text = text.Text.Replace("bidname", WordUtils.checkNull(item.BidName));
                    text.Text = text.Text.Replace("costnumber", " " + string.Format("{0:0,0}", Totalcost).Replace(",", "."));
                    text.Text = text.Text.Replace("coststring", WordUtils.checkNull(Utils.NumberToTextVN((decimal)Totalcost)));
                    text.Text = text.Text.Replace("bidtime", WordUtils.checkNull(item.BidTime));
                    text.Text = text.Text.Replace("capname", WordUtils.checkNull(item.CapitalName));
                    text.Text = text.Text.Replace("bidcontracttype", WordUtils.checkNull(item.BidType));
                    text.Text = text.Text.Replace("bidExpirated", WordUtils.checkNull(item.BidExpirated + " " + item.BidExpiratedUnit));
                    text.Text = text.Text.Replace("bidmethod", WordUtils.checkNull(HardData.bidMethod[item.BidMethod - 1]));
                    text.Text = text.Text.Replace("auditdate", auditDateInStr);
                    text.Text = text.Text.Replace("auditcode", audit.AuditCode + "/BB-BKG");
                    text.Text = text.Text.Replace("location", WordUtils.checkNull(HardData.location[Int32.Parse(item.BidLocation) - 1]));
                    if (text.Text == "table1")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData1, textP2);
                        textP1.Remove();
                    }
                    if (text.Text == "table2")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData2, textP2);
                        textP1.Remove();
                    }
                }

                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
Пример #11
0
        public static MemoryStream GetTemplate(int id, string path, string _userID)
        {
            var            memoryStream = new MemoryStream();
            AcceptanceInfo item         = AcceptanceServices.GetInstance().GetDetail(id, _userID);
            var            type         = item.AcceptanceType;
            string         fileName     = string.Empty;

            if (type == 1)
            {
                fileName = @"NghiemThu.docx";
            }
            else
            {
                fileName = @"NghiemThuSuaChua.docx";
            }

            string filePath = path + "/" + fileName;

            using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date        = DateTime.Now;
                string   currentDate = "Ngày " + date.ToString("dd/MM/yyyy");
                var      body        = document.MainDocumentPart.Document.Body;
                var      paras       = body.Elements <Paragraph>();



                List <string>         headers = new List <string>();
                List <List <string> > items   = new List <List <string> >();
                headers.Add("Các công việc đã thực hiện");
                headers.Add("Đạt");
                headers.Add("Không Đạt");
                foreach (DeliveryReceiptItemInfoNew record in item.Items)
                {
                    List <string> row = new List <string>();
                    row.Add(record.ItemName);
                    if (record.AcceptanceResult)
                    {
                        row.Add("☒");
                        row.Add("☐");
                    }
                    else
                    {
                        row.Add("☐");
                        row.Add("☒");
                    }
                    items.Add(row);
                }

                string typeis1 = "☐";
                string typeis2 = "☐";
                string typeis3 = "☐";

                if (item.AcceptanceResult == 1)
                {
                    typeis1 = "☒";
                }
                if (item.AcceptanceResult == 2)
                {
                    typeis2 = "☒";
                }
                if (item.AcceptanceResult == 3)
                {
                    typeis3 = "☒";
                }

                Table tableData = CreateTableInternal(headers, items);
                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    string nameItem = string.Empty;
                    foreach (DeliveryReceiptItemInfoNew row in item.Items)
                    {
                        nameItem += row.ItemName + "\n";
                    }
                    text.Text = text.Text.Replace("datein", $"Ngày {item.CreateTime.Day} Tháng {item.CreateTime.Month} Năm {item.CreateTime.Year}");
                    text.Text = text.Text.Replace("itemName", nameItem);
                    text.Text = text.Text.Replace("departmentName", item.DepartmentName);
                    text.Text = text.Text.Replace("acceptanceNote", WordUtils.checkNull(item.AcceptanceNote));
                    text.Text = text.Text.Replace("typeis1", typeis1);
                    text.Text = text.Text.Replace("typeis2", typeis2);
                    text.Text = text.Text.Replace("typeis3", typeis3);


                    if (text.Text == "lstItem")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData, textP2);
                        textP1.Remove();
                    }
                }

                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
Пример #12
0
        public static MemoryStream GetTemplate(int id, string path, out string code)
        {
            var memoryStream        = new MemoryStream();
            ProposalDetailInfo item = ProposalService.GetInstance().getDetailProposal(id, "");
            var index = item.ProposalType - 1;

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            code = item.ProposalCode;
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date        = DateTime.Now;
                string   currentDate = "Ngày " + date.ToString("dd/MM/yyyy");
                var      body        = document.MainDocumentPart.Document.Body;
                var      paras       = body.Elements <Paragraph>();

                List <string>         headers = new List <string>();
                List <List <string> > items   = new List <List <string> >();
                headers.Add("Tên");
                headers.Add("Số Lượng");
                headers.Add("Ghi Chú");
                foreach (ItemPropsalInfo record in item.Items)
                {
                    List <string> row = new List <string>();
                    row.Add(record.ItemName);
                    row.Add(record.Amount.ToString());
                    row.Add(record.Note);
                    items.Add(row);
                }
                Table tableData = CreateTable(headers, items);
                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("reason", WordUtils.checkNull(item.FollowComment));
                    text.Text = text.Text.Replace("survey", WordUtils.checkNull(item.Comment));
                    text.Text = text.Text.Replace("currentdate", WordUtils.checkNull(currentDate));
                    text.Text = text.Text.Replace("curdepart", WordUtils.checkNull(item.CurDepartmentCode));
                    text.Text = text.Text.Replace("proposalcode", WordUtils.checkNull(item.ProposalCode));
                    text.Text = text.Text.Replace("depart", WordUtils.checkNull(item.DepartmentCode));
                    if (text.Text == "lstItem")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData, textP2);
                        textP1.Remove();
                    }
                }
                int i = 0;
                foreach (SdtContentCheckBox ctrl in body.Descendants <SdtContentCheckBox>())
                {
                    if (i == index)
                    {
                        ctrl.Checked.Val = OnOffValues.One;
                        ctrl.Parent.Parent.Descendants <Run>().First().GetFirstChild <Text>().Text = "☒";
                        break;
                    }
                    i++;
                }
                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
 public ElementPropertyCollection(OpenXmlElement element, ReadOnlyArray <ElementProperty <T> > tags)
 {
     _tags    = tags;
     _element = element;
 }
Пример #14
0
        public static MemoryStream GetTemplate(int id, string rootpath, string _userID)
        {
            var memoryStream         = new MemoryStream();
            DeliveryReceiptInfo item = DeliveryReceiptServices.GetInstance().GetDetail(id, _userID);
            var    type     = item.DeliveryReceiptType;
            string fileName = "";

            switch (type)
            {
            case 1:
                fileName = @"GiaoNhan34.docx";
                break;

            case 2:
                fileName = @"GiaoNhanC50.docx";
                break;

            case 3:
                fileName = @"BBGNNOIBO.docx";
                break;

            default:
                fileName = @"GiaoNhan34.docx";
                break;
            }


            string filePath = rootpath + "/" + fileName;


            using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);

            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date = DateTime.Now;

                var body  = document.MainDocumentPart.Document.Body;
                var paras = body.Elements <Paragraph>();

                List <string>         headers = new List <string>();
                List <List <string> > items   = new List <List <string> >();



                if (type == 1)
                {
                    headers.Add("STT");
                    headers.Add("Tên nhãn hiệu, quy cách, phẩm chất nguyên liệu, vật liệu, công cụ, dụng cụ");
                    headers.Add("Mã số");
                    headers.Add("Đơn vị tính");
                    headers.Add("Số lượng");
                    headers.Add("Đơn giá");
                    headers.Add("Thành tiền");
                    headers.Add("Ghi chú");
                    var    index     = 1;
                    double totalcost = 0;
                    foreach (DeliveryReceiptItemInfoNew record in item.Items)
                    {
                        List <string> row = new List <string>();
                        row.Add(index.ToString());
                        row.Add(record.ItemName);
                        row.Add("");
                        row.Add(record.ItemUnit);
                        row.Add(record.Amount.ToString());
                        row.Add(record.ItemPrice.ToString());
                        row.Add((record.Amount * record.ItemPrice).ToString());
                        row.Add(WordUtils.checkNull(record.Description));
                        items.Add(row);
                        totalcost += record.Amount * record.ItemPrice;
                        index++;
                    }
                    Table tableData = CreateTablec34(headers, items, totalcost);

                    string dateInStr       = "Ngày " + item.DeliveryReceiptDate.Day + " tháng " + item.DeliveryReceiptDate.Month + " năm " + item.DeliveryReceiptDate.Year;
                    string proposalDateStr = "ngày " + item.ProposalTime.Day + " tháng " + item.ProposalTime.Month + " năm " + item.ProposalTime.Year;
                    foreach (var text in body.Descendants <Text>())
                    {
                        text.Text = text.Text.Replace("#", "");

                        text.Text = text.Text.Replace("DeliveryReceiptDate", WordUtils.checkNull(dateInStr));
                        text.Text = text.Text.Replace("DeliveryReceiptCode", WordUtils.checkNull(item.DeliveryReceiptCode));
                        text.Text = text.Text.Replace("DeliveryReceiptPlace", WordUtils.checkNull(HardData.location[Int32.Parse(item.DeliveryReceiptPlace)]));
                        text.Text = text.Text.Replace("ProposalCode", WordUtils.checkNull(item.ProposalCode));
                        text.Text = text.Text.Replace("ProposalTime", WordUtils.checkNull(proposalDateStr));
                        text.Text = text.Text.Replace("CurDepartmentName", WordUtils.checkNull(item.CurDepartmentName));
                        text.Text = text.Text.Replace("DepartmentName", WordUtils.checkNull(item.DepartmentName));
                        if (text.Text == "lstItem")
                        {
                            DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                            DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                            body.InsertAfter(tableData, textP2);
                            textP1.Remove();
                        }
                    }
                }
                else
                {
                    if (type == 2)
                    {
                        headers.Add("STT");
                        headers.Add("Tên, ký hiệu quy cách (cấp hạng TSCĐ)");
                        headers.Add("Số hiệu TSCĐ");
                        headers.Add("Nước sản xuất");
                        headers.Add("Năm sản xuất");
                        headers.Add("Năm đưa vào sử dụng");
                        headers.Add("Đvt");
                        headers.Add("Số lượng");
                        headers.Add("Giá mua (ZSX)");
                        headers.Add("Chi phí vận chuyển");
                        headers.Add("Chi phí chạy thử");
                        headers.Add("Nguyên giá TSCĐ");
                        headers.Add("TL kỹ thuật kèm theo");
                        var    index       = 1;
                        double totalcost   = 0;
                        var    currentDate = DateTime.Now;
                        foreach (DeliveryReceiptItemInfoNew record in item.Items)
                        {
                            List <string> row = new List <string>();
                            row.Add(index.ToString());
                            row.Add(record.ItemName);
                            row.Add("");
                            row.Add("");
                            row.Add("");
                            row.Add(currentDate.Year.ToString());
                            row.Add(record.ItemUnit);
                            row.Add(record.Amount.ToString());
                            row.Add(record.ItemPrice.ToString());
                            row.Add("");
                            row.Add("");
                            row.Add((record.Amount * record.ItemPrice).ToString());
                            row.Add("");
                            items.Add(row);
                            totalcost += record.Amount * record.ItemPrice;
                            index++;
                        }
                        Table tableData = CreateTablec50(headers, items, totalcost);

                        string dateInStr       = "Ngày " + item.DeliveryReceiptDate.Day + " tháng " + item.DeliveryReceiptDate.Month + " năm " + item.DeliveryReceiptDate.Year;
                        string proposalDateStr = "ngày " + item.ProposalTime.Day + " tháng " + item.ProposalTime.Month + " năm " + item.ProposalTime.Year;
                        foreach (var text in body.Descendants <Text>())
                        {
                            text.Text = text.Text.Replace("#", "");

                            text.Text = text.Text.Replace("DeliveryReceiptDate", WordUtils.checkNull(dateInStr));
                            text.Text = text.Text.Replace("DeliveryReceiptCode", WordUtils.checkNull(item.DeliveryReceiptCode));
                            text.Text = text.Text.Replace("DeliveryReceiptPlace", WordUtils.checkNull(HardData.location[Int32.Parse(item.DeliveryReceiptPlace)]));
                            text.Text = text.Text.Replace("ProposalCode", WordUtils.checkNull(item.ProposalCode));
                            text.Text = text.Text.Replace("ProposalTime", WordUtils.checkNull(proposalDateStr));
                            text.Text = text.Text.Replace("CurDepartmentName", WordUtils.checkNull(item.CurDepartmentName));
                            if (text.Text == "lstIlistItemtem")
                            {
                                DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                                DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                                body.InsertAfter(tableData, textP2);
                                textP1.Remove();
                            }
                        }
                    }
                    else
                    {
                        headers.Add("STT");
                        headers.Add("Tên mặt hàng");
                        headers.Add("Đơn vị tính");
                        headers.Add("Số lượng");

                        var index = 1;

                        var currentDate = DateTime.Now;
                        foreach (DeliveryReceiptItemInfoNew record in item.Items)
                        {
                            List <string> row = new List <string>();
                            row.Add(index.ToString());
                            row.Add(record.ItemName);
                            row.Add(record.ItemUnit);
                            row.Add(record.Amount.ToString());
                            index++;
                            items.Add(row);
                        }
                        Table tableData = CreateTableInternal(headers, items);

                        string dateInStr       = "Ngày " + item.DeliveryReceiptDate.Day + " tháng " + item.DeliveryReceiptDate.Month + " năm " + item.DeliveryReceiptDate.Year;
                        string proposalDateStr = "ngày " + item.ProposalTime.Day + " tháng " + item.ProposalTime.Month + " năm " + item.ProposalTime.Year;
                        foreach (var text in body.Descendants <Text>())
                        {
                            text.Text = text.Text.Replace("#", "");

                            text.Text = text.Text.Replace("currentyear", WordUtils.checkNull(currentDate.Year.ToString()));
                            text.Text = text.Text.Replace("departmentName", WordUtils.checkNull(item.DepartmentName));
                            text.Text = text.Text.Replace("curDepartmentName", WordUtils.checkNull(item.CurDepartmentName));
                            if (text.Text == "lstItem")
                            {
                                DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                                DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                                body.InsertAfter(tableData, textP2);
                                textP1.Remove();
                            }
                        }
                    }
                }

                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
 internal void ElementRemovedEvent(OpenXmlElement element, OpenXmlElement parent)
 {
     ElementRemoved?.Invoke(this, new ElementEventArgs(element, parent));
 }
 public OpenXmlChildElements(OpenXmlElement container)
 {
     this._container = container;
 }
Пример #17
0
 /// <summary>
 /// Writes out a start tag of the element. And write the attributes in attributes. The attributes of the element will be omitted.
 /// </summary>
 /// <param name="elementObject">The OpenXmlElement object to be writen.</param>
 /// <param name="attributes">The attributes to be writtern.</param>
 public abstract void WriteStartElement(OpenXmlElement elementObject, IEnumerable <OpenXmlAttribute> attributes);
Пример #18
0
 public static OpenXmlReader Create(OpenXmlElement openXmlElement) => new OpenXmlDomReader(openXmlElement);
Пример #19
0
 /// <summary>
 /// Write the OpenXmlElement to the writer.
 /// </summary>
 /// <param name="elementObject">The OpenXmlElement object to be writen.</param>
 public abstract void WriteElement(OpenXmlElement elementObject);
Пример #20
0
 /// <summary>
 /// Initializes a new instance of the ElementEventArgs class using the
 ///  supplied elements.
 /// </summary>
 /// <param name="element">
 /// The element that caused the event.
 /// </param>
 /// <param name="parentElement">
 /// The parent element of the element that caused the event.
 /// </param>
 public ElementEventArgs(OpenXmlElement element, OpenXmlElement parentElement)
 {
     Element       = element;
     ParentElement = parentElement;
 }
Пример #21
0
 internal bool IsProcessContent(OpenXmlElement element)
 {
     // TODO: performance tuning
     return(ContainsQName(element.LocalName, element.NamespaceUri, _currentProcessContent));
 }
Пример #22
0
 private protected bool SetElement(OpenXmlElement value)
 => Metadata.Particle.Set(this, value);
 /// <summary>
 /// Initializes a new instance of the ElementEventArgs class using the
 ///  supplied elements.
 /// </summary>
 /// <param name="element">
 /// The element that caused the event.
 /// </param>
 /// <param name="parentElement">
 /// The parent element of the element that caused the event.
 /// </param>
 public ElementEventArgs(OpenXmlElement element, OpenXmlElement parentElement)
 {
     this._element       = element;
     this._parentElement = parentElement;
 }
Пример #24
0
        public static MemoryStream GetTemplate(int id, string path, out string code, string _userID)
        {
            double Totalcost    = 0;
            var    memoryStream = new MemoryStream();

            DecisionInfo item = DecisionService.GetInstance().GetDecision(id, _userID);

            QuoteRelation relation = ProposalService.GetInstance().getQuoteRelation(item.QuoteID);

            item.AuditCode   = relation.AuditCode;
            item.AuditTime   = relation.AuditTime;
            item.BidPlanCode = relation.BidPlanCode;
            item.BidPlanTime = relation.BidPlanTime;

            item.NegotiationCode = relation.NegotiationCode;
            item.NegotiationTime = relation.NegotiationTime;

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            code = "";//item.ProposalCode;
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date = DateTime.Now;

                var body  = document.MainDocumentPart.Document.Body;
                var paras = body.Elements <Paragraph>();
                foreach (ItemInfo record in item.Items)
                {
                    Totalcost += record.ItemPrice * record.Amount;
                }

                if (item.IsVAT)
                {
                    Totalcost = Totalcost * (item.VATNumber + 100) / 100;
                }

                Table tableData = CreateTable(item, Totalcost);

                string dateInStr = "";
                dateInStr = "ngày " + item.DateIn.Day + " tháng " + item.DateIn.Month + " năm " + item.DateIn.Year;

                string audittimeStr       = "ngày " + item.AuditTime.Day + "/" + item.AuditTime.Month + "/" + item.AuditTime.Year;
                string bidplantimeStr     = "ngày " + item.BidPlanTime.Day + "/" + item.BidPlanTime.Month + "/" + item.BidPlanTime.Year;
                string negotiationtimeStr = "ngày " + item.NegotiationTime.Day + "/" + item.NegotiationTime.Month + "/" + item.NegotiationTime.Year;

                string decisionCodeStr = "";
                if (item.DecisionCode != null && item.DecisionCode != "")
                {
                    decisionCodeStr = item.DecisionCode + "/QĐ-TMHH";
                }
                else
                {
                    decisionCodeStr = "...../QĐ-TMHH";
                }


                var newType = "Về việc chọn đơn vị cung cấp hàng hóa ";
                if (item.BidMethod != 1)
                {
                    newType += "theo hình thức " + HardData.bidMethod[item.BidMethod - 1];
                }
                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("auditcode", WordUtils.checkNull(item.AuditCode));
                    text.Text = text.Text.Replace("bidplancode", WordUtils.checkNull(item.BidPlanCode));
                    text.Text = text.Text.Replace("negotiationcode", WordUtils.checkNull(item.NegotiationCode));
                    text.Text = text.Text.Replace("audittime", audittimeStr);
                    text.Text = text.Text.Replace("bidplantime", bidplantimeStr);
                    text.Text = text.Text.Replace("negotiationtime", negotiationtimeStr);
                    text.Text = text.Text.Replace("newtype", newType);
                    text.Text = text.Text.Replace("datein", WordUtils.checkNull(dateInStr));
                    text.Text = text.Text.Replace("newtype", WordUtils.checkNull(dateInStr));
                    text.Text = text.Text.Replace("costnumber", string.Format("{0:0,0}", Totalcost).Replace(",", "."));
                    text.Text = text.Text.Replace("coststring", WordUtils.checkNull(Utils.NumberToTextVN((decimal)Totalcost)));
                    text.Text = text.Text.Replace("capname", WordUtils.checkNull(item.CapitalName));
                    text.Text = text.Text.Replace("bidtype", item.BidType);
                    text.Text = text.Text.Replace("bidexpired", item.BidExpirated + " " + item.BidExpiratedUnit);
                    text.Text = text.Text.Replace("customername", WordUtils.checkNull(item.CustomerName));
                    text.Text = text.Text.Replace("address", WordUtils.checkNull(item.Address));
                    text.Text = text.Text.Replace("departmentNames", WordUtils.checkNull(item.DepartmentNames));
                    text.Text = text.Text.Replace("vatnumber", WordUtils.checkNull(item.VATNumber.ToString()));
                    //   text.Text = text.Text.Replace("currentyear", );
                    text.Text = text.Text.Replace("bidmethod", HardData.bidMethod[item.BidMethod - 1]);
                    text.Text = text.Text.Replace("decisionCode", " " + WordUtils.checkNull(decisionCodeStr));
                    if (text.Text == "table")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData, textP2);
                        textP1.Remove();
                    }
                }

                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
Пример #25
0
 /// <summary>
 /// Creates an OpenXmlReader from the OpenXmlElement (travel the DOM tree).
 /// </summary>
 /// <param name="openXmlElement">The OpenXmlElement to read.</param>
 /// <param name="readMiscNodes">Specify false to indicate to the reader to skip all miscellaneous nodes. The default value is false.</param>
 /// <returns>The newly created OpenXmlReader.</returns>
 public static OpenXmlReader Create(OpenXmlElement openXmlElement, bool readMiscNodes)
 {
     return(new OpenXmlDomReader(openXmlElement, readMiscNodes));
 }
        /// <summary>
        /// Gets the child element that has the specified sequence number.
        /// Sequence numbers are generated by a code generator.
        /// </summary>
        /// <param name="sequenceNumber">The sequence number of the element.</param>
        /// <returns>An element that has the specified sequence number. Returns null (Nothing in Visual Basic) if no element is found having the specified sequence number.</returns>
        /// <remarks>
        /// Returns null if there are invalid children.
        /// </remarks>
        private protected T GetElement <T>(int sequenceNumber)
            where T : OpenXmlElement
        {
            T theChild;

            switch (OpenXmlCompositeType)
            {
            case OpenXmlCompositeType.Other:
                throw new InvalidOperationException();

            case OpenXmlCompositeType.OneAll:
                foreach (OpenXmlElement child in ChildElements)
                {
                    // skip unknown element and MiscNode
                    if (IsKnownElement(child))
                    {
                        int childSequenceNumber = GetSequenceNumber(child);
                        if (childSequenceNumber == sequenceNumber)
                        {
                            theChild = child as T;
                            if (theChild != null)
                            {
                                return(theChild);
                            }
                        }
                    }
                }

                // TODO: should we handle error case?
                //  1: there are more than 1 elements for a type?
                //  2: there are more than 2 elements?
                //  3. there are other elements other than allowed children?
                break;

            case OpenXmlCompositeType.OneChoice:
            {
                OpenXmlElement child = FirstChild;

                // skip unknown element and MiscNode
                while (child != null && !IsKnownElement(child))
                {
                    child = child.NextSibling();
                }

                // There should be only one valid child.
                if (child != null)
                {
                    Debug.Assert(IsKnownElement(child));

                    int childSequenceNumber = GetSequenceNumber(child);
                    if (childSequenceNumber == sequenceNumber)
                    {
                        theChild = child as T;
                        if (theChild != null)
                        {
                            return(theChild);
                        }
                    }
                }
            }

                // TODO: should we handle error case?
                //  1: there are more than 1 elements for a type?
                //  2: there are more than 2 elements?
                //  3. there are other elements other than allowed children?
                break;

            case OpenXmlCompositeType.OneSequence:
            {
                OpenXmlElement child = FirstChild;

                while (child != null)
                {
                    if (IsKnownElement(child))
                    {
                        int childSequenceNumber = GetSequenceNumber(child);

                        if (childSequenceNumber == sequenceNumber)
                        {
                            theChild = child as T;
                            if (theChild != null)
                            {
                                return(theChild);
                            }
                            else
                            {
                                // same tag name, but wrong type, see bug 448241
                                child = child.NextSibling();
                            }
                        }
                        else if (childSequenceNumber > sequenceNumber)
                        {
                            return(null);
                        }
                        else
                        {
                            child = child.NextSibling();
                        }
                    }
                    else
                    {
                        // skip unknown element and MiscNode
                        child = child.NextSibling();
                    }
                }
            }

                // TODO: should we handle error case?
                //  1: there are more than 1 elements for a type?
                //  2: there are more than 2 elements?
                //  3. there are other elements other than allowed children?
                break;
            }

            return(null);
        }
        /// <summary>
        /// Populates the XML into a strong typed DOM tree.
        /// </summary>
        /// <param name="xmlReader">The XmlReader to read the XML content.</param>
        /// <param name="loadMode">Specifies a load mode that is either lazy or full.</param>
        private protected override void Populate(XmlReader xmlReader, OpenXmlLoadMode loadMode)
        {
            LoadAttributes(xmlReader);

            if (!xmlReader.IsEmptyElement)
            {
                xmlReader.Read(); // read this element

                while (!xmlReader.EOF)
                {
                    // O15:#3024890, OpenXmlCompositElement ignores the Whitespace NodeType.
                    if (xmlReader.NodeType == XmlNodeType.Whitespace)
                    {
                        xmlReader.Skip();
                        continue;
                    }
                    else if (xmlReader.NodeType == XmlNodeType.EndElement)
                    {
                        Debug.Assert(xmlReader.LocalName.Equals(LocalName));
                        xmlReader.Skip(); // move to next node
                        break;
                    }

                    OpenXmlElement element = ElementFactory(xmlReader);

                    // set parent before Load( ) call. AlternateContentChoice need parent info on loading.
                    element.Parent = this;

                    bool isACB = element is AlternateContent;
                    if (isACB && element.OpenXmlElementContext != null)
                    {
                        element.OpenXmlElementContext.ACBlockLevel++;
                    }

                    bool mcContextPushed = false;
                    if (!(element is OpenXmlMiscNode))
                    {
                        // push MC context based on the context of the child element to be loaded
                        mcContextPushed = PushMcContext(xmlReader);
                    }

                    //Process the element according to the MC behavior
                    var action = ElementAction.Normal;
                    if (OpenXmlElementContext != null && OpenXmlElementContext.MCSettings.ProcessMode != DocumentFormat.OpenXml.Packaging.MarkupCompatibilityProcessMode.NoProcess)
                    {
                        action = OpenXmlElementContext.MCContext.GetElementAction(element, OpenXmlElementContext.MCSettings.TargetFileFormatVersions);
                    }

                    element.Load(xmlReader, loadMode);

                    if (mcContextPushed)
                    {
                        PopMcContext();
                    }

                    if (isACB && element.OpenXmlElementContext != null)
                    {
                        element.OpenXmlElementContext.ACBlockLevel--;
                    }

                    switch (action)
                    {
                    case ElementAction.Normal:
                    {
                        AddANode(element);
                        break;
                    }

                    case ElementAction.Ignore:
                    {
                        element.Parent = null;
                        continue;
                    }

                    case ElementAction.ProcessContent:
                    {
                        element.Parent = null;
                        while (element.ChildElements.Count > 0)
                        {
                            var node = element.FirstChild;
                            node.Remove();
                            OpenXmlElement newnode = null;

                            // If node is an UnknowElement, we should try to see whether the parent element can load the node as strong typed element
                            if (node is OpenXmlUnknownElement)
                            {
                                newnode = ElementFactory(node.Prefix, node.LocalName, node.NamespaceUri);
                                if (!(newnode is OpenXmlUnknownElement))
                                {
                                    // The following method will load teh element in MCMode.Full
                                    // since the node is already MC-processed when loading as unknown type, full loading the outerXml is fine
                                    newnode.OuterXml = node.OuterXml;

                                    // unnecessary xmlns attribute will be added, remove it.
                                    RemoveUnnecessaryExtAttr(node, newnode);
                                }
                                else
                                {
                                    newnode = null;
                                }
                            }

                            if (newnode != null)
                            {
                                AddANode(newnode);
                            }
                            else
                            {
                                //append the orignal node
                                AddANode(node);
                            }
                        }

                        break;
                    }

                    case ElementAction.ACBlock:
                    {
                        var effectiveNode = OpenXmlElementContext.MCContext.GetContentFromACBlock(element as AlternateContent, OpenXmlElementContext.MCSettings.TargetFileFormatVersions);
                        if (effectiveNode == null)
                        {
                            break;
                        }

                        element.Parent       = null;
                        effectiveNode.Parent = null;
                        while (effectiveNode.FirstChild != null)
                        {
                            var node = effectiveNode.FirstChild;
                            node.Remove();
                            AddANode(node);
                            node.CheckMustUnderstandAttr();
                        }

                        break;
                    }
                    }
                }
            }
            else
            {
                xmlReader.Skip();
            }

            // Set raw outer xml to empty to indicate that it passed
            RawOuterXml = string.Empty;
        }
 internal void ElementInsertingEvent(OpenXmlElement element, OpenXmlElement parent)
 {
     ElementInserting?.Invoke(this, new ElementEventArgs(element, parent));
 }
Пример #29
0
        public static MemoryStream GetTemplate(int id, string path, out string code, string _userID)
        {
            double Totalcost           = 0;
            var    memoryStream        = new MemoryStream();
            NegotiationPrintModel item = NegotiationService.GetInstance().GetNegotiationPrintModel(id, _userID);

            code = item.NegotiationCode;
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            //  code = item.ProposalCode;
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date        = DateTime.Now;
                string   currentDate = " Ngày " + date.ToString("dd/MM/yyyy");
                var      body        = document.MainDocumentPart.Document.Body;
                var      paras       = body.Elements <Paragraph>();

                List <string>         headers = new List <string>();
                List <List <string> > items   = new List <List <string> >();
                headers.Add("STT");
                headers.Add("Tên gói thầu");
                headers.Add("Giá gói thầu");
                headers.Add("Nguồn vốn");
                headers.Add("Hình thức phương thức lựa chọn nhà thầu");
                headers.Add("Thời gian tổ chức lựa chọn nhà thầu");
                headers.Add("Loại hợp đồng");
                headers.Add("Thời gian thực hiện hợp đồng");

                foreach (ItemInfo record in item.Items)
                {
                    Totalcost += record.ItemPrice * record.Amount;
                }

                List <string> row = new List <string>();



                Table tableData = CreateTable(item, Totalcost);


                string dateInStr      = "";
                string auditDateInStr = "";
                dateInStr = item.DateIn.Hour + " giờ ";
                if (item.DateIn.Minute != 0)
                {
                    dateInStr += item.DateIn.Minute + " phút ";
                }
                dateInStr += ", ngày" + item.DateIn.Day + " tháng " + item.DateIn.Month + " năm " + item.DateIn.Year;
                //    auditDateInStr = "ngày " + item.AuditTime.Day + " tháng " + item.AuditTime.Month + " năm " + item.AuditTime.Year;
                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("datein", WordUtils.checkNull(dateInStr));
                    text.Text = text.Text.Replace("audittime", WordUtils.checkNull(auditDateInStr));
                    text.Text = text.Text.Replace("inputcode", WordUtils.checkNull(item.Code));
                    //A side
                    text.Text = text.Text.Replace("aaddress", WordUtils.checkNull(HardData.location[Int32.Parse(item.ALocation) - 1]));
                    text.Text = text.Text.Replace("aside", WordUtils.checkNull(item.ASide));
                    text.Text = text.Text.Replace("aphone", WordUtils.checkNull(item.APhone));
                    text.Text = text.Text.Replace("arepresent", WordUtils.checkNull(item.ARepresent));
                    text.Text = text.Text.Replace("afax", WordUtils.checkNull(item.AFax));
                    text.Text = text.Text.Replace("aposition", WordUtils.checkNull(item.APosition));
                    text.Text = text.Text.Replace("ataxcode", WordUtils.checkNull(item.ATaxCode));
                    text.Text = text.Text.Replace("abankidlabel", WordUtils.checkNull(HardData.NegotiationBankIDArr[Int32.Parse(item.ABankID) - 1]));
                    //B side
                    text.Text = text.Text.Replace("baddress", WordUtils.checkNull(item.BLocation));
                    text.Text = text.Text.Replace("bside", WordUtils.checkNull(item.BSide));
                    text.Text = text.Text.Replace("bphone", WordUtils.checkNull(item.BPhone));
                    text.Text = text.Text.Replace("brepresent", WordUtils.checkNull(item.BRepresent));
                    text.Text = text.Text.Replace("bfax", WordUtils.checkNull(item.BFax));
                    text.Text = text.Text.Replace("bposition", WordUtils.checkNull(item.BPosition));
                    text.Text = text.Text.Replace("btaxcode", WordUtils.checkNull(item.BTaxCode));
                    text.Text = text.Text.Replace("bbankidlabel", WordUtils.checkNull(item.BBankID));

                    text.Text = text.Text.Replace("costnumber", string.Format("{0:0,0}", Totalcost).Replace(",", "."));
                    text.Text = text.Text.Replace("coststring", WordUtils.checkNull(Utils.NumberToTextVN((decimal)Totalcost)));
                    text.Text = text.Text.Replace("bidtype", item.BidType);
                    text.Text = text.Text.Replace("term", WordUtils.checkNull(item.Term.ToString()));
                    text.Text = text.Text.Replace("bidtime", item.BidExpirated + " " + item.BidExpiratedUnit);
                    if (text.Text == "table")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData, textP2);
                        textP1.Remove();
                    }
                }

                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
Пример #30
0
 public T GetValue(OpenXmlElement element) => _accessor.Get(element);