private void printRingForUser(UserShows userShow, int UserID, Document doc, ref List<int> defaultUsers, ref int pageCount)
        {
            float[] ringColumns = new float[] { 300, 300, 300, 300 };

            User currentUser = new User(userShow.Userid);
            Shows show = new Shows(userShow.ShowID);

            List<ShowDetails> showDetailsList = ShowDetails.GetShowDetails(userShow.ShowID);

            Rings r = new Rings();
            DataSet ringList = r.GetAllRingsForShow(userShow.ShowID, "ShowDate");

            Dogs d = new Dogs();

            DogClasses dc = new DogClasses();
            DateTime dt = DateTime.Now;
            string currentJudge = "";
            int currentRingID = 0;
            int ShowDetailsID = -1;
            int PrevShowDetailsID = -1;
            PdfPTable rings = new PdfPTable(ringColumns);

            int ringCnt = 0;
            PdfPCell cell = null;
            PdfPTable ringDetails = null;
            PdfPTable classDetailsTable = null;
            List<int> dogsRunningToday = new List<int>();
            PdfPTable headerPage = null;
            List<TeamPairsTrioDto> pairsTeams = new List<TeamPairsTrioDto>();
            try
            {
                foreach (DataRow ringRow in ringList.Tables[0].Rows)
                {
                    Rings ring = new Rings(ringRow);
                    int RingID = Convert.ToInt32(ringRow["RingID"]);
                    int EntryType = Convert.ToInt32(ringRow["EntryType"]);
                    int Lho = Convert.ToInt32(ringRow["Lho"]);
                    ShowDetailsID = Convert.ToInt32(ringRow["ShowDetailsID"]);

                    if (ringRow.IsNull("ClassID"))
                    {
                        continue;
                    }
                    int ClassID = Convert.ToInt32(ringRow["ClassID"]);
                    int ClassNo = Convert.ToInt32(ringRow["ClsNo"]);
                    DateTime rowDT = Convert.ToDateTime(ringRow["ShowDate"]);
                    if (rowDT != dt)
                    {
                        if (currentRingID != 0)
                        {
                            if (ringCnt % MaxColumns != 0)
                            {
                                var remind = ringCnt % MaxColumns;
                                while (remind-- > 0)
                                {
                                    cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                    cell.BorderWidth = 0;
                                    rings.AddCell(cell);
                                }
                            }
                            if (dogsRunningToday.Count() > 0 || UserID == -1)
                            {
                                doc.Add(headerPage);
                                doc.Add(rings);
                                if (UserID > -1)
                                {
                                    if (currentUser.UserID != UserID)
                                    {
                                        User defaultHandler = new User(UserID);
                                    }
                                }

                                doc.NewPage();
                                pageCount++;
                            }
                        }

                        dogsRunningToday.Clear();
                        if (UserID > -1)
                        {
                            if (currentUser.UserID == UserID)
                            {
                                headerPage = DrawHeader(show, rowDT, currentUser, userShow);
                            }
                            else
                            {
                                User defaultHandler = new User(UserID);
                                headerPage = DrawHeader(show, rowDT, defaultHandler, userShow);
                            }
                        }
                        else
                        {
                            headerPage = DrawHeader(show, rowDT, null, null);

                        }
                        dt = rowDT;
                        rings = new PdfPTable(ringColumns);
                        rings.WidthPercentage = 100;
                        ringCnt = 0;
                    }

                    if (currentRingID != RingID)
                    {
                        currentJudge = "";
                        ringCnt++;
                        ringDetails = new PdfPTable(1);
                        rings.AddCell(new PdfPCell(ringDetails));

                        //List<Judge> judgeList = Judge.getJudgesForRingList(RingID);
                        string JudgeName = Judge.getJudgeForClass(ClassID).Name;
                        int ClsCount = DogClasses.GetDogsInRing(RingID);

                        cell = new PdfPCell(new Phrase(new Chunk(string.Format("Ring No {0} ({1})", ringRow["RingNo"].ToString(), ClsCount), judgeFont)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                        ringDetails.AddCell(cell);

                        if (currentJudge != JudgeName)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(JudgeName), judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);
                            currentJudge = JudgeName;
                        }
                        currentRingID = RingID;
                        classDetailsTable = new PdfPTable(DetailsColWidths);
                        classDetailsTable.DefaultCell.BorderWidth = 0;
                        ringDetails.AddCell(classDetailsTable);
                    }
                    else
                    {
                        string JudgeName = Judge.getJudgeForClass(ClassID).Name;
                        if (currentJudge != JudgeName)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk("  ", judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);
                            cell = new PdfPCell(new Phrase(new Chunk(Fpp.Core.Utils.TitleCaseString(JudgeName), judgeFont)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                            ringDetails.AddCell(cell);

                            classDetailsTable = new PdfPTable(DetailsColWidths);
                            classDetailsTable.DefaultCell.BorderWidth = 0;
                            ringDetails.AddCell(classDetailsTable);
                            currentJudge = JudgeName;
                        }
                    }
                    DataSet dogsList = d.GetDogsInClass(userShow.Userid, ClassID);
                    int dogsInClass = d.dogsInClassCount(ClassID);
                    List<DogClassCount> dcCounts = DogClasses.GetEntryCountsByClassId(userShow.ShowID, ClassID);

                    String clsName;
                    var part = Convert.ToInt32(ringRow["Part"]);
                    var lhoInd = "";
                    var dogsInClassDisplay = "";
                    if (dcCounts.Count > 1)
                    {
                        if (Lho == 1) {
                            dogsInClassDisplay = String.Format("({0}/{1})", dcCounts[0].Count, dcCounts[1].Count);
                        }
                        else
                        {
                            dogsInClassDisplay = String.Format("({0}/{1})", dcCounts[1].Count, dcCounts[0].Count);
                        }
                    }
                    else
                    {
                        dogsInClassDisplay = String.Format("({0})", dogsInClass);
                    }

                    if (Lho == 1)
                    {
                        lhoInd = "(FH 1st)";
                    }
                    else if (Lho == 2)
                    {
                        lhoInd = "(LHO 1st)";
                    }
                    if (EntryType != 10)
                    {
                        clsName = new ShowClasses(ClassID).NormalName(withClassNo:false, useAbbrFlag:true);
                    }
                    else
                    {
                        clsName = String.Format("{0} {1} {2} ",
                                        ShowClasses.expandHeight(ringRow),
                                        ringRow["LongName"].ToString().Trim(),
                                        ringRow["name"].ToString().Trim());
                    }
                    clsName = clsName.Replace("(Special Class", "S");
                    clsName = clsName.Replace("(Money Class", "Money");
                    clsName = clsName.Replace("First Place Processing", "FPP");
                    clsName = clsName.Replace("First Contact", "FC");
                    clsName = clsName.Replace("Qualifier", "Q");

                    if (part > 0 && EntryType != 10)
                    {
                        clsName += "Pt " + part;
                    }

                    if (dogsList.Tables[0].Rows.Count > 0)
                    {
                        /*
                        Combined 1-7 All Allsorts Agility sponsored by paws for a walk
                        Combined 6-7 Medium Agility

                            * */
                        var WrapClassDescription = clsName.Length > 45;
                        Phrase[] tmpCells = new Phrase[3];
                        tmpCells[0] = new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogInClass));
                        tmpCells[1] = new Phrase(new Chunk(clsName, dogInClass));
                        tmpCells[2] = new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass ));

                        int countDogs = 0;
                        int DefaultHandler;

                        Paragraph p = new Paragraph();
                        List<Paragraph> allDogsInClass = new List<Paragraph>();
                        foreach (DataRow dogRow in dogsList.Tables[0].Rows)
                        {
                            var dogLho = Convert.ToInt32(dogRow["Lho"]);
                            int DogID = Convert.ToInt32(dogRow["DogID"]);
                            DefaultHandler = Convert.ToInt32(dogRow["DefaultHandler"]);
                            if (DefaultHandler == 0) DefaultHandler = -1;
                            if ((DefaultHandler == -1 && currentUser.UserID == UserID) ||
                                (DefaultHandler == UserID)
                                )
                            {
                                if (countDogs == 0)
                                {
                                    cell = new PdfPCell(tmpCells[0]);
                                    cell.BorderWidth = 0;
                                    cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                                    classDetailsTable.AddCell(cell);
                                    var namePara = new Paragraph();
                                    namePara.Add(tmpCells[1]);
                                    namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                                    p.Add(namePara);
                                }
                                if (!dogsRunningToday.Contains(DogID))
                                {
                                    dogsRunningToday.Add(DogID);
                                }
                                String dogName = dogRow["DogName"].ToString();
                                if (dogName.Length == 0)
                                {
                                    dogName = dogRow["KCName"].ToString();
                                }
                                var chunk = new Chunk("   ", dogDetailsInClass);
                                chunk.SetBackground(new Color(System.Drawing.ColorTranslator.FromHtml(dogRow["DogColour"].ToString())));

                                var dogPara = new Paragraph();
                                dogPara.Add(new Phrase(chunk));

                                if (TeamPairsManager.isMultiDog( EntryType ))
                                {
                                    pairsTeams.Add(new TeamPairsTrioDto
                                    {
                                        ClassId = ClassID,
                                        ClassNo = ClassNo,
                                        DogId = DogID,
                                        DogName = dogName,
                                        RO = -1
                                    });
                                }
                                dogPara.Add(new Phrase(new Chunk(String.Format(" [{1}] {0}", Fpp.Core.Utils.TitleCaseString(dogName), dogRow["RO"]), dogDetailsInClass)));
                                dogPara.Add(new Phrase(new Chunk(String.Format("{0}", (dogLho == 0 ? "" : " (LHO)")), font8)));
                                dogPara.Add(Chunk.NEWLINE);

                                int AltHandler = Convert.ToInt32(dogRow["AltHandler"]);
                                String HandlerName = "";
                                if (AltHandler > 0)
                                {
                                    User u = new User(AltHandler);
                                    HandlerName = u.Name;
                                    dogPara.Add(new Phrase(new Chunk(String.Format("Handler:{0}", Fpp.Core.Utils.TitleCaseString(HandlerName)), dogInClass)));
                                }
                                allDogsInClass.Add(dogPara);
                                countDogs++;
                            }
                            else
                            {
                                if (defaultUsers != null && defaultUsers.IndexOf(DefaultHandler) == -1)
                                {
                                    defaultUsers.Add(DefaultHandler);
                                }
                            }
                        }
                        if (countDogs == 0)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);

                            var namePara = new Paragraph();
                            namePara.Add(new Phrase(new Chunk(clsName, dogNotInClass)));
                            namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                            p.Add(namePara);
                            cell = new PdfPCell(p);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;
                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);
                        }
                        else
                        {

                            cell = new PdfPCell(p);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;

                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(tmpCells[2]);
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                            classDetailsTable.AddCell(cell);

                            cell = new PdfPCell(new Phrase(new Chunk("", dogDetailsInClass)));
                            cell.BorderWidth = 0;
                            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                            cell.NoWrap = false;
                            classDetailsTable.AddCell(cell);

                            var tbl4Dogs = new PdfPTable(1);
                            foreach (var item in allDogsInClass)
                            {
                                cell = new PdfPCell(new Phrase(item));
                                cell.BorderWidth = 0;
                                cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                                tbl4Dogs.AddCell(cell);
                            }
                            cell = new PdfPCell();
                            cell.BorderWidth = 0;
                            cell.FixedHeight = 4f;
                            tbl4Dogs.AddCell(cell);

                            cell = new PdfPCell(tbl4Dogs);
                            cell.BorderWidth = 0;
                            cell.Colspan = 2;
                            classDetailsTable.AddCell(cell);
                        }
                    }
                    else
                    {
                        cell = new PdfPCell(new Phrase(new Chunk(ringRow["ClsNo"].ToString(), dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);

                        var namePara = new Paragraph();
                        namePara.Add(new Phrase(new Chunk(clsName, dogNotInClass)));
                        namePara.Add(new Phrase(new Chunk(lhoInd, lhoFontBold)));
                        cell = new PdfPCell(namePara);
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                        cell.NoWrap = false;
                        classDetailsTable.AddCell(cell);

                        cell = new PdfPCell(new Phrase(new Chunk(dogsInClassDisplay, dogNotInClass)));
                        cell.BorderWidth = 0;
                        cell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                        classDetailsTable.AddCell(cell);

                    }

                    PrevShowDetailsID = ShowDetailsID;
                }

                if (dogsRunningToday.Count() > 0 || UserID == -1)
                {
                    if (ringCnt % MaxColumns != 0)
                    {
                        var remind = ringCnt % MaxColumns;
                        while (remind-- > 0)
                        {
                            cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                            cell.BorderWidth = 0;
                            rings.AddCell(cell);
                        }
                        doc.Add(headerPage);
                        doc.Add(rings);
                    }

                    if (UserID > -1)
                    {
                        if (currentUser.UserID != UserID)
                        {
                            User defaultHandler = new User(UserID);
                        }
                    }
                    doc.NewPage();
                    pageCount++;
                }
                else
                {
                    if (dogsRunningToday.Count() > 0)
                    {
                        if (ringCnt % MaxColumns != 0)
                        {
                            var remind = ringCnt % MaxColumns;
                            while (remind-- > 0)
                            {
                                cell = new PdfPCell(new Phrase(new Chunk(" ", pageFont)));
                                cell.BorderWidth = 0;
                                rings.AddCell(cell);
                            }
                            doc.Add(headerPage);
                            doc.Add(rings);
                        }

                        if (UserID > -1)
                        {
                            if (currentUser.UserID != UserID)
                            {
                                User defaultHandler = new User(UserID);
                            }
                        }
                        doc.NewPage();
                        pageCount++;
                    }
                }
            }
            catch (Exception e)
            {
                AppException.LogError($"Error Running Plan:{e.Message},{e.StackTrace}");
            }
        }
示例#2
0
        public static AnalyticsReport GetProfileReport(string id, IAuthenticator authenticator)
        {
            AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = authenticator });

            var data =
                   service.Data.Ga.Get("ga:" + id, "2012-10-01", "2012-11-01", "ga:visits,ga:bounces,ga:pageviews");
            data.Dimensions = "ga:source,ga:keyword,ga:pagePath,ga:city,ga:date,ga:landingPagePath,ga:visitorType";
               // data.MaxResults = 500;

            GaData garesults = data.Fetch();
            AnalyticsReport report = new AnalyticsReport();
            report.id = id;
            report.JSON = garesults.Rows;

            var test = garesults.TotalsForAllResults;
            report.TotalVisits = Convert.ToInt32(test["ga:visits"]);
            report.TotalPageViews = Convert.ToInt32(test["ga:pageviews"]);
            var bounces = Convert.ToInt32(test["ga:bounces"]);
            var visits = Convert.ToInt32(test["ga:visits"]);
            report.BounceRate = (bounces / visits);

            //Referral List
            List<string> reflinks = new List<string>();
            List<string> keyWordList = new List<string>();
            List<string> landingPages = new List<string>();
            List<string> pagePathList = new List<string>();
            List<string> cityList = new List<string>();

            List<string> visitorType = new List<string>();
            List<int> dayList = new List<int>();
            List<int> newVisitors = new List<int>();
            List<int> returningVisitors = new List<int>();
            int maxReturningVisitors = 0;
            int maxNewVisitors = 0;
            foreach (var a in garesults.Rows)
            {
            string visType = a[6];
            var day = Convert.ToInt32(a[4]);
            if (dayList.Count() == 0)
            {
                dayList.Add(day);
            }
            else
            {
                var lastday = dayList.Last();
                if (day != lastday)
                {
                    dayList.Add(day);
                    filltoSameSize(newVisitors, returningVisitors);
                }
            }
            int numVisits = Convert.ToInt32(a[7]);
            if(visType == "New Visitor"){
                newVisitors.Add(numVisits);
                report.TotalNewVisitors = (report.TotalNewVisitors + numVisits);
                maxNewVisitors = Math.Max(maxNewVisitors, numVisits);
            }
            else
            {
                returningVisitors.Add(numVisits);
                report.TotalReturningVisitors = (report.TotalReturningVisitors + numVisits);
                maxReturningVisitors = Math.Max(maxReturningVisitors, numVisits);
            }

            reflinks.Add(a[0]);
            keyWordList.Add(a[1]);
            pagePathList.Add(a[2]);
            cityList.Add(a[3]);
            dayList.Add(day);
            landingPages.Add(a[5]);
            visitorType.Add(a[6]);
            }
            filltoSameSize(newVisitors, returningVisitors);
            report.maxNewVisitors = maxNewVisitors;
            report.maxReturningVisitors = maxReturningVisitors;
            report.newVisitors = newVisitors;
            report.retVisitors = returningVisitors;
            report.keylist = keyWordList;
            report.reflist = reflinks;
            report.citylist = cityList;
            report.landingpagelist = pagePathList;
            report.daylist = dayList;

            //KeyWord Entrances
               //  report.newVisitors = (from pages in arrPage group pages by pages into p where p.Key != null && !p.Key.Contains("Error") orderby p.Count() descending select new { Key = p.Key, Count = p.Count() }).Take(7);

            return report;
        }
示例#3
0
        public static AnalyticsReport GetReport(AnalyticsProfile profile, IAuthenticator authenticator)
        {
            AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = authenticator });

            var data =
                   service.Data.Ga.Get("ga:" + profile.id, profile.startDate.ToString("yyyy-MM-dd"), profile.endDate.ToString("yyyy-MM-dd"), "ga:visits,ga:bounces,ga:pageviews");
            data.Dimensions = "ga:source,ga:keyword,ga:pagePath,ga:city,ga:date,ga:landingPagePath,ga:visitorType";
            // data.MaxResults = 500;
            if (data.Fetch() == null)
            {
            try
            {
                //reauth if auth fail
                IAuthenticator auth = Utils.getCredsnew(AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue());
                 data =service.Data.Ga.Get("ga:" + profile.id, profile.startDate.ToString("yyyy-MM-dd"), profile.endDate.ToString("yyyy-MM-dd"), "ga:visits,ga:bounces,ga:pageviews");
                data.Dimensions = "ga:source,ga:keyword,ga:pagePath,ga:city,ga:date,ga:landingPagePath,ga:visitorType";
            }
            catch (Exception ex)
            {
            }

            }

            GaData garesults = data.Fetch();
            AnalyticsReport report = new AnalyticsReport();
            report.id = profile.id;
            report.JSON = garesults.Rows;

            var test = garesults.TotalsForAllResults;
            report.TotalVisits = Convert.ToInt32(test["ga:visits"]);
            report.TotalPageViews = Convert.ToInt32(test["ga:pageviews"]);
            var bounces = Convert.ToInt32(test["ga:bounces"]);
            var visits = Convert.ToInt32(test["ga:visits"]);
            report.BounceRate = ( visits / 2);

            //Referral List
            List<string> reflinks = new List<string>();
            List<string> keyWordList = new List<string>();
            List<string> landingPages = new List<string>();
            List<string> cityList = new List<string>();
            List<string> pagePathList = new List<string>();
            List<string> visitorType = new List<string>();
            List<int> dayList = new List<int>();
            List<int> totalVisitors = new List<int>();
            List<int> newVisitors = new List<int>();
            List<int> returningVisitors = new List<int>();
            int maxReturningVisitors = 0;
            int maxNewVisitors = 0;
            if (garesults.Rows != null){
            foreach (var a in garesults.Rows)
            {
            string visType = a[6];
            var day = Convert.ToInt32(a[4]);
            if (dayList.Count() == 0)
            {
                dayList.Add(day);
            }
            else
            {
                var lastday = dayList.Last();
                if (day != lastday)
                {
                    dayList.Add(day);
                    filltoSameSize(newVisitors, returningVisitors);
                }
            }
            int numVisits = Convert.ToInt32(a[7]);
            if (visType == "New Visitor")
            {
                newVisitors.Add(numVisits);
                report.TotalNewVisitors = (report.TotalNewVisitors + numVisits);
                maxNewVisitors = Math.Max(maxNewVisitors, numVisits);
                totalVisitors.Add(numVisits);
            }

            else
            {
                totalVisitors.Add(numVisits);
                returningVisitors.Add(numVisits);
                report.TotalReturningVisitors = (report.TotalReturningVisitors + numVisits);
                maxReturningVisitors = Math.Max(maxReturningVisitors, numVisits);
            }
            reflinks.Add(a[0]);
            keyWordList.Add(a[1]);
            pagePathList.Add(a[2]);
            cityList.Add(a[3]);
            dayList.Add(day);
            landingPages.Add(a[5]);
            visitorType.Add(a[6]);
            }
            filltoSameSize(newVisitors, returningVisitors);
            report.totalVisitors = totalVisitors;
            report.maxNewVisitors = maxNewVisitors;
            report.maxReturningVisitors = maxReturningVisitors;
            report.newVisitors = newVisitors;
            report.retVisitors = returningVisitors;
            report.landingpagelist = landingPages;
            report.keylist = keyWordList;
            report.reflist = reflinks;
            report.keylist = keyWordList;
            report.citylist = cityList;
            report.pagelist = pagePathList;
            report.daylist = dayList;

            //KeyWord Entrances
            //  report.newVisitors = (from pages in arrPage group pages by pages into p where p.Key != null && !p.Key.Contains("Error") orderby p.Count() descending select new { Key = p.Key, Count = p.Count() }).Take(7);

            return report;
            }
            else
            {
            return null;
            }
        }
        public JsonResult RetrieveSPFs(int pupilID)
        {
            if (IsAuthorized())
            {
                Teacher user = VaKEGradeRepository.Instance.GetTeacher(((Teacher)Session["User"]).ID);
                Session["User"] = user;
                Pupil pupil = VaKEGradeRepository.Instance.GetPupil(pupilID);
                //Session["SelPupilID"] = pupil.ID;
                if (pupil != null)
                {
                    List<Database.SPF> spfs = pupil.SPFs.ToList();
                    GridData gData = new GridData() { page = 1 };
                    List<RowData> rows = new List<RowData>();
                    Session["pupilID"] = pupilID;

                    foreach (SPF spf in spfs)
                    {
                        rows.Add(new RowData() { id = spf.ID, cell = new string[] { spf.Subject.Name, spf.Level.ToString() } });
                    }

                    gData.records = rows.Count();
                    gData.total = rows.Count();
                    gData.rows = rows.ToArray();

                    return Json(gData, JsonRequestBehavior.AllowGet);
                }
                return null;
            }
            return null;
        }
