Пример #1
0
        public virtual void ExportAndSend2(int bookmarkId, string fileName, string subjectKey, string messageKey, string to, string from)
        {
            Durados.Bookmark bookmark = BookmarksHelper.GetBookmark(bookmarkId);
            if (bookmark == null)
            {
                return;
            }

            Durados.Web.Mvc.View view = GetView(bookmark.ViewName, "SubscribeBatch");
            if (view.Database.IsConfig)
            {
                return;
            }

            fileName = string.IsNullOrEmpty(fileName) ? bookmark.Name : fileName;

            string subject = string.IsNullOrEmpty(subjectKey) ? "Attached, please find " + fileName + "_" + DateTime.Now.ToString("yyyy-MM-dd") : GetSubject(view, subjectKey, 0);
            string message = string.IsNullOrEmpty(messageKey) ? "Please review " + fileName + "_" + DateTime.Now.ToString("yyyy-MM-dd") : GetSubject(view, messageKey, 0);

            from    = string.IsNullOrEmpty(from) ? Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["fromAlert"]) : from;
            subject = subject.Replace(Durados.Database.CurrentDatePlaceHolder, DateTime.Now.ToString(Database.DateFormat));
            message = message.Replace(Durados.Database.CurrentDatePlaceHolder, DateTime.Now.ToString(Database.DateFormat));

            if (string.IsNullOrEmpty(to))
            {
                return;
            }

            fileName = fileName + "_" + Guid.NewGuid();

            fileName = Export(view, GetDataViewByBookmark(bookmarkId), fileName);

            SendEmail(from, to.Split(';'), new string[0], message, subject, new string[1] {
                fileName
            });
        }
Пример #2
0
        public JsonResult getview(int bookmarkid, int?pageSize, int?pageNumber)
        {
            Guid guid = Guid.NewGuid();

            Database.Logger.Log(GetControllerNameForLog(this.ControllerContext), this.ControllerContext.RouteData.Values["action"].ToString(), "getview(" + guid.ToString() + ")", "Start", null, 3, "Parameters:" + bookmarkid.ToString(), DateTime.Now);
            if (!IsValidatUser())
            {
                return(Json(new TableForJson {
                    ErrorCode = 101, ErrorDescription = "User is not recognize"
                }));
            }

            int maxPageSize = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ApiGetViewMaxPageSize"] ?? "10000");

            if (!pageSize.HasValue)
            {
                pageSize = maxPageSize;
            }

            if (pageSize.HasValue && pageSize.Value > maxPageSize)
            {
                return(Json(new TableForJson {
                    ErrorCode = 121, ErrorDescription = "Page size exceeded the allowed value of 10000"
                }));
            }
            if (!pageNumber.HasValue)
            {
                pageNumber = 1;
            }

            List <Dictionary <object, object> > rows;
            int rowCount;

            try
            {
                Durados.Bookmark bookmark = BookmarksHelper.GetBookmark(bookmarkid);
                if (bookmark == null)
                {
                    return(Json(new TableForJson {
                        ErrorCode = 102, ErrorDescription = "Bookmark was not found"
                    }));
                }
                ;

                Durados.Web.Mvc.View view = GetView(bookmark.ViewName, "getview");
                if (view == null)
                {
                    return(Json(new TableForJson {
                        ErrorCode = 103, ErrorDescription = "View " + bookmark.ViewName + "was not found"
                    }));
                }
                if (view.Database.IsConfig)
                {
                    return(Json(new TableForJson {
                        ErrorCode = 104, ErrorDescription = "Bookmark view is a config view! notofication services for these views is not implemeneted."
                    }));
                }



                DataAccess.Filter filter = MailingServiceHelper.GetBookmarkFilter(view, bookmark, new SqlAccess());
                Dictionary <string, SortDirection> sortColumns = GetSortColumns(bookmark.SortColumn, bookmark.SortDirection);
                DataView dataview;
                try
                {
                    dataview = view.FillPage(pageNumber.Value, pageSize.Value, filter, null, null, sortColumns, out rowCount, null, null);//GetDataViewByBookmark(bookmarkid,pageNumber,pageSize,out rowCount);
                }
                catch (Exception ex)
                {
                    throw new DuradosException("Faild to fill data view from database", ex);
                }
                //DataTable dt;
                //try
                //{
                //    dt = CreateResponseDataTable(view, dataview);
                //}
                //catch (Exception ex)
                //{
                //    throw new DuradosException("Faild to create response ", ex);
                //}

                rows = dataview.GetTableForJson(view, rowCount, pageNumber.Value);

                TableForJson tableJson = new TableForJson();
                tableJson.totalRowCount = rowCount;
                tableJson.results       = rows;
                tableJson.rowsInPage    = rows.Count;
                tableJson.pageNumber    = pageNumber.Value;
                Database.Logger.Log(GetControllerNameForLog(this.ControllerContext), this.ControllerContext.RouteData.Values["action"].ToString(), "getview(" + guid.ToString() + ")", "end", null, 3, null, DateTime.Now);
                return(Json(tableJson));
            }
            catch (Exception ex)
            {
                Database.Logger.Log(GetControllerNameForLog(this.ControllerContext), this.ControllerContext.RouteData.Values["action"].ToString(), "getview(" + guid.ToString() + ")", ex, 3, "end", DateTime.Now);
                return(Json(new TableForJson {
                    ErrorCode = 105, ErrorDescription = (ex.InnerException == null ? ex.Message : string.Format("Exeception Message {0};Inner Exception Message:{1}", ex.Message, ex.InnerException.Message))
                }));
            }
        }