Пример #1
0
        public ActionResult Generate(SRViewModel model)
        {
            //get temp name from reg expression plus lang plus symb
            string fname = model.temp.ToString();

            g_assembly = Assembly.GetExecutingAssembly();

            //string source = Server.MapPath(Path.Combine("/" + "IN/CEDAW01SRE.docx"));
            //string Dest = Server.MapPath(Path.Combine("/" + "OUT/CEDAW01SRE.docx"));

            string source = Server.MapPath(Path.Combine("/", "GDGS/IN/" + fname + ".docx"));
            string Dest   = Server.MapPath(Path.Combine("/", "GDGS/OUT/" + fname + ".docx"));

            //string tempname = fname.Remove(fname.Length - 1);
            //model.tempname = tempname;
            g_document = DocX.Load(source);
            g_document = CreateDocA(DocX.Load(source), model);

            g_document.SaveAs(Dest);
            if (!String.IsNullOrEmpty(model.author))
            {
                g_document.AddCoreProperty("dc:creator", model.author.ToString());
                g_document.Save();
            }
            return(RedirectToAction("download", "Unog", new { name = fname }));
        }
Пример #2
0
        public static string[] info(SRViewModel model)
        {
            gdgs1Entities db1 = new gdgs1Entities();

            var item  = db1.categories.FirstOrDefault(p => p.ID == model.Cat);
            var item1 = db1.doc_type.FirstOrDefault(p => p.ID == item.type_ID);
            var item2 = db1.committees.FirstOrDefault(p => p.ID == item1.committee_ID);

            string[] info = new string[3];
            info[0] = item.Name.ToString();
            info[1] = item1.Name.ToString();
            info[2] = item2.Name.ToString();
            return(info);
        }
Пример #3
0
        public static string formatdate1(SRViewModel model)
        {
            DateTime date  = model.ldate;
            string   final = "day,d month year,at time";
            string   datex = date.ToString();

            string[] d = datex.Split('/');
            // int[] convert = Array.ConvertAll<string, int>(d, int.Parse);
            var    frenchCultureInfo = CultureInfo.CreateSpecificCulture("en-US");
            string month             = frenchCultureInfo.DateTimeFormat.GetMonthName(Convert.ToInt32(d[1]));
            string day = frenchCultureInfo.DateTimeFormat.GetDayName(date.DayOfWeek);

            string[] d2 = d[2].Split(' ');
            string[] d3 = d2[1].Split(':');
            //d2[2]=d
            final = day + ", " + d[0] + " " + month + " " + d2[0] + ", " + model.time.ToString();
            //}
            return(final);
        }
Пример #4
0
        public static string formatdate(string date, SRViewModel model)
        {
            gdgs1Entities db1 = new gdgs1Entities();

            var item = db1.languages.FirstOrDefault(p => p.ID == model.lang_ID);
            // string lang = item.Lang_Name.ToString();

            string final = "day month year";

            //if (lang == "French")
            //{
            //    string[] d = date.Split('/');
            //    int[] convert = Array.ConvertAll<string, int>(d, int.Parse);
            //    var frenchCultureInfo = CultureInfo.CreateSpecificCulture("fr-fr");
            //    string month = frenchCultureInfo.DateTimeFormat.GetMonthName(convert[0]);
            //    if (d[1] == "1")
            //    {
            //        d[1] = d[1] + "\u1D49" + "\u02B3";
            //    }
            //    final = d[1] + " " + month + " " + d[2];
            //}
            //else if (lang == "Spanish")
            //{
            //    string[] d = date.Split('/');
            //    int[] convert = Array.ConvertAll<string, int>(d, int.Parse);
            //    var frenchCultureInfo = CultureInfo.CreateSpecificCulture("es-es");
            //    string month = frenchCultureInfo.DateTimeFormat.GetMonthName(convert[0]);
            //    final = d[1] + " de " + month + " de " + d[2];
            //}
            //else
            //{
            string[] d                 = date.Split('/');
            int[]    convert           = Array.ConvertAll <string, int>(d, int.Parse);
            var      frenchCultureInfo = CultureInfo.CreateSpecificCulture("en-US");
            string   month             = frenchCultureInfo.DateTimeFormat.GetMonthName(convert[1]);

            final = d[0] + " " + month + " " + d[2];
            //}
            return(final);
        }
Пример #5
0
        public static string Sessionnum(SRViewModel model)
        {
            string final = "";

            int num = Convert.ToInt32(model.sNum.ToString());

            if (num <= 99)
            {
                final = num.ToOrdinalWords();
                final = char.ToUpper(final[0]) + final.Substring(1);
            }
            else if (num >= 100)
            {
                final = model.sNum.ToString();
                string TH = "th";



                num %= 100;
                if ((num >= 11) && (num <= 13))
                {
                    return(final + TH);
                }

                switch (num % 10)
                {
                case 1: return(final + "st");

                case 2: return(final + "nd");

                case 3: return(final + "rd");

                default: return(final + TH);
                }
            }



            return(final);
        }
