private static DaysOff GetDaysOff(DataRow HRow)
        {
            SqlDataAdapter mySqlDataAdapter = DataAdapter("Days_Off");
            int            index            = 0;
            List <string>  arrList          = new List <string>();

            foreach (DataRow row in db.Days_Off.Rows)
            {
                if (row["Habit_Id"].Equals(HRow["Id"]))
                {
                    string days = GetDaysByID((int)row["Days_Id"]);
                    if (days != null)
                    {
                        arrList.Add(days);
                    }
                }
            }
            string[] value = new string[arrList.Count];
            foreach (string i in arrList)
            {
                value[index++] = i;
            }

            DaysOff daysOff = new DaysOff(value);

            return(daysOff);
        }
        public ActionResult <Habit> AddNewHabit(Guid user_id, [FromBody] RequestData data)
        {
            DaysOff daysoff = new DaysOff(data.DaysOff);

            HabitRepository.RegisterHabit(user_id, data.Name, daysoff, DateTime.Now);
            return(Ok(HabitRepository.GetNewestHabit(user_id)));
        }
예제 #3
0
 public void Setup()
 {
     DaysOff.Initialize(new List <DayOff>
     {
         new DayOff("WD", null, 0, 6, 0, 50)
     });
 }
예제 #4
0
 private void SetupDaysOff()
 {
     DaysOff.Initialize(new List <DayOff>
     {
         new DayOff("WD", null, 1, 5, 23, 50)
     });
 }
예제 #5
0
        public JsonResult InsertOffDays(string daysOffString = "")
        {
            DaysOffModel model = new DaysOffModel();

            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                serializer.MaxJsonLength = Int32.MaxValue;
                DaysOff daysOff = serializer.Deserialize <DaysOff>(daysOffString);

                daysOff.AgencyId          = new Guid(Session["AgencyId"].ToString());
                daysOff.CreatedBy         = new Guid(Session["UserID"].ToString());
                daysOff.RoleId            = new Guid(Session["RoleId"].ToString());
                model                     = new CenterData().InsertDaysOff(daysOff);
                model.OffDaysString       = serializer.Serialize(model.DatesList);
                model.CenterListString    = serializer.Serialize(model.CenterList);
                model.ClassRoomListString = serializer.Serialize(model.ClassRoomList);
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                clsError.WriteException(ex);
                return(Json(model, JsonRequestBehavior.AllowGet));
            }
        }
예제 #6
0
 /// <summary>
 ///     Generate the Market Statistics
 /// </summary>
 public static void GenerateMarketStats()
 {
     MarketStatsValue[0]  = Symbol;
     MarketStatsValue[1]  = DataPeriodToString(Period);
     MarketStatsValue[2]  = Bars.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[3]  = Update.ToString(Df);
     MarketStatsValue[4]  = Update.ToString("HH:mm");
     MarketStatsValue[5]  = Time[0].ToString(Df);
     MarketStatsValue[6]  = Time[0].ToString("HH:mm");
     MarketStatsValue[7]  = MinPrice.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[8]  = MaxPrice.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[9]  = AverageGap + " " + Language.T("points");
     MarketStatsValue[10] = MaxGap + " " + Language.T("points");
     MarketStatsValue[11] = AverageHighLow + " " + Language.T("points");
     MarketStatsValue[12] = MaxHighLow + " " + Language.T("points");
     MarketStatsValue[13] = AverageCloseOpen + " " + Language.T("points");
     MarketStatsValue[14] = MaxCloseOpen + " " + Language.T("points");
     MarketStatsValue[15] = DaysOff.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[16] = Configs.MaxBars.ToString(CultureInfo.InvariantCulture);
     MarketStatsValue[17] = Configs.UseStartTime
                                ? Configs.DataStartTime.ToShortDateString()
                                : Language.T("No limits");
     MarketStatsValue[18] = Configs.UseEndTime
                                ? Configs.DataEndTime.ToShortDateString()
                                : Language.T("No limits");
     MarketStatsValue[19] = Configs.FillInDataGaps ? Language.T("Accomplished") : Language.T("Switched off");
     MarketStatsValue[20] = Configs.CutBadData ? Language.T("Accomplished") : Language.T("Switched off");
 }
