Exemple #1
0
        public static MemoryStream GetTempPlate(int id, string path, out string code, string _userID)
        {
            var memoryStream      = new MemoryStream();
            SurveyDetailInfo item = SurveyService.GetInstance().GetDetailSurvey(id, _userID);

            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   curDate     = date.ToString("dd/MM/yyyy");
                string   currentdate = "Ngày " + date.Day + " tháng " + date.Month + " năm" + date.Year;
                var      body        = document.MainDocumentPart.Document.Body;
                var      paras       = body.Elements <Paragraph>();
                var      itemName    = "";
                foreach (ItemPropsalInfo record in item.Items)
                {
                    itemName = itemName + record.ItemName + ", ";
                }
                itemName = itemName.Substring(0, itemName.Length - 1);
                List <string>         headers = new List <string>();
                List <List <string> > items   = new List <List <string> >();
                headers.Add("STT");
                headers.Add("Tên linh kiện, tài sản");
                headers.Add("ĐVT");
                headers.Add("Số Lượng");
                headers.Add("Ghi Chú");

                var sttIndex = 1;

                foreach (ItemSurveyInfo record in item.SurveyItems)
                {
                    List <string> row = new List <string>();
                    row.Add(sttIndex.ToString());
                    row.Add(record.ItemName);
                    row.Add(record.ItemUnit);
                    row.Add(record.ItemAmount.ToString());
                    row.Add(record.Note);
                    items.Add(row);
                    sttIndex++;
                }
                Table tableData = CreateTable(headers, items);


                foreach (var text in body.Descendants <Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("proposalcode", WordUtils.checkNull(item.ProposalCode));
                    text.Text = text.Text.Replace("surveycode", WordUtils.checkNull(item.SurveyCode));
                    text.Text = text.Text.Replace("solution", WordUtils.checkNull(item.SolutionText));
                    text.Text = text.Text.Replace("validtext", WordUtils.checkNull(item.ValidText));
                    text.Text = text.Text.Replace("proposaldate", WordUtils.checkNull(item.ProposalDate.ToString("dd/MM/yyyy")));
                    text.Text = text.Text.Replace("curdate", WordUtils.checkNull(curDate));
                    text.Text = text.Text.Replace("currentdate", WordUtils.checkNull(currentdate));
                    text.Text = text.Text.Replace("itemname", WordUtils.checkNull(itemName));
                    text.Text = text.Text.Replace("depart", 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();
                    }
                }
                List <int> Checks = new List <int>();

                Checks.Add(item.Solution - 1);

                if (item.IsSample == true)
                {
                    Checks.Add(4);
                }

                if (item.Valid == true)
                {
                    Checks.Add(5);
                }
                else
                {
                    Checks.Add(6);
                }

                int i = 0;
                foreach (SdtContentCheckBox ctrl in body.Descendants <SdtContentCheckBox>())
                {
                    if (Checks.IndexOf(i) > -1)
                    {
                        ctrl.Checked.Val = OnOffValues.One;
                        ctrl.Parent.Parent.Descendants <Run>().First().GetFirstChild <Text>().Text = "☒";
                    }
                    i++;
                }
                document.Save();
                document.Close();
            }
            return(memoryStream);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
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);
        }