private void SavePosition() { if (this.IsPositionDataValid()) { int selectedPositionId = 0; bool isFullySaved = true; selectedPosition.AgreementId = (int)gridExPositions.CurrentRow.Cells["umowaId"].Value; selectedPosition.KTM = txtKTM.Text; selectedPosition.CurrencyId = (int)cboCurrency.SelectedValue; selectedPosition.Descriptor = txtDescriptor.Text; selectedPosition.FreeCopies = (int)numFreeCopies.Value; selectedPosition.ExpirationDate = dtExpiration.Text == " " ? (DateTime?)null : dtExpiration.Value; selectedPosition.IsChargedFromFirstSale = chkFirstSale.Checked; selectedPosition.IsIndifinitePeriod = chkIndefinitePeriod.Checked; selectedPosition.Comments = txtPositionComments.Text; selectedPosition.ModelId = (int)cboSettlementModel.SelectedValue; selectedPosition.ModelPercent = numModelPercent.Visible ? numModelPercent.Value : 0; selectedPosition.ModelFixedPrice = numModelFixedPrice.Visible ? numModelFixedPrice.Value : 0; selectedPosition.BillingPeriod = (int)cboBillingPeriod.SelectedValue; selectedPosition.BillingPeriodStart = dtBillingPeriodFrom.Value; selectedPosition.BillingPeriodEnd = dtBillingPeriodTo.Text == " " ? (DateTime?)null : dtBillingPeriodTo.Value; try { // update podstawowych danych zaznaczonej pozycji AgreementPositionsRepo.InsertUpdate(this.selectedPosition); selectedPositionId = selectedPosition.Id; // update grida z programi dla zaznaczonej pozycji this.gridThresholdsRepo.Update(); //update grida z produktami dla zaznaczonej pozycji this.gridRelatedProductsRepo.Update(); } catch (Exception ex) { MessageBox.Show("Nie udało się zapisać bieżącej pozycji.\r\nSpróbuj ponownie", "Zapis pozycji", MessageBoxButtons.OK, MessageBoxIcon.Error); isFullySaved = false; } if (isFullySaved) { this.SetPositionChangesPending(false); if (this.isPositionAddPending) { this.isPositionAddPending = false; } this.LoadData(); this.SelectPositionById(selectedPositionId); } } }
private void BindKTM() { if (this.IsPositionSelected()) { string ktm = gridExProductsAndArticles.CurrentRow.Cells["KTM"].Value.ToString(); string descriptor = gridExProductsAndArticles.CurrentRow.Cells["Deskryptor"].Value.ToString(); string positionKtm = gridExAgreementsListGrouped.CurrentRow.Cells["KTM"].Value.ToString(); string positionDescriptor = gridExAgreementsListGrouped.CurrentRow.Cells["Deskryptor"].Value.ToString(); int agreementId = (int)gridExAgreementsListGrouped.CurrentRow.Cells["IdUmowy"].Value; int agreementPositionId = (int)gridExAgreementsListGrouped.CurrentRow.Cells["PozycjaId"].Value; if (MessageBox.Show(string.Format("W pozycji:\r\n\r\nKTM:\t\t{0}\r\nDeskryptor:\t{1}\r\n\r\nna umowie {2} zostanie zmieniony parametr:\r\n\r\nKTM:\t\t{3}", positionKtm, positionDescriptor, agreementId.ToString(), ktm), "Przypisanie", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { try { AgreementPosition agreementPosition = AgreementPositionsRepo.GetByID(agreementPositionId); agreementPosition.KTM = ktm; AgreementPositionsRepo.InsertUpdate(agreementPosition); MessageBox.Show("KTM został poprawnie zmieniony.", "Przypisanie", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Nie udało się wykonać powiązania.\r\nOdśwież listę i spróbuj ponownie.", "Przypisanie", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.LoadData(); } } else { MessageBox.Show("Ta opcja wymaga zaznaczenia jednej pozycji umowy.", "Przypisanie", MessageBoxButtons.OK, MessageBoxIcon.Information); } }