예제 #7
0
 public static Habit CreateHabit(Guid user_id, string name, DaysOff daysOff, DateTime created_at)
 {
     if (name.Length < 2 || name.Length > 100)
     {
         throw new Exception("Name must be between 2 and 100 characters");
     }
     return(new Habit(System.Guid.NewGuid(), user_id, name, daysOff, 0, 0, 0, created_at));
 }
예제 #8
0
        public void CheckTheDay()
        {
            string[] arr = { "Mon", "Tue" };
            DaysOff  str = new DaysOff(arr);

            Assert.Equal("Mon", str.Days[0]);
            Assert.Equal("Tue", str.Days[1]);
        }
        public ActionResult UseDayOff(int id)
        {
            var model = new DaysOff {
                EmployeeId = id
            };

            return(View(model));
        }
예제 #10
0
 /// <summary>
 /// Initialise une nouvelle instance pour la classe <see cref="JE"/>.
 /// </summary>
 public JE()
 {
     Code       = "JE";
     Alpha3Code = "JEY";
     Names      = NamesBuilder.Make.Add(Langue.EN, "Jersey").AsDictionary();
     DaysOff.Add(Sunday);
     Langues.Add(Langue.EN);
     SupportedCalendar.Add(Gregorian);
     Rules = new ListRule()
     {
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Fix(On.January.The1st),
             Names      = NamesBuilder.Make.Add(Langue.EN, "New Year's Day").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Catholic.GoodFriday,
             Names      = NamesBuilder.Make.Add(Langue.EN, "Good Friday").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Catholic.EasterMonday,
             Names      = NamesBuilder.Make.Add(Langue.EN, "Easter Monday").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Movable(First, Monday).In(May),
             Names      = NamesBuilder.Make.Add(Langue.EN, "Early May Bank Holiday").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Fix(On.May.The9th),
             Names      = NamesBuilder.Make.Add(Langue.EN, "Liberation Day").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Movable(First, Monday).Before(June),
             Names      = NamesBuilder.Make.Add(Langue.EN, "Spring Bank Holiday").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Movable(First, Monday).Before(September),
             Names      = NamesBuilder.Make.Add(Langue.EN, "Summer Bank Holiday").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Fix(On.December.The25th),
             Names      = NamesBuilder.Make.Add(Langue.EN, "Christmas Day").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Fix(On.December.The26th),
             Names      = NamesBuilder.Make.Add(Langue.EN, "Boxing Day").AsDictionary()
         }
     };
 }
        public IList <IDayOff> GetDaysOff(Month month)
        {
            if (month == Month.None)
            {
                throw new ArgumentException("Month cannot be 'None'");
            }

            return(DaysOff.Where(d => d.Date.Month == (int)month).ToList());
        }
예제 #12
0
파일: Paycheck.cs 프로젝트: zszqwe/Wilson
        private static SubTotals CalculateSubTotals(WorkingHours workingHours, DaysOff daysOff, PayRate payRate)
        {
            var payForHours        = workingHours.Hours * payRate.Hour;
            var payForBusinessTrip = workingHours.HourOnBusinessTrip * payRate.BusinessTripHour;
            var payForExtraHours   = workingHours.ExtraHours * payRate.ExtraHour;
            var payForHolidayHours = workingHours.HourOnHolidays * payRate.HoidayHour;
            var payForPayedDaysOff = daysOff.PaidDaysOff * (payRate.Hour * 8);

            return(ValueObjects.SubTotals.Create(payForHours, payForBusinessTrip, payForExtraHours, payForHolidayHours, payForPayedDaysOff));
        }
