Exemplo n.º 1
0
        public int RemoveVanneCalendar(int idNoeudIrrig, int number, string start, string end)
        {
            var      vanne     = agriEntities.electrovanne.SingleOrDefault(x => x.FK_IdImlpNoeudIrrigation == idNoeudIrrig && x.Nombre == number);
            DateTime startDate = DateTime.ParseExact(start.Remove(24), "ddd MMM dd yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); //Wed Feb 05 2014 00:00:00 GMT+0100
            DateTime endtDate  = DateTime.ParseExact(end.Remove(24), "ddd MMM dd yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);   //Wed Feb 05 2014 00:00:00 GMT+0100

            var cals = agriEntities.calendirer_irrigation.Where(x => x.FK_IdElectrovanne == vanne.IdElectrovanne);
            calendirer_irrigation cal = null;

            foreach (var _cal in cals)
            {
                if ((DateTime.Compare(_cal.Datedebut.Value, startDate) == 0) && (_cal.Duree.Value == Math.Truncate((endtDate - startDate).TotalMinutes)))
                {
                    cal = _cal;
                    break;
                }
            }
            if (cal != null)
            {
                try
                {
                    agriEntities.calendirer_irrigation.DeleteObject(cal);
                }
                catch (ApplicationException ex)
                {
                    throw new ApplicationException(
                              "An error occurred when saving changes.", ex);
                }
            }
            return(agriEntities.SaveChanges());
        }
Exemplo n.º 2
0
        public int CreateVanneCalendar(int idNoeudIrrig, int number, string start, string end, string recurrenceRule, string isAllDay)
        {
            var      vanne            = agriEntities.electrovanne.SingleOrDefault(x => x.FK_IdImlpNoeudIrrigation == idNoeudIrrig && x.Nombre == number);
            DateTime startDate        = DateTime.ParseExact(start.Remove(24), "ddd MMM dd yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); //Wed Feb 05 2014 00:00:00 GMT+0100
            DateTime endtDate         = DateTime.ParseExact(end.Remove(24), "ddd MMM dd yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);   //Wed Feb 05 2014 00:00:00 GMT+0100
            double   m                = (endtDate - startDate).TotalMinutes;
            calendirer_irrigation cal = new calendirer_irrigation
            {
                FK_IdElectrovanne = vanne.IdElectrovanne,
                Datedebut         = startDate,
                Duree             = (int)(endtDate - startDate).TotalMinutes
            };

            try
            {
                agriEntities.calendirer_irrigation.AddObject(cal);
                return(agriEntities.SaveChanges());
            }
            catch (ApplicationException ex)
            {
                throw new ApplicationException(
                          "An error occurred when saving changes.", ex);
            }
        }
Exemplo n.º 3
0
        public int UpdateVanneCalendar(int idNoeudIrrig, int prev_number, int number, string start, string end, int taskId, string recurrenceRule, string isAllDay)
        {
            var      vanne = agriEntities.electrovanne.SingleOrDefault(x => x.FK_IdImlpNoeudIrrigation == idNoeudIrrig && x.Nombre == prev_number);
            DateTime startDate = DateTime.ParseExact(start.Remove(24), "ddd MMM dd yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); //Wed Feb 05 2014 00:00:00 GMT+0100
            DateTime endtDate = DateTime.ParseExact(end.Remove(24), "ddd MMM dd yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);    //Wed Feb 05 2014 00:00:00 GMT+0100
            int      n = (int)Math.Ceiling(Math.Log10(taskId)), rest = 0;

            switch (n)
            {
            case 2:
                rest = taskId % 10;
                break;

            case 3:
                rest = taskId % 100;
                break;

            case 4:
                rest = taskId % 1000;
                break;

            case 5:
                rest = taskId % 10000;
                break;

            default:
                break;
            }
            //FREQ=DAILY;COUNT=1;WKST=SU;BYMONTHDAY=11s

            var cals                  = agriEntities.calendirer_irrigation.Where(x => x.FK_IdElectrovanne == vanne.IdElectrovanne);
            calendirer_irrigation cal = null;
            int compt                 = 1;

            foreach (var _cal in cals)
            {
                if ((DateTime.Compare(_cal.Datedebut.Value, startDate) == 0) || (DateTime.Compare(_cal.Datedebut.Value.AddMinutes(_cal.Duree.Value), endtDate) == 0) ||
                    (compt == rest))
                {
                    cal = _cal;
                    break;
                }
                compt++;
            }
            if (cal != null)
            {
                try
                {
                    cal.Datedebut = startDate;
                    double mn  = (endtDate - startDate).TotalMinutes;
                    int    mn1 = (int)Math.Truncate(mn);
                    cal.Duree = mn1;
                    if (prev_number != number)
                    {
                        cal.FK_IdElectrovanne = new VanneService().GetElectroByIdIrrigNodeByNumber(idNoeudIrrig, number).IdElectrovanne;
                    }
                }
                catch (ApplicationException ex)
                {
                    throw new ApplicationException(
                              "An error occurred when saving changes.", ex);
                }
            }
            return(agriEntities.SaveChanges());
        }