Example #1
0
 public JsonResult GetChungTuKemTheoByHoSoIDJsonResult(int hoSoID = 0)
 {
     try
     {
         using (MotCuaService = new MotCuaServiceClient())
         {
             var response = MotCuaService.MotCua_ChungTuKemTheo_GetByHoSoID(hoSoID);
             if (response.StatusCode != HttpStatusCode.OK)
             {
                 return(Json(new { result = "" }, JsonRequestBehavior.AllowGet));
             }
             return(Json(new { result = response.Content }, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception e)
     {
         Logger.Error(e.Message);
         Console.WriteLine(e);
         throw;
     }
 }
Example #2
0
        public ActionResult InBienNhan(int hoSoID)
        {
            try
            {
                var tableChungTu = new DataTable();
                //Thong tin chung
                var hosotiepnhan = new DataTableViewModel();
                using (MotCuaService = new MotCuaServiceClient())
                {
                    var data = MotCuaService.MotCua_HoSoTiepNhan_InBienNhan(hoSoID);
                    if (data.StatusCode == HttpStatusCode.OK || data.Data == null)
                    {
                        hosotiepnhan = data.Data;
                    }
                    else
                    {
                        return new JsonResult()
                               {
                               }
                    };
                }
                var fields = new List <string>();
                var value  = new List <object>();
                foreach (var col in hosotiepnhan.Columns)
                {
                    fields.Add(col.Name);
                }
                foreach (var row in hosotiepnhan.Rows)
                {
                    foreach (var cell in row.Cells)
                    {
                        value.Add(cell.Value);
                    }
                }
                //Chung tu kem theo
                var chungtukemtheo = new List <ChungTuKemTheo>();
                using (MotCuaService = new MotCuaServiceClient())
                {
                    var data = MotCuaService.MotCua_ChungTuKemTheo_GetByHoSoID(hoSoID);
                    if (data.StatusCode == HttpStatusCode.OK || data.Data == null)
                    {
                        chungtukemtheo = data.Data;
                    }
                    else
                    {
                        return new JsonResult()
                               {
                               }
                    };
                }
                if (chungtukemtheo.Count == 0)
                {
                    chungtukemtheo.Add(new ChungTuKemTheo {
                        STT = 0, TenChungTu = ""
                    });
                }
                tableChungTu           = chungtukemtheo.ToDataTable();
                tableChungTu.TableName = "tableChungTu";
                var template = Server.MapPath(@"~/Upload/Template/InBienNhan.doc");
                var doc      = new Document(template);
                doc.MailMerge.Execute(fields.ToArray(), value.ToArray());

                doc.MailMerge.ExecuteWithRegions(tableChungTu);
                doc.MailMerge.ExecuteWithRegions(tableChungTu);
                MemoryStream stream = new MemoryStream();
                doc.Save(stream, SaveFormat.Doc);
                stream.Position = 0;

                return(new JsonResult()
                {
                    Data = new { Data = Convert.ToBase64String(stream.ToArray()), FileName = "InBienNhan" + hoSoID + ".doc" }
                });
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                Console.WriteLine(e);
                throw;
            }
        }