示例#1
0
 private void GenerationData(EventCalendarModel parserActivityModel, int indexRow, int indexColumn, IXLRangeColumns columns)
 {
     for (int i = indexRow, j = indexColumn; j < columns.Count(); j++)
     {
         parserActivityModel.NameAllStav = columns.ElementAt(j).Cell(i).Value.ToString();
     }
 }
示例#2
0
        public JsonResult DeleteEvent(Table t)
        {
            var status = false;

            //System.Diagnostics.Debug.WriteLine("event ID to delete is: "+ e.EventID);
            try
            {
                using (var ecm = new EventCalendarModel())
                {
                    var entry = ecm.Tables.Where(e => e.EventID == t.EventID).FirstOrDefault();
                    if (entry != null)
                    {
                        ecm.Tables.Remove(entry);
                        ecm.SaveChanges();
                        status = true;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Delete exception message is: " + ex.ToString());
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
示例#3
0
        private PlanCalendarModel GenerationListActivitysInCurrentMoth(IXLWorksheet worksheet)
        {
            if (new Regex(@"\d").Matches(worksheet.Name).Count != 4)
            {
                return(null);
            }

            var rows = worksheet.RangeUsed().RowsUsed(); // Skip header row

            var dataBaseParserModel = new PlanCalendarModel();

            dataBaseParserModel.Year  = GetYear(worksheet.Name);
            dataBaseParserModel.Month = GetMoth(worksheet.Name);

            for (int i = 0; i < rows.Count(); i++)
            {
                if (CheckStartingFiled(rows.ElementAt(i).Cell(1).Value))
                {
                    var countMergeColumn = rows.ElementAt(i).Cell(1).MergedRange().RowCount();
                    var date             = GenerationDayDictionary(rows, i);

                    for (int currentIndexActivity = i + countMergeColumn + 1, k = 2, programIndex = -1; currentIndexActivity < rows.Count(); currentIndexActivity++)
                    {
                        var currentActivity = rows.ElementAt(currentIndexActivity).Cell(k);

                        if (!String.IsNullOrWhiteSpace(currentActivity.Value.ToString()))
                        {
                            foreach (var element in GenerationMarksInCurrentActivity(currentIndexActivity, date, rows))
                            {
                                EventCalendarModel parserActivityModel = new EventCalendarModel();
                                parserActivityModel.Day         = element.IsExist ? element.day.ToString() : element.Text;
                                parserActivityModel.Name        = currentActivity.Value.ToString();
                                parserActivityModel.NameAllStav = GenerationData(currentActivity.Value.ToString(), currentIndexActivity, date.Last().Key + 1, rows);
                                parserActivityModel.Leader      = GenerationData(parserActivityModel.NameAllStav, currentIndexActivity, date.Last().Key + 2, rows);
                                parserActivityModel.Location    = GenerationData(parserActivityModel.Leader, currentIndexActivity, date.Last().Key + 3, rows);
                                parserActivityModel.Time        = GenerationData(parserActivityModel.Location, currentIndexActivity, date.Last().Key + 4, rows);
                                parserActivityModel.Result      = GenerationData(parserActivityModel.Time, currentIndexActivity, date.Last().Key + 5, rows);
                                parserActivityModel.NameProgram = rows.ElementAt(programIndex).Cell(1).Value.ToString();

                                dataBaseParserModel.Events.Add(parserActivityModel);
                            }
                        }
                        else
                        {
                            if (String.IsNullOrWhiteSpace(rows.ElementAt(currentIndexActivity).Cell(1).Value.ToString()))
                            {
                                break;
                            }
                            programIndex = currentIndexActivity;
                        }
                    }

                    return(dataBaseParserModel);
                }
                //break;
            }

            return(dataBaseParserModel);
        }
示例#4
0
        public JsonResult SaveEvent(Table t)
        {
            var status = false;

            try
            {
                using (EventCalendarModel ecm = new EventCalendarModel())
                {
                    //System.Diagnostics.Debug.WriteLine("event id is: " + e.EventID);
                    // if >0, then this entry is already in our db
                    if (t.EventID > 0) // 0 is the default, which is not allowed in our db
                    {
                        //Update the event
                        var entry = ecm.Tables.Where(e => e.EventID == t.EventID).FirstOrDefault();
                        if (entry != null)
                        {
                            entry.Subject     = t.Subject;
                            entry.Start       = t.Start;
                            entry.End         = t.End;
                            entry.Description = t.Description;
                            entry.EventColor  = t.EventColor;
                        }
                        // else, something unexpected occured.
                    }
                    else
                    {
                        t.EventID = 1;
                        // if table is not empty
                        if (ecm.Tables.Any())
                        {
                            t.EventID = ecm.Tables.Max(e => e.EventID) + 1;
                        }

                        ecm.Tables.Add(t);

                        /* System.Diagnostics.Debug.WriteLine("start is: " + e.Start.ToString());
                         * System.Diagnostics.Debug.WriteLine("end is: " + e.End.ToString());*/
                    }

                    ecm.SaveChanges();
                    status = true;
                }
            }
            catch (Exception ex) //Catch Other Exception
            {
                System.Diagnostics.Debug.WriteLine("Exception message is: " + ex.ToString());
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
示例#5
0
        // assumed Get by default
        public JsonResult GetEvents()
        {
            using (var ecm = new EventCalendarModel())
            {
                //System.Diagnostics.Debug.WriteLine("get events");
                var events = ecm.Tables.ToList();

                /*foreach(var singleEvent in events)
                 * {
                 *  System.Diagnostics.Debug.WriteLine(singleEvent.EventID);
                 *  System.Diagnostics.Debug.WriteLine(singleEvent.Subject);
                 *  System.Diagnostics.Debug.WriteLine(singleEvent.Description);
                 *  System.Diagnostics.Debug.WriteLine(singleEvent.Start);
                 *  System.Diagnostics.Debug.WriteLine(singleEvent.End);
                 * }*/
                return(new JsonResult {
                    Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
        }