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       = "";
            }
        }
Exemple #2
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 btnDELETE_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;
            }
            if (_context.Contracts.Where(j => j.CardholderID == CARDHOLDERID && j.ActiveState == true).Select(s => s.ContractID).Count() == 0)
            {
            }
            else
            {
                try
                {
                    if (MessageBox.Show("Do you really want to delete contract?", "Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        CONTRACTID = _context.Contracts.Where(j => j.CardholderID == CARDHOLDERID && j.ActiveState == true).Select(s => s.ContractID).First();
                        double?b = _context.Contracts.Where(j => j.CardholderID == CARDHOLDERID && j.ActiveState == true).Select(s => s.FreeDays).First();

                        var k = new NonWorkingDay();
                        k.CardholderID = CARDHOLDERID;
                        k.TotalNWD     = a;
                        k.Description  = "Contract -" + b;
                        _context.NonWorkingDays.AddObject(k);
                        _context.SaveChanges();

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

                        txtTOTAL.Text = CardholderVar.SumNWD.ToString();
                        if (_context.Cardholders.Where(w => w.CardholderID == CARDHOLDERID).Select(s => s.SumNWD).First() is null)
                        {
                            txtTOTAL.Text = "";
                        }
                        else
                        {
                            txtTOTAL.Text = queryCARDHOLDER.First().SumNWD.ToString();
                        }
                        gbCONTRACT.BackColor = Color.FromArgb(255, 0, 0);

                        System.Data.EntityKey contractKey = new System.Data.EntityKey("MojaEntities.Contracts", "ContractID", CONTRACTID);
                        var ContractDelete = _context.GetObjectByKey(contractKey);
                        _context.DeleteObject(ContractDelete);
                        _context.SaveChanges();


                        MessageBox.Show("Contract has been successfully deleted!", "Success",
                                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        cboxCARDHOLDER.Text  = "";
                        gbCONTRACT.BackColor = System.Drawing.SystemColors.ControlLightLight;
                    }
                }
                catch
                {
                    MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        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;
            }
            if (dateTimePicker1.Value > dateTimePicker2.Value)
            {
                errorProvider2.SetError(cboxCARDHOLDER, "Incorect dates.");
                dateTimePicker1.Focus();
                dateTimePicker1.TextChanged += (s, ex) => { errorProvider1.SetError(dateTimePicker1, ""); };
                return;
            }

            if (dateTimePicker2.Value.Date <= System.DateTime.Now || _context.Contracts.Where(j => j.CardholderID == CARDHOLDERID && j.ActiveState == true).Select(s => s.ContractID).Count() != 0)
            {
                MessageBox.Show("Sorry, but you did not put valid date or active contract already exists. Delete it or contact your administrator.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                try
                {
                    var i = new Contract();
                    i.ActiveState  = true;
                    i.CardholderID = CARDHOLDERID;
                    i.FromDate     = dateTimePicker1.Value.Date;
                    i.ToDate       = dateTimePicker2.Value.Date;
                    a          = ((((dateTimePicker1.Value.Year - dateTimePicker2.Value.Year) * 12) + dateTimePicker2.Value.Month - dateTimePicker1.Value.Month) * 1.66);
                    i.FreeDays = a;
                    MessageBox.Show((i.FreeDays) + "");
                    _context.Contracts.AddObject(i);
                    _context.SaveChanges();

                    var k = new NonWorkingDay();
                    k.CardholderID = CARDHOLDERID;
                    k.TotalNWD     = a;
                    k.Description  = "Contract +" + a;
                    _context.NonWorkingDays.AddObject(k);
                    _context.SaveChanges();

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

                    txtTOTAL.Text = CardholderVar.SumNWD.ToString();
                    if (_context.Cardholders.Where(w => w.CardholderID == CARDHOLDERID).Select(s => s.SumNWD).First() is null)
                    {
                        txtTOTAL.Text = "";
                    }
                    else
                    {
                        txtTOTAL.Text = queryCARDHOLDER.First().SumNWD.ToString();
                    }
                    MessageBox.Show("New contract has been successfully added.", "Successful",
                                    MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    gbCONTRACT.BackColor = Color.FromArgb(0, 255, 0);
                }
                catch
                {
                    MessageBox.Show("Something went wrong. Please try again or contact your administrator.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
        }