예제 #1
0
        internal static void AddIllness(Illness illness, int dayCounter)
        {
            string holidayDescription = "";
            int    numbersOfDays      = DateTime.DaysInMonth(MainForm.mainDate.Year, MainForm.mainDate.Month);

            Polaczenia.BeginTransactionSerializable();
            for (int i = 1; i <= dayCounter; i++)
            {
                if (illness.Date.DayOfWeek == DayOfWeek.Sunday)
                {
                    string       temp   = string.Format("Podawany dzień {0} jest dniem wolnym od pracy - NIEDZIELA\n Czy napewno dodać zasiłek do bazy danych?", illness.Date.ToShortDateString());
                    DialogResult result = MessageBox.Show(temp, "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        WorkManager.AddWorkTime(illness, ConnectionToDB.notDisconnect);
                    }
                }
                else if (illness.Date.DayOfWeek == DayOfWeek.Saturday)
                {
                    string       temp   = string.Format("Podawany dzień {0} jest dniem wolnym od pracy - SOBOTA\n Czy napewno dodać zasiłek do bazy danych?", illness.Date.ToShortDateString());
                    DialogResult result = MessageBox.Show(temp, "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        WorkManager.AddWorkTime(illness, ConnectionToDB.notDisconnect);
                    }
                }
                //sprawdza czy nie przypada w dzień wolny - święto
                else if (Holidays.IsHoliday(illness.Date, out holidayDescription, ConnectionToDB.notDisconnect))
                {
                    string       temp   = string.Format("W dniu {0} przypada {1}.\nCzy napewno dodać zasiłek do bazy danych?", illness.Date.ToShortDateString(), holidayDescription);
                    DialogResult result = MessageBox.Show(temp, "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        WorkManager.AddWorkTime(illness, ConnectionToDB.notDisconnect);
                    }
                }
                else
                {
                    WorkManager.AddWorkTime(illness, ConnectionToDB.notDisconnect);
                }

                illness.Date = illness.Date.AddDays(1);//next day
            }
            Polaczenia.CommitTransaction();
            //jeżeli wpisuje godziny w ostatni dzień miesiąca to nie przechodzi na kolejny
            if (numbersOfDays != MainForm.mainDate.Day)
            {
                MainForm.mainDate = MainForm.mainDate.AddDays(1);
            }
        }
예제 #2
0
        public void ChildrensDay_NOK()
        {
            var childrensDay = new List <DateTime>();

            childrensDay.Add(new DateTime(1980, 10, 11));
            childrensDay.Add(new DateTime(2018, 10, 13));
            childrensDay.Add(new DateTime(2040, 09, 12));
            childrensDay.Add(new DateTime(1994, 11, 12));

            foreach (var item in childrensDay)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #3
0
        public void BlackConsciousnessDay_NOK()
        {
            var blackConsciousness = new List <DateTime>();

            blackConsciousness.Add(new DateTime(1980, 11, 19));
            blackConsciousness.Add(new DateTime(2018, 11, 21));
            blackConsciousness.Add(new DateTime(2040, 11, 24));
            blackConsciousness.Add(new DateTime(1994, 11, 23));
            blackConsciousness.Add(new DateTime(2019, 11, 24));

            foreach (var item in blackConsciousness)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #4
0
        public void ChristmasDay_NOK()
        {
            var christmas = new List <DateTime>();

            christmas.Add(new DateTime(1980, 12, 26));
            christmas.Add(new DateTime(2018, 11, 23));
            christmas.Add(new DateTime(2040, 10, 24));
            christmas.Add(new DateTime(1994, 12, 22));
            christmas.Add(new DateTime(2019, 09, 25));

            foreach (var item in christmas)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #5
0
        public void AnoNovo_OK()
        {
            var newYears = new List <DateTime>();


            newYears.Add(new DateTime(1980, 01, 01));
            newYears.Add(new DateTime(2019, 01, 01));
            newYears.Add(new DateTime(2040, 01, 01));
            newYears.Add(new DateTime(1994, 01, 01));

            foreach (var item in newYears)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(true, result);
            }
        }
예제 #6
0
        public void AllSoulsDay_NOK()
        {
            var allSoulsDay = new List <DateTime>();

            allSoulsDay.Add(new DateTime(1980, 11, 03));
            allSoulsDay.Add(new DateTime(2018, 11, 01));
            allSoulsDay.Add(new DateTime(2040, 11, 01));
            allSoulsDay.Add(new DateTime(1994, 12, 02));
            allSoulsDay.Add(new DateTime(2019, 10, 02));

            foreach (var item in allSoulsDay)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #7
0
        public void IndependenceDay_NOK()
        {
            var independenceDay = new List <DateTime>();

            independenceDay.Add(new DateTime(1980, 09, 08));
            independenceDay.Add(new DateTime(2018, 09, 06));
            independenceDay.Add(new DateTime(2040, 09, 05));
            independenceDay.Add(new DateTime(1994, 09, 12));
            independenceDay.Add(new DateTime(2019, 10, 07));

            foreach (var item in independenceDay)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #8
0
        public void AnoNovo_ComFacultativos_NOK()
        {
            var newYearsOpt = new List <DateTime>();

            newYearsOpt.Add(new DateTime(1999, 12, 29));
            newYearsOpt.Add(new DateTime(1996, 12, 02));
            newYearsOpt.Add(new DateTime(2025, 12, 29));
            newYearsOpt.Add(new DateTime(2042, 12, 02));
            newYearsOpt.Add(new DateTime(1993, 12, 29));

            foreach (var item in newYearsOpt)
            {
                var result = Holidays.IsHoliday(item, true);

                Assert.AreEqual(false, result);
            }
        }
예제 #9
0
        public void Tirandentes_OK()
        {
            var tiradentes = new List <DateTime>();

            tiradentes.Add(new DateTime(1980, 04, 21));
            tiradentes.Add(new DateTime(2019, 04, 21));
            tiradentes.Add(new DateTime(2018, 04, 21));
            tiradentes.Add(new DateTime(2030, 04, 21));
            tiradentes.Add(new DateTime(2040, 04, 21));

            foreach (var item in tiradentes)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(true, result);
            }
        }
예제 #10
0
        public void RepublicProclamation_NOK()
        {
            var republicProclamation = new List <DateTime>();

            republicProclamation.Add(new DateTime(1980, 11, 16));
            republicProclamation.Add(new DateTime(2018, 11, 14));
            republicProclamation.Add(new DateTime(2040, 11, 17));
            republicProclamation.Add(new DateTime(1994, 10, 13));
            republicProclamation.Add(new DateTime(2019, 12, 15));

            foreach (var item in republicProclamation)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #11
0
        public void WordDay_OK()
        {
            var WorkDay = new List <DateTime>();

            WorkDay.Add(new DateTime(1980, 05, 01));
            WorkDay.Add(new DateTime(2019, 05, 01));
            WorkDay.Add(new DateTime(2030, 05, 01));
            WorkDay.Add(new DateTime(2040, 05, 01));
            WorkDay.Add(new DateTime(1940, 05, 01));
            WorkDay.Add(new DateTime(2089, 05, 01));

            foreach (var item in WorkDay)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(true, result);
            }
        }
예제 #12
0
        public void AnoNovo_ComFacultativos_OK()
        {
            var newYearsOpt = new List <DateTime>();

            newYearsOpt.Add(new DateTime(1979, 12, 31));
            newYearsOpt.Add(new DateTime(1980, 01, 01));
            newYearsOpt.Add(new DateTime(2019, 12, 31));
            newYearsOpt.Add(new DateTime(2020, 01, 01));
            newYearsOpt.Add(new DateTime(1994, 12, 31));
            newYearsOpt.Add(new DateTime(1995, 01, 01));

            foreach (var item in newYearsOpt)
            {
                var result = Holidays.IsHoliday(item, true);

                Assert.AreEqual(true, result);
            }
        }
예제 #13
0
        public void SaoPauloBirthday_OK()
        {
            var birthdaySP = new List <DateTime>();

            birthdaySP.Add(new DateTime(1980, 01, 25));
            birthdaySP.Add(new DateTime(2019, 01, 25));
            birthdaySP.Add(new DateTime(2018, 01, 25));
            birthdaySP.Add(new DateTime(2019, 01, 25));
            birthdaySP.Add(new DateTime(2040, 01, 25));
            birthdaySP.Add(new DateTime(1994, 01, 25));

            foreach (var item in birthdaySP)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(true, result);
            }
        }
예제 #14
0
        public void OptionalDate_NOK()
        {
            var optionalDate = new List <DateTime>();

            optionalDate.Add(new DateTime(2018, 12, 30));
            optionalDate.Add(new DateTime(2018, 12, 23));
            optionalDate.Add(new DateTime(2040, 12, 23));
            optionalDate.Add(new DateTime(2040, 12, 26));
            optionalDate.Add(new DateTime(2019, 03, 03));
            optionalDate.Add(new DateTime(2020, 02, 26));

            foreach (var item in optionalDate)
            {
                var result = Holidays.IsHoliday(item, true);

                Assert.AreEqual(false, result);
            }
        }
예제 #15
0
        public void Natal_ComFacultativos_NOK()
        {
            var christmasOpt = new List <DateTime>();

            christmasOpt.Add(new DateTime(1999, 12, 23));
            christmasOpt.Add(new DateTime(1999, 12, 26));
            christmasOpt.Add(new DateTime(2025, 12, 23));
            christmasOpt.Add(new DateTime(2025, 12, 26));
            christmasOpt.Add(new DateTime(2030, 12, 23));
            christmasOpt.Add(new DateTime(2030, 12, 26));

            foreach (var item in christmasOpt)
            {
                var result = Holidays.IsHoliday(item, true);

                Assert.AreEqual(false, result);
            }
        }
예제 #16
0
        public void CorpusChrist_NOK()

        {
            List <DateTime> carnaval = new List <DateTime>();

            carnaval.Add(new DateTime(2006, 06, 14));
            carnaval.Add(new DateTime(2019, 06, 21));
            carnaval.Add(new DateTime(2020, 06, 12));
            carnaval.Add(new DateTime(1980, 06, 04));
            carnaval.Add(new DateTime(1986, 05, 28));

            foreach (var item in carnaval)

            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #17
0
        private void Parse(ICSCalendar calendar)
        {
            Calendar.Clear();
            //2017.09.01 je prvni den pocitani supportu
            var validCalendar = calendar.Events.Where(e => e.StartDate > new DateTime(2017, 8, 31)).OrderBy(e => e.StartDate.Year).ThenBy(e => e.StartDate.Month);

            foreach (ICSEvent icsEvent in validCalendar)
            {
                var supportEvent = new SupportEvent(icsEvent, Holidays.IsHoliday(icsEvent.StartDate));
                var key          = $"{supportEvent.Date.Year}/{supportEvent.Date.Month}";
                if (!Calendar.ContainsKey(key))
                {
                    Calendar[key] = new List <SupportEvent>();
                }
                Calendar[key].Add(supportEvent);
            }

            CalendarDefinitions = calendar.Definition;
        }
예제 #18
0
        public void Carnaval_NOK()

        {
            List <DateTime> carnaval = new List <DateTime>();

            carnaval.Add(new DateTime(2006, 02, 27));
            carnaval.Add(new DateTime(2019, 03, 04));
            carnaval.Add(new DateTime(2020, 02, 24));
            carnaval.Add(new DateTime(1980, 02, 18));
            carnaval.Add(new DateTime(1986, 02, 12));

            foreach (var item in carnaval)

            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #19
0
        internal static void CheckPossibilityToSaveDayOff(DayOff dayOff, int dayCounter)
        {
            string holidayDescription = "";

            if (dayOff.IsAlreadyInDataBase())
            {
                throw new AlreadyExistsException(string.Format("W dniu {0} pracownik był na urlopie.\nProszę sprawdzić datę i spróbować ponownie.", dayOff.Date.ToShortDateString()));
            }
            else if (Illness.IsAlreadyInDataBase(dayOff.IdEmployee, dayOff.Date))
            {
                throw new AlreadyExistsException(string.Format("W dniu {0} pracownik był na zwolnieniu lekarskim.\nProszę sprawdzić datę i spróbować ponownie.", dayOff.Date.ToShortDateString()));
            }
            else if (Work.IsAlreadyInDataBase(dayOff.IdEmployee, dayOff.Date))
            {
                string       temp   = string.Format("W dniu {0} pracownik był w pracy.\nCzy napewno dodać urlop do bazy danych?", dayOff.Date.ToShortDateString());
                DialogResult result = MessageBox.Show(temp, "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    throw new CancelException("Anulowano");
                }
            }

            if (dayCounter > 1)//jeżeli wpisywanie wielu dni to exit
            {
                return;
            }

            if (dayOff.Date.DayOfWeek == DayOfWeek.Sunday)
            {
                throw new WrongDateTimeException(string.Format("Podawany dzień {0} jest dniem wolnym od pracy - NIEDZIELA", dayOff.Date.ToShortDateString()));
            }
            else if (dayOff.Date.DayOfWeek == DayOfWeek.Saturday)
            {
                throw new WrongDateTimeException(string.Format("Podawany dzień {0} jest dniem wolnym od pracy - SOBOTA", dayOff.Date.ToShortDateString()));
            }
            else if (Holidays.IsHoliday(dayOff.Date, out holidayDescription))
            {
                throw new WrongDateTimeException(string.Format("W dniu {0} przypada {1}.", dayOff.Date.ToShortDateString(), holidayDescription));
            }
        }
예제 #20
0
        public void Carnaval_ComFacultativo_NOK()

        {
            List <DateTime> carnaval = new List <DateTime>();

            carnaval.Add(new DateTime(2006, 02, 26));
            carnaval.Add(new DateTime(2019, 03, 03));
            carnaval.Add(new DateTime(2019, 03, 06));
            carnaval.Add(new DateTime(2020, 02, 23));
            carnaval.Add(new DateTime(2020, 02, 26));
            carnaval.Add(new DateTime(1980, 02, 17));
            carnaval.Add(new DateTime(1980, 02, 20));
            carnaval.Add(new DateTime(1986, 02, 12));

            foreach (var item in carnaval)

            {
                var result = Holidays.IsHoliday(item, true);

                Assert.AreEqual(false, result);
            }
        }
예제 #21
0
        internal static void CheckPossibilityToSaveWork(Work work)
        {
            string holidayDescription = "";

            //sprawdza, czy był już wpis o podanej dacie w tabeli praca
            if (work.IsAlreadyInDataBase())
            {
                throw new AlreadyExistsException(string.Format("W dniu {0} pracownik był w pracy.\nProszę sprawdzić datę i spróbować ponownie.", work.Date.ToShortDateString()));
            }//sprawdza, czy był już wpis o podanej dacie w tabeli choroba
            else if (Illness.IsAlreadyInDataBase(work.IdEmployee, work.Date))
            {
                string       temp   = string.Format("W dniu {0} pracownik był na zwolnieniu lekarskim.\nCzy napewno dodać godziny do bazy danych?", work.Date.ToShortDateString());
                DialogResult result = MessageBox.Show(temp, "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    throw new CancelException("Anulowano");
                }
            }
            //jeżeli nie było wpisu to sprawdza następnie tabele urlop
            else if (DayOff.IsAlreadyInDataBase(work.IdEmployee, work.Date))
            {
                string       temp   = string.Format("W dniu {0} pracownik był na urlopie.\nCzy napewno dodać godziny do bazy danych?", work.Date.ToShortDateString());
                DialogResult result = MessageBox.Show(temp, "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    throw new CancelException("Anulowano");
                }
            }
            else if (Holidays.IsHoliday(work.Date, out holidayDescription))
            {
                string       temp   = string.Format("W dniu {0} przypada {1}.\nCzy napewno dodać godziny do bazy danych?", work.Date.ToShortDateString(), holidayDescription);
                DialogResult result = MessageBox.Show(temp, "Pytanie", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    throw new CancelException("Anulowano");
                }
            }
        }
예제 #22
0
        public void RevolutionDay_NOK()
        {
            var revolutionDay = new List <DateTime>();

            revolutionDay.Add(new DateTime(1980, 07, 06));
            revolutionDay.Add(new DateTime(2019, 07, 08));
            revolutionDay.Add(new DateTime(2030, 07, 11));
            revolutionDay.Add(new DateTime(2040, 03, 09));
            revolutionDay.Add(new DateTime(2040, 04, 09));
            revolutionDay.Add(new DateTime(2040, 06, 09));
            revolutionDay.Add(new DateTime(2040, 08, 09));
            revolutionDay.Add(new DateTime(2040, 09, 09));
            revolutionDay.Add(new DateTime(2040, 10, 09));
            revolutionDay.Add(new DateTime(2040, 11, 09));
            revolutionDay.Add(new DateTime(2040, 12, 09));

            foreach (var item in revolutionDay)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #23
0
        public void Tirandentes_NOK()
        {
            var tiradentes = new List <DateTime>();

            tiradentes.Add(new DateTime(1980, 04, 20));
            tiradentes.Add(new DateTime(2018, 04, 23));
            tiradentes.Add(new DateTime(2030, 03, 21));
            tiradentes.Add(new DateTime(2040, 05, 21));
            tiradentes.Add(new DateTime(2040, 06, 21));
            tiradentes.Add(new DateTime(2040, 07, 21));
            tiradentes.Add(new DateTime(2040, 08, 21));
            tiradentes.Add(new DateTime(2040, 09, 21));
            tiradentes.Add(new DateTime(2040, 10, 21));
            tiradentes.Add(new DateTime(2040, 11, 21));
            tiradentes.Add(new DateTime(2040, 12, 21));

            foreach (var item in tiradentes)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #24
0
        public void SaoPauloBirthday_NOK()
        {
            var birthdaySP = new List <DateTime>();

            birthdaySP.Add(new DateTime(1980, 01, 26));
            birthdaySP.Add(new DateTime(2019, 01, 24));
            birthdaySP.Add(new DateTime(2019, 02, 25));
            birthdaySP.Add(new DateTime(2040, 04, 25));
            birthdaySP.Add(new DateTime(1994, 05, 25));
            birthdaySP.Add(new DateTime(1994, 06, 25));
            birthdaySP.Add(new DateTime(1994, 07, 25));
            birthdaySP.Add(new DateTime(1994, 08, 25));
            birthdaySP.Add(new DateTime(1994, 09, 25));
            birthdaySP.Add(new DateTime(1994, 10, 25));
            birthdaySP.Add(new DateTime(1994, 11, 25));

            foreach (var item in birthdaySP)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #25
0
        public void GoodFriday_OK()
        {
            var goodFriday = new List <DateTime>();

            goodFriday.Add(new DateTime(2019, 4, 19));
            goodFriday.Add(new DateTime(2020, 4, 10));
            goodFriday.Add(new DateTime(2021, 4, 2));
            goodFriday.Add(new DateTime(2022, 4, 15));
            goodFriday.Add(new DateTime(2023, 4, 7));
            goodFriday.Add(new DateTime(2024, 3, 29));
            goodFriday.Add(new DateTime(2025, 4, 18));
            goodFriday.Add(new DateTime(2026, 4, 3));
            goodFriday.Add(new DateTime(2027, 3, 26));
            goodFriday.Add(new DateTime(2028, 4, 14));
            goodFriday.Add(new DateTime(2029, 3, 30));

            foreach (var item in goodFriday)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(true, result);
            }
        }
예제 #26
0
        public void WorDay_NOK()
        {
            var WorkDay = new List <DateTime>();

            WorkDay.Add(new DateTime(1980, 05, 02));
            WorkDay.Add(new DateTime(2019, 04, 01));
            WorkDay.Add(new DateTime(2030, 02, 01));
            WorkDay.Add(new DateTime(2040, 03, 01));
            WorkDay.Add(new DateTime(2040, 04, 30));
            WorkDay.Add(new DateTime(2040, 06, 01));
            WorkDay.Add(new DateTime(2040, 07, 01));
            WorkDay.Add(new DateTime(2040, 08, 01));
            WorkDay.Add(new DateTime(2040, 09, 01));
            WorkDay.Add(new DateTime(2040, 10, 01));
            WorkDay.Add(new DateTime(2040, 11, 01));
            WorkDay.Add(new DateTime(2040, 12, 01));

            foreach (var item in WorkDay)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(false, result);
            }
        }
예제 #27
0
        public void Carnaval_ComFacultativo_OK()

        {
            List <DateTime> carnaval = new List <DateTime>();

            carnaval.Add(new DateTime(2006, 02, 28));
            carnaval.Add(new DateTime(2006, 02, 27));
            carnaval.Add(new DateTime(2019, 03, 05));
            carnaval.Add(new DateTime(2019, 03, 04));
            carnaval.Add(new DateTime(2020, 02, 25));
            carnaval.Add(new DateTime(2020, 02, 24));
            carnaval.Add(new DateTime(1980, 02, 19));
            carnaval.Add(new DateTime(1980, 02, 18));
            carnaval.Add(new DateTime(1986, 02, 11));
            carnaval.Add(new DateTime(1986, 02, 10));

            foreach (var item in carnaval)

            {
                var result = Holidays.IsHoliday(item, true);

                Assert.AreEqual(true, result);
            }
        }
예제 #28
0
        public void RevolutionDay_OK()
        {
            var revolutionDay = new List <DateTime>();

            revolutionDay.Add(new DateTime(1980, 07, 09));
            revolutionDay.Add(new DateTime(2019, 07, 09));
            revolutionDay.Add(new DateTime(2030, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));
            revolutionDay.Add(new DateTime(2040, 07, 09));

            foreach (var item in revolutionDay)
            {
                var result = Holidays.IsHoliday(item, false);

                Assert.AreEqual(true, result);
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (isWorkTimeChange)
                {
                    Work w = new Work();
                    w.IdEmployee = idEmployee;
                    w.Date       = date;
                    w.StartTime  = Convert.ToDateTime(tbWorkFrom.Text.ToString());
                    w.StopTime   = Convert.ToDateTime(tbWorkTo.Text.ToString());
                    //to sprawdza czy godzina przyjścia jest mniejsza od godziny wyjścia
                    if (w.StartTime.TimeOfDay > w.StopTime.TimeOfDay)
                    {
                        throw new WrongDateTimeException("Godzina wyjścia jest mniejsza od godziny przyjścia.");
                    }
                    w.Edit(w, ConnectionToDB.disconnect);
                }
                else
                {
                    Polaczenia.BeginTransactionSerializable();

                    //usuwanie zamienianych danych z bazy
                    switch (currentWorkType)
                    {
                    case WorkType.work:    //praca
                        WorkManager.DeleteWorkTime(WorkType.work, idEmployee, date, ConnectionToDB.notDisconnect);
                        break;

                    case WorkType.illness:    //choroba
                        WorkManager.DeleteWorkTime(WorkType.illness, idEmployee, date, ConnectionToDB.notDisconnect);
                        break;

                    case WorkType.dayOff:    //urlop
                        DayOff dayOff = WorkManager.GetDayOff(idEmployee, date, ConnectionToDB.notDisconnect);
                        WorkManager.DeleteWorkTime(WorkType.dayOff, idEmployee, date, ConnectionToDB.notDisconnect);
                        //dodaje urlop do puli urlopów z bazy danych
                        if (dayOff.IdTypeDayOff == (int)DayOffType.halfDay)
                        {
                            dayOff.DayOffAddition("0.5", ConnectionToDB.notDisconnect);
                        }
                        if (dayOff.IdTypeDayOff == (int)DayOffType.rest)
                        {
                            dayOff.DayOffAddition("1", ConnectionToDB.notDisconnect);
                        }
                        break;
                    }
                    //Polaczenia.CommitTransaction();
                    //dodawanie nowych danych do bazy
                    switch (changeForWhatWorkType)
                    {
                    case WorkType.work:    //praca
                        Work w = new Work();
                        w.IdEmployee = idEmployee;
                        w.Date       = date;
                        w.StartTime  = Convert.ToDateTime(tbWorkFrom.Text.ToString());
                        w.StopTime   = Convert.ToDateTime(tbWorkTo.Text.ToString());
                        //to sprawdza czy godzina przyjścia jest mniejsza od godziny wyjścia
                        if (w.StartTime.TimeOfDay > w.StopTime.TimeOfDay)
                        {
                            throw new WrongDateTimeException("Godzina wyjścia jest mniejsza od godziny przyjścia.");
                        }
                        WorkManager.AddWorkTime(w, ConnectionToDB.notDisconnect);
                        break;

                    case WorkType.illness:    //choroba
                        Illness illness = new Illness();
                        illness.IdEmployee    = idEmployee;
                        illness.Date          = date;
                        illness.IdIllnessType = Convert.ToInt32(cbType.SelectedValue);
                        WorkManager.AddWorkTime(illness, ConnectionToDB.notDisconnect);
                        break;

                    case WorkType.dayOff:    //urlop
                        DayOff dayOff = new DayOff();
                        dayOff.IdEmployee   = idEmployee;
                        dayOff.Date         = date;
                        dayOff.IdTypeDayOff = Convert.ToInt32(cbType.SelectedValue);
                        if (dayOff.Date.DayOfWeek != DayOfWeek.Sunday && dayOff.Date.DayOfWeek != DayOfWeek.Saturday && !Holidays.IsHoliday(dayOff.Date, ConnectionToDB.notDisconnect))
                        {
                            WorkManager.AddWorkTime(dayOff, ConnectionToDB.notDisconnect);
                            if (dayOff.IdTypeDayOff == (int)DayOffType.halfDay)
                            {
                                dayOff.DayOffSubtraction("0.5", ConnectionToDB.notDisconnect);
                            }
                            if (dayOff.IdTypeDayOff == (int)DayOffType.rest)
                            {
                                dayOff.DayOffSubtraction("1", ConnectionToDB.notDisconnect);
                            }
                        }
                        else
                        {
                            throw new WrongDateTimeException(string.Format("Podawany dzień {0} jest dniem wolnym od pracy", dayOff.Date.ToShortDateString()));
                        }
                        break;
                    }
                    Polaczenia.CommitTransaction();
                }
            }
            catch (WrongDateTimeException ex)
            {
                MessageBox.Show(ex.Message, "Błąd przy zmianie godzin.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (CancelException ex)
            {
                MessageBox.Show(ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Polaczenia.RollbackTransaction();
                Polaczenia.OdlaczenieOdBazy();
                MessageBox.Show(ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //log
                LogErr.DodajLogErrorDoBazy(new LogErr(Polaczenia.idUser, DateTime.Now, Polaczenia.ip, 0, NazwaTabeli.praca, "ZamianaRodzajuPracyForm.btnZatwierdz_Click()/n/n" + ex.Message));
            }
            finally
            {
                this.Close();
            }
        }
예제 #30
0
        internal static void AddDayOff(DayOff dayOff, int dayCounter)
        {
            string holidayDescription = "";

            Polaczenia.BeginTransaction();
            for (int i = 1; i <= dayCounter; i++)
            {
                if (dayOff.Date.DayOfWeek != DayOfWeek.Sunday && dayOff.Date.DayOfWeek != DayOfWeek.Saturday && !Holidays.IsHoliday(dayOff.Date, out holidayDescription, ConnectionToDB.notDisconnect))
                {
                    WorkManager.AddWorkTime(dayOff, ConnectionToDB.notDisconnect);
                    if (dayOff.IdTypeDayOff == (int)DayOffType.halfDay)
                    {
                        dayOff.DayOffSubtraction("0.5", ConnectionToDB.notDisconnect);
                    }
                    if (dayOff.IdTypeDayOff == (int)DayOffType.rest)
                    {
                        dayOff.DayOffSubtraction("1", ConnectionToDB.notDisconnect);
                    }

                    dayOff.Date = dayOff.Date.AddDays(1);//next day
                }
                else
                {
                    dayOff.Date = dayOff.Date.AddDays(1);//next day
                }
            }
            Polaczenia.CommitTransaction();
            //jeżeli wpisuje godziny w ostatni dzień miesiąca to nie przechodzi na kolejny
            int numbersOfDays = DateTime.DaysInMonth(MainForm.mainDate.Year, MainForm.mainDate.Month);

            if (numbersOfDays != MainForm.mainDate.Day)
            {
                //dodaje jeden dzień do aktualnej daty do zmiennej pomocniczej
                MainForm.mainDate = MainForm.mainDate.AddDays(dayCounter);
            }
        }