示例#1
0
        private void bttEdit_Click(object sender, EventArgs e)
        {
            if (!ValidateChildren(ValidationConstraints.Enabled)) return;

            PrepareObject();
            ContaContext contaContext = new ContaContext();
            UnitOfWork unitOfWork = new UnitOfWork(contaContext);
            unitOfWork.Contracte.UpdateEntry(_contract);
            unitOfWork.Complete();
            unitOfWork.Dispose();

            FillGridView(_filter, DateTime.Today.Year.ToString());

            ClearFormContract();

            bttClear.Visible = true;
            bttClear.Enabled = true;
            bttSave.Visible = true;
            bttSave.Enabled = true;
            bttEdit.Visible = false;
            bttCancel.Visible = false;
            bttNewContract.Enabled = true;
            bttDeleteContract.Enabled = false;
            grBoxContract.Enabled = false;
        }
示例#2
0
 private void bttSave_Click(object sender, EventArgs e)
 {
     PrepareObject();
     ContaContext contaContext = new ContaContext();
     UnitOfWork unityOfWork = new UnitOfWork(contaContext);
     IList<Contract> checkIfIsExist = (IList<Contract>)unityOfWork.Contracte.GetContractByNumberAndYear(_contract.NrContract, DateTime.Today);
     if (checkIfIsExist == null || checkIfIsExist.Count > 0)
     {
         MessageBox.Show(@"Contractul cu numarul " + _contract.NrContract + @" exista deja.",
             @"Eroare la salvare", MessageBoxButtons.OK, MessageBoxIcon.Error);
         txtNrContr.Text = "";
         return;
     }
     if (_contract.BeneficiarId <= 0)
     {
         MessageBox.Show(@"Contractul nu poate fi salvat fara Beneficiar.\nVa rugam selectati unul sau creati unul nou ",
              @"Eroare la salvare", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     unityOfWork.Contracte.Add(_contract);
     unityOfWork.Complete();
     unityOfWork.Dispose();
     contaContext.Dispose();
     grBoxContract.Enabled = false;
     bttNewContract.Enabled = true;
     FillGridView(_filter, DateTime.Today.Year.ToString());
     OnUpdateLucrariCombo();
 }
示例#3
0
        private void bttDeleteContract_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedRow = null;
            foreach (DataGridViewRow iterator in gridViewContract.SelectedRows)
            {
                selectedRow = iterator;
            }

            var selRow = selectedRow?.Cells["ContractId"].Value;

            if (selRow == null) return;
            ContaContext contaContext = new ContaContext();
            UnitOfWork unityOfWork = new UnitOfWork(contaContext);

            Contract contract = unityOfWork.Contracte.Get((int) selRow);
            if (contract == null) return;
            var userConfirm =
                MessageBox.Show(
                    @"Confirmati stergerea din baza de date a contractului cu nr. " + contract.NrContract + @"/" +
                    contract.Data, @"Delete confirmation",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (userConfirm == DialogResult.Yes)
            {
                try
                {
                    unityOfWork.Contracte.Remove(contract);
                    unityOfWork.Complete();
                    unityOfWork.Dispose();
                    contaContext.Dispose();
                    bttDeleteContract.Enabled = false;
                    FillGridView(_filter, DateTime.Now.Year.ToString());
                    ClearFormContract();
                }
                catch (DbUpdateException)
                {
                    // ReSharper disable once LocalizableElement
                    MessageBox.Show("Contractul este folosit de o alta intrare din baza de date.\nStergere refuzata", @"Eroare stergere contract", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch(Exception ex) { MessageBox.Show(ex.Message, @"Eroare stergere contract", MessageBoxButtons.OK, MessageBoxIcon.Error); }

            }
            else
            {
                bttDeleteContract.Enabled = false;
                unityOfWork.Dispose();
                contaContext.Dispose();
            }
        }
示例#4
0
 private void UpDate()
 {
     ContaContext contaContext = new ContaContext();
     UnitOfWork unitOfWork = new UnitOfWork(contaContext);
     unitOfWork.Beneficiari.UpdateEntry(_beneficiar);
     unitOfWork.Complete();
     unitOfWork.Dispose();
 }
示例#5
0
 private void Save()
 {
     ContaContext contaContext = new ContaContext();
     UnitOfWork unitOfWork = new UnitOfWork(contaContext);
     unitOfWork.Beneficiari.Add(_beneficiar);
     unitOfWork.Complete();
     unitOfWork.Dispose();
 }
示例#6
0
        private void bttDeleteLucrari_Click(object sender, EventArgs e)
        {
            DataGridViewRow selectedRow = null;
            foreach (DataGridViewRow iterator in LucrariView.SelectedRows)
            {
                selectedRow = iterator;
            }

            var dataGridViewCell = selectedRow?.Cells["LucrareId"].Value;
            if (dataGridViewCell == null) return;
            //var id = dataGridViewCell;
            ContaContext contaContext = new ContaContext();
            UnitOfWork unityOfWork = new UnitOfWork(contaContext);
            Lucrare lucrare = unityOfWork.Lucrari.Get((int)dataGridViewCell);
            var userConfirm = MessageBox.Show(@"Confirmati stergerea din baza de date a documentatiei cu nr. " + lucrare.NrProiect + @"/" +
                lucrare.AnProiect, @"Delete confirmation",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (userConfirm == DialogResult.Yes)
            {
                try
                {
                    unityOfWork.Lucrari.Remove(lucrare);
                    unityOfWork.Complete();
                    unityOfWork.Dispose();
                    contaContext.Dispose();
                    bttDeleteLucrari.Enabled = false;
                    FillGridView(_filter, DateTime.Now.Year.ToString());
                }
                catch (DbUpdateException)
                {
                    // ReSharper disable once LocalizableElement
                    MessageBox.Show("Documentatie este folosit de o alta intrare din baza de date.\nStergere refuzata", @"Eroare stergere contract", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex) { MessageBox.Show(ex.Message, @"Eroare stergere contract", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
            else
            {
                bttDeleteLucrari.Enabled = false;
                unityOfWork.Dispose();
                contaContext.Dispose();
            }
        }
示例#7
0
        private void bttSave_Click(object sender, EventArgs e)
        {
            if (!ValidateChildren(ValidationConstraints.Enabled)) return;

            PrepareObject();
            var con = new ContaContext();
            var unitOfWork = new UnitOfWork(con);

            IList<Lucrare> checkIfIsExist = (IList<Lucrare>)unitOfWork.Lucrari.GetLucrariByNumberAndYear(_lucrare.NrProiect, DateTime.Today);
            if (checkIfIsExist == null || checkIfIsExist.Count > 0)
            {
                MessageBox.Show(@"Documentatia cu numarul " + _lucrare.NrProiect +@"/" +_lucrare.AnProiect+ @" exista deja.",
                    @"Eroare la salvare", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtDoc.Text = "";
                return;
            }

            unitOfWork.Lucrari.Add(_lucrare);
            unitOfWork.Complete();
            unitOfWork.Dispose();
            FillGridView(_filter, _filterKeyWordS);

            ClearFormLucrare();
            if (!bttNewLucrare.Enabled)
                bttNewLucrare.Enabled = true;
            // Disable grupbox Lucrari
            if (grBoxLucrare.Enabled)
                grBoxLucrare.Enabled = false;
        }