Ejemplo n.º 1
0
        public bool EditPostReport(ReportVM r)
        {
            r.ModifiedBy   = 1;
            r.ModifiedDate = DateTime.Now;
            bool flag = false;

            if (r.ReportUrl == null)
            {
                r.ReportUrl = ModernMarketResearch.Areas.Admin.Models.Common.GenerateSlug(r.ReportTitle) + "-" + r.ReportId;
            }

            if (IsSameReportData(r))
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var          report             = serializer.Serialize(r);
                ReportMaster repo = serializer.Deserialize <ReportMaster>(report);
                db.Entry(repo).State = EntityState.Modified;
                db.SaveChanges();
                flag = true;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 2
0
        public bool EditPostReport(ReportVM r)
        {
            r.ModifiedBy   = 1;
            r.ModifiedDate = DateTime.Now;
            bool flag = false;

            if (r.ReportUrl == null)
            {
                r.ReportUrl = ExcellentMarketResearch.Areas.Admin.Models.Common.GenerateSlug(r.ReportTitle) + "-" + r.ReportId;
            }

            if (IsSameReportData(r))
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                var          report             = serializer.Serialize(r);
                ReportMaster repo = serializer.Deserialize <ReportMaster>(report);
                repo.LongDescritpion      = r.FullDescription;
                repo.SinglePrice          = r.PriceSingleUser;
                repo.MultiUserPrice       = r.PriceMultiUser;
                repo.CorporateUserPrice   = r.PriceCUL;
                repo.NumberOfPages        = r.NumberOfPage;
                repo.PublishereId         = r.PublisherId;
                repo.ReportDeliveryTypeId = r.DeliveryTypeId;
                db.Entry(repo).State      = EntityState.Modified;
                db.SaveChanges();
                flag = true;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            ReportMaster reportMaster = db.ReportMasters.Find(id);

            db.ReportMasters.Remove(reportMaster);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        public XDocument GetReport(long masterreportId, List <ReportXMLPrintParameterModel> filters)
        {
            this.masterReport_Id = masterreportId;

            this.repo = new BuildReportRepository();

            XDocument result = this.repo.GetReportXml(this.masterReport_Id);

            ReportMaster reportMaster = this.repo.GetReportMaster(this.masterReport_Id);

            return(this.GetReport(result, null, reportMaster, filters));
        }
Ejemplo n.º 5
0
        public ReportMaster GetReportMasterData(int reportID)
        {
            ReportMaster reportMaster  = new ReportMaster();
            var          tmpReportData = dbContext.GetReportMasterData(reportID);

            reportMaster = (from m in tmpReportData
                            select new ReportMaster
            {
                ReportID = m.reportID,
                ReportDatasetName = m.rptDataSetName
            }).FirstOrDefault();
            return(reportMaster);
        }
        public ReportMasterModel GetReportMasterByPrimaryKey(Int64 MasterReport_Id)
        {
            ReportMaster result = this.dataContext
                                  .ReportsMaster
                                  .FirstOrDefault(pk => pk.MasterReport_Id == MasterReport_Id);

            if (result == null)
            {
                return(null);
            }

            return(result.CopyToObject(new ReportMasterModel()) as ReportMasterModel);
        }
Ejemplo n.º 7
0
        // GET: Business/ReportMasters/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ReportMaster reportMaster = db.ReportMasters.Find(id);

            if (reportMaster == null)
            {
                return(HttpNotFound());
            }
            return(View(reportMaster));
        }
Ejemplo n.º 8
0
        public void InsertReport(ReportVM r)
        {
            r.CreatedBy   = 1;
            r.CreatedDate = DateTime.Now;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var          s  = serializer.Serialize(r);
            ReportMaster re = serializer.Deserialize <ReportMaster>(s);

            db.ReportMasters.Add(re);
            db.SaveChanges();
            re.ReportUrl       = re.ReportUrl + "-" + re.ReportId;
            db.Entry(re).State = EntityState.Modified;
            db.SaveChanges();
        }
Ejemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "Id,BusinessId,ServiceId,ProviderId,PracticeId,RepId,CreatedOn,CreatedBy,UpdatedOn,UpdatedBy")] ReportMaster reportMaster)
 {
     if (ModelState.IsValid)
     {
         reportMaster.UpdatedBy       = CurrentUserId;
         reportMaster.UpdatedOn       = System.DateTime.UtcNow;
         db.Entry(reportMaster).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ServiceId  = new SelectList(db.LookupEnrolledServices.Where(a => a.BusinessId == CurrentBusinessId), "Id", "ServiceName", reportMaster.ServiceId);
     ViewBag.PracticeId = new SelectList(db.Practices, "Id", "PracticeName", reportMaster.PracticeId);
     ViewBag.ProviderId = new SelectList(db.Providers, "Id", "FirstName", reportMaster.ProviderId);
     ViewBag.RepId      = new SelectList(db.Users.Where(a => a.BusinessId == CurrentBusinessId && a.IsActive == true), "Id", "FirstName", reportMaster.RepId);
     return(View(reportMaster));
 }
Ejemplo n.º 10
0
        // GET: Business/ReportMasters/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ReportMaster reportMaster = db.ReportMasters.Find(id);

            if (reportMaster == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ServiceId  = new SelectList(db.LookupEnrolledServices.Where(a => a.BusinessId == CurrentBusinessId), "Id", "ServiceName", reportMaster.ServiceId);
            ViewBag.PracticeId = new SelectList(db.Practices, "Id", "PracticeName", reportMaster.PracticeId);
            ViewBag.ProviderId = new SelectList(db.Providers, "Id", "FirstName", reportMaster.ProviderId);
            ViewBag.RepId      = new SelectList(db.Users.Where(a => a.BusinessId == CurrentBusinessId && a.IsActive == true), "Id", "FirstName", reportMaster.RepId);
            return(View(reportMaster));
        }
        public void UpdateReportMaster(ReportMasterModel model)
        {
            ReportMaster existing = this.dataContext
                                    .ReportsMaster
                                    .Where(rx => rx.MasterReport_Id == model.MasterReport_Id)
                                    .FirstOrDefault();

            if (existing == null)
            {
                existing = model.CopyToObject(new ReportMaster()) as ReportMaster;

                this.dataContext.ReportsMaster.Add(existing);
            }
            else
            {
                existing = model.CopyToObject(existing) as ReportMaster;
            }

            this.dataContext.SaveChanges();

            model = existing.CopyToObject(model) as ReportMasterModel;
        }
Ejemplo n.º 12
0
        public void InsertReport(ReportVM r)
        {
            r.CreatedBy   = 1;
            r.CreatedDate = DateTime.Now;

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var          s  = serializer.Serialize(r);
            ReportMaster re = serializer.Deserialize <ReportMaster>(s);

            re.LongDescritpion      = r.FullDescription;
            re.SinglePrice          = r.PriceSingleUser;
            re.MultiUserPrice       = r.PriceMultiUser;
            re.CorporateUserPrice   = r.PriceCUL;
            re.NumberOfPages        = r.NumberOfPage;
            re.PublishereId         = r.PublisherId;
            re.ReportDeliveryTypeId = r.DeliveryTypeId;
            db.ReportMasters.Add(re);
            db.SaveChanges();
            re.ReportUrl       = re.ReportUrl + "-" + re.ReportId;
            db.Entry(re).State = EntityState.Modified;
            db.SaveChanges();
        }
Ejemplo n.º 13
0
        public void CreateReport(DataSet ds)
        {
            DataTable           dtReport   = CreateDataSet();
            DataSet             dsReport   = new DataSet();
            ReportMaster        r          = new ReportMaster();
            List <ReportMaster> reportlist = new List <ReportMaster>();

            string HTMLTable = "<table border='1'>";

            for (int tables = 0; tables < ds.Tables.Count; tables++)
            {
                #region rowdata
                for (int rows = 0; rows < ds.Tables[tables].Rows.Count; rows++)
                {
                    int      _SerialNumber;
                    int      SerialNumber = 0;
                    int      _CategoryID;
                    int      _PublisherID;
                    int      _DeliveryFormatID;
                    DateTime _PublishedDate;
                    int      _NumberOfPages;
                    Decimal  _SingleUserPrice;
                    Decimal  _MultiUserPrice;
                    Decimal  _CorporateUserPrice;
                    bool     IsVaidate       = true;
                    string   Message         = "";
                    string   ReportTitleTemp = string.Empty;

                    for (int columns = 0; columns < ds.Tables[tables].Columns.Count; columns++)
                    {
                        if (ds.Tables[tables].Columns[columns].ToString() == "Serial Number")
                        {
                            if (Int32.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _SerialNumber))
                            {
                                SerialNumber = _SerialNumber;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Serial Number<br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Category ID")
                        {
                            if (Int32.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _CategoryID))
                            {
                                r.CategoryId = _CategoryID;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Category ID <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Publisher ID")
                        {
                            if (Int32.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _PublisherID))
                            {
                                r.PublishereId = _PublisherID;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Publisher ID <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Delivery Format ID")
                        {
                            if (Int32.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _DeliveryFormatID))
                            {
                                r.ReportDeliveryTypeId = _DeliveryFormatID;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Delivery Format ID <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Title")
                        {
                            ReportTitleTemp = Convert.ToString(ds.Tables[tables].Rows[rows][columns].ToString().Trim());
                            if (db.ReportMasters.Count(g => g.ReportTitle == ReportTitleTemp) > 0 ? true : false)

                            {
                                IsVaidate = false; Message += "Title <br />";
                            }
                            else
                            {
                                r.ReportTitle = ds.Tables[tables].Rows[rows][columns].ToString().Trim().Replace("   ", " ").Replace("  ", " ").Replace("  ", " ");
                            }

                            r.ReportUrl = ExcellentMarketResearch.Areas.Admin.Models.Common.GenerateSlug(ds.Tables[tables].Rows[rows][columns].ToString().Trim());

                            if (db.ReportMasters.Count(url => url.ReportUrl == r.ReportUrl.ToLower()) > 0 ? true : false)
                            {
                                r.ReportUrl = ""; IsVaidate = false; Message += "Long URL <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Published Date")
                        {
                            if (DateTime.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _PublishedDate))
                            {
                                r.PublishingDate = _PublishedDate;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Published Date <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Number Of Pages")
                        {
                            if (Int32.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _NumberOfPages))
                            {
                                r.NumberOfPages = _NumberOfPages;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Number Of Pages <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Long Description")
                        {
                            if (ds.Tables[tables].Rows[rows][columns].ToString().Trim() != "")
                            {
                                r.LongDescritpion = "<pre>" + ds.Tables[tables].Rows[rows][columns].ToString().Trim() + "</pre>";
                            }
                            else
                            {
                                IsVaidate = false; Message += "Long Description \n";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Long Table Of Content")
                        {
                            r.TableOfContent = "<pre>" + ds.Tables[tables].Rows[rows][columns].ToString().Trim() + "</pre>";
                        }

                        else if (ds.Tables[tables].Columns[columns].ToString() == "Single User Price")
                        {
                            if (Decimal.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim() == "" ? "0" : ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _SingleUserPrice))
                            {
                                r.SinglePrice = _SingleUserPrice;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Single User Price <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Multi User Price")
                        {
                            if (Decimal.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim() == "" ? "0" : ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _MultiUserPrice))
                            {
                                r.MultiUserPrice = _MultiUserPrice;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Multi User Price <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Corporate User Price")
                        {
                            if (Decimal.TryParse(ds.Tables[tables].Rows[rows][columns].ToString().Trim() == "" ? "0" : ds.Tables[tables].Rows[rows][columns].ToString().Trim(), out _CorporateUserPrice))
                            {
                                r.CorporateUserPrice = _CorporateUserPrice;
                            }
                            else
                            {
                                IsVaidate = false; Message += "Corporate User Price <br />";
                            }
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Meta Title")
                        {
                            r.MetaTitle = ds.Tables[tables].Rows[rows][columns].ToString().Trim();
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Meta Description")
                        {
                            r.MetaDescription = ds.Tables[tables].Rows[rows][columns].ToString().Trim();
                        }
                        else if (ds.Tables[tables].Columns[columns].ToString() == "Meta Keywords")
                        {
                            r.Keywords = ds.Tables[tables].Rows[rows][columns].ToString().Trim();
                        }
                    }

                    if (r.SinglePrice <= 0 && r.MultiUserPrice <= 0 && r.CorporateUserPrice <= 0)
                    {
                        IsVaidate = false; Message += "Add Atleast one Price <br />";
                    }

                    //Save data in Database.
                    if (IsVaidate)
                    {
                        r.ReportImage = null;
                        //  r.ListOfCharts = null;
                        //  r.FreeAnalysis = null;
                        //   r.Summary = "null";
                        //   r.Methodology = null;

                        // r.DiscountPrice = 0;
                        r.IsActive = true;
                        // r.IsUpcomming = true;
                        r.ReportTypeId = r.ReportDeliveryTypeId;
                        r.CreatedBy    = 1;//Convert.ToInt32(QYGroupRepository.Areas.Admin.Models.CommonCode.MySession());
                        r.CreatedDate  = DateTime.Now;
                        reportlist.Add(r);
                        db.ReportMasters.Add(r);
                        db.SaveChanges();
                        var repturl = r.ReportUrl + ".html";
                        r.ReportUrl       = repturl;
                        db.Entry(r).State = EntityState.Modified;
                        db.SaveChanges();

                        //PriceMaster p = new PriceMaster();

                        //p.PriceType = "Single User Price ";
                        //p.Price = r.PriceSingleUser;
                        //db.PriceMasters.Add(p);
                        //db.SaveChanges();

                        //p.PriceType = "Multi User Price ";
                        //p.Price = r.PriceMultiUser;
                        //db.PriceMasters.Add(p);
                        //db.SaveChanges();

                        //p.PriceType = "Corporate User Price ";
                        //p.Price = r.PriceCUL;
                        //db.PriceMasters.Add(p);
                        //db.SaveChanges();

                        Message += "Inserted <br/>";
                    }
                    HTMLTable += "<tr><td>" + SerialNumber + "</td><td>" + ReportTitleTemp + "</td><td>" + r.ReportUrl + "</td><td>" + Message + "</td></tr>";
                }
                HTMLTable += "</table>";

                ViewData.Add("HTMLTable", HTMLTable);
                #endregion rows
            }
            //return View();
        }
Ejemplo n.º 14
0
        public XDocument GetReport(
            XDocument xmlReport,
            DatabaseModel connection,
            ReportMaster reportMaster,
            List <ReportXMLPrintParameterModel> filters)
        {
            if (filters.Count > 0 && filters.Any(p => p.IsRequired.IsTrue() && p.FilterValue.IsNullEmptyOrWhiteSpace()))
            {
                throw new ApplicationException("One or more required filters was not passed with a value. Report Print canceled.");
            }

            if (this.repo == null)
            {
                this.repo = new BuildReportRepository();
            }

            if (filters.Count == 0)
            {
                this.tableFilters = new Dictionary <string, List <ReportXMLPrintParameterModel> >();
            }
            else
            {
                this.tableFilters = filters
                                    .GroupBy(g => g.TableName)
                                    .ToDictionary(t => t.Key, c => c.ToList());
            }

            this.dataAccessConnection = connection;

            Dictionary <string, XElement[]> sqlOrderBy = xmlReport
                                                         .Root
                                                         .Descendants("ReportObject")
                                                         .Where(ro => ro.IsDataObject() && ro.Attribute("UseInOrderBy").Value == "true")
                                                         .GroupBy(tn => tn.Attribute("ObjectTable").Value)
                                                         .ToDictionary(td => td.Key, td => td.ToArray());

            Dictionary <string, string> orderByDictionary = new Dictionary <string, string>();

            foreach (KeyValuePair <string, XElement[]> orderKey in sqlOrderBy)
            {
                string[] orderString = orderKey.Value
                                       .Select(x => x.Attribute("ObjectColumn").Value)
                                       .ToArray();

                this.orderByDictionary.Add(orderKey.Key, orderString.Concatenate(","));
            }

            string reportTypeValue = xmlReport.Root.Element("ReportSettings").Attribute("ReportTypeEnum").Value;

            #region BUILD REPORT DATA

            ReportTypeEnum reportType = (ReportTypeEnum)reportTypeValue.ToInt32();

            if (reportType == ReportTypeEnum.ReportContent)
            {
                this.CreateConnectionObject();

                XElement dataNode = new XElement("ReportData");

                this.dataSections = xmlReport.Root
                                    .Descendants("ReportSection")
                                    .Where(st => st.Attribute("SectionType").Value == "5") // SectionTypeEnum.TableData
                                    .ToDictionary(d => d.Attribute("SectionIndex").Value.ToInt32());

                this.sectionIndex = 1;

                this.DoSectionSetup();

                this.BuildReportData(dataNode);

                xmlReport.Root.Add(dataNode);
            }

            #endregion

            foreach (XElement reportSum in xmlReport.Root.Descendants().Where(a => a.Attribute("ObjectType") != null &&
                                                                              a.Attribute("ObjectType").Value == "ReportSum"))
            {
                int parentSetionGroupIndex = reportSum.Attribute("ParentSectionGroupIndex").Value.ToInt32();

                int sectionGroupIndex = reportSum.Attribute("SectionGroupIndex").Value.ToInt32();

                string sumColumn = reportSum.Attribute("SumColumn").Value;

                if (sumColumn.IsNullEmptyOrWhiteSpace())
                {                   // The user did not perfom a full setup
                    continue;
                }

                foreach (XElement tableRow in xmlReport.Root
                         .Element("ReportData")
                         .Descendants()
                         .Where(pg => pg.Attribute("SectionGroupIndex") != null &&
                                pg.Attribute("SectionGroupIndex").Value.ToInt32() == parentSetionGroupIndex))
                {
                    IEnumerable <XElement> sumItems = parentSetionGroupIndex == sectionGroupIndex?
                                                      tableRow
                                                      .Elements()
                                                      .Elements()
                                                      .Where(ln => ln.Name.LocalName == sumColumn)
                                                          :
                                                          tableRow
                                                          .Descendants()
                                                          .Where(ln => ln.Name.LocalName == sumColumn &&
                                                                 ln.Parent.Parent.Attribute("SectionGroupIndex") != null &&
                                                                 ln.Parent.Parent.Attribute("SectionGroupIndex").Value.ToInt32() == sectionGroupIndex);

                    decimal result = 0;

                    if (sumItems.Count() != 0)
                    {
                        result = sumItems.Sum(si =>
                        {
                            decimal?innerResult = si.Value.TryToDecimal().Value;

                            return(innerResult.HasValue ? innerResult.Value : 0);
                        });
                    }

                    XElement sumElemet = new XElement(sumColumn);

                    sumElemet.Add(new XAttribute("Value", result));

                    sumElemet.Add(new XAttribute("TableRowIndex", tableRow.Attribute("TableRowIndex").Value));

                    reportSum.Add(sumElemet);
                }
            }

            #region PAGE OPTIONS

            if (reportMaster.FinalPage_Id.HasValue && reportMaster.FinalPage_Id.Value > 0)
            {
                XDocument finalPage = this.repo.GetReportXml(reportMaster.FinalPage_Id.Value);

                if (finalPage != null)
                {
                    xmlReport.Root.AddFirst(finalPage.Root.Elements());
                }
            }

            if (reportMaster.HeaderAndFooterPage_Id.HasValue && reportMaster.HeaderAndFooterPage_Id.Value > 0)
            {
                XDocument headerAndFooterPage = this.repo.GetReportXml(reportMaster.HeaderAndFooterPage_Id.Value);

                if (headerAndFooterPage != null)
                {
                    xmlReport.Root.AddFirst(headerAndFooterPage.Root.Elements());
                }
            }

            if (reportMaster.CoverPage_Id.HasValue && reportMaster.CoverPage_Id.Value > 0)
            {
                XDocument coverPage = this.repo.GetReportXml(reportMaster.CoverPage_Id.Value);

                if (coverPage != null)
                {
                    xmlReport.Root.AddFirst(coverPage.Root.Elements());
                }
            }

            #endregion

            #region PAGE SETUP

            XElement pageSetup = new XElement("PageSetup");

            pageSetup.Add(new XAttribute("PaperKindEnum", reportMaster.PaperKindEnum));
            pageSetup.Add(new XAttribute("PageOrientationEnum", reportMaster.PageOrientationEnum));
            pageSetup.Add(new XAttribute("PageMarginBottom", reportMaster.PageMarginBottom));
            pageSetup.Add(new XAttribute("PageMarginLeft", reportMaster.PageMarginLeft));
            pageSetup.Add(new XAttribute("PageMarginRight", reportMaster.PageMarginRight));
            pageSetup.Add(new XAttribute("PageMarginTop", reportMaster.PageMarginTop));

            xmlReport.Root.AddFirst(pageSetup);

            #endregion

            this.repo.UpdateXmlPrinteCount(reportMaster.MasterReport_Id);

            this.RunUpdateStements(xmlReport);

            return(xmlReport);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            ReportMaster rm = new ReportMaster(args[0], args[1], args[2]);

            rm.Run();
        }
Ejemplo n.º 16
0
        public ActionResult SearchedReports(int?pageno, string searchkey, ReportMaster r, string sortby)
        {
            /* Report Search  by its ReportTitle */
            searchkey = searchkey.Trim();
            if (!string.IsNullOrEmpty(searchkey))
            {
                #region ReportTitleOnly
                var pricesort = sortby;

                var SearchedReport = (from x in db.ReportMasters
                                      join c in db.CategoryMasters
                                      on x.CategoryId equals c.CategoryId
                                      join p in db.PublisherMasters
                                      on x.PublishereId equals p.PublisherId
                                      where x.ReportTitle.Contains(searchkey)
                                      orderby x.PublishingDate descending
                                      select new ReportVM
                {
                    ReportTitle = x.ReportTitle,
                    ReportUrl = x.ReportUrl,
                    FullDescription = x.LongDescritpion.Substring(0, 300),
                    NumberOfPage = x.NumberOfPages,
                    PriceSingleUser = x.SinglePrice,
                    PublishingDate = x.PublishingDate,
                    CategoryName = c.CategoryName,
                    CategoryUrl = c.CategoryUrl,
                    PublisherName = p.ContactName,
                    PublisherId = p.PublisherId,
                    PublishingUrl = p.publisherUrl,
                    CategoryId = c.CategoryId,
                    ReportImage = ""
                }).ToList();
                foreach (var item in SearchedReport)
                {
                    item.ReportImage = DDLGetparents(item.CategoryId);
                }
                var Reports = (from z in SearchedReport
                               select new ReportVM
                {
                    ReportTitle = z.ReportTitle,
                    ReportUrl = z.ReportUrl,
                    FullDescription = Regex.Replace(z.FullDescription, @"<[^>]+>|&nbsp;", "").Trim(),
                    NumberOfPage = z.NumberOfPage,
                    PriceSingleUser = z.PriceSingleUser,
                    PublishingDate = z.PublishingDate,
                    CategoryName = z.CategoryName,
                    CategoryUrl = z.CategoryUrl,
                    PublisherId = z.PublisherId,
                    PublisherName = z.PublisherName,
                    PublishingUrl = z.PublishingUrl,
                    ReportImage = z.ReportImage
                }).ToPagedList(pageno ?? 1, 10);

                if (Reports.Count > 0)
                {
                    //var z = new StaticPagedList<ReportDetails>(Reports, pageno ?? 1, 10, Reports.TotalItemCount);
                    ViewBag.TotalReports    = Reports.Count;
                    ViewBag.SearchedKeyword = searchkey;
                    return(View(Reports));
                }
                else
                {
                    ViewBag.NoReport = "Reports not found for such keyword !....";
                    return(View());
                }

                #endregion ReportTitle
            }
            else
            {
                // return View(r);
                return(HttpNotFound());
            }
        }
Ejemplo n.º 17
0
        // [CustomAuthentication("ReportUploader", "Create,Edit,Delete")]
        public ActionResult Import(HttpPostedFileBase excelfile)
        {
            string Value = string.Empty;
            List <ReportMaster> reportlist = new List <ReportMaster>();

            //   Excelimport (excelfile);
            if (excelfile == null || excelfile.ContentLength == 0)
            {
                ViewBag.Error = "Upload the excel file !....";
                return(View("Index"));
            }

            else
            {
                if (excelfile.FileName.EndsWith("xsl") || excelfile.FileName.EndsWith("xlsx"))
                {
                    string path = "";
                    //   string path = Server.MapPath("~/Content/" + excelfile.FileName + DateTime.Now.ToString("MM.dd.yyyy-hh.mm.ss"));
                    try
                    {
                        //path = Server.MapPath("~/UploadSheet/" + excelfile.FileName + DateTime.Now.ToString("MM.dd.yyyy"));
                        path = Server.MapPath("~/UploadSheet/");
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                        excelfile.SaveAs(path + Path.GetFileName(excelfile.FileName));
                        path = path + Path.GetFileName(excelfile.FileName);
                        string sFileExtention = Path.GetExtension(path);
                        ISheet sheet;

                        using (var stream = new FileStream(path, FileMode.Open))
                        {
                            stream.Position = 0;
                            if (sFileExtention == ".xls")
                            {
                                HSSFWorkbook hSSFWorkbook = new HSSFWorkbook(stream);
                                sheet = hSSFWorkbook.GetSheetAt(0);
                            }
                            else
                            {
                                XSSFWorkbook sSFWorkbook = new XSSFWorkbook(stream);
                                sheet = sSFWorkbook.GetSheetAt(0);
                            }
                            IRow   hrow      = sheet.GetRow(0);
                            int    lastcell  = hrow.LastCellNum;
                            string HTMLTable = "<table border='1'>";
                            for (int i = 1; i <= sheet.LastRowNum; i++)
                            {
                                IRow         row1 = sheet.GetRow(i);
                                ReportMaster r    = new ReportMaster();

                                int      _SerialNumber;
                                int      SerialNumber = 0;
                                int      _CategoryID;
                                int      _PublisherID;
                                int      _DeliveryFormatID;
                                DateTime _PublishedDate;
                                int      _NumberOfPages;
                                Decimal  _SingleUserPrice;
                                Decimal  _MultiUserPrice;
                                Decimal  _CorporateUserPrice;
                                bool     IsVaidate       = true;
                                string   _MetaTitle      = "";
                                string   Message         = "";
                                string   ReportTitleTemp = string.Empty;
                                for (int j = 0; j < lastcell; j++)
                                {
                                    if (Convert.ToString(hrow.Cells[j]) == "Serial Number")
                                    {
                                        if (Int32.TryParse(row1.Cells[j].ToString().Trim(), out _SerialNumber))
                                        {
                                            SerialNumber = _SerialNumber;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Serial Number<br />";
                                        }
                                    }
                                    else if (Convert.ToString(hrow.Cells[j]) == "Category ID")
                                    {
                                        if (Int32.TryParse(row1.Cells[j].ToString().Trim(), out _CategoryID))
                                        {
                                            r.CategoryId = _CategoryID;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Category ID <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Publisher ID")
                                    {
                                        if (Int32.TryParse(row1.Cells[j].ToString().Trim(), out _PublisherID))
                                        {
                                            r.PublishereId = _PublisherID;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Publisher ID <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Delivery Format ID")
                                    {
                                        if (Int32.TryParse(row1.Cells[j].ToString().Trim(), out _DeliveryFormatID))
                                        {
                                            r.ReportDeliveryTypeId = _DeliveryFormatID;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Delivery Format ID <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Title")
                                    {
                                        ReportTitleTemp = Convert.ToString(row1.Cells[j].ToString().Trim());
                                        if (db.ReportMasters.Count(g => g.ReportTitle == ReportTitleTemp) > 0 ? true : false)

                                        {
                                            IsVaidate = false; Message += "Title <br />";
                                        }
                                        else
                                        {
                                            r.ReportTitle = row1.Cells[j].ToString().Trim().Replace("   ", " ").Replace("  ", " ").Replace("  ", " ");
                                        }

                                        r.ReportUrl = ExcellentMarketResearch.Areas.Admin.Models.Common.GenerateSlug(row1.Cells[j].ToString().Trim());

                                        if (db.ReportMasters.Count(url => url.ReportUrl == r.ReportUrl.ToLower()) > 0 ? true : false)
                                        {
                                            r.ReportUrl = ""; IsVaidate = false; Message += "Long URL <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Published Date")
                                    {
                                        if (DateTime.TryParse(row1.Cells[j].ToString().Trim(), out _PublishedDate))
                                        {
                                            r.PublishingDate = _PublishedDate;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Published Date <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Number Of Pages")
                                    {
                                        if (Int32.TryParse(row1.Cells[j].ToString().Trim(), out _NumberOfPages))
                                        {
                                            r.NumberOfPages = _NumberOfPages;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Number Of Pages <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Long Description")
                                    {
                                        if (row1.Cells[j].ToString().Trim() != "")
                                        {
                                            r.LongDescritpion = "<pre>" + row1.Cells[j].ToString().Trim() + "</pre>";
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Long Description \n";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Long Table Of Content")
                                    {
                                        r.TableOfContent = "<pre>" + row1.Cells[j].ToString().Trim() + "</pre>";
                                    }

                                    else if (hrow.Cells[j].ToString() == "Single User Price")
                                    {
                                        if (Decimal.TryParse(row1.Cells[j].ToString().Trim() == "" ? "0" : row1.Cells[j].ToString().Trim(), out _SingleUserPrice))
                                        {
                                            r.SinglePrice = _SingleUserPrice;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Single User Price <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Multi User Price")
                                    {
                                        if (Decimal.TryParse(row1.Cells[j].ToString().Trim() == "" ? "0" : row1.Cells[j].ToString().Trim(), out _MultiUserPrice))
                                        {
                                            r.MultiUserPrice = _MultiUserPrice;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Multi User Price <br />";
                                        }
                                    }
                                    else if (hrow.Cells[j].ToString() == "Corporate User Price")
                                    {
                                        if (Decimal.TryParse(row1.Cells[j].ToString().Trim() == "" ? "0" : row1.Cells[j].ToString().Trim(), out _CorporateUserPrice))
                                        {
                                            r.CorporateUserPrice = _CorporateUserPrice;
                                        }
                                        else
                                        {
                                            IsVaidate = false; Message += "Corporate User Price <br />";
                                        }
                                    }
                                }
                                if (r.SinglePrice <= 0 && r.MultiUserPrice <= 0 && r.CorporateUserPrice <= 0)
                                {
                                    IsVaidate = false; Message += "Add Atleast one Price <br />";
                                }

                                if (IsVaidate)
                                {
                                    r.ReportImage = null;

                                    r.IsActive = true;

                                    r.ReportTypeId = r.ReportDeliveryTypeId;
                                    r.CreatedBy    = 1; //Convert.ToInt32(QYGroupRepository.Areas.Admin.Models.CommonCode.MySession());
                                    r.CreatedDate  = DateTime.Now;
                                    //reportlist.Add(r);
                                    db.ReportMasters.Add(r);
                                    db.SaveChanges();
                                    var repturl = r.ReportUrl + ".html";
                                    r.ReportUrl       = repturl;
                                    db.Entry(r).State = EntityState.Modified;
                                    db.SaveChanges();
                                    Message += "Inserted <br/>";
                                }
                                HTMLTable += "<tr><td>" + SerialNumber + "</td><td>" + ReportTitleTemp + "</td><td>" + r.ReportUrl + "</td><td>" + Message + "</td></tr>";
                            }
                            HTMLTable   += "</table>";
                            ViewBag.Html = HTMLTable;
                            return(View());
                            //ViewData.Add("HTMLTable", HTMLTable);
                            //ViewData["HTMLTable"] = HTMLTable;
                        }
                    }



                    catch (Exception ex)
                    {
                        var x = "<br />Report status: The file could not be processed. The following error occured: " + ex.Message;
                    }
                    finally
                    {
                    }
                }
            }
            return(View());
        }