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(); }
private void gridViewContract_CellDoubleClick(object sender, DataGridViewCellEventArgs 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 unitOfWork = new UnitOfWork(contaContext); _contract = unitOfWork.Contracte.Get((int) selRow); unitOfWork.Dispose(); contaContext.Dispose(); if (_contract == null) return; // Completeaza formul cu datele din baza de date txtNrContr.Text = _contract.NrContract; txtSuma.Text = _contract.Suma.ToString(CultureInfo.InstalledUICulture); txtObiect.Text = _contract.ObiectulContractului; txtObs.Text = _contract.Observatii; dateTimePickerContr.Value = _contract.Data; //Set enable disabe or visibilty for controls bttNewContract.Enabled = false; bttDeleteContract.Enabled = false; grBoxContract.Enabled = true; bttEdit.Visible = true; bttCancel.Visible = true; bttSave.Visible = false; bttClear.Visible = false; }
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(); } }
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; }
private void Save() { ContaContext contaContext = new ContaContext(); UnitOfWork unitOfWork = new UnitOfWork(contaContext); unitOfWork.Beneficiari.Add(_beneficiar); unitOfWork.Complete(); unitOfWork.Dispose(); }
private void UpDate() { ContaContext contaContext = new ContaContext(); UnitOfWork unitOfWork = new UnitOfWork(contaContext); unitOfWork.Beneficiari.UpdateEntry(_beneficiar); unitOfWork.Complete(); unitOfWork.Dispose(); }
private void GetBeneficiariForDb() { ContaContext contaContext = new ContaContext(); UnitOfWork unitOfWork = new UnitOfWork(contaContext); _mlBeneficiari =(List<Beneficiar>) unitOfWork.Beneficiari.GetAll(); unitOfWork.Dispose(); contaContext.Dispose(); _names = new AutoCompleteStringCollection(); foreach (var str in _mlBeneficiari) _names.Add(str.Nume); }
private void FillComboBox() { ContaContext contaContext = new ContaContext(); UnitOfWork unitOfWork = new UnitOfWork(contaContext); BindingSource bindTipAct = new BindingSource {DataSource = unitOfWork.TipActe.GetAll()}; unitOfWork.Dispose(); contaContext.Dispose(); cbTipAct.DataSource = bindTipAct; cbTipAct.DisplayMember = "TipAct1"; cbAtribFiscal.Items.Add(""); cbAtribFiscal.Items.Add("RO"); }
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(); } }
private void LucrariView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = null; foreach (DataGridViewRow iterator in LucrariView.SelectedRows) { row = iterator; } if (row == null) return; var conta = new ContaContext(); var unitOfWork = new UnitOfWork(conta); // ReSharper disable once ConstantConditionalAccessQualifier var id = row?.Cells["LucrareId"].Value; if (id == null) return; _lucrare = unitOfWork.Lucrari.Get((int)id); if (_lucrare == null) return; int sStatusAccept = unitOfWork.AcceptateRespinse.Get(_lucrare.AcceptataRefuzataId).AcceptataRefuzataId; if (--sStatusAccept >= 0) cbAcceptResp.SelectedIndex = sStatusAccept; int sStatusRec = unitOfWork.ReceptionateRespinse.Get(_lucrare.ReceptionatRespinsId).ReceptionatRespinsId; if(--sStatusRec >= 0) cbReceptionatRespins.SelectedIndex = sStatusRec; if (_lucrare.ContractId != null) cbContract.SelectedText = unitOfWork.Contracte.Get((int)_lucrare.ContractId).NrContract; if (_lucrare.DataInregistrare != null) dateTimePickerInreg.Value = (DateTime)_lucrare.DataInregistrare; if (_lucrare.TermenSolutionare != null) dateTimePickerTermen.Value = (DateTime)_lucrare.TermenSolutionare; unitOfWork.Dispose(); conta.Dispose(); txtInreg.Text = _lucrare.Nr_OCPI; txtDoc.Text = _lucrare.NrProiect; txtAvizator.Text = _lucrare.AvizatorRegistrator; txtUAT.Text = _lucrare.UAT; txtObservatii.Text = _lucrare.Observatii; txtCad.Text = _lucrare.CadTop; //Set enable disabe or visibilty for controls bttNewLucrare.Enabled = false; bttDeleteLucrari.Enabled = false; grBoxLucrare.Enabled = true; bttEdit.Visible = true; bttCancel.Visible = true; bttSave.Visible = false; bttClearlucrare.Visible = false; }
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; }