示例#5
0
 public static void filltoSameSize(List<int> firstArray, List<int> secondArray)
 {
     if (firstArray.Count() < secondArray.Count())
      {
      firstArray.Add(0);
      }
      else if (secondArray.Count() < firstArray.Count())
      {
      secondArray.Add(0);
      }
 }
示例#6
0
        public async Task<ActionResult> Create(IEnumerable<HttpPostedFileBase> file, Result model)
        //public ActionResult Create(IEnumerable<HttpPostedFileBase> file, Result model)
        {
            try
            {
                // model.
                List<Result> checkForResult = new List<Result>();
                checkForResult = work.ResultRepository.Get().Where(a => a.Session == model.Session && a.Term == model.Term && a.Class == model.Class).ToList();

                if (checkForResult.Count() > 0)
                {
                    List<Level> theLevels = work.LevelRepository.Get().ToList();
                    List<SelectListItem> theItem = new List<SelectListItem>();
                    theItem.Add(new SelectListItem() { Text = "None", Value = "" });

                    foreach (var level in theLevels)
                    {
                        theItem.Add(new SelectListItem() { Text = level.LevelName + ":" + level.Type, Value = level.LevelName + ":" + level.Type });
                    }

                    ViewData["Class"] = theItem;
                    ModelState.AddModelError("", "You have uploaded for the class earlier!");
                    return View();
                }

                // TODO: Add insert logic here
                if (string.IsNullOrEmpty(Request.Files[0].FileName))
                {
                  ModelState.AddModelError("","No Uploaded Document!");
                    return View();
                }//xlsx or xls
                if ((Request.Files[0].FileName.EndsWith(".xlsx")) || (Request.Files[0].FileName.EndsWith(".xls")))
                {
                    string fileExtension = System.IO.Path.GetExtension(Request.Files[0].FileName);
                    //    string physicalPath = HttpContext.Server.MapPath("~/Content/") + Request.Files[0].FileName;


                    HttpPostedFileBase theFile = Request.Files[0];
                    var fileName = Path.GetFileName(Request.Files[0].FileName);



                    await new ReadResultExcelFile().Read(fileExtension, model.Class, model.Session, model.Term, theFile);
                    //new ReadResultExcelFile().Read( fileExtension, model.Class, model.Session, model.Term, theFile);
                }
                else
                {
                    ModelState.AddModelError("", "The Input File is not a valid Excel  file!");
                    return View();
                }



                return RedirectToAction("Index");
            }
            catch
            {
                List<Level> theLevels = work.LevelRepository.Get().ToList();
                List<SelectListItem> theItem = new List<SelectListItem>();
                theItem.Add(new SelectListItem() { Text = "None", Value = "" });

                foreach (var level in theLevels)
                {
                    theItem.Add(new SelectListItem() { Text = level.LevelName + ":" + level.Type, Value = level.LevelName + ":" + level.Type });
                }

                ViewData["Class"] = theItem;
                return View();
            }
        }
        public JsonResult RetrieveAllStudents()
        {
            if (IsAuthorized()) {
                Teacher user = VaKEGradeRepository.Instance.GetTeacher(((Teacher)Session["User"]).ID);
                Session["User"] = user;
                List<Database.Pupil> pupils = user.PrimaryClasses.First().Pupils.ToList();

                GridData gData = new GridData() { page = 1 };
                List<RowData> rows = new List<RowData>();

                foreach (Database.Pupil pupil in pupils)
                {
                    rows.Add(new RowData() { id = pupil.ID, cell = new string[] { pupil.LastName, pupil.FirstName, pupil.Religion, pupil.Birthdate.ToShortDateString(), pupil.Gender } });
                }

                gData.records = rows.Count();
                gData.total = rows.Count();
                gData.rows = rows.ToArray();
                return Json(gData, JsonRequestBehavior.AllowGet);
            }
            return null;
        }
        public ActionResult editFootnoteMaps(Int16 fiscalYear, Int16? indicatorID)
        {
            List<Indicator_Footnote_Maps> footnoteMaps = new List<Indicator_Footnote_Maps>();
            foreach (var footnote in db.Indicator_Footnote_Maps.Where(x => x.Fiscal_Year == fiscalYear).OrderBy(e => e.Map_ID).ToList())
            {
                footnoteMaps.Add(footnote);
            }

            var allIndicator = new List<Indicators>();
            if (indicatorID.HasValue)
            {
                allIndicator = db.Indicators.Where(x => x.Indicator_ID == indicatorID).OrderBy(x => x.Indicator_ID).ToList();
            }
            else
            {
                allIndicator = db.Indicators.OrderBy(x => x.Indicator_ID).ToList();
            }

            var viewModel = allIndicator.Select(x => new Indicator_Footnote_MapsViewModel
            {
                Indicator_ID = x.Indicator_ID,
                Indicator = x.Indicator,
                Fiscal_Year = fiscalYear,
            }).ToList();

            viewModel.FirstOrDefault().allFootnotes = new List<string>();

            viewModel.FirstOrDefault().allFootnotes.AddRange(db.Footnotes.Select(x => x.Footnote_Symbol + ", " + x.Footnote).ToList());

            foreach (var Indicator in viewModel)
            {
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 0)
                {
                    Indicator.Footnote_ID_1 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).First().Footnote_ID;
                    Indicator.Map_ID_1 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).First().Map_ID;
                    Indicator.Footnote_Symbol_1 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_1).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 1)
                {
                    Indicator.Footnote_ID_2 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(1).First().Footnote_ID;
                    Indicator.Map_ID_2 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(1).First().Map_ID;
                    Indicator.Footnote_Symbol_2 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_2).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 2)
                {
                    Indicator.Footnote_ID_3 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(2).First().Footnote_ID;
                    Indicator.Map_ID_3 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(2).First().Map_ID;
                    Indicator.Footnote_Symbol_3 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_3).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 3)
                {
                    Indicator.Footnote_ID_4 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(3).First().Footnote_ID;
                    Indicator.Map_ID_4 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(3).First().Map_ID;
                    Indicator.Footnote_Symbol_4 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_4).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 4)
                {
                    Indicator.Footnote_ID_5 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(4).First().Footnote_ID;
                    Indicator.Map_ID_5 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(4).First().Map_ID;
                    Indicator.Footnote_Symbol_5 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_5).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 5)
                {
                    Indicator.Footnote_ID_6 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(5).First().Footnote_ID;
                    Indicator.Map_ID_6 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(5).First().Map_ID;
                    Indicator.Footnote_Symbol_6 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_6).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 6)
                {
                    Indicator.Footnote_ID_7 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(6).First().Footnote_ID;
                    Indicator.Map_ID_7 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(6).First().Map_ID;
                    Indicator.Footnote_Symbol_7 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_7).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 7)
                {
                    Indicator.Footnote_ID_8 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(7).First().Footnote_ID;
                    Indicator.Map_ID_8 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(7).First().Map_ID;
                    Indicator.Footnote_Symbol_8 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_8).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 8)
                {
                    Indicator.Footnote_ID_9 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(8).First().Footnote_ID;
                    Indicator.Map_ID_9 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(8).First().Map_ID;
                    Indicator.Footnote_Symbol_9 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_9).Footnote_Symbol;
                }
                if (footnoteMaps.Count(e => e.Indicator_ID == Indicator.Indicator_ID) > 9)
                {
                    Indicator.Footnote_ID_10 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(9).First().Footnote_ID;
                    Indicator.Map_ID_10 = footnoteMaps.Where(e => e.Indicator_ID == Indicator.Indicator_ID).OrderBy(e => e.Map_ID).Skip(9).First().Map_ID;
                    Indicator.Footnote_Symbol_10 = db.Footnotes.FirstOrDefault(e => e.Footnote_ID == Indicator.Footnote_ID_10).Footnote_Symbol;
                }
            }

            return View(viewModel);
        }
 private void ScoreBoardColumnHeaders(ShowClasses showClass, PdfPTable callingListTbl, List<CallingListDto> callingList, float[] colWidths)
 {
     if (TeamPairsManager.isMultiDog(showClass.EntryType))
     {
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("RO", headerHFont))) { BorderWidth = 0 });
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Team Name", headerHFont)))
         {
             BorderWidth = 0,
             Colspan = 2
         });
     }
     else
     {
         if (showClass.Lho == 1 || showClass.Lho == 2)
         {
             if (callingList.Any())
             {
                 var item = callingList.First();
                 var cnt = callingList.Count(x => x.Lho == item.Lho);
                 var title = $"{(item.Lho == 0 ? "Full Height " : "Lower Height")} ({cnt})";
                 callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(title, headerHFont)))
                 {
                     BorderWidth = 0,
                     Colspan = colWidths.Length,
                     BackgroundColor = Color.LIGHT_GRAY,
                     HorizontalAlignment = Element.ALIGN_CENTER,
                     FixedHeight = 20,
                     BorderColorBottom = Color.BLACK,
                     BorderWidthBottom = 2
                 });
             }
             else
             {
                 var title = $"Dont Know (9999)";
                 callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk(title, headerHFont)))
                 {
                     BorderWidth = 0,
                     Colspan = colWidths.Length,
                     BackgroundColor = Color.LIGHT_GRAY,
                     HorizontalAlignment = Element.ALIGN_CENTER,
                     FixedHeight = 20,
                     BorderColorBottom = Color.BLACK,
                     BorderWidthBottom = 2
                 });
             }
         }
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("RO", headerHFont))) { BorderWidth = 0 });
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Ring No", headerHFont))) {BorderWidth = 0});
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Handler", headerHFont))) { BorderWidth = 0 });
         callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Dog Name", headerHFont))) { BorderWidth = 0 });
     }
     callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Clears", headerHFont))) { BorderWidth = 0 });
     callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Faults", headerHFont))) { BorderWidth = 0 });
     callingListTbl.AddCell(new PdfPCell(new Phrase(new Chunk("Time", headerHFont))) { BorderWidth = 0 });
 }
        private void GenerateCommunityExplorerListDetailsExcel(HSSFWorkbook workbook, string title, List<CommunityReportDataModel> list)
        {
            this.rowCount = 0;
            var sheet = workbook.CreateSheet(title);
            //(Optional) freeze the header row so it is not scrolled
            sheet.CreateFreezePane(0, 1);

            //Create a header row
            var headerRow = sheet.CreateRow(this.rowCount++);

            //Set the column names in the header row
            headerRow.CreateCell(0).SetCellValue("Name");
            headerRow.CreateCell(1).SetCellValue("Individuals");
            headerRow.CreateCell(2).SetCellValue("Households");

            var dataFormat = workbook.CreateCellStyle();
            dataFormat.DataFormat = workbook.CreateDataFormat().GetFormat("#,##0");

            int rowNumber = 1;
            //Populate the sheet with values from the grid data
            foreach (var detail in list)
            {
                //Create a new row
                var row = sheet.CreateRow(rowNumber++);

                var idCell = row.CreateCell(0);
                idCell.SetCellType(NPOI.SS.UserModel.CellType.String);
                idCell.SetCellValue(detail.Name);

                var countCell = row.CreateCell(1);
                countCell.SetCellType(NPOI.SS.UserModel.CellType.Numeric);
                countCell.SetCellValue((double)detail.IndividualCount);
                countCell.CellStyle = dataFormat;

                var paymentsCell = row.CreateCell(2);
                paymentsCell.SetCellType(NPOI.SS.UserModel.CellType.Numeric);
                paymentsCell.SetCellValue((double)detail.HouseholdCount);
                paymentsCell.CellStyle = dataFormat;
            }

            //if no data is available, create blank page.
            if (list.Count() == 0)
            {
                var row = sheet.CreateRow(rowNumber++);
                row.CreateCell(0).SetCellValue(string.Empty);
                row.CreateCell(1).SetCellValue(string.Empty);
                row.CreateCell(2).SetCellValue(string.Empty);
            }

            //set column sizes
            for (int i = 0; i <= 3; i++)
            {
                sheet.AutoSizeColumn(i);
            }
        }
