private void btnRemoveReligion_Click(object sender, EventArgs e)
        {
            try
            {
                if (_context.Religions.Where(j => j.Name == cbxReligionName.Text).Select(s => s.ReligionID).Count() != 0)
                {
                    if (MessageBox.Show("Do you really want to delete religion?", "Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        RELIGIONID = _context.Religions.Where(j => j.Name == cbxReligionName.Text).Select(s => s.ReligionID).First();

                        System.Data.EntityKey religionKey = new System.Data.EntityKey("MojaEntities.Religions", "ReligionID", RELIGIONID);
                        var religionDelete = _context.GetObjectByKey(religionKey);
                        _context.DeleteObject(religionDelete);
                        _context.SaveChanges();

                        MessageBox.Show("You have successfully deleted religion from database.", "Successful",
                                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        cbxReligionName.Text = "";

                        cbxReligionName.DataSource = _context.Religions.OrderBy(o => o.Name).ToList();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        private void btnREMOVE_Click(object sender, EventArgs e)
        {
            try
            {
                if (_context.Firms.Where(j => j.Name == cboxFIRM.Text).Select(s => s.FirmID).Count() != 0)
                {
                    if (MessageBox.Show("Do you really want to delete shift?", "Delete",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        FIRMID = _context.Firms.Where(j => j.Name == cboxFIRM.Text).Select(s => s.FirmID).First();

                        System.Data.EntityKey firmKey = new System.Data.EntityKey("MojaEntities.Firms", "FirmID", FIRMID);
                        var firmDelete = _context.GetObjectByKey(firmKey);
                        _context.DeleteObject(firmDelete);
                        _context.SaveChanges();

                        MessageBox.Show("You have successfully deleted firm from database.", "Successful",
                                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        cboxFIRM.Text = "";

                        cboxFIRM.DataSource = _context.Firms.OrderBy(o => o.Name).ToList();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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);
                }
            }
        }
Example #4
0
        private void dgSICKLEAVE_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //SAVE BUTTON IN DATAGRIDVIEW
            if (e.ColumnIndex == 1)
            {
                DataGridViewRow row = this.dgSICKLEAVE.Rows[e.RowIndex];


                if (!row.IsNewRow)
                {
                    var      date        = row.Cells["Date"].Value;
                    DateTime dateTime    = Convert.ToDateTime(date);
                    int      SICKLEAVEID = Convert.ToInt16(row.Cells["SickLeaveIDCell"].Value);

                    if (_context.SickLeaves.Where(w => w.SickLeaveID == SICKLEAVEID).Select(s => s.SickLeaveID).Count() == 0)
                    {
                    }
                    else
                    {
                        if (_context.SickLeaves.Where(j => j.Date == dateTime && j.CardholderID == CARDHOLDERID).Select(s => s.SickLeaveID).Count() != 0)
                        {
                            MessageBox.Show("Save operation was not successful. Input date already exists.", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);


                            _context               = new MojaEntities();
                            ListaSICKLEAVE         = _context.SickLeaves.OrderBy(o => o.Date).ToList();
                            dgSICKLEAVE.DataSource = ListaSICKLEAVE.Where(j => j.CardholderID == CARDHOLDERID).ToList();
                        }
                        else
                        {
                            //SICKLEAVEID = _context.SickLeaves.Where(w => w.CardholderID == CARDHOLDERID && w.Date == dateTime).Select(s => s.SickLeaveID).First();
                            var leaveQuery    = _context.SickLeaves.Where(w => w.SickLeaveID == SICKLEAVEID).ToList();
                            var sickleavesave = leaveQuery[0];
                            sickleavesave.Date = Convert.ToDateTime(row.Cells["Date"].Value);

                            _context.SaveChanges();

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

            //BRISANJE SELEKTOVANOG REDA

            if (e.ColumnIndex == 2)
            {
                try
                {
                    DataGridViewRow row = this.dgSICKLEAVE.Rows[e.RowIndex];

                    if (!row.IsNewRow)
                    {
                        var      date     = row.Cells["Date"].Value;
                        DateTime dateTime = Convert.ToDateTime(date);

                        if (_context.SickLeaves.Where(w => w.Date == dateTime).Select(s => s.SickLeaveID).Count() == 0)
                        {
                        }
                        else
                        {
                            if (MessageBox.Show("Do you really want to delete sick leave date?", "Delete",
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {
                                SICKLEAVEID = _context.SickLeaves.Where(w => w.Date == dateTime && w.CardholderID == CARDHOLDERID).Select(s => s.SickLeaveID).First();

                                System.Data.EntityKey sickleaveKey = new System.Data.EntityKey("MojaEntities.SickLeaves", "SickLeaveID", SICKLEAVEID);
                                var SickLeaveDelete = _context.GetObjectByKey(sickleaveKey);
                                _context.DeleteObject(SickLeaveDelete);
                                _context.SaveChanges();

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

                                ListaSICKLEAVE         = _context.SickLeaves.OrderBy(o => o.Date).ToList();
                                dgSICKLEAVE.DataSource = ListaSICKLEAVE.Where(j => j.CardholderID == CARDHOLDERID).ToList();
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Delete operation was not successful. Please, contact your administrator.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }