Esempio n. 1
0
        public void SaveChanges()
        {
            if (!ValidateForm())
            {
                return;
            }
            ContractBindingSource.EndEdit();
            RenewalBindingSource.EndEdit();
            _contract = (Contract)ContractBindingSource.DataSource;
            var renewal = (ContractRenewal)RenewalBindingSource.DataSource;
            int month   = 0;

            month            = Convert.ToInt32(CmboDuration.SelectedValue) == 1 ? (renewal.Duration ?? 0) : (renewal.Duration * 12 ?? 0);
            renewal.Duration = month;
            renewal.Status   = 1;
            _contract.Status = 1;
            try
            {
                InsertRenewal(renewal);
                _context.Contracts.AddObject(_contract);
                _context.SaveChanges();
                if (CustomerView == null)
                {
                    if (_saveAndNew)
                    {
                        ContractBindingSource.DataSource = new Contract();
                        RenewalBindingSource.DataSource  = new ContractRenewal();
                    }
                    else
                    {
                        this.Close();
                        var ct = new ContractDetailView();
                        var contractDetailView = new ContractDetailView();
                        contractDetailView.ShowObject(_contract);
                        contractDetailView.MdiParent = this.MainParent;
                        contractDetailView.Show();
                    }
                }
                else
                {
                    this.Close();
                    CustomerView.ReloadContracts();
                }
            }
            catch (Exception e)
            {
                ViewHelper.ShowSaveError();
                ErrorLogger.LogError(this, e);
            }
        }
Esempio n. 2
0
 public void SaveChanges()
 {
     if (!ValidateForm())
     {
         return;
     }
     ContractBindingSource.EndEdit();
     try
     {
         _context.SaveChanges();
         BtnSaveContract.Enabled = false;
         ReloadContract(_contract.ContractId);
     }
     catch (Exception ex)
     {
         ViewHelper.ShowErrorMessage("Error occured while saving the current contract.", ex);
     }
 }