public ActionMessage DeleteAll(string ids, string _userID)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = DeliveryReceiptServices.GetInstance().DeleteMuti(ids, _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
        public ListResponeMessage <DeliveryReceiptInfo> GetList([FromQuery] DeliveryReceiptCriteria criteria, string _userID)
        {
            ListResponeMessage <DeliveryReceiptInfo> ret = new ListResponeMessage <DeliveryReceiptInfo>();

            try
            {
                ret.isSuccess    = true;
                ret.data         = DeliveryReceiptServices.GetInstance().GetList(criteria, _userID);
                ret.totalRecords = DeliveryReceiptServices.GetInstance().getTotalRecords(criteria, _userID);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "005";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
Beispiel #3
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);
        }