예제 #1
0
        public ActionResult ShowPlat(List <PlatType> ClientList)
        {
            var platList = new PlatForDNView
            {
                Payments    = new List <PaymentsRU>(),
                SelectedSum = null
            };

            foreach (var item in ClientList)
            {
                var localInventionsList = new List <PaymentsRU>();
                localInventionsList = db.PaymentsRU.Where(x => x.id_plat == item.Id).ToList();
                platList.Payments.AddRange(localInventionsList);
            }
            platList.Payments    = platList.Payments.Distinct().OrderBy(x => x.id_plat).ToList();
            platList.SelectedSum = platList.Payments.Sum(x => x.sum).ToString();
            return(PartialView("/Views/Payments/Partial/ShowPlats.cshtml", platList));
        }
        public ActionResult genDn(PlatForDNView platList)
        {
            nemo_freshEntities db = new nemo_freshEntities();

            if (platList == null)
            {
                return(Json(new JsonResponseModel("Error", "No dn"), JsonRequestBehavior.AllowGet));
            }

            TableContent t1         = new TableContent("OurActionsTable");
            int          i_servises = 1;

            foreach (var a in platList.Payments)
            {
                if (a.PurOfPayment != null || a.PurOfPayment.Length != 0)
                {
                    t1.AddRow(
                        new FieldContent("Num", i_servises++.ToString() ?? ""),
                        new FieldContent("ActionDescr", a.PurOfPayment),
                        new FieldContent("Sum", a.sum != null ? String.Format("{0:f2}", a.sum) : "")
                        );
                }
            }

            var valuesToFill = new Content(t1, new FieldContent("Total", String.Format("{0:f2}", platList.SelectedSum))

                                           );

            var newNameFolder = Properties.Resources.DiscLetter + @"\DNDocs\";
            // var newNameFolder = @"C:\DNDocs\Plat\";
            var newNameDoc = "PatentRegistry.docx";

            if (!Directory.Exists(newNameFolder))
            {
                Directory.CreateDirectory(newNameFolder);
            }
            string fullPathFile = newNameFolder + newNameDoc;

            int    count        = 1;
            string fileNameOnly = Path.GetFileNameWithoutExtension(fullPathFile);
            string extension    = Path.GetExtension(fullPathFile);
            string path         = Path.GetDirectoryName(fullPathFile);
            string newFullPath  = fullPathFile;

            while (System.IO.File.Exists(newFullPath))
            {
                string tempFileName = string.Format("{0}({1})", fileNameOnly, count++);
                newFullPath  = Path.Combine(path, tempFileName + extension);
                fullPathFile = newFullPath;
            }


            var templatePath = System.AppDomain.CurrentDomain.BaseDirectory.ToString() + "DnTemplates/RegistrPlat.docx";

            System.IO.File.Copy(templatePath, fullPathFile, true);
            using (var outputDoc = new TemplateProcessor(fullPathFile).SetRemoveContentControls(true))
            {
                outputDoc.FillContent(valuesToFill);
                outputDoc.SaveChanges();
            }
            // var doc = DocumentsGetter.GetDnDocument(dn.No, Url.Content("~"), fullPathFile);

            db.SaveChanges();

            var doc = DocumentGetter.GetDnDocument("8888", Url.Content("~"), fullPathFile);

            return(Json(new JsonResponseModel("Ok", "")
            {
                Doc = doc
            }, JsonRequestBehavior.AllowGet));
            //return "OK";
        }