Beispiel #1
0
        private void AddEvent(Reminder reminder)
        {
            var calendar = (CalendarListEntry)cbCalendars.SelectedItem;

            var calEvent = new Event
            {
                Summary = tbEventName.Text,
                Location = "Check Point Software Technologies, הסוללים 5, Tel Aviv-Yafo, 67897, Israel",
                Start = new EventDateTime
                {
                    DateTime = reminder.Start
                },
                End = new EventDateTime
                {
                    DateTime = reminder.End
                },
                Description = $"{GoogleCalendarIdentifyer}\nJob: {reminder.JobName}\nHours: {(reminder.End - reminder.Start).TotalHours} h\nSalary: {CalculateSalaryPerDay(reminder)} NIS",
                //Reminders = new Event.RemindersData {UseDefault = false}
            };

            //Set Remainder
            var prevEvents = IsEventExist(calEvent.Summary, calEvent.Start.DateTime);
            if (prevEvents.IsNotEmptyObject())
            {
                prevEvents.ForEach(e => DeleteEvent(e.Id));
            }

            _googleCalendar.CalendarConnection.Events.Insert(calEvent, calendar.Id).Execute();
        }
        private static Excel.Range _range; // current range of curent excel

        #endregion Fields

        #region Methods

        public static WorkSchedule GetWorkHours(string filePath, string workerName)
        {
            var xlApp = new Excel.Application();
            var xlWorkBook = xlApp.Workbooks.Open(filePath, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
            var xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.Item[1];

            _range = xlWorkSheet.UsedRange;

            var name = workerName.Trim();
            var counter = 0;

            var workSchedule = new WorkSchedule
            {
                Name = name,
                //StartDateTime = Convert.ToDateTime(GetCellValue(4, 2)),
                //EndDateTime = Convert.ToDateTime(GetCellValue(4, 14))
                StartDateTime = DateTime.ParseExact(GetCellValue(4, 2), "d.M.yyyy", CultureInfo.InvariantCulture),
                EndDateTime = DateTime.ParseExact(GetCellValue(22, 2), "d.M.yyyy", CultureInfo.InvariantCulture)
            };

            for (var i = 1; i <= _range.Rows.Count; i++)
            {
                for (var j = 1; j <= _range.Columns.Count; j++)
                {
                    var cell = GetCellValue(i, j);

                    #region Old Discount
                    //if (cell == name)
                    //{
                    //    counter++;
                    //    string[] start = null, end = null;
                    //    var cellTimes = GetCellValue(i - 1, j);
                    //    if (!string.IsNullOrEmpty(cellTimes) && cellTimes.Contains(":"))
                    //    {
                    //        start = cellTimes.Split(':');
                    //    }

                    //    cellTimes = GetCellValue(i - 1, j + 1);
                    //    if (!string.IsNullOrEmpty(cellTimes) && cellTimes.Contains(":"))
                    //    {
                    //        end = cellTimes.Split(':');
                    //    }

                    //    var date = Convert.ToDateTime(GetCellValue(4, j));
                    //    if (start != null && end != null)
                    //    {
                    //        var reminder = new Reminder
                    //        {
                    //            DayDesc = GetCellValue(3, j),
                    //            Start = date.AddHours(int.Parse(start[0])).AddMinutes(int.Parse(start[1])),
                    //            End = date.AddHours(int.Parse(end[0])).AddMinutes(int.Parse(end[1])),
                    //            JobName = GetCellValue(i - 1, 1),
                    //        };

                    //        // check if end time in next day
                    //        if ((reminder.End - reminder.Start).TotalHours < 0)
                    //        {
                    //            reminder.End = reminder.End.AddDays(1);
                    //        }

                    //        workSchedule.Reminders.Add(reminder);
                    //    }
                    //}
                    #endregion

                    #region CheckPoint
                    if (cell != null && cell.Contains(name))
                    {
                        counter++;
                        int[] start = null, end = null;
                        var cellTimes = GetCellValue(i, 3);
                        if (!string.IsNullOrEmpty(cellTimes))
                        {
                            cellTimes = cellTimes.Trim();

                            if (cellTimes.Equals("בוקר"))
                            {
                                start = new [] {07 ,00};
                                end = new [] {15 ,00};
                            }

                            if(cellTimes.Equals("צהריים"))
                            {
                                start = new[] { 15, 00 };
                                end = new[] { 23, 00 };
                            }

                            if(cellTimes.Equals("לילה"))
                            {
                                start = new[] {23, 00 };
                                end = new[] { 07, 00 };
                            }
                        }
                        var date = TryGetDate(i, 2);
                        if (start.IsAny() && end.IsAny())
                        {
                            var reminder = new Reminder
                            {
                                DayDesc = TryGetDayDesc(i, 2),
                                Start = date.AddHours(start[0]).AddMinutes(start[1]),
                                End = date.AddHours(end[0]).AddMinutes(end[1]),
                                JobName = GetCellValue(2, j)
                            };

                            // check if end time in next day
                            if ((reminder.End - reminder.Start).TotalHours < 0)
                            {
                                reminder.End = reminder.End.AddDays(1);
                            }

                            workSchedule.Reminders.Add(reminder);
                        }
                    }
                    #endregion
                }
            }

            workSchedule.Reminders = workSchedule.Reminders.OrderBy(r => r.Start).ToList();

            //MessageBox.Show(text);

            xlWorkBook.Close(true);
            xlApp.Quit();

            ReleaseObject(xlWorkSheet);
            ReleaseObject(xlWorkBook);
            ReleaseObject(xlApp);

            if (counter > 0)
            {
                var json = JsonConvert.SerializeObject(workSchedule, Formatting.Indented);
                var fileName =
                    $@"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\{
                        workSchedule.StartDateTime.ToString("dd.MM.yy")}-{workSchedule.EndDateTime.ToString("dd.MM.yy")
                        }_{name}.txt";

                if (Utils.IsMishaPc())
                {
                    File.WriteAllText(fileName, json);
                }

                return workSchedule;
            }
            else
            {
                return null;
            }
        }
Beispiel #3
0
        private void btnAddEvent_Click(object sender, EventArgs e)
        {
            btnAddEvent.Enabled = false;
            var endTime = cbEnd.SelectedItem.ToString().Split(':').Select(int.Parse).ToList();
            var endDateTime = dtPicker.Value.ChangeTime(endTime[0], endTime[1]);

            var reminder = new Reminder
            {
                JobName = "Custom Job",
                Start = dtPicker.Value,
                End = dtPicker.Value > endDateTime ? endDateTime.AddDays(1) : endDateTime
            };

            AddEvent(reminder);
            btnAddEvent.Enabled = true;
            MessageBox.Show(reminder.ToString());
        }
Beispiel #4
0
        private double? CalculateSalaryPerDay(Reminder reminder)
        {
            if (reminder.IsNotEmptyObject())
            {
                double sum = 0;
                var totalHours = (reminder.End - reminder.Start).TotalHours;
                var salary = double.Parse(tbSalary.Text);
                double percent = 1;
                var counter = 1;

                while (totalHours > 0)
                {
                    if (counter > 8 && counter % 2 != 0)
                    {
                        percent += 0.25;
                    }

                    if (totalHours < 1)
                    {
                        sum += salary * totalHours * percent;
                    }
                    else
                    {
                        sum += salary * percent;
                    }
                    totalHours--;
                    counter++;
                }

                return sum;
            }

            return null;
        }