Esempio n. 1
0
        public override void FillSelectedRecordInContent(object RecordToFill)
        {
            LoanAdjustmentEditListModel EditingRecord = (LoanAdjustmentEditListModel)RecordToFill;
            tblLoanAdjustment           SaveModel     = DALObject.FindSaveModelByPrimeKey(EditingRecord.LoanAdjustmentID);

            if (SaveModel == null)
            {
                return;
            }

            deLoanAdjustmentDate.DateTime          = SaveModel.LoanAdjustmentDate;
            lookupLoanAdjustmentNoPrefix.EditValue = SaveModel.LoanAdjustmentNoPrefixID;
            txtLoanAdjustmentNo.EditValue          = SaveModel.LoanAdjustmentNo;
            lookupEmployee.EditValue = SaveModel.EmployeeID;
            lookupLoan.EditValue     = SaveModel.LoanApplicationID;

            var loan = ((List <LoanApplicationLookupListModel>)lookupLoan.Properties.DataSource).FirstOrDefault(r => r.LoanApplicationID == SaveModel.LoanApplicationID);

            if (loan != null)
            {
                txtLoanAmount.EditValue = loan.LoanApplicationAmount;
            }

            txtLoanAdjustmentAmount.EditValue = SaveModel.LoanAdjustmentAmount;
            deDateOfDeposite.DateTime         = SaveModel.DateOfDeposite;
            cmbPaymentMode.SelectedIndex      = SaveModel.PaymentModeID;
            lookupBankAccount.EditValue       = SaveModel.CompanyBankAccountID;
            txtReasonForLoanAdj.Text          = SaveModel.ReasonForLoanAdjustment;
            txtRemarks.Text  = SaveModel.Remarks;
            txtDocument.Text = SaveModel.ApplicationDocumentFileName;

            base.FillSelectedRecordInContent(RecordToFill);
        }
Esempio n. 2
0
        public SavingResult SaveNewRecord(tblLoanAdjustment SaveModel)
        {
            SavingResult res = new SavingResult();

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

            //--
            using (dbVisionEntities db = new dbVisionEntities())
            {
                //tblLoanAdjustment SaveModel;
                if (SaveModel.LoanAdjustmentNo == 0)
                {
                    res.ValidationError = "Please enter Loan Adjustment No.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }
                else if (IsDuplicateRecord(SaveModel.LoanAdjustmentNoPrefixID, SaveModel.LoanAdjustmentNo, SaveModel.LoanAdjustmentID, db))
                {
                    res.ValidationError = "Can not accept duplicate value. The Loan Adjustment No. is already exists.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }

                if (SaveModel.LoanAdjustmentID == 0) // New Entry
                {
                    SaveModel.rcuid       = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.rcdt        = DateTime.Now;
                    SaveModel.CompanyID   = Model.CommonProperties.LoginInfo.LoggedInCompany.CompanyID;
                    SaveModel.FinPeriodID = Model.CommonProperties.LoginInfo.LoggedInFinPeriod.FinPeriodID;
                    db.tblLoanAdjustments.Add(SaveModel);
                }
                else
                {
                    SaveModel.reuid = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.redt  = DateTime.Now;
                    db.tblLoanAdjustments.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;
                }

                //--
                try
                {
                    db.SaveChanges();
                    res.PrimeKeyValue   = SaveModel.LoanAdjustmentID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    CommonFunctions.GetFinalError(res, ex);
                }
            }
            return(res);
        }
Esempio n. 3
0
        public SavingResult DeleteRecord(long DeleteID)
        {
            SavingResult res = new SavingResult();

            using (dbVisionEntities db = new dbVisionEntities())
            {
                if (DeleteID != 0)
                {
                    tblLoanAdjustment RecordToDelete = db.tblLoanAdjustments.FirstOrDefault(r => r.LoanAdjustmentID == DeleteID);

                    if (RecordToDelete == null)
                    {
                        res.ValidationError = "Selected record not found. May be it has been deleted by another user over network.";
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        return(res);
                    }
                    else
                    {
                        //db.tblLoanAdjustments.Remove(RecordToDelete);
                        byte RecordState_Deleted = (byte)eRecordState.Deleted;
                        RecordToDelete.rstate = RecordState_Deleted;
                        db.tblLoanAdjustments.Attach(RecordToDelete);
                        db.Entry(RecordToDelete).State = System.Data.Entity.EntityState.Modified;
                    }

                    try
                    {
                        db.SaveChanges();
                        res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                    }
                    catch (Exception ex)
                    {
                        CommonFunctions.GetFinalError(res, ex);
                    }
                }
            }
            return(res);
        }
Esempio n. 4
0
        public override void SaveRecord(SavingParemeter Paras)
        {
            DAL.tblLoanAdjustment SaveModel = null;
            if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew || EditRecordDataSource == null)
            {
                SaveModel = new tblLoanAdjustment();
            }
            else
            {
                SaveModel = DALObject.FindSaveModelByPrimeKey(((LoanAdjustmentEditListModel)EditRecordDataSource).LoanAdjustmentID);

                if (SaveModel == null)
                {
                    Paras.SavingResult = new SavingResult();
                    Paras.SavingResult.ExecutionResult = eExecutionResult.ValidationError;
                    Paras.SavingResult.ValidationError = "Can not edit. Selected record not found, it may be deleted by another user.";
                    return;
                }
            }

            SaveModel.LoanAdjustmentDate       = deLoanAdjustmentDate.DateTime.Date;
            SaveModel.LoanAdjustmentNoPrefixID = (int)lookupLoanAdjustmentNoPrefix.EditValue;
            SaveModel.LoanAdjustmentNo         = Model.CommonFunctions.ParseInt(txtLoanAdjustmentNo.Text);
            SaveModel.EmployeeID              = (int)lookupEmployee.EditValue;
            SaveModel.LoanApplicationID       = (int)lookupLoan.EditValue;
            SaveModel.PaymentModeID           = (byte)cmbPaymentMode.SelectedIndex;
            SaveModel.DateOfDeposite          = deDateOfDeposite.DateTime.Date;
            SaveModel.CompanyBankAccountID    = (int?)lookupBankAccount.EditValue;
            SaveModel.LoanAdjustmentAmount    = Model.CommonFunctions.ParseDecimal(txtLoanAdjustmentAmount.Text);
            SaveModel.ReasonForLoanAdjustment = txtReasonForLoanAdj.Text;
            SaveModel.Remarks = txtRemarks.Text;

            // if new record or document has been changed then update it.
            if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew || SaveModel.ApplicationDocumentFileName != txtDocument.Text)
            {
                SaveModel.ApplicationDocumentFileName = null;
                if (!String.IsNullOrWhiteSpace(txtDocument.Text) && System.IO.File.Exists(txtDocument.Text))
                {
                    string DocumentNewPath     = Path.GetFullPath(Path.Combine(CommonProperties.LoginInfo.SoftwareSettings.DocumentLocation_LoanAdjustmentDocument));
                    string DocumentNewFileName = Path.Combine(DocumentNewPath,
                                                              "LAdjD" + CommonProperties.LoginInfo.LoggedInCompany.CompanyID.ToString("000") + CommonProperties.LoginInfo.LoggedInFinPeriod.FinPeriodID.ToString("000") +
                                                              SaveModel.LoanAdjustmentNo.ToString("0000000000") + Path.GetExtension(txtDocument.Text));
                    try
                    {
                        if (!Directory.Exists(DocumentNewPath))
                        {
                            Directory.CreateDirectory(DocumentNewPath);
                        }
                        // Allow to overwrite the document only if in edit mode
                        File.Copy(txtDocument.Text, DocumentNewFileName, (SaveModel.LoanAdjustmentID != 0));
                    }
                    catch (System.IO.IOException ex)
                    {
                        SavingResult res = new SavingResult();
                        DAL.CommonFunctions.GetFinalError(res, ex);
                        Paras.SavingResult = res;
                        return;
                    }
                    SaveModel.ApplicationDocumentFileName = DocumentNewFileName;
                }
            }

            Paras.SavingResult = DALObject.SaveNewRecord(SaveModel);

            base.SaveRecord(Paras);
        }