Пример #6
0
        public ActionResult FindTemplate(SRViewModel model)
        {
            gdgs1Entities db1 = new gdgs1Entities();

            //Filtering possible Matches according to Symbole structure
            var    temp     = db.final_temp.Where(x => x.categories_ID == model.Cat).FirstOrDefault();
            string tempname = temp.Name.ToString();

            // var langtemp = db.languages.Where(x => x.ID == model.lang_ID).FirstOrDefault();
            //  string lang = langtemp.Lang_Name.ToString();
            // model.temp = tempname + lang[0].ToString();
            if (model.RC == false)
            {
                model.temp = tempname + "E";
            }
            if (model.RC == true)
            {
                model.temp = tempname + "RE";
            }

            return(RedirectToAction("Generate", model));
        }
Пример #7
0
        public static DocX CreateDocA(DocX template, SRViewModel model)
        {
            //Create Date for Header
            // string Fdate = model.date.ToString();
            //string[] d = Fdate.Split(' ');
            //Fdate = d[0];
            //Fdate = formatdate(Fdate, model);
            //Create Distrbution for Header

            string Fdist = distrb(model.Cat);

            string Folang = "English";

            //Session Numer
            string Fsnum = "[NUMBER]";

            if (!String.IsNullOrEmpty(model.sNum))
            {
                Fsnum = Sessionnum(model);
            }

            //sYMBOLE
            string symb = getSym(model.Cat);

            string[] sym = symb.Split(new string[] { "#" }, StringSplitOptions.None);
            string   x   = sym[1];

            x = model.Prep.ToString() + x;
            string Fsym1 = x;

            string Fmnum = GetOrdinalSuffix(Convert.ToInt32(model.Prep.ToString()));
            //second page meeting date
            string Fsodate = "";

            if (model.time.ToString() == "at 10 a.m.")
            {
                Fsodate = "The meeting was called to order at 10 a.m.";
            }
            if (model.time.ToString() == "at 3 p.m.")
            {
                Fsodate = "The meeting was called to order at 3 p.m.";
            }



            //QR code and Bar code

            string lang = getlanguageQR(model.lang_ID);

            string Fsym = getSym(model.Cat);

            //Fsym = Fsym.Remove(Fsym.Length-1);
            // Fsym = Fsym + Fsym1;

            Fsym = Fsym.Replace("#", model.Prep.ToString());

            string url = "http://undocs.org/m2/QRCode.ashx?DS=" + Fsym + "&Size=2&Lang=" + lang;

            using (var client = new WebClient())
            {
                //var content = client.DownloadData("https://api.qrserver.com/v1/create-qr-code/?size=66x66&data=http://undocs.org/fr/A/HRC/70");
                //var content = client.DownloadData("http://undocs.org/m2/QRCode.ashx?DS=A/HRC/70&Size=2&Lang=F");
                var content = client.DownloadData(url);

                using (var str1 = new MemoryStream(content))
                {
                    Image   image = template.AddImage(str1);
                    Picture p     = image.CreatePicture();
                    Footer  f     = template.Footers.first;
                    Table   t     = f.Tables[0];
                    //t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(pR);
                    t.Rows[0].Cells[1].Paragraphs.First().AppendPicture(p);
                }
            }
            string Floc = model.loca.ToString() + ", " + model.locb.ToString();
            //string Fvirs = "";

            //if (model.ver != null)
            //{
            //    Fvirs = getVerisons(model);
            //}

            //create barcode & gdoc
            string Fbar   = " ";
            string gdoc   = " ";
            string Fgdocf = " ";

            if (!String.IsNullOrEmpty(model.Gdoc))
            {
                gdoc   = model.Gdoc.ToString();
                Fbar   = "*" + gdoc + "*";
                Fgdocf = gdoc;
                gdoc   = gdoc.Insert(2, "-");
            }
            string Fdname = "";

            if (!String.IsNullOrEmpty(model.Cname))
            {
                Fdname = model.Ctitle.ToString() + model.Cname.ToString();
            }
            if (String.IsNullOrEmpty(model.Cname))
            {
                int deleteStart = 0;
                int deleteEnd   = 0;

                //Get the array of the paragraphs containing the start and end catches
                for (int i = 0; i < template.Paragraphs.Count; i++)
                {
                    if (template.Paragraphs[i].Text.Contains("Chair:"))
                    {
                        deleteStart = i;
                    }
                    if (template.Paragraphs[i].Text.Contains("dname"))
                    {
                        deleteEnd = i;
                    }
                }

                if (deleteStart > 0 && deleteEnd > 0)
                {
                    //delete from the paraIndex as the arrays will shift when a paragraph is deleted
                    int paraIndex = deleteStart;
                    for (int i = deleteStart; i <= deleteEnd; i++)
                    {
                        template.RemoveParagraphAt(paraIndex);
                    }
                }
            }

            string Flname1 = "";
            string Flname2 = "";

            if (!String.IsNullOrEmpty(model.L1name))
            {
                Flname1 = model.L1title.ToString() + model.L1name.ToString();
            }
            if (!String.IsNullOrEmpty(model.L2name))
            {
                Flname2 = model.L2title.ToString() + model.L2name.ToString();
            }
            if (String.IsNullOrEmpty(model.L1name))
            {
                int deleteStart  = 0;
                int deleteEnd    = 0;
                int deleteStart1 = 0;
                int deleteEnd1   = 0;
                for (int i = 0; i < template.Paragraphs.Count; i++)
                {
                    if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname2"))
                    {
                        deleteStart1 = i;
                    }
                    if (template.Paragraphs[i].Text.Contains("lname2"))
                    {
                        deleteEnd1 = i;
                    }
                }
                //Get the array of the paragraphs containing the start and end catches
                for (int i = 0; i < template.Paragraphs.Count; i++)
                {
                    if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname1"))
                    {
                        deleteStart = i;
                    }
                    if (template.Paragraphs[i].Text.Contains("lname1"))
                    {
                        deleteEnd = i;
                    }
                }
                if (deleteStart1 > 0 && deleteEnd1 > 0)
                {
                    //delete from the paraIndex as the arrays will shift when a paragraph is deleted
                    int paraIndex = deleteStart1;
                    for (int i = deleteStart1; i <= deleteEnd1; i++)
                    {
                        template.RemoveParagraphAt(paraIndex);
                    }
                }
                if (deleteStart > 0 && deleteEnd > 0)
                {
                    //delete from the paraIndex as the arrays will shift when a paragraph is deleted
                    int paraIndex = deleteStart;
                    for (int i = deleteStart; i <= deleteEnd; i++)
                    {
                        template.RemoveParagraphAt(paraIndex);
                    }
                }
                //Get the array of the paragraphs containing the start and end catches
            }



            if (String.IsNullOrEmpty(model.L2name) && !String.IsNullOrEmpty(model.L1name))
            {
                int deleteStart = 0;
                int deleteEnd   = 0;

                for (int i = 0; i < template.Paragraphs.Count; i++)
                {
                    if (template.Paragraphs[i].Text.Contains("later") && template.Paragraphs[i].Text.Contains("lname2"))
                    {
                        deleteStart = i;
                    }
                    if (template.Paragraphs[i].Text.Contains("lname2"))
                    {
                        deleteEnd = i;
                    }
                }

                if (deleteStart > 0 && deleteEnd > 0)
                {
                    //delete from the paraIndex as the arrays will shift when a paragraph is deleted
                    int paraIndex = deleteStart;
                    for (int i = deleteStart; i <= deleteEnd; i++)
                    {
                        template.RemoveParagraphAt(paraIndex);
                    }
                }
            }
            string[] info1  = info(model);
            string   Fldate = formatdate1(model);
            string   xxx    = DateTime.Now.ToString();

            template.AddCustomProperty(new CustomProperty("gdoc", gdoc));
            template.AddCustomProperty(new CustomProperty("gdocf", Fgdocf));
            template.AddCustomProperty(new CustomProperty("bar", Fbar));

            template.AddCustomProperty(new CustomProperty("osdate", Fsodate));
            template.AddCustomProperty(new CustomProperty("sym1", Fsym1));
            //template.
            //    template.ReplaceText(Fsym, Fsym, false, RegexOptions.IgnoreCase);

            template.AddCustomProperty(new CustomProperty("symh", Fsym));
            // template.ReplaceText(sym, sym, false, RegexOptions.IgnoreCase);

            template.AddCustomProperty(new CustomProperty("olang", Folang));

            template.AddCustomProperty(new CustomProperty("dist", Fdist));
            //    template.ReplaceText("dist", Fdist, false, RegexOptions.IgnoreCase);

            template.AddCustomProperty(new CustomProperty("date", " "));
            template.AddCustomProperty(new CustomProperty("ldate", Fldate));
            //   template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase);
            template.AddCustomProperty(new CustomProperty("dname", Fdname));
            //   template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase);
            template.AddCustomProperty(new CustomProperty("lname1", Flname1));
            template.AddCustomProperty(new CustomProperty("lname2", Flname2));

            template.AddCustomProperty(new CustomProperty("loca", Floc));
            //   template.ReplaceText("date", Fdate, false, RegexOptions.IgnoreCase);
            //template.AddCustomProperty(new CustomProperty("virs", Fvirs));
            //      template.ReplaceText("virs", "", false, RegexOptions.IgnoreCase);

            template.AddCustomProperty(new CustomProperty("snum", Fsnum));
            //    template.ReplaceText("snum", Fsnum, false, RegexOptions.IgnoreCase);



            template.AddCustomProperty(new CustomProperty("mnum", Fmnum));
            //  template.ReplaceText("prep", Fprep, false, RegexOptions.IgnoreCase);


            template.AddCustomProperty(new CustomProperty("Date-Generated", xxx));

            template.AddCustomProperty(new CustomProperty("Org", "SR"));
            template.AddCustomProperty(new CustomProperty("Entity", info1[0]));
            template.AddCustomProperty(new CustomProperty("doctype", info1[1]));
            template.AddCustomProperty(new CustomProperty("category", info1[2]));



            return(template);
        }