示例#11
0
        private void SetMetaDataTitle(FactoryStrategy strategy, List<IApplication> Applications)
        {
            if (Applications.Count() > 1)
                Title = (strategy.isOnlySummary) ? "My Enbloc Assignments" : "My Council Assignments";
            else
            {
                title = "Generic ID";
                if (Applications.Count > 0)
                {
                    var application = Applications[0];

                    switch (application.GetType().ToString())
                    {
                        case "CMWModels.CMWRfa":
                            var rfa = (CMWRfa)application;
                            title = rfa.RFAPANumber;
                            break;
                        case "CMWModels.CMWGrant":
                            var grant = (CMWGrant)application;
                            title = grant.FullGrantNum;
                            break;

                        default:
                            var fdappl = (FDApplication)application;
                            title = fdappl.ProjectNumber;
                            break;
                    }
                }
            }
        }
        private IElement Content()
        {
            var table = new PdfPTable(2);
            table.SetWidths(new[] { 1, 3 });
            table.WidthPercentage = 100f;
            table.SpacingAfter = 5f;

            var titles = new List<string>
            {
                "Date", "Paid By",
                "Amount", "In respect of"
            };

            var bankPayment = _feePayment.Bank != null && _feePayment.ReceiptNumber != null;
            var chequePayment = _feePayment.ChequeNumber != null;

            if (bankPayment)
            {
                titles.Add("Bank");
                titles.Add("Receipt No");
            }
            else if (chequePayment)
            {
                titles.Add("Cheque No");
            }

            var commentExist = _feePayment.Comment != null;

            if (commentExist)
            {
                titles.Add("Comment");
            }

            var texts = new List<string>
            {
                DateTime.Now.ToString(),
                _feePayment.PaidBy,
               $"{NumberText.NumberToWords((int)_feePayment.Amount)} Naira Only ({_feePayment.Amount} Naira)",
               $"{_student.FirstName} {_student.LastName}"
            };

            if (bankPayment)
            {
                texts.Add(_feePayment.Bank);
                texts.Add(_feePayment.ReceiptNumber);
            }
            else if (chequePayment)
            {
                texts.Add(_feePayment.ChequeNumber);
            }

            if (commentExist)
            {
                texts.Add(_feePayment.Comment);
            }
            
            for (int i = 0; i < titles.Count(); i++)
            {
                table.AddCell(AddTitle(titles[i].ToUpper(), Font8B));
                table.AddCell(AddText(texts[i], Font8));
            }

            return table;
        }
