Beispiel #1
0
        }// Get Letest report Written

        public static IEnumerable <FieldReportDoc> GetReportsByKeyWords(string [] words)
        {
            using (FieldReportDBEntities DB = new FieldReportDBEntities())
            {
                var ReportTable = DB.FieldReports.ToList();
                var FR          = new List <FieldReport>(); // filterResult
                for (int i = 0; i < words.Length; i++)
                {
                    //Check if each word is contained in Table (Title col and Content col)

                    FR.AddRange(ReportTable.Where(report =>
                                                  ((report.Content.Contains(words[i]) || report.Title.Contains(words[i])) && //1st if he contains word in Title or Content
                                                   !FR.Exists(item => item.Id == report.Id)))                                //2nd is he already in FR list
                                .ToList());
                }

                var documents = new List <FieldReportDoc>();
                documents = (from item in FR
                             select new FieldReportDoc()
                {
                    Id = item.Id,
                    Date = new SimpleDate(item.ReportDate),
                    Text = Utilities.RenderTextTohtml(item.Content),
                    Title = item.Title
                }).ToList();
                return(documents);
            }
        } //Get list of Reports
Beispiel #2
0
        }//Get list of Report Id

        /// <summary>
        /// Write a new Report
        /// </summary>
        /// <param name="documentary"></param>
        public static int Report(FieldReportDoc documentary)
        {
            using (FieldReportDBEntities DB = new FieldReportDBEntities())
            {
                DB.FieldReports.Add(documentary.ConvertToRow());
                DB.SaveChanges();
                var id = ByNewestId();
                return(id);
            }
        } // Post/Create new Report
Beispiel #3
0
 /// <summary>
 /// Get full report fields from a specific date
 /// </summary>
 /// <param name="date"></param>
 /// <returns></returns>
 public static IEnumerable <FieldReport> GetReportsByDate(SimpleDate date)
 {
     using (FieldReportDBEntities DB = new FieldReportDBEntities())
     {
         var Results = DB.FieldReports.Where(EachReport => EachReport.ReportDate.Year == (int)date.Year);
         Results = Results.Where(EachReport => EachReport.ReportDate.Month == (int)date.Month);
         Results = Results.Where(EachReport => EachReport.ReportDate.Day == (int)date.Day);
         return(Results);
     }
 } //Get list of Reports
Beispiel #4
0
        } //Get list of Reports

        private static int ByNewestId()
        {
            using (FieldReportDBEntities DB = new FieldReportDBEntities())
            {
                var Ids = (from item in DB.FieldReports
                           select item.Id).ToList();
                int Retunred_Id = Ids.Max();
                return(Retunred_Id);
            }
        }
Beispiel #5
0
        } //Get list of Reports

        /// <summary>
        /// Get a short list of Field report (can filter with date)
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <ReportTagNumber> GetListOfReportTags()
        {
            using (FieldReportDBEntities DB = new FieldReportDBEntities())
            {
                List <ReportTagNumber> list = new List <ReportTagNumber>();
                foreach (var item in DB.FieldReports)
                {
                    list.Add(new ReportTagNumber()
                    {
                        ReportNumberID = item.Id,
                        SetDate        = item.ReportDate, Title = item.Title
                    });
                }
                return(list);
            }
        }//Get list of Report Id
Beispiel #6
0
 public static bool DeleteReportFromDB(int ID)
 {
     using (FieldReportDBEntities DB = new FieldReportDBEntities())
     {
         var row = DB.FieldReports.SingleOrDefault(One => One.Id == ID);
         if (row != null)
         {
             DB.FieldReports.Remove(row);
             DB.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 } // Delete Report
Beispiel #7
0
 public static int UpdateReport(FieldReportDoc Updated)
 {
     using (FieldReportDBEntities DB = new FieldReportDBEntities())
     {
         var row = DB.FieldReports.SingleOrDefault(rw => rw.Id == Updated.Id);
         if (row != null)
         {
             row.ReportDate = Updated.Date.ToDateTime;            // Date
             row.Title      = Updated.Title;                      // Title
             row.Content    = Utilities.StoreInSQL(Updated.Text); // Text/Content
             DB.SaveChanges();
             return(Updated.Id.Value);
         }
         else
         {
             return(-1);
         }
     }
 }
Beispiel #8
0
        } // Post/Create new Report

        /// <summary>
        /// Gets the specific Report , will return null if not found
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static FieldReportDoc GetFieldReport(int ID)
        {
            using (FieldReportDBEntities DB = new FieldReportDBEntities())
            {
                var item = DB.FieldReports.SingleOrDefault(One => One.Id == ID);
                if (item != null)
                {
                    var R = new FieldReportDoc()
                    {
                        Id    = item.Id,
                        Date  = new SimpleDate(item.ReportDate),
                        Text  = Utilities.RenderTextTohtml(item.Content),
                        Title = item.Title
                    };
                    return(R);
                }
                else
                {
                    return(null);
                }
            }
        } // Get One
Beispiel #9
0
        } // Delete Report

        public static FieldReportDoc GetReportForEdit(int ID)
        {
            using (FieldReportDBEntities DB = new FieldReportDBEntities())
            {
                var item = DB.FieldReports.SingleOrDefault(One => One.Id == ID);
                if (item != null)
                {
                    var R = new FieldReportDoc()
                    {
                        Id    = item.Id,
                        Date  = new SimpleDate(item.ReportDate),
                        Text  = Utilities.BackToOldNativeString(item.Content), // In here we render the text back to native string
                        Title = item.Title
                    };
                    return(R);
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #10
0
        } // Get One

        public static FieldReportDoc LastReport()
        {
            using (FieldReportDBEntities DB = new FieldReportDBEntities())
            {
                var dates = (from item in DB.FieldReports
                             select item.ReportDate).ToList();

                DateTime MaxDate = Utilities.FindYoungestDate(dates);

                var FilteredReports = DB.FieldReports.Where(report =>
                                                            report.ReportDate.Year == MaxDate.Year && report.ReportDate.Month == MaxDate.Month &&
                                                            report.ReportDate.Day == MaxDate.Day).ToList();

                FieldReport FR = FilteredReports.OrderByDescending(fr => fr.Id).First();

                return(new FieldReportDoc()
                {
                    Id = FR.Id,
                    Date = FR.ReportDate.ToSimpleDate(),
                    Text = Utilities.RenderTextTohtml(FR.Content),
                    Title = FR.Title
                });
            }
        }// Get Letest report Written