예제 #1
0
        public SingleResponeMessage <AcceptanceInfo> Get(int id, string _userID)
        {
            SingleResponeMessage <AcceptanceInfo> ret = new SingleResponeMessage <AcceptanceInfo>();

            try
            {
                AcceptanceInfo item = AcceptanceServices.GetInstance().GetDetail(id, _userID);
                if (item == null)
                {
                    ret.isSuccess     = false;
                    ret.err.msgCode   = "001";
                    ret.err.msgString = "no  Acceptance found";
                    return(ret);
                }
                ret.item      = item;
                ret.isSuccess = true;
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #2
0
        public async Task <ActionMessage> Put([FromForm] AcceptanceInfo obj, [FromForm] List <IFormFile> files)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = await AcceptanceServices.GetInstance().Update(obj, files, GetUserId());
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #3
0
        public ActionMessage DeleteAll(string ids)
        {
            ActionMessage ret = new ActionMessage();

            try
            {
                ret = AcceptanceServices.GetInstance().DeleteMuti(ids);
            }
            catch (Exception ex)
            {
                ret.isSuccess     = false;
                ret.err.msgCode   = "Internal Error !!!";
                ret.err.msgString = ex.ToString();
            }
            return(ret);
        }
예제 #4
0
        public ListResponeMessage <AcceptanceInfo> GetList([FromQuery] AcceptanceCriteria criteria, string _userID)
        {
            ListResponeMessage <AcceptanceInfo> ret = new ListResponeMessage <AcceptanceInfo>();

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