예제 #13
0
 /// <summary>
 /// Initialise une nouvelle instance pour la classe <see cref="AE"/>.
 /// </summary>
 public AE()
 {
     Code       = "AE";
     Alpha3Code = "ARE";
     Names      = NamesBuilder.Make.Add(Langue.EN, "United Arab Emirates").Add(Langue.AR, "دولة الإمارات العربية المتحدة").AsDictionary();
     DaysOff.Add(Sunday);
     Langues = new List <Langue>()
     {
         Langue.AR
     };
     SupportedCalendar.AddRange(Gregorian, Hijri);
     Rules = new ListRule()
     {
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Fix(On.January.The1st),
             Names      = NamesBuilder.Make.Add(Langue.AR, "رأس السنة الميلادية").AsDictionary()
         },
         new GregorianRule()
         {
             Expression = ExpressionTree.Date.Fix(On.December.The2nd),
             Names      = NamesBuilder.Make.Add(Langue.AR, "اليوم الوطني").AsDictionary()
         },
         new HijriRule()
         {
             Expression = ExpressionTree.Date.Fix(OnM.Muharram.The1st).Over.Hijri(),
             Names      = NamesBuilder.Make.Add(Langue.AR, "رأس السنة الهجرية").AsDictionary()
         },
         new HijriRule()
         {
             Expression = ExpressionTree.Date.Fix(OnM.Shawwal.The1st).StartAtMidnight.Duration.P3D().Over.Hijri(),
             Names      = NamesBuilder.Make.Add(Langue.AR, "عيد الفطر").AsDictionary()
         },
         new HijriRule()
         {
             Expression = ExpressionTree.Date.Fix(OnM.DhuAlHijjah.The10th).StartAtMidnight.Duration.P3D().Over.Hijri(),
             Names      = NamesBuilder.Make.Add(Langue.AR, "عيد الأضحى").AsDictionary()
         },
         new HijriRule()
         {
             Expression = ExpressionTree.Date.Fix(OnM.Rajab.The27th).Over.Hijri(),
             Names      = NamesBuilder.Make.Add(Langue.AR, "الإسراء والمعراج").AsDictionary()
         },
         new HijriRule()
         {
             Expression = ExpressionTree.Date.Fix(OnM.Ramadan.The1st).Over.Hijri(),
             Names      = NamesBuilder.Make.Add(Langue.AR, "اليوم الأول من رمضان").AsDictionary()
         },
         new HijriRule()
         {
             Expression = ExpressionTree.Date.Fix(OnM.RabiAlAwwal.The12th).Over.Hijri(),
             Names      = NamesBuilder.Make.Add(Langue.AR, "المولد النبويّ").AsDictionary()
         }
     };
 }