示例#13
0
        private void button1_Click(object sender, EventArgs e)
        {
            lista = _reporteServicio.FiltrarAgenteDTO(this.dateTimePicker1.Value.Date);

            this.dataGridView1.DataSource = lista;

            this.nudAusentes.Value = lista.Count(x => x.Ausente == "SI");
            this.nudPresentes.Value = Convert.ToDecimal(lista.Count(x => x.Ausente != "SI"));
            this.nudTarde.Value = Convert.ToDecimal(lista.Count(x => x.Tarde == "SI"));
        }
        private void saveResultsToPDFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            iTextSharp.text.Font times = new iTextSharp.text.Font(bfTimes, 12, iTextSharp.text.Font.ITALIC, BaseColor.DARK_GRAY);
            Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 42);
            PdfWriter pdw = PdfWriter.GetInstance(doc, new FileStream("TextsStats"+DateTime.Now.GetHashCode().ToString() + ".pdf", FileMode.Create));
            doc.Open();
            Paragraph p = new Paragraph("Text Stats for : " + DateTime.Now, times);
            doc.Add(p);
            p.Alignment = 1;
            PdfPTable pdt = new PdfPTable(4);
            pdt.HorizontalAlignment = 1;
            pdt.SpacingBefore = 20f;
            pdt.SpacingAfter = 20f;
            pdt.AddCell("Name of Text");
            pdt.AddCell("MSE (Naivna)");
            pdt.AddCell("MSE (Gramatika)");
            pdt.AddCell("PCT");
            c_tekst.SelectedIndex = 0;
            c_analiza.SelectedIndex = 0;
            foreach (Tekst t in lista_teksta)
            {
                c_analiza.SelectedIndex = 0;
                calculateStats("Pojedinačan tekst", 1);
                c_analiza.SelectedIndex = 1;
                calculateStats("Pojedinačan tekst", 2);
                if(c_tekst.SelectedIndex+1 < c_tekst.Items.Count)
                    c_tekst.SelectedIndex++;
            }
            List<StatistikaTekst> cista_lista_PDF = new List<StatistikaTekst>();
            List<String> help = new List<String>();
            StatistikaTekst ukupno = new StatistikaTekst();
            foreach(StatistikaTekst st in lista_PDF)
            {
                if (!help.Contains(st.Ime_teksta))
                {
                    help.Add(st.Ime_teksta);
                    ukupno.RMSE_G1 += st.RMSE_G1;
                    ukupno.RMSE_N1 += st.RMSE_N1;
                    cista_lista_PDF.Add(st);
                }
            }
            ukupno.Ime_teksta = "TOTAL";
            ukupno.RMSE_G1 /= cista_lista_PDF.Count();
            ukupno.RMSE_N1 /= cista_lista_PDF.Count();
            ukupno.RMSE_G1 = Math.Round(ukupno.RMSE_G1, 5);
            ukupno.RMSE_N1 = Math.Round(ukupno.RMSE_N1, 5);
            ukupno.Pct_diff = Math.Round(ukupno.RMSE_G1 / ukupno.RMSE_N1, 5);
            cista_lista_PDF.Add(ukupno);
            foreach (StatistikaTekst st in cista_lista_PDF)
            {
                pdt.AddCell(st.Ime_teksta);
                pdt.AddCell(Convert.ToString(st.RMSE_N1));
                pdt.AddCell(Convert.ToString(st.RMSE_G1));
                pdt.AddCell(Convert.ToString(st.Pct_diff*100)+'%');
            }
            /*using (MemoryStream stream = new MemoryStream())
            {
                chart1.SaveImage(stream, ChartImageFormat.Png);
                iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                chartImage.ScalePercent(75f);
                chartImage.Alignment = 1;
                doc.Add(chartImage);
            }*/
            doc.Add(pdt);
            doc.Close();
            using (ExcelPackage ep = new ExcelPackage())
            {
                //Here setting some document properties
                ep.Workbook.Properties.Author = "MasterWordCounter";
                ep.Workbook.Properties.Title = "Text Data";

                //Create a sheet
                ep.Workbook.Worksheets.Add("Text Data");
                ExcelWorksheet ws = ep.Workbook.Worksheets[1];
                ws.Name = "Text Data"; //Setting Sheet's name
                ws.Cells.Style.Font.Size = 11; //Default font size for whole sheet
                ws.Cells.Style.Font.Name = "Calibri"; //Default Font name for whole sheet

                DataTable dt = new DataTable("TextsStats" + DateTime.Now.GetHashCode().ToString()); //My Function which generates DataTable
                dt.Columns.Add("Ime Djela");
                dt.Columns.Add("MSE (Naivna)");
                dt.Columns.Add("MSE (Gramatika)");
                dt.Columns.Add("Procenat (%)");
                foreach (StatistikaTekst st in cista_lista_PDF)
                {
                    DataRow dr = dt.NewRow();
                    dr["Ime Djela"] = (st.Ime_teksta);
                    dr["MSE (Naivna)"] = st.RMSE_N1;
                    dr["MSE (Gramatika)"] = st.RMSE_G1;
                    dr["Procenat (%)"] = st.Pct_diff * 100;
                    dt.Rows.Add(dr);
                }
                //Merging cells and create a center heading for out table
                ws.Cells[1, 1].Value = "Ime Djela";
                ws.Cells[1, 2].Value = "MSE (Naivna)";
                ws.Cells[1, 3].Value = "MSE (Gramatika)";
                ws.Cells[1, 4].Value = "Procenat (%)";

                int colIndex = 1;
                int rowIndex = 2;

                foreach (DataColumn dc in dt.Columns) //Creating Headings
                {
                    var cell = ws.Cells[rowIndex, colIndex];

                    //Setting the background color of header cells to Gray
                    var fill = cell.Style.Fill;
                    fill.PatternType = ExcelFillStyle.Solid;
                    fill.BackgroundColor.SetColor(Color.Gray);

                    //Setting Top/left,right/bottom borders.
                    var border = cell.Style.Border;
                    border.Bottom.Style =
                        border.Top.Style =
                        border.Left.Style =
                        border.Right.Style = ExcelBorderStyle.Thin;

                    //Setting Value in cell
                    cell.Value = "Heading " + dc.ColumnName;

                    colIndex++;
                }

                foreach (DataRow dr in dt.Rows) // Adding Data into rows
                {
                    colIndex = 1;
                    rowIndex++;
                    foreach (DataColumn dc in dt.Columns)
                    {
                        var cell = ws.Cells[rowIndex, colIndex];
                        //Setting Value in cell
                        cell.Value = dr[dc.ColumnName];

                        //Setting borders of cell
                        var border = cell.Style.Border;
                        border.Left.Style =
                            border.Right.Style = ExcelBorderStyle.Thin;
                        colIndex++;
                    }
                }

                colIndex = 0;
                foreach (DataColumn dc in dt.Columns) //Creating Headings
                {
                    colIndex++;
                    var cell = ws.Cells[rowIndex, colIndex];

                    //Setting Sum Formula
                    cell.Formula = "Sum(" +
                                    ws.Cells[3, colIndex].Address +
                                    ":" +
                                    ws.Cells[rowIndex - 1, colIndex].Address +
                                    ")";

                    //Setting Background fill color to Gray
                    cell.Style.Fill.PatternType = ExcelFillStyle.Solid;
                    cell.Style.Fill.BackgroundColor.SetColor(Color.Gray);
                }

                //Generate A File with Random name
                Byte[] bin = ep.GetAsByteArray();
                string file = Guid.NewGuid().ToString() + ".xlsx";
                File.WriteAllBytes(file, bin);
            }
            MessageBox.Show("PDF created!");
        }
