示例#1
0
        public ActionResult PrintToPdf(int id)
        {
            payfee payfee = db.payfees.Find(id);

            Document doc = new Document(PageSize.A5);

            // Set the document to write to memory.
            MemoryStream memStream = new MemoryStream();
            PdfWriter    writer    = PdfWriter.GetInstance(doc, memStream);

            writer.CloseStream = false;
            doc.Open();

            // string html = ControllerExtensions.RenderPartialViewToString(this, "Print", payfee);
            string html = ControllerExtensions.RenderPartialToString2("Print", payfee, this.ControllerContext);

            var dir  = Server.MapPath("/Content");
            var path = Path.Combine(dir, "banner_" + payfee.student.dept.college.collegeCode + ".gif");

            Image pic = Image.GetInstance(path);

            //  iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(path);

            pic.ScalePercent(76f);
            doc.Add(pic);

            StringReader str = new StringReader(html);

            XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, str);

            if (doc.IsOpen())
            {
                doc.Close();
            }

            return(new FileContentResult(memStream.ToArray(), "application/pdf"));
        }
示例#2
0
        public ActionResult exportGridToExcel(string sidx,
                                              string sord,
                                              int?page,
                                              int?rows,
                                              string HTNo,
                                              string Name,
                                              string Batchid,
                                              string feetypeid,
                                              string acayearid,
                                              string Quota,
                                              string Caste,
                                              string Dept,
                                              string Sem,
                                              DateTime?Time1,
                                              DateTime?Time2)
        {
            if (sidx == null)
            {
                sidx = "Time";
            }
            if (sord == null)
            {
                sord = "asc";
            }
            if (!page.HasValue)
            {
                page = 1;
            }
            if (!rows.HasValue)
            {
                rows = 10;
            }


            var concessions = db.concessions.Where(s =>
                                                   s.student.htno.Contains(HTNo) &&
                                                   s.student.name.Contains(Name) &&
                                                   //s.student.quota.name.Contains(Quota) &&
                                                   //s.student.caste.name.Contains(Caste) &&
                                                   s.student.dept.name.Contains(Dept) &&
                                                   s.student.sem.name.Contains(Sem));

            if (Quota != null && Quota != "null")
            {
                var Quotas = Quota.Split(',');
                for (int i = 0; i < Quotas.Count(); i++)
                {
                    Quotas[i] = "student.quotaid==" + Quotas[i];
                }

                string where = String.Join(" || ", Quotas);

                concessions = concessions.Where(where);
            }

            if (feetypeid != null && feetypeid != "null")
            {
                var feetypeids = feetypeid.Split(',');
                for (int i = 0; i < feetypeids.Count(); i++)
                {
                    feetypeids[i] = "feeTypeid==" + feetypeids[i];
                }

                string where = String.Join(" || ", feetypeids);

                concessions = concessions.Where(where);
            }

            if (acayearid != null && acayearid != "null")
            {
                var acayearids = acayearid.Split(',');
                for (int i = 0; i < acayearids.Count(); i++)
                {
                    acayearids[i] = "acaYearid==" + acayearids[i];
                }

                string where = String.Join(" || ", acayearids);

                concessions = concessions.Where(where);
            }

            if (Batchid != null && Batchid != "null")
            {
                var Batchids = Batchid.Split(',');

                for (int i = 0; i < Batchids.Count(); i++)
                {
                    Batchids[i] = "student.batchid==" + Batchids[i];
                }

                string where = String.Join(" || ", Batchids);
                concessions  = concessions.Where(where);
            }

            if (Time1.HasValue)
            {
                concessions = concessions.Where(s => s.time.CompareTo(Time1) >= 0);
            }
            if (Time2.HasValue)
            {
                concessions = concessions.Where(s => s.time.CompareTo(Time2) <= 0);
            }

            int pageIndex    = Convert.ToInt32(page) - 1;
            int pageSize     = Convert.ToInt32(rows);
            int totalRecords = concessions.Count();//articleList.Count();
            int totalPages   = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            var concessions1 = concessions.AsQueryable().OrderByDescending(p => p.time).Skip(pageIndex * pageSize).Take(pageSize).ToList();

            string html = ControllerExtensions.RenderPartialToString2("exportGridToExcel", concessions1, this.ControllerContext);

            MemoryStream memStream = new MemoryStream();
            TextWriter   writer    = new StreamWriter(memStream);

            try
            {
                writer.Write(html);
            }
            catch (Exception e)
            {
            }
            finally
            {
                writer.Close();
            }
            return(File(memStream.ToArray(), "application/ms-excel", "ConcessionsList.xls"));
        }