예제 #14
0
        private void HandleChangedMonthYear(object newValue)
        {
            char[] sep = new char[1] {
                '.'
            };
            var value = YearMonth;
            int day   = 1;

            if (value == null)
            {
                return;
            }
            string[] yearmonth = value.Split(sep);
            if (yearmonth.Length != 2)
            {
                return;
            }
            var      year          = Convert.ToInt16(yearmonth[0]);
            var      month         = Convert.ToInt16(yearmonth[1]);
            DateTime firstDayMonth = new DateTime(year, month, day);

            if (month == 12)
            {
                var m = false;
            }

            // now i shall generate the numbers.
            DayOfWeek dayOfWeek = firstDayMonth.DayOfWeek;

            MonthName = firstDayMonth.ToString("Y");
            int currentIterator = (int)dayOfWeek;
            int numdays         = computeNumberDays(year, month - 1);
            int j = 1;

            for (int k = currentIterator; k < 38; ++k)
            {
                if (j > numdays)
                {
                    break;
                }

                _monthGrid[k] = string.Format("{0}", j);
                if (DaysOff.Contains <int>(k))
                {
                    HighlightOffDay(k);
                }
                else
                {
                    HighlightWorkingDay(k);
                }
                j++;
            }
            RaisePropertyChanged("MonthGrid");
        }
        public void Update(Habit habit, string name, DaysOff daysOff)
        {
            string query = "update habit set name = @name, days_off = @days_off where id = @id";

            using (var cmd = new NpgsqlCommand(query, _connection, _transaction))
            {
                cmd.Parameters.AddWithValue("name", name);
                cmd.Parameters.AddWithValue("days_off", daysOff);
                cmd.Parameters.AddWithValue("id", habit.ID);
                cmd.ExecuteNonQuery();
            }
        }
        public ActionResult <Habit> UpdateHabit(Guid user_id, Guid id, [FromBody] RequestData data)
        {
            Habit h = HabitRepository.GetHabitByID(id, user_id);

            if (h != null)
            {
                DaysOff daysoff = new DaysOff(data.DaysOff);
                HabitRepository.UpdateHabitData(id, user_id, data.Name, daysoff);
                return(Ok(h));
            }
            return(NotFound("habit not found"));
        }
 public ActionResult UseDayOff(DaysOff model)
 {
     try
     {
         _employeeService.UseDayOff(model);
         return(RedirectToAction("DaysLeft", new { id = model.EmployeeId }));
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         return(RedirectToAction("UseDayOff", new { id = model.EmployeeId }));
     }
 }
        public static void UpdateHabitData(Guid id, Guid user_id, string name, DaysOff daysOff)
        {
            SqlDataAdapter mySqlDataAdapter = DataAdapter("Habit");
            DataRow        row = db.Habit.Rows.Find(id);

            if (row != null && row["User_Id"].Equals(user_id))
            {
                row.BeginEdit();
                row["Name"] = name;
                UpdateDaysOff(id, user_id, daysOff);
                row.EndEdit();
                mySqlDataAdapter.Update(db, "Habit");
            }
        }
        public static void RegisterHabit(Guid user_id, string name, DaysOff daysOff, DateTime created_at)
        {
            Habit h = HabitFactory.CreateHabit(user_id, name, daysOff, created_at);

            SqlDataAdapter mySqlDataAdapter = DataAdapter("Habit");

            db.Habit.AddHabitRow(h.ID, h.UserID, h.Name, h.CurrentStreak, h.LongestStreak, h.LogCount, h.CreatedAt);

            mySqlDataAdapter.Update(db, "Habit");

            if (daysOff != null)
            {
                AssignDaysOff(h.ID, h.DaysOff);
            }
        }
예제 #20
0
 private void ValidateExistence(int id)
 {
     try
     {
         DaysOff daysOff = _daysOffRepository.Query().Where(_ => _.Id == id).FirstOrDefault();
         if (daysOff == null)
         {
             throw new InvalidDaysOffException("The Days Off already exists .");
         }
     }
     catch (ValidationException ex)
     {
         throw new CreateContractInvalidException(ex.ToListOfMessages());
     }
 }
        public static void AssignDaysOff(Guid habit_id, DaysOff daysOff)
        {
            List <int> DaysIDList = new List <int>();

            DaysIDList = GetDaysID(daysOff);

            SqlDataAdapter mySqlDataAdapter = DataAdapter("Days_Off");

            foreach (int i in DaysIDList)
            {
                DataRow dr = db.Days_Off.NewRow();
                dr["Habit_Id"] = habit_id.ToString();
                dr["Days_Id"]  = i.ToString();
                db.Tables["Days_Off"].Rows.Add(dr);
                mySqlDataAdapter.Update(db, "Days_Off");
            }
        }
        private static void UpdateDaysOff(Guid habit_id, Guid user_id, DaysOff daysOff)
        {
            SqlDataAdapter mySqlDataAdapter = DataAdapter("Days_Off");
            int            index            = 0;

            foreach (DataRow row in db.Days_Off.Rows)
            {
                if (row["Habit_Id"].Equals(habit_id))
                {
                    List <int> daysId = GetDaysID(daysOff);
                    row.BeginEdit();
                    row["Days_Id"] = daysId.ElementAt(index++).ToString();
                    row.EndEdit();
                }
            }
            mySqlDataAdapter.Update(db, "Days_Off");
        }
예제 #23
0
        private void Text_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            TextBlock currentButton = sender as TextBlock;

            if (currentButton != null)
            {
                int day    = SelectedDay.GetDayIndex(currentButton);
                int mIndex = MonthIndex;
                // i shall check if i can stay on the ranges.

                var value = YearMonthArray();
                var year  = Convert.ToInt16(value[0]);
                var month = Convert.ToInt16(value[1]);
                day = filterLimit(day, mIndex, year);
                var        param   = CreateCommand(day, false);
                List <int> daysOff = DaysOff.ToList();
                // avoid correction if it i have just clicked.


                if (SelectedDay.GetIsDaySelected(currentButton))
                {
                    currentButton.Background = Brushes.White;
                    daysOff.Remove(day);
                    SelectedDay.SetIsDaySelected(currentButton, false);
                }
                else
                {
                    param = CreateCommand(day, true);
                    currentButton.Background = Brushes.Yellow;
                    daysOff.Add(day);
                    SelectedDay.SetIsDaySelected(currentButton, true);
                }
                DaysOff = daysOff;
                // this make in a way that the reset command is internally called.

                if ((_resetCommand != null) && (!_resetCommand.Equals(ResetCommand)))
                {
                    ResetCommand = _resetCommand;
                }
                if (SelectedDayCommand != null)
                {
                    SelectedDayCommand.Execute(param);
                }
            }
        }
        private static List <int> GetDaysID(DaysOff days)
        {
            SqlDataAdapter mySqlDataAdapter = DataAdapter("Days");

            List <int> daysIDList = new List <int>();

            for (int i = 0; i < days.value.Length; i++)
            {
                for (int row = 0; row < db.Days.Rows.Count; row++)
                {
                    if (db.Days.Rows[row]["Name"].Equals(days.value.ElementAt(i)))
                    {
                        daysIDList.Add(int.Parse(db.Days.Rows[row]["Id"].ToString()));
                    }
                }
            }
            return(daysIDList);
        }
예제 #25
0
        public static Paycheck Create(
            DateTime date, Period period, WorkingHours workingHours, DaysOff daysOff, PayRate payRate, string employeeId)
        {
            var subTotal = CalculateSubTotals(workingHours, daysOff, payRate);

            return(new Paycheck()
            {
                Date = date,
                Period = period,
                WorkingHours = workingHours,
                DaysOff = daysOff,
                PayRate = payRate,
                SubTotals = subTotal,
                Total = CalculateTotal(subTotal),
                IsPaied = false,
                EmployeeId = employeeId
            });
        }
예제 #26
0
        public void Delete(int id)
        {
            _log.LogInformation($"Searching days Off {id}");
            DaysOff daysOff = _daysOffRepository.Query().Where(_ => _.Id == id).FirstOrDefault();

            if (daysOff == null)
            {
                throw new DeleteDaysOffNotFoundException(id);
            }
            _log.LogInformation($"Deleting days Off {id}");
            _daysOffRepository.Delete(daysOff);

            if (string.IsNullOrEmpty(daysOff.GoogleCalendarEventId) && !DeleteEventInGoogleCalendar(daysOff))
            {
                _log.LogInformation($"Could not delete google calendar event for days off {id}");
            }

            _unitOfWork.Complete();
        }
        public void UseDayOff(DaysOff model)
        {
            if (model == null)
            {
                return;
            }
            if ((model.EndDate - model.StartDate).Days < model.AmountOfDays)
            {
                return;
            }
            if (model.EndDate < model.StartDate)
            {
                return;
            }
            var vacay = RemainingDaysOff(model.EmployeeId);

            switch (model.Discriminator)
            {
            case "sick leave" when vacay.SickLeaveDays < model.AmountOfDays:
                return;

            case "sick leave":
                vacay.SickLeaveDays -= model.AmountOfDays;
                ExecuteNonQuery("insert into DaysOffs ([EmployeeId],[Discriminator],[StartDate],[EndDate],[AmountOfDays],[Approved]) " +
                                $"values({model.EmployeeId}, '{model.Discriminator}',  ('{model.StartDate:yyyy-MM-dd HH:mm:ss.fff}'),  ('{model.EndDate:yyyy-MM-dd HH:mm:ss.fff}'), {model.AmountOfDays}, {(model.Approved ? 1 : 0)})");
                SaveChanges();
                Context.Entry(vacay).State = EntityState.Modified;
                SaveChanges();
                break;

            case "vacation" when vacay.VacationDays < model.AmountOfDays:
                return;

            case "vacation":
                vacay.VacationDays -= model.AmountOfDays;
                ExecuteNonQuery("insert into DaysOffs ([EmployeeId],[Discriminator],[StartDate],[EndDate],[AmountOfDays],[Approved]) " +
                                $"values({model.EmployeeId}, '{model.Discriminator}',  ('{model.StartDate:yyyy-MM-dd HH:mm:ss.fff}'),  ('{model.EndDate:yyyy-MM-dd HH:mm:ss.fff}'), {model.AmountOfDays}, {(model.Approved ? 1 : 0)})");
                SaveChanges();
                Context.Entry(vacay).State = EntityState.Modified;
                SaveChanges();
                break;
            }
        }
예제 #28
0
        public void addNewHabit(string name, Guid userID, string[] days)
        {
            if (name == null)
            {
                throw new ArgumentException("name cannot be empty");
            }

            Habit h = HabitFactory.addNewHabit(userID, name);

            _context.Habits.Add(h);

            DaysOffValue dv = HabitFactory.value(days);

            if (!days.Equals(null))
            {
                DaysOff d = HabitFactory.AssignDaysOff(h.ID, dv.value);
                _context.daysOffs.Add(d);
            }
        }
예제 #29
0
        private void HandleChangedMonthYear()
        {
            int day = 1;

            string[] yearMonth = YearMonthArray();
            if ((yearMonth.Length == 2) && (!string.IsNullOrEmpty(yearMonth[0])) && (!string.IsNullOrEmpty(yearMonth[1])))
            {
                var      year          = Convert.ToInt16(yearMonth[0]);
                var      month         = Convert.ToInt16(yearMonth[1]);
                DateTime firstDayMonth = new DateTime(year, month, day);
                // now i shall generate the numbers.
                DayOfWeek dayOfWeek = firstDayMonth.DayOfWeek;
                MonthName = firstDayMonth.ToString("Y");
                int currentIterator = (int)dayOfWeek;
                int numdays         = computeNumberDays(year, month - 1);
                int j = 1;
                for (int k = currentIterator; k < 38; ++k)
                {
                    if (j > numdays)
                    {
                        break;
                    }

                    _monthGrid[k] = string.Format("{0}", j);
                    if (DaysOff.Contains <int>(j))
                    {
                        HighlightOffDay(j, k);
                    }
                    else
                    {
                        HighlightWorkingDay(j, k);
                    }
                    j++;
                }
                RaisePropertyChanged("MonthGrid");
            }
        }
예제 #30
0
        public string AddModelToGoogleCalendar(DaysOff daysOff)
        {
            Event newEvent = new Event
            {
                Summary = ((DaysOffType)daysOff.Type).ToString(),
                Start   = new EventDateTime()
                {
                    DateTime = new System.DateTime(daysOff.Date.Date.Year, daysOff.Date.Date.Month, daysOff.Date.Date.Day, 8, 0, 0)
                },
                End = new EventDateTime()
                {
                    DateTime = new System.DateTime(daysOff.EndDate.Date.Year, daysOff.EndDate.Date.Month, daysOff.EndDate.Date.Day, 8, 0, 0)
                },
                Attendees = new List <EventAttendee>()
            };

            newEvent.Attendees.Add(new EventAttendee()
            {
                Email = daysOff.Employee.EmailAddress
            });
            //newEvent.Attendees.Add(new EventAttendee() { Email = "*****@*****.**" });

            return(_googleCalendarService.CreateEvent(newEvent));
        }