示例#15
0
        public ActionResult CreateToSiemens([Bind(Include = "project_id")] feedbacks feedbacks, List<string> partners)
        {
            int a = partners.Count();

            string[] partnerIDs = new string[a];

            AspNetUsers anu;

            int inc = 0;

            foreach (var partner in partners)
            {

                anu = db.AspNetUsers.Single(asn => asn.Email == partner);
                partnerIDs[inc] = anu.Id;
                inc++;
            }

            inc = 0;
            int iterations = 0;
            int count = partnerIDs.Count();
            iterations = count / 2;
            int[] b = new int[a];

            if (ModelState.IsValid)
            {
                foreach (var id in partnerIDs)
                {
                    // return RedirectToAction("IndexMy", "feedbacks", new { perkelt = partnerIDs.Count()});

                    feedbacks.Id = id;
                    feedbacks.initiated = null;
                    feedbacks.received = null;
                    db.feedbacks.Add(feedbacks);
                    db.SaveChanges();
                    b[inc] = feedbacks.feedback_id;
                    inc++;

                }

                inc = 0;

                foreach (var c in b)
                {

                    foreach (var question in db.questions.Where(q => q.deprecated == "n" && q.for_project_role == "siemens").ToList())
                    {
                        feedback_questions feedback_question = new feedback_questions();
                        feedback_question.feedback_id = c;
                        feedback_question.question_id = question.question_id;

                        db.feedback_questions.Add(feedback_question);
                        db.SaveChanges();
                    }
                }

                TempData["successCreatedFeedback"] = "Úspešne ste vytvorili feedback";
                return RedirectToAction("IndexForMe", "feedbacks");

                //return RedirectToAction("Create", "feedback_questions", new { feedback_id = feedbacks.feedback_id });
            }
            return RedirectToAction("Index", "locations");
        }
        private string GetJobFormHTMLForStoreNonVisit(JobFormNew JobFormNew)
        {
            try
            {
                List<string> parentIDList = new List<string>();
                List<string> controlIDList = new List<string>();
                int imagecount = 0;
                List<WorkersInMotion.Model.ViewModel.JobFormValueDetails> FormValues = new List<WorkersInMotion.Model.ViewModel.JobFormValueDetails>();
                StringBuilder sbJobForm = new StringBuilder();
                // sbJobForm.Append("<div style='page-break-before:always'>&nbsp;</div>");
                sbJobForm.Append("<html>");
                sbJobForm.Append("<head><script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false'></script></head>");
                sbJobForm.Append("<body>");
                #region Generate JobForm
                if (JobFormNew.JobFormHeading != null)
                {
                    sbJobForm.Append("<div id='" + JobFormNew.JobFormHeading.JobGUID + "' name='" + JobFormNew.JobFormHeading.JobGUID + "'>");
                    sbJobForm.Append("<div align='center'>");
                    sbJobForm.Append("<table style='width:100%' align='center' cellpadding='0'>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td colspan='2' style='font-size:18px;font-family:verdana;font-weight:bold;text-align:center;'>" + JobFormNew.JobFormHeading.JobName + "&nbsp;Report</td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td colspan='2' style='font-size:18px;font-family:verdana;font-weight:bold;text-align:center;'>&nbsp;</td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 65%;' align='left'>Client Name :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.PlaceName + "</span> </td>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 35%;' align='left'>Client ID :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.PlaceID + "</span> </td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 65%;' align='left'>Store ID :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.MarketID + "</span> </td>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 35%;' align='left'>Check-In :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.CheckInTime + "</span> </td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 65%;' align='left'>Store Name : <span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.MarketName + "</span></td>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;width: 35%;' align='left'>Check-Out : <span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.CheckOutTime + "</span></td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("<tr>");
                    sbJobForm.Append("<td style='font-size:12px;font-family:verdana;font-weight:bold;text-align:left;' align='left'>Address :<span style='font-weight:normal;'>" + JobFormNew.JobFormHeading.MarketAddress + "</span> </td>");
                    sbJobForm.Append("</tr>");
                    sbJobForm.Append("</table>");
                    sbJobForm.Append("</div>");
                    sbJobForm.Append("<a name='" + JobFormNew.JobFormHeading.JobGUID + "' style='text-decoration: none;'>&nbsp;</a>");
                    sbJobForm.Append("<hr style='boder:1px solid black;width:100%'/>");
                }
                else
                {
                    sbJobForm.Append("<div>");
                }

                if (JobFormNew != null && JobFormNew.FormValues != null)
                {
                    foreach (var item1 in JobFormNew.FormValues)
                    {
                        if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID == -100) || (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.controlParentLabel == "Email") || (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.controlParentLabel == "Phone"))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                //if (!parentIDList.Contains(item1.parentID.ToString()))
                                //{
                                //    parentIDList.Add(item1.parentID.ToString());
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<p style='color:black;font-weight:bold;font-size:12px;margin-left:1px;'>" + item1.controlParentLabel + "</p>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT) || ((one.ControlLabel == "Email" || one.ControlLabel == "Phone") && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                        // sbJobForm.Append("<p>&nbsp;</p>");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");

                            }
                        }
                        //}
                        //else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID == -101) || (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.controlParentLabel == "Date"))
                        //{
                        //    if (!parentIDList.Contains(item1.parentID.ToString()))
                        //    {
                        //        parentIDList.Add(item1.parentID.ToString());
                        //        sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                        //        sbJobForm.Append("<p style='color:black;font-weight:bold;font-size:12px;margin-left:1px;'>" + item1.controlParentLabel + "</p>");
                        //        sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                        //        sbJobForm.Append("<tr>");
                        //        sbJobForm.Append("<td align='left'>");
                        //        foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.parentID && ((one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID == -101) || (one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && one.ControlLabel == "Date")))))
                        //        {
                        //            if (!controlIDList.Contains(items.ControlID.ToString()))
                        //            {

                        //                controlIDList.Add(items.ControlID.ToString());
                        //                if (items.ControlLabel == "Year" || items.ControlLabel == "Day")
                        //                {
                        //                    sbJobForm.Append(" <span style='padding-left:0px;line-height:20px;font-size:10px;'>-" + items.Value + "</span>");
                        //                }
                        //                else
                        //                {
                        //                    sbJobForm.Append(" <span style='padding-left:10px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                        //                }


                        //            }
                        //        }
                        //        sbJobForm.Append("</td>");
                        //        sbJobForm.Append("</tr>");
                        //        sbJobForm.Append("</table>");
                        //        sbJobForm.Append("</div>");

                        //    }
                        //}

                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT) && (item1.ControlLabel == "Region"))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => ((one.ControlLabel == "Region" || one.ControlLabel == "Market") && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + items.ControlLabel + "</label><br></br>");
                                        sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                        // sbJobForm.Append("<p style='padding:0px 10px 0px 10px; border-bottom: 1px solid gray; border-left: 1px solid gray; border-right: 1px solid gray; line-height: 2px;'>&nbsp;</p>");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT) && (item1.ControlLabel == "Store Number # *" || item1.ControlLabel == "Store Address"))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => ((one.ControlLabel == "Store Number # *" || one.ControlLabel == "Store Address") && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + items.ControlLabel + "</label><br></br>");
                                        sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                        //sbJobForm.Append("<p>&nbsp;</p>");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT && item1.parentID < 0))
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<p style='color:black;font-weight:bold;font-size:12px;margin-left:1px;'>" + item1.controlParentLabel + "</p>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='0'>");
                                sbJobForm.Append("<tr>");
                                //sbJobForm.Append("<td align='left'>");
                                //sbJobForm.Append("</td>");
                                foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        if (!controlIDList.Contains(items.ControlID.ToString()))
                                        {

                                            controlIDList.Add(items.ControlID.ToString());
                                            sbJobForm.Append("<td align='left' style='width:25%'>");
                                            sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + items.Value + "</span>");
                                            sbJobForm.Append("</td>");

                                        }

                                    }
                                }

                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");

                            }
                        }
                        else if ((item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT || item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_DROP_DOWN) && item1.controlParentLabel != "Email" && item1.controlParentLabel != "Phone")
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                if (!string.IsNullOrEmpty(item1.ControlLabel) && !string.IsNullOrEmpty(item1.Value))
                                {
                                    sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                    sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>&nbsp;" + item1.ControlLabel + "</label>");
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    sbJobForm.Append("<tr>");
                                    sbJobForm.Append("<td align='left' style='width:40%'>");
                                    sbJobForm.Append("<span style='padding-left:0px;line-height:20px;font-size:10px;'>" + item1.Value + "</span>");
                                    // sbJobForm.Append("<p style='padding:0px 10px 0px 10px; border-bottom: 1px solid gray; border-left: 1px solid gray; border-right: 1px solid gray; line-height: 2px;'>&nbsp;</p>");
                                    sbJobForm.Append("</td>");
                                    sbJobForm.Append("</tr>");
                                    sbJobForm.Append("</table>");
                                    sbJobForm.Append("</div>");
                                }
                            }
                        }

                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_CHECKBOX)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_CHECKBOX).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {

                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());


                                                sbJobForm.Append("<td align='left' style='width:25%'>");
                                                if (items.Value == "true")
                                                {

                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/checkbox_yes.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='checkbox' name='checked' id='mychk' value='on'/>");
                                                }
                                                else
                                                {
                                                    //sbJobForm.Append("<img src='http://localhost:4100/assets/img/1403875956_ui-check-box.png' alt='logo'  width='20px' height='20px' />");
                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/checkbox_no.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='checkbox' name='checked' id='mychk' value='on'/>");
                                                }
                                                sbJobForm.Append("<span style='color:black;font-size:10px;vertical-align:top'>" + items.ControlLabel + "</span>&nbsp;");
                                                sbJobForm.Append("</td>");

                                            }
                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_MULTITEXT)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left'>");
                                sbJobForm.Append("<tr>");
                                sbJobForm.Append("<td align='left'>");
                                sbJobForm.Append("<label style='font-size:12px;'>" + item1.ControlLabel + "</label>");

                                sbJobForm.Append("<label>:</label>");

                                sbJobForm.Append("<textarea cols='20' rows='2' style='background-color:#FFFFFD;font-size:10px;'>" + item1.Value + "</textarea>");
                                sbJobForm.Append("</td>");
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }
                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_LABEL)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<table style='width:100%' align='left'>");
                                sbJobForm.Append("<tr>");
                                sbJobForm.Append("<td align='left'>");
                                sbJobForm.Append("<label style='font-size:12px;'>" + item1.ControlLabel + "</label>");

                                sbJobForm.Append("<label>:</label>");

                                sbJobForm.Append("<label style='font-size:10px;'>&nbsp;&nbsp;" + item1.Value + "</label>&nbsp;");
                                sbJobForm.Append("</td>");
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");


                                sbJobForm.Append("</div>");
                            }
                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_RADIO_GROUP)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                sbJobForm.Append("<div id='Div' class='leftbar-heading'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;border-bottom:10px;'>" + item1.ControlLabel + "</label>");
                                sbJobForm.Append("<table style='width:100%' align='left' cellpadding='5'>");
                                sbJobForm.Append("<tr>");
                                foreach (var items in JobFormNew.FormValues.Where(one => (one.parentID == item1.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_RADIO_BUTTON)))
                                {
                                    if (!controlIDList.Contains(items.ControlID.ToString()))
                                    {

                                        controlIDList.Add(items.ControlID.ToString());

                                        sbJobForm.Append("<td align='left' style='width:25%'>");
                                        if (items.Value == "true")
                                        {
                                            sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876293_radiobutton_yes.png") + "' alt='logo'  width='20px' height='20px' />");
                                            //sbJobForm.Append("<input type='radio' disabled='disabled' checked />");
                                        }
                                        else
                                        {
                                            // sbJobForm.Append("<input type='radio' disabled='disabled' />");
                                            sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876299_radiobutton_no.png") + "' alt='logo'  width='20px' height='20px' />");
                                        }
                                        sbJobForm.Append("<span style='color:black;border-bottom:10px;;font-size:10px;vertical-align:top;'>" + items.ControlLabel + "</span>&nbsp;");
                                        sbJobForm.Append("</td>");

                                    }
                                }
                                sbJobForm.Append("</tr>");
                                sbJobForm.Append("</table>");
                                sbJobForm.Append("</div>");
                            }
                        }


                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_SWITCH)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                controlIDList.Add(item1.ControlID.ToString());
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.ControlLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_RADIO_BUTTON).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {

                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];

                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());

                                                sbJobForm.Append("<td align='left' style='width:25%'>");
                                                if (items.Value == "true")
                                                {
                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876293_radiobutton_yes.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<img src='http://localhost:4100/assets/img/1403876293_radiobutton_yes.png' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='radio' disabled='disabled' checked></input>");
                                                }
                                                else
                                                {
                                                    sbJobForm.Append("<img src='" + Server.MapPath("~/assets/img/1403876299_radiobutton_no.png") + "' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<img src='http://localhost:4100/assets/img/1403876299_radiobutton_no.png' alt='logo'  width='20px' height='20px' />");
                                                    //sbJobForm.Append("<input type='radio' disabled='disabled'></input>");
                                                }
                                                sbJobForm.Append("<span style='color:black;font-size:10px;vertical-align:top;'>" + items.ControlLabel + "</span>&nbsp;");
                                                sbJobForm.Append("</td>");
                                            }

                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }

                                sbJobForm.Append("<div id='Div'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    if (!parentIDList.Contains(item1.ControlID.ToString()))
                                    {
                                        parentIDList.Add(item1.ControlID.ToString());
                                        sbJobForm.Append("<table style='width:100%' align='left'>");
                                        for (int i = 0; i < FormValues.Count; i = i + 3)
                                        {
                                            sbJobForm.Append("<tr>");
                                            for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                            {
                                                WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                                if (!controlIDList.Contains(items.ControlID.ToString()))
                                                {
                                                    controlIDList.Add(items.ControlID.ToString());


                                                    sbJobForm.Append("<td align='left'>");
                                                    if (!string.IsNullOrEmpty(items.ImagePath) && !string.IsNullOrEmpty(items.Value))
                                                    {
                                                        sbJobForm.Append("<div>");
                                                        sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' alt='logo'  width='120px' height='120px' />");
                                                        Logger.Debug(items.ImagePath + '/' + items.Value);
                                                        //sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' style='width:120px;height:120px;' />");
                                                        sbJobForm.Append("</div>");
                                                    }
                                                    sbJobForm.Append("<span style='color:black;font-size:10px;'>" + items.ControlLabel + "</span>&nbsp;");
                                                    sbJobForm.Append("</td>");

                                                }
                                            }
                                            sbJobForm.Append("</tr>");
                                        }
                                        sbJobForm.Append("</table>");
                                    }
                                }
                                sbJobForm.Append("</div>");

                                sbJobForm.Append("</div>");
                            }
                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {
                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());


                                                sbJobForm.Append("<td align='left'>");
                                                if (!string.IsNullOrEmpty(items.ImagePath) && !string.IsNullOrEmpty(items.Value))
                                                {
                                                    sbJobForm.Append("<div>");
                                                    sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' alt='logo'  width='120px' height='120px' />");
                                                    Logger.Debug(items.ImagePath + '/' + items.Value);
                                                    //sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + " style='width:120px;height:120px;'/>");
                                                    sbJobForm.Append("</div>");
                                                }
                                                sbJobForm.Append("<span style='color:black;font-size:10px;'>" + items.ControlLabel + "</span>&nbsp;");
                                                sbJobForm.Append("</td>");
                                            }
                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE_DESC)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.controlParentLabel + "</label>");

                                FormValues = JobFormNew.FormValues.Where(one => one.parentID == item1.parentID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_IMAGE_DESC).ToList();

                                if (FormValues.Count() > 0)
                                {
                                    sbJobForm.Append("<table style='width:100%' align='left'>");
                                    for (int i = 0; i < FormValues.Count; i = i + 3)
                                    {
                                        sbJobForm.Append("<tr>");
                                        for (int j = i; j < i + 3 && j < FormValues.Count; j++)
                                        {
                                            WorkersInMotion.Model.ViewModel.JobFormValueDetails items = (WorkersInMotion.Model.ViewModel.JobFormValueDetails)FormValues[j];
                                            if (!controlIDList.Contains(items.ControlID.ToString()))
                                            {
                                                controlIDList.Add(items.ControlID.ToString());


                                                sbJobForm.Append("<td align='left'>");
                                                if (!string.IsNullOrEmpty(items.ImagePath) && !string.IsNullOrEmpty(items.Value))
                                                {
                                                    sbJobForm.Append("<div>");

                                                    //string base64String = string.Empty;
                                                    //using (var webClient = new WebClient())
                                                    //{
                                                    //    byte[] imageAsByteArray = webClient.DownloadData(items.ImagePath + '/' + items.Value);
                                                    //    base64String = Convert.ToBase64String(imageAsByteArray, 0, imageAsByteArray.Length);
                                                    //}

                                                    //sbJobForm.Append("<img src='data:image/jpeg;base64," + base64String + "' alt='logo'  width='120' height='120' />");


                                                    sbJobForm.Append("<img src='" + items.ImagePath + '/' + items.Value + "' alt='logo'  width='120px' height='120px' />");
                                                    Logger.Debug(items.ImagePath + '/' + items.Value);
                                                    sbJobForm.Append("</div>");
                                                }
                                                foreach (var item in JobFormNew.FormValues.Where(one => one.parentID == items.ControlID && one.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_EDIT))
                                                {
                                                    if (!controlIDList.Contains(item.ControlID.ToString()))
                                                    {

                                                        controlIDList.Add(item.ControlID.ToString());
                                                        sbJobForm.Append("<span style='color:black;font-size:10px;'>" + item.ControlLabel + "</span>");
                                                    }
                                                }
                                                sbJobForm.Append("&nbsp;");
                                                sbJobForm.Append("</td>");
                                            }
                                        }
                                        sbJobForm.Append("</tr>");
                                    }
                                    sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                            }

                        }
                        else if (item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_ISSUES_TO_REPORT || item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_OPEN_CHARGEBACKS || item1.ControlType == WorkersInMotion.Model.ViewModel.ControlType.CONTROL_TYPE_UNSOLD_QUOTES)
                        {
                            if (!controlIDList.Contains(item1.ControlID.ToString()))
                            {
                                sbJobForm.Append("<div style='padding-top:5px;padding-bottom:5px'>");
                                sbJobForm.Append("<label style='color:black;font-weight:bold;font-size:12px;'>" + item1.ControlLabel + "</label>");


                                sbJobForm.Append("<div id='div_" + item1.ControlID + "'>");
                                if (JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID).ToList().Count > 0)
                                {
                                    foreach (var items in JobFormNew.FormValues.Where(one => one.parentID == item1.ControlID))
                                    {
                                        if (!controlIDList.Contains(items.ControlID.ToString()))
                                        {
                                            controlIDList.Add(items.ControlID.ToString());
                                            sbJobForm.Append("<table style='width:100%' align='left'>");
                                            sbJobForm.Append("<tr>");
                                            sbJobForm.Append("<td align='left' style='width:100px'>");
                                            if (items.currentValueID > 0)
                                            {
                                                sbJobForm.Append("<span style='color:black;font-weight:bold;font-size:10px;'>" + items.Value + "</span>");
                                            }
                                            else
                                            {
                                                sbJobForm.Append("<span style='color:black;font-size:10px;'>" + items.Value + "</span>");
                                            }
                                            sbJobForm.Append("&nbsp;");
                                            sbJobForm.Append("</td>");
                                            sbJobForm.Append("</tr>");
                                            sbJobForm.Append("</table>");
                                        }
                                    }
                                }
                                else
                                {
                                    //sbJobForm.Append("<table style='width:100%' align='left'>");
                                    //sbJobForm.Append("<tr>");
                                    sbJobForm.Append("<div align='left' style='width:100px;font-size:10px;'>None</div>");
                                    //sbJobForm.Append("<tr>");
                                    //sbJobForm.Append("</table>");
                                }
                                sbJobForm.Append("</div>");
                                sbJobForm.Append("</div>");
                            }
                        }

                    }
                }
                sbJobForm.Append("</div>");

                #endregion
                string marker = string.Empty;
                if (JobFormNew != null && JobFormNew.CoordinateList != null && JobFormNew.CoordinateList.Count > 0)
                {

                    int i = 0;
                    string address = string.Empty;
                    foreach (CoOrdinates items in JobFormNew.CoordinateList)
                    {
                        i++;
                        if (i == JobFormNew.CoordinateList.Count)
                        {
                            if (!string.IsNullOrEmpty(items.EndTime))
                                marker = marker + "markers=size:small%7Ccolor:0xcc0000%7C" + items.Latitude + "," + items.Longitude;
                            else if (!string.IsNullOrEmpty(items.StartTime))
                                marker = marker + "markers=size:mid%7Ccolor:0x33d100%7C" + items.Latitude + "," + items.Longitude;
                            else if (!string.IsNullOrEmpty(items.StoreName))
                                marker = marker + "markers=color:0xff6600%7C" + items.Latitude + "," + items.Longitude;
                        }
                        else
                        {

                            if (!string.IsNullOrEmpty(items.EndTime))
                                marker = marker + "markers=size:small%7Ccolor:0xcc0000%7C" + items.Latitude + "," + items.Longitude + "&";
                            else if (!string.IsNullOrEmpty(items.StartTime))
                                marker = marker + "markers=size:mid%7Ccolor:0x33d100%7C" + items.Latitude + "," + items.Longitude + "&";
                            else if (!string.IsNullOrEmpty(items.StoreName))
                                marker = marker + "markers=color:0xff6600%7C" + items.Latitude + "," + items.Longitude + "&";


                        }
                        if (!string.IsNullOrEmpty(items.City))
                        {
                            address = address + "+" + items.City;
                        }
                        if (!string.IsNullOrEmpty(items.State))
                        {
                            address = address + "+" + items.State;
                        }
                        if (!string.IsNullOrEmpty(items.Country))
                        {
                            address = address + "+" + items.Country;
                        }
                        //markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284

                    }
                    sbJobForm.Append("<div style='page-break-before:always'>");
                    sbJobForm.Append("<img src='http://maps.googleapis.com/maps/api/staticmap?center=" + address + "&zoom=10&size=1000x1000&maptype=roadmap&" + marker + "'></img>");
                    sbJobForm.Append("</div>");
                }

                sbJobForm.Append("</body>");
                sbJobForm.Append("</html>");
                return sbJobForm.ToString();
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return "";
            }
        }
