示例#1
0
        public override void SaveRecord(SavingParemeter Paras)
        {
            var RecordsToSave = dsImportedData.Where(r => r.CanImport && (r.SavingResult == null || r.SavingResult.ExecutionResult != eExecutionResult.CommitedSucessfuly));

            DALObj.SaveNewRecord(RecordsToSave);

            RecordsToSave = dsImportedData.Where(r => r.SavingResult != null && r.SavingResult.ExecutionResult == eExecutionResult.CommitedSucessfuly);
            if (!String.IsNullOrWhiteSpace(txtDocument.Text) && File.Exists(txtDocument.Text))
            {
                foreach (var ViewModel in RecordsToSave)
                {
                    DAL.tblTAApproval SaveModel = DALObj.FindSaveModelByPrimeKey(ViewModel.TAApprovalID);
                    if (SaveModel == null)
                    {
                        continue;
                    }

                    if (!String.IsNullOrWhiteSpace(txtDocument.Text) && System.IO.File.Exists(txtDocument.Text))
                    {
                        string DocumentNewPath     = Path.GetFullPath(Path.Combine(CommonProperties.LoginInfo.SoftwareSettings.DocumentLocation_TAApprovalDocument));
                        string DocumentNewFileName = Path.Combine(DocumentNewPath,
                                                                  "TAAD" +
                                                                  CommonProperties.LoginInfo.LoggedInCompany.CompanyID.ToString("000") +
                                                                  CommonProperties.LoginInfo.LoggedInFinPeriod.FinPeriodID.ToString("000") +
                                                                  ViewModel.ApprovalNoPrefixName +
                                                                  SaveModel.TAApprovalNo.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.TAApprovalID != 0));
                        }
                        catch (System.IO.IOException ex)
                        {
                            SavingResult res = new SavingResult();
                            DAL.CommonFunctions.GetFinalError(res, ex);
                            Paras.SavingResult = res;
                            return;
                        }
                        SaveModel.ApplicationDocumentFileName = DocumentNewFileName;
                    }

                    ViewModel.SavingResult = DALObj.SaveNewRecord(SaveModel);
                }
            }
            //--
            var SkippedRecords = dsImportedData.Where(r => !r.CanImport);

            foreach (var r in SkippedRecords)
            {
                r.SavingResult = new SavingResult()
                {
                    ExecutionResult = eExecutionResult.ValidationError,
                    ValidationError = "Skipped"
                };
            }

            gridviewImportData.RefreshData();

            base.SaveRecord(Paras);
        }
示例#2
0
        public override void SaveRecord(SavingParemeter Paras)
        {
            DAL.tblTAApproval SaveModel = null;
            if (Paras.SavingInterface == SavingParemeter.eSavingInterface.AddNew || EditRecordDataSource == null)
            {
                SaveModel = new tblTAApproval();
            }
            else
            {
                SaveModel = DALObject.FindSaveModelByPrimeKey(((TAApprovalEditListModel)EditRecordDataSource).TAApprovalID);

                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.TAApprovalDate       = deTAApprovalDate.DateTime.Date;
            SaveModel.TAApprovalNoPrefixID = (int)lookupTAApprovalNoPrefix.EditValue;
            SaveModel.TAApprovalNo         = Model.CommonFunctions.ParseInt(txtTAApprovalNo.Text);
            SaveModel.EmployeeID           = (int)lookupEmployee.EditValue;

            SaveModel.ApprovedDate   = deApprovedDate.DateTime;
            SaveModel.ApprovalTypeID = (byte)cmbApprovalType.SelectedIndex;
            SaveModel.ApprovedHours  = txtNofHours.EditValueToDecimal();

            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_TAApprovalDocument));
                    string DocumentNewFileName = Path.Combine(DocumentNewPath,
                                                              "TAAD" +
                                                              CommonProperties.LoginInfo.LoggedInCompany.CompanyID.ToString("000") +
                                                              CommonProperties.LoginInfo.LoggedInFinPeriod.FinPeriodID.ToString("000") +
                                                              lookupTAApprovalNoPrefix.Text +
                                                              SaveModel.TAApprovalNo.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.TAApprovalID != 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);
        }