Esempio n. 1
0
        private void gvPAYERelief_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            if (e.Row == null)
            {
                return;
            }
            SavingResult         res = null;
            PAYEReliefeViewModel Row = (PAYEReliefeViewModel)e.Row;

            if (dePAYEReliefWED.EditValue == null)
            {
                res = new SavingResult();
                res.ExecutionResult = eExecutionResult.ValidationError;
                res.ValidationError = "Please enter Effective date.";
            }
            else
            {
                res = PAYEReliefDALObj.SaveNewRecord(Row, (DateTime)dePAYEReliefWED.EditValue);
            }

            Row.SavingError = null;
            if (res.ExecutionResult == eExecutionResult.CommitedSucessfuly)
            {
                var newRow = PAYEReliefDALObj.GetViewModelByID((int)res.PrimeKeyValue);
                if (newRow != null)
                {
                    int newRowIndex = PAYEReliefeViewModelBindingSource.IndexOf(Row);
                    //Row = newRow;
                    PAYEReliefeViewModelBindingSource[newRowIndex] = newRow;
                }
                else
                {
                    PAYEReliefeViewModelBindingSource.RemoveAt(gvPAYERelief.GetFocusedDataSourceRowIndex());
                }
            }
            else if (res.ExecutionResult == eExecutionResult.ErrorWhileExecuting)
            {
                Row.SavingError = "Error while saving.\r\n" + res.Exception.Message;
            }
            else if (res.ExecutionResult == eExecutionResult.ValidationError)
            {
                Row.SavingError = "Validation Errors.\r\n" + res.ValidationError;
            }
            else if (!String.IsNullOrWhiteSpace(res.MessageAfterSave))
            {
                Row.SavingError = "Please note:\r\n" + res.MessageAfterSave;
            }
        }
Esempio n. 2
0
        private void repositoryItemButtonEditRemovePAYERelief_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            PAYEReliefeViewModel Row = (PAYEReliefeViewModel)gvPAYERelief.GetFocusedRow();

            if (Row == null)
            {
                return;
            }

            var resValidation = PAYEReliefDALObj.ValidateBeforeDelete(Row.PAYEReliefID);

            if (!resValidation.IsValidForDelete)
            {
                Row.SavingError = resValidation.ValidationMessage;
                return;
            }

            var res = PAYEReliefDALObj.DeleteRecord(Row.PAYEReliefID);

            if (res.ExecutionResult == eExecutionResult.CommitedSucessfuly)
            {
                PAYEReliefeViewModelBindingSource.RemoveAt(gvPAYERelief.GetFocusedDataSourceRowIndex());
                gvPAYERelief.RefreshData();
            }
            if (res.ExecutionResult == eExecutionResult.ErrorWhileExecuting)
            {
                Row.SavingError = "Error while saving.\r\n" + res.Exception.Message;
            }
            else if (res.ExecutionResult == eExecutionResult.ValidationError)
            {
                Row.SavingError = "Validation Errors.\r\n" + res.ValidationError;
            }
            else if (!String.IsNullOrWhiteSpace(res.MessageAfterSave))
            {
                Row.SavingError = "Please note:\r\n" + res.MessageAfterSave;
            }
        }
Esempio n. 3
0
        public SavingResult SaveNewRecord(PAYEReliefeViewModel ViewModel, DateTime WEDate)
        {
            SavingResult res = new SavingResult();

            //-- Perform Validation
            //res.ExecutionResult = eExecutionResult.ValidationError;
            //res.ValidationError = "Validation error message";
            //return res;

            tblPAYERelief SaveModel = null;

            //--
            using (dbVisionEntities db = new dbVisionEntities())
            {
                //tblPAYERelief SaveModel;
                if (String.IsNullOrWhiteSpace(ViewModel.PAYEReliefName))
                {
                    res.ValidationError = "Can not accept blank value. Please enter PAYE Relief Name.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }
                else if (IsDuplicateRecord(ViewModel.PAYEReliefName, ViewModel.PAYEReliefID, db))
                {
                    res.ValidationError = "Can not accept duplicate value. The PAYE Relief Name is already exists.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }

                if (ViewModel.PAYEReliefID != 0)
                {
                    SaveModel = db.tblPAYEReliefs.Find(ViewModel.PAYEReliefID);
                }

                tblPAYEReliefRate RateSaveModel = null;
                if (SaveModel == null) // New Entry
                {
                    SaveModel           = new tblPAYERelief();
                    SaveModel.CompanyID = CommonProperties.LoginInfo.LoggedInCompany.CompanyID;
                    SaveModel.rcuid     = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.rcdt      = DateTime.Now;
                    db.tblPAYEReliefs.Add(SaveModel);
                }
                else
                {
                    SaveModel.reuid = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.redt  = DateTime.Now;
                    db.tblPAYEReliefs.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;

                    db.tblPAYEReliefRates.RemoveRange(db.tblPAYEReliefRates.Where(r => r.PAYEReliefID == SaveModel.PAYEReliefID && (WEDate == null || r.WEDate >= WEDate)));
                }

                SaveModel.PAYEReliefName = ViewModel.PAYEReliefName;
                SaveModel.Mandatory      = ViewModel.Mandatory == ePAYEReliefeMandatory.Yes;
                SaveModel.PAYEReliefType = (byte)ViewModel.PAYEReliefType;

                RateSaveModel = new tblPAYEReliefRate()
                {
                    WEDate       = WEDate,
                    MonthlyLimit = ViewModel.MonthlyLimit,
                    AnnualLimit  = ViewModel.AnnualLimit,

                    tblPAYERelief = SaveModel,
                    rcuid         = Model.CommonProperties.LoginInfo.LoggedinUser.UserID,
                    rcdt          = DateTime.Now,
                };
                db.tblPAYEReliefRates.Add(RateSaveModel);

                //--
                try
                {
                    db.SaveChanges();
                    //ViewModel.PAYEReliefID = SaveModel.PAYEReliefID;
                    res.PrimeKeyValue   = SaveModel.PAYEReliefID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    CommonFunctions.GetFinalError(res, ex);
                }
            }
            return(res);
        }