示例#17
0
        public static response_item_type[] FillForm(pdf_stamper_request request,string mapping_root_path,string template_root_path, string output_root_path, DataTable data, string fonts_root_path, bool force_unc) {
            lock (_lock) {
                try {

                    List<Item> items_with_path = new List<Item>();
                    mappings mapping = new mappings();
                    if (File.Exists(mapping_root_path))
                        mapping = File.ReadAllText(mapping_root_path).DeserializeXml2<mappings>();

                    FileInfo mapping_path  = new FileInfo(mapping_root_path);
                    /*
                    string fox_helper_path = Path.Combine(mapping_path.DirectoryName, "Fox.txt");
                    if (!File.Exists(fox_helper_path)) {
                        StringBuilder b = new StringBuilder();
                        b.Append(@"
DIMENSION laArray[30,2]
laArray[1,1] = 'Obrazac1'
laArray[2,1] = 'Obrazac2'
laArray[3,1] = 'Obrazac3'
laArray[4,1] = 'Obrazac4'
laArray[5,1] = 'Obrazac5'
laArray[6,1] = 'Obrazac6'
laArray[7,1] = 'Obrazac7'
laArray[8,1] = 'Obrazac8'
laArray[9,1] = 'Obrazac9'
laArray[10,1] ='Obrazac10'
laArray[11,1] = 'Obrazac11'
laArray[12,1] = 'Obrazac12'
laArray[13,1] = 'Obrazac13'
laArray[14,1] = 'Obrazac14'
laArray[15,1] = 'Obrazac15'
laArray[16,1] = 'Obrazac16'
laArray[17,1] = 'Obrazac17'
laArray[18,1] = 'Obrazac18'
laArray[19,1] = 'Obrazac19'
laArray[20,1] ='Obrazac20'
laArray[21,1] = 'Obrazac21'
laArray[22,1] = 'Obrazac22'
laArray[23,1] = 'Obrazac23'
laArray[24,1] = 'Obrazac24'
laArray[25,1] = 'Obrazac25'
laArray[26,1] = 'Obrazac26'
laArray[27,1] = 'Obrazac27'
laArray[28,1] = 'Obrazac28'
laArray[29,1] = 'Obrazac29'
laArray[30,1] ='Obrazac30'
");
                        int current_index = -1;
                        foreach (var item in mapping.mapping_item) {
                            current_index = Int32.Parse(item.pdf_template.ToString().Replace("Obrazac", ""));
                            string source_document_path = item.file_path.Replace("@root", template_root_path);
                            FileInfo info = new FileInfo(source_document_path);
                            string value = string.Format("laArray[{0},2] = '{1}'", current_index, info.Name.Replace(info.Extension,String.Empty));
                            b.AppendLine(value);                            
                        }
                        File.WriteAllText(fox_helper_path,b.ToString());     
                     
                    }
                    */
                    if (data.Rows.Count == 0) {
                        Logging.Singleton.WriteDebug("There is no data in the provided data table!");

                        foreach (var template in request.pdf_template_list) {
                            mapping_item_type selected = mapping.mapping_item.Where(p => p.pdf_template == template).First();

                            string source_document_path = selected.file_path.Replace("@root", template_root_path);
                            items_with_path.Add(new Item() { Path = source_document_path, PdfTemplate = template });
                        }
                        if (request.merge_output == true) {
                            string merged_document_path = Path.Combine(output_root_path, String.Format("{0}_{1}{2}", "merged", DateTime.Now.ToFileTimeUtc().ToString(), ".pdf"));

                            PdfMerge merge = new PdfMerge();
                            foreach (var item in items_with_path) {
                                merge.AddDocument(item.Path);
                            }
                            merge.EnablePagination = false;
                            merge.Merge(merged_document_path);
                            string result = Convert.ToBase64String(File.ReadAllBytes(merged_document_path));
                            return new response_item_type[] { new response_item_type() { pdf_template = template.MergedContent, data = force_unc? string.Empty : result, unc_path=merged_document_path } };
                        }
                        else {
                            List<response_item_type> items = new List<response_item_type>();
                            foreach (var item in items_with_path) {
                                var temp = new response_item_type() { pdf_template = item.PdfTemplate, data = force_unc ? string.Empty : Convert.ToBase64String(File.ReadAllBytes(item.Path)), unc_path = item.Path };
                                items.Add(temp);
                            }
                            return items.ToArray();
                        }
                    }
                    else {

                        DataRow row = data.Rows[0];
                        string id_pog = string.Empty;
                        if (data.Columns.Contains("id_pog"))
                            id_pog = row["id_pog"].ToString();

                        if (request.debug_mode) {
                            foreach (DataColumn column in data.Columns) {
                                Logging.Singleton.WriteDebugFormat("Data column [{0}] has a value [{1}]", column.ToString(), row[column].ToString());
                            }
                        }

                        foreach (var template in request.pdf_template_list) {
                            mapping_item_type selected = mapping.mapping_item.Where(p => p.pdf_template == template).First();

                            string source_document_path = selected.file_path.Replace("@root", template_root_path);
                            FileInfo f = new FileInfo(source_document_path);

                            string destination_document_path = Path.Combine(output_root_path,
                                String.Format("{0}_{1}_{2}{3}",
                                id_pog.Replace("/","-").Trim(),
                                f.Name.Replace(f.Extension, ""),
                                DateTime.Now.ToFileTimeUtc().ToString(),
                                f.Extension)
                                );

                            items_with_path.Add(new Item() { Path = destination_document_path, PdfTemplate = template });

                            PdfReader reader = new PdfReader(source_document_path);
                            using (PdfStamper stamper = new PdfStamper(reader, new FileStream(destination_document_path, FileMode.Create))) {
                                AcroFields fields = stamper.AcroFields;


                                //Full path to the Unicode Arial file
                                //string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");

                                //Create a base font object making sure to specify IDENTITY-H
                                //BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                                //Create a specific font object
                                //Font f = new Font(bf, 12, Font.NORMAL);
                                iTextSharp.text.pdf.BaseFont baseFont  = iTextSharp.text.pdf.BaseFont.CreateFont(Path.Combine(fonts_root_path,"arial.ttf"),"Windows-1250", true);

                                fields.AddSubstitutionFont(baseFont);
                                if (request.debug_mode) {
                                    foreach (var key in fields.Fields.Keys) {
                                        Logging.Singleton.WriteDebugFormat("Pdf field [{0}]. Data type [{1}]", key, fields.GetFieldType(key));
                                    }
                                }

                                foreach (var key in fields.Fields.Keys) {

                                    var items = selected.mapping.Where(p => p.data_field == key);
                                    if (items.Count() == 1) {
                                        var item = items.First();
                                        if (item.column_name == UNKNOWN)
                                            continue;
                                        if (data.Columns.Contains(item.column_name)) {
                                            string value = row[item.column_name].ToString();

                                            if (item.field_type == data_field_type.CheckBox) {
                                                int int_value = 0;
                                                bool boolean_value = false;
                                                if(Int32.TryParse(value, out int_value))
                                                {
                                                    value = int_value == 0? "No" : "Yes";
                                                }
                                                else if (Boolean.TryParse(value, out boolean_value))
                                                {
                                                    value = boolean_value == false? "No" : "Yes";
                                                }
                                                else
                                                {
                                                    throw new NotImplementedException(string.Format("Invalid Value [{0}] was provided for Check box type field!", value));
                                                }
                                            }
                                            fields.SetField(key, value);
                                        }
                                        else {
                                            Logging.Singleton.WriteDebugFormat("Column {0} does not belong to table {1}! Check your mappings for template {2}", item.column_name, data.TableName, template);
                                        }
                                    }
                                    else if (items.Count() == 0) {

                                        var current = selected.mapping.ToList();

                                        data_field_type field_type = data_field_type.Text;
                                        if (key.Contains("Check"))
                                            field_type = data_field_type.CheckBox;
                                        else if (key.Contains("Radio"))
                                            field_type = data_field_type.RadioButton;

                                        current.Add(new mapping_type() { column_name = UNKNOWN, data_field = key, field_type = field_type });

                                        selected.mapping = current.ToArray();

                                        File.WriteAllText(mapping_root_path, mapping.SerializeXml());
                                    }
                                    else {
                                        throw new NotImplementedException();
                                    }
                                }
                                // flatten form fields and close document
                                if (request.read_only || (request.merge_output && request.pdf_template_list.Length > 1)) {
                                    Logging.Singleton.WriteDebugFormat("Form flattening requested... Read only {0}, Merge output {1}, Template list count {2}", request.read_only, request.merge_output, request.pdf_template_list.Length);
                                    stamper.FormFlattening = true;
                                }

                                stamper.Close();
                            }
                        }
                        if (items_with_path.Count() == 1) {
                            string path = items_with_path.First().Path;
                            var bytes = File.ReadAllBytes(path);
                            string result = Convert.ToBase64String(bytes);
                            Logging.Singleton.WriteDebugFormat("Response lenght is {0} bytes", bytes.Length);
                            return new response_item_type[] { new response_item_type() { pdf_template = items_with_path.First().PdfTemplate, data = force_unc ? string.Empty : result, unc_path = path } };
                            //return new response_item_type[] { new response_item_type() { pdf_template = items_with_path.First().PdfTemplate, data = Convert.ToBase64String(new byte[] {1,2,3,4,5,6,7,8,9}) } };
                        }
                        else {
                            if (request.merge_output == true) {
                                string merged_document_path = Path.Combine(output_root_path, String.Format("{0}_{1}{2}{3}", id_pog.Replace("/","-").Trim(), "merged", DateTime.Now.ToFileTimeUtc().ToString(), ".pdf"));

                                //List<string> file_names = new List<string>();
                                //foreach (var item in items_with_path) {
                                //    file_names.Add(item.Path);
                                //}
                                //var path = MergePdfForms(file_names, merged_document_path);

                                PdfMerge merge = new PdfMerge();
                                foreach (var item in items_with_path) {
                                    merge.AddDocument(item.Path);
                                }



                                merge.EnablePagination = false;
                                merge.Merge(merged_document_path);
                                //using (FileStream file = new FileStream(merged_document_path, FileMode.Create, System.IO.FileAccess.Write)) {
                                //    byte[] bytes = new byte[stream.Length];
                                //    stream.Read(bytes, 0, (int)stream.Length);
                                //    file.Write(bytes, 0, bytes.Length);
                                //    stream.Close();
                                //}

                                var bytes = File.ReadAllBytes(merged_document_path);
                                string result = Convert.ToBase64String(bytes);
                                Logging.Singleton.WriteDebugFormat("Response lenght is {0} bytes", bytes.Length);
                                return new response_item_type[] { new response_item_type() { pdf_template = template.MergedContent, data = force_unc ? string.Empty : result, unc_path = merged_document_path } };
                            }
                            else {
                                List<response_item_type> items = new List<response_item_type>();
                                foreach (var item in items_with_path) {
                                    var bytes = File.ReadAllBytes(item.Path);
                                    string result = Convert.ToBase64String(bytes);
                                    Logging.Singleton.WriteDebugFormat("Response lenght is {0} bytes", bytes.Length);
                                    var temp = new response_item_type() { pdf_template = item.PdfTemplate, data = force_unc ? string.Empty : result, unc_path = item.Path };
                                    //var temp = new response_item_type() { pdf_template = item.PdfTemplate, data = Convert.ToBase64String(new byte[] {1,2,3,4,5,6,7,8,9}) };
                                    items.Add(temp);
                                }

                                return items.ToArray();
                            }
                        }
                    }                    
                }
                catch (Exception ex) {
                    string message = Logging.CreateExceptionMessage(ex);
                    Logging.Singleton.WriteDebug(message);
                    return null;
                }
            }
        }
        List<GridViewModel> GetInterpolationsList()
        {
            try
            {
                int customer = 0;
                int farm = 0;

                if (cbSearchCustomers.SelectedIndex >= 0)
                {
                    customer = Convert.ToInt32(cbSearchCustomers.SelectedValue);
                }

                if (cbFarm.SelectedIndex >= 0)
                {
                    farm = Convert.ToInt32(cbFarm.SelectedValue);
                }

                var result = new List<GridViewModel>();

                foreach (var item in _farmRepository.FilterFarms(customer, farm, dateTimePicker1.Value, dateTimePicker2.Value))
                {
                    if (item.Interpolations != null)
                    {
                        item.Interpolations.ToList().ForEach(c =>
                        {
                            result.Add(new GridViewModel
                            {
                                ID = c.CustomerInterpolationId,
                                FarmId = c.CustomerFarmId,
                                Farm = item.Name,
                                Customer = item.Customer != null ? item.Customer.Name : string.Empty,
                                Name = c.Name,
                                ProjectFile = c.ProjectFiles,
                                Date = c.Created,
                                isChecked = false
                            });
                        });
                    }
                }

                if (result.Count() > 0 && !string.IsNullOrEmpty(txtSearchInterpolationName.Text))
                {
                    result = result.Where(c => c.Name.Contains(txtSearchInterpolationName.Text)).ToList();
                }

                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }