Beispiel #1
0
        public SavingResult SaveNewRecord(tblLeaveEncashment SaveModel)
        {
            SavingResult res = new SavingResult();

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

            //--
            using (dbVisionEntities db = new dbVisionEntities())
            {
                //tblLeaveEncashment SaveModel;
                if (SaveModel.LeaveEncashmentNo == 0)
                {
                    res.ValidationError = "Please enter Leave Application No..";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }
                else if (IsDuplicateRecord(SaveModel.LeaveEncashmentNoPrefixID, SaveModel.LeaveEncashmentNo, SaveModel.LeaveEncashmentID, db))
                {
                    res.ValidationError = "Can not accept duplicate value. The Leave Application No. is already exists.";
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    return(res);
                }

                if (SaveModel.LeaveEncashmentID == 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.tblLeaveEncashments.Add(SaveModel);
                }
                else
                {
                    SaveModel.reuid = Model.CommonProperties.LoginInfo.LoggedinUser.UserID;
                    SaveModel.redt  = DateTime.Now;
                    db.tblLeaveEncashments.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;
                }

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

            using (dbVisionEntities db = new dbVisionEntities())
            {
                if (DeleteID != 0)
                {
                    tblLeaveEncashment RecordToDelete = db.tblLeaveEncashments.FirstOrDefault(r => r.LeaveEncashmentID == 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.tblLeaveEncashments.Remove(RecordToDelete);
                        byte RecordState_Deleted = (byte)eRecordState.Deleted;
                        RecordToDelete.rstate = RecordState_Deleted;
                        db.tblLeaveEncashments.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);
        }
Beispiel #3
0
        public override void FillSelectedRecordInContent(object RecordToFill)
        {
            LeaveEncashmentEditListModel EditingRecord = (LeaveEncashmentEditListModel)RecordToFill;
            tblLeaveEncashment           SaveModel     = DALObject.FindSaveModelByPrimeKey(EditingRecord.LeaveEncashmentID);

            if (SaveModel == null)
            {
                return;
            }

            deLeaveEncashmentDate.DateTime          = SaveModel.LeaveEncashmentDate;
            lookupLeaveEncashmentNoPrefix.EditValue = SaveModel.LeaveEncashmentNoPrefixID;
            txtLeaveEncashmentNo.EditValue          = SaveModel.LeaveEncashmentNo;
            lookupEmployee.EditValue  = SaveModel.EmployeeID;
            lookupLeaveType.EditValue = SaveModel.LeaveTypeID;

            txtNofDays.EditValue = SaveModel.NofLeaves;
            LeaveBalance         = SaveModel.NofLeaves + LeaveTypeDALObj.GetLeaveBalance(SaveModel.EmployeeID, SaveModel.LeaveTypeID, deLeaveEncashmentDate.DateTime);

            txtRemarks.Text  = SaveModel.Remarks;
            txtDocument.Text = SaveModel.ApplicationDocumentFileName;

            base.FillSelectedRecordInContent(RecordToFill);
        }
Beispiel #4
0
        public override void SaveRecord(SavingParemeter Paras)
        {
            DAL.tblLeaveEncashment SaveModel = null;
            if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew || EditRecordDataSource == null)
            {
                SaveModel = new tblLeaveEncashment();
            }
            else
            {
                SaveModel = DALObject.FindSaveModelByPrimeKey(((LeaveEncashmentEditListModel)EditRecordDataSource).LeaveEncashmentID);

                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.LeaveEncashmentDate       = deLeaveEncashmentDate.DateTime.Date;
            SaveModel.LeaveEncashmentNoPrefixID = (int)lookupLeaveEncashmentNoPrefix.EditValue;
            SaveModel.LeaveEncashmentNo         = Model.CommonFunctions.ParseInt(txtLeaveEncashmentNo.Text);
            SaveModel.EmployeeID  = (int)lookupEmployee.EditValue;
            SaveModel.LeaveTypeID = (int)lookupLeaveType.EditValue;
            SaveModel.NofLeaves   = Model.CommonFunctions.ParseDecimal(txtNofDays.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_LeaveEncashmentDocument));
                    string DocumentNewFileName = Path.Combine(DocumentNewPath,
                                                              "LED" + CommonProperties.LoginInfo.LoggedInCompany.CompanyID.ToString("000") + CommonProperties.LoginInfo.LoggedInFinPeriod.FinPeriodID.ToString("000") +
                                                              SaveModel.LeaveEncashmentNo.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.LeaveEncashmentID != 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);
        }