Exemplo n.º 1
0
        private void btnADD_Click(object sender, EventArgs e)
        {
            if (CARDHOLDERID == 0)
            {
                errorProvider1.SetError(cboxCARDHOLDER, "Please, choose the worker.");
                cboxCARDHOLDER.Focus();
                cboxCARDHOLDER.TextChanged += (s, ex) => { errorProvider1.SetError(cboxCARDHOLDER, ""); };
                return;
            }
            else
            {
                errorProvider1.SetError(cboxCARDHOLDER, "");
            }

            if (_context.SickLeaves.Where(j => j.Date == dateTimePicker1.Value.Date && j.CardholderID == CARDHOLDERID).Select(s => s.SickLeaveID).Count() != 0)
            {
                errorProvider1.SetError(dateTimePicker1, "Sick leave date has been already set. Please choose another date.");
                dateTimePicker1.Focus();
                dateTimePicker1.ValueChanged += (s, ex) => { errorProvider1.SetError(dateTimePicker1, ""); };
                return;
            }
            else
            {
                errorProvider1.SetError(dateTimePicker1, "");
            }


            try
            {
                var newSickLeave = new SickLeave();
                newSickLeave.CardholderID = CARDHOLDERID;
                newSickLeave.Date         = dateTimePicker1.Value.Date;

                _context.SickLeaves.AddObject(newSickLeave);
                _context.SaveChanges();

                MessageBox.Show("Sick leave has been successfully added.", "Successful",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                ListaSICKLEAVE         = _context.SickLeaves.OrderBy(o => o.Date).ToList();
                dgSICKLEAVE.DataSource = ListaSICKLEAVE.Where(j => j.CardholderID == CARDHOLDERID).ToList();
            }
            catch
            {
                MessageBox.Show("Something went wrong. Please try again or contact your administrator.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
Exemplo n.º 2
0
        private void btnSAVE_Click(object sender, EventArgs e)
        {
            if (cboxCARDHOLDER.Text == "")
            {
            }
            else
            {
                try
                {
                    bud = _context.Cardholders.Where(w => w.Name == txtTOTAL.Text).Select(s => s.CardholderID).First();

                    var i = new NonWorkingDay();
                    i.CardholderID = CARDHOLDERID;
                    i.TotalNWD     = Convert.ToInt32(txtTOTAL.Text);
                    _context.NonWorkingDays.Add(i);
                    _context.SaveChanges();


                    MessageBox.Show("Number of non-working days are successfully added.", "Successful",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                catch
                {
                    MessageBox.Show("Something went wrong. Please try again.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }


                cboxCARDHOLDER.Text = "";
                txtTOTAL.Text       = "";
            }
        }
Exemplo n.º 3
0
        private void btnACCEPT_Click(object sender, EventArgs e)
        {
            CheckDates();

            if (CARDHOLDERID == 0 || dateTimePicker2.Value <= dateTimePicker1.Value)
            {
                MessageBox.Show("Date or worker name is not valid.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                var holi = new Holiday();
                holi.CardholderID = CARDHOLDERID;
                holi.LeaveDate    = dateTimePicker1.Value;
                holi.ReturnDate   = dateTimePicker2.Value;
                holi.NumberOfDays = NUMBEROFDAYS;
                _context.Holidays.AddObject(holi);
                _context.SaveChanges();

                var queryCARDHOLDER = _context.Cardholders.Where(j => j.CardholderID == CARDHOLDERID).ToList();
                var CardholderVar   = queryCARDHOLDER[0];
                CardholderVar.SumNWD = TLEFT - NUMBEROFDAYS;
                _context.SaveChanges();

                var k = new NonWorkingDay();
                k.CardholderID = CARDHOLDERID;
                k.TotalNWD     = NUMBEROFDAYS;
                k.Description  = "Holiday" + "-" + NUMBEROFDAYS + " from " + dateTimePicker1.Value.Date.ToString().Substring(0, 8) + " to" + dateTimePicker2.Value.Date.ToString().Substring(0, 8);
                _context.NonWorkingDays.AddObject(k);
                _context.SaveChanges();
                MessageBox.Show("Leave request successfully added.", "Successful",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                CARDHOLDERID       = 0;
                NUMBEROFDAYS       = 0;
                cmbCARDHOLDER.Text = "";
                RELIGIONID         = 0;
                txtTOTAL.Text      = "";
                txtTOTALLEFT.Text  = "";
                TxtAVAILABLE.Text  = "";
            }
        }
        private void btnReligionName_Click(object sender, EventArgs e)
        {
            if (_context.Religions.Where(j => j.Name == cbxReligionName.Text).Select(s => s.ReligionID).Count() == 0)
            {
                if (cbxReligionName.Text == "")
                {
                }
                else
                {
                    var queryReligion = new Religion();
                    queryReligion.Name = cbxReligionName.Text;
                    queryReligion.TotalReligiousDays = 0;

                    _context.Religions.AddObject(queryReligion);
                    _context.SaveChanges();

                    MessageBox.Show("You have successfully added new religion to database.", "Successful",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    RefreshDates();
                }
            }
            else
            {
                MessageBox.Show("Allready exist. ");
            }
        }
Exemplo n.º 5
0
        private void btnADD_Click(object sender, EventArgs e)
        {
            if (_context.Firms.Where(j => j.Name == cboxFIRM.Text).Select(s => s.FirmID).Count() == 0)
            {
                if (cboxFIRM.Text == "")
                {
                }
                else
                {
                    var queryFirm = new Firm();
                    queryFirm.Name      = cboxFIRM.Text;
                    queryFirm.StartDate = System.DateTime.Now;

                    _context.Firms.AddObject(queryFirm);
                    _context.SaveChanges();

                    MessageBox.Show("You have successfully added new firm to database.", "Successful",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                    cboxFIRM.DataSource = _context.Firms.OrderBy(o => o.Name).ToList();
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // RACUNANJE AKTIVNOG VREMENA NA POSLU

            WORKTIMESUM = 0;
            DIRECT      = _context.AccessLogs.Where(w => w.LocalTime >= dateTimePicker1.Value.Date && w.LocalTime <= dateTimePicker2.Value.Date && w.CardholderID == CARDHOLDERID).Select(s => s.Direction).First();

            if (DIRECT == 1)
            {
                ListaACCESSLOG = _context.AccessLogs.Where(w => w.LocalTime >= dateTimePicker1.Value.Date && w.LocalTime <= dateTimePicker2.Value.Date && w.CardholderID == CARDHOLDERID).ToList();

                foreach (var item in ListaACCESSLOG)
                {
                    //   DIRECT = item.Direction;
                    if (item.Direction == 1)
                    {
                        indikator = 0;
                        DATUM1    = item.LocalTime.Value;
                    }
                    else
                    {
                        if (indikator == 1)
                        {
                        }
                        else
                        {
                            DATUM2 = item.LocalTime.Value;
                            TimeSpan timeSpan = DATUM2 - DATUM1;

                            WORKTIMESUM += Convert.ToInt32(timeSpan.TotalMinutes);

                            var queryLogException = _context.LogExceptions.Where(w => w.LogExceptionDate == dateTimePicker1.Value.Date && w.CardholderID == CARDHOLDERID).ToList();
                            var i = queryLogException[0];
                            i.Worktime = WORKTIMESUM;

                            _context.SaveChanges();

                            indikator = 1;
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void btnACCEPT_Click(object sender, EventArgs e)
        {
            if (dateTimePicker2.Value <= dateTimePicker1.Value)
            {
                MessageBox.Show("Invalid return date");
            }

            else
            {
                //var query = from s in _context.Holidays
                //            where s.CardholderID == CARDHOLDERID
                //            select new { s.HolidayID };
                //foreach (var item in query)
                //{
                //    HOLIDAYID = item.HolidayID;
                //}
                if (CARDHOLDERID == 0 || dateTimePicker2.Value <= dateTimePicker1.Value)
                {
                    MessageBox.Show("Date or worker name is not valid.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                else
                {
                    var holi = new Holiday();
                    holi.CardholderID = CARDHOLDERID;
                    holi.LeaveDate    = dateTimePicker1.Value;
                    holi.ReturnDate   = dateTimePicker2.Value;
                    holi.NumberOfDays = Convert.ToInt32(txtTOTAL.Text);
                    _context.Holidays.AddObject(holi);
                    _context.SaveChanges();

                    MessageBox.Show("Leave request successfully added.", "Successful",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                    CARDHOLDERID       = 0;
                    cmbCARDHOLDER.Text = "";
                    HOLIDAYID          = 0;
                    txtTOTAL.Text      = "";
                    txtTOTALLEFT.Text  = "";
                }
            }
        }
Exemplo n.º 8
0
        public void InsertAllTables()
        {
            _context = new konekcija.MojaEntities();

            ListaLOGEXCEPTION = _context.LogExceptions.ToList();
            ListaACCESSLOG    = _context.AccessLogs.ToList();
            ListaCARDHOLDER   = _context.Cardholders.ToList();
            foreach (var i in ListaCARDHOLDER)
            {
                CARDHOLDERID   = i.CardholderID;
                ListaACCESSLOG = _context.AccessLogs.Where(w => w.CardholderID == CARDHOLDERID).ToList();
                indikator      = 1;
                var ListaACCESSLOGa = ListaACCESSLOG.GroupBy(u => u.LocalTime.Value.Date).Select(grp => grp.ToList()).ToList();

                foreach (var j in ListaACCESSLOGa)
                {
                    indikator   = 1;
                    CHECKError  = 0;
                    WORKTIMESUM = 0;
                    int c = j.Count();
                    DATUM = j.First().LocalTime;
                    foreach (var k in j)
                    {
                        if (c == 1)
                        {
                            CHECKError  = 2;
                            WORKTIMESUM = 0;
                        }
                        else
                        {
                            if (k.Direction == 2 && indikator == 1)
                            {
                                CHECKError = 2;
                                continue;
                            }
                            else
                            {
                                if (c == 2)
                                {
                                    CHECKError = 1;
                                }
                                else
                                if (c % 2 != 0)
                                {
                                    CHECKError = 2;
                                }
                                if (k.Direction == 1)
                                {
                                    indikator = 0;
                                    DATUM1    = k.LocalTime.Value;
                                }
                                else
                                {
                                    if (indikator == 1)
                                    {
                                        CHECKError = 2;
                                    }
                                    else
                                    {
                                        DATUM2 = k.LocalTime.Value;
                                        TimeSpan timeSpan = DATUM2 - DATUM1;

                                        WORKTIMESUM += Convert.ToInt32(timeSpan.TotalMinutes);

                                        indikator = 1;
                                    }
                                }
                            }
                        }
                    }


                    if (!ListaLOGEXCEPTION.Any(w => w.CardholderID == CARDHOLDERID && w.LogExceptionDate == DATUM.Value.Date) && DATUM.Value.Date != System.DateTime.Now.Date)
                    {
                        var a = new LogException();
                        a.Worktime = WORKTIMESUM;
                        var b = DATUM.Value.Date;
                        a.LogExceptionDate = b;
                        a.ExcIN_OUT        = CHECKError;
                        a.CardholderID     = CARDHOLDERID;
                        _context.LogExceptions.AddObject(a);
                        _context.SaveChanges();
                    }
                }
            }
        }