public long SaveToDatabase() { // Save all table in dataset to database and clear transaction. long caDocumentID = CADocumentService.SaveCADocument(this.TransactionID, this.CADocumentID); // Get ta document CADocument caDocument = ScgeAccountingQueryProvider.CADocumentQuery.FindProxyByIdentity(caDocumentID); TransactionService.Commit(this.TransactionID); #region Work Flow long workFlowID = 0; // Save New WorkFlow. if ((caDocument != null) && (caDocument.DocumentID != null)) { SCGDocument document = ScgeAccountingQueryProvider.SCGDocumentQuery.FindProxyByIdentity(caDocument.DocumentID.DocumentID); SS.Standard.WorkFlow.DTO.WorkFlow workFlow = new SS.Standard.WorkFlow.DTO.WorkFlow(); // WorkFlow Type ID = 9 is CA Workflow Image. wait confirm where to store this data. workFlow.WorkFlowType = new SS.Standard.WorkFlow.DTO.WorkFlowType(WorkFlowTypeID.CAWorkFlow); // WorkFlow Type ID = 9 is CA Workflow Image. wait confirm where to store this data. workFlow.CurrentState = WorkFlowQueryProvider.WorkFlowStateQuery.FindWorkFlowStateIDByTypeIDAndStateName(WorkFlowTypeID.CAWorkFlow, WorkFlowStateFlag.Draft); workFlow.Description = null; workFlow.Document = document; workFlow.Active = true; workFlow.CreBy = document.CreBy; workFlow.CreDate = document.CreDate; workFlow.UpdBy = document.UpdBy; workFlow.UpdDate = document.UpdDate; workFlow.UpdPgm = document.UpdPgm; workFlowID = WorkFlowService.CheckExistAndAddNew(workFlow); } #endregion Work Flow return(workFlowID); }
public long Save() { Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors(); CADocumentDataSet caDocumentDS = (CADocumentDataSet)TransactionService.GetDS(this.TransactionID); if (caDocumentDS == null) { OnDsNull(); } CADocumentDataSet.CADocumentRow caDocumentRow = caDocumentDS.CADocument.FindByCADocumentID(this.CADocumentID); long tempDocumentID = caDocumentRow.DocumentID; #region SCGDocument SCGDocument scgDocument = new SCGDocument(tempDocumentID); if (!string.IsNullOrEmpty(ctlCompanyField.CompanyID)) { scgDocument.CompanyID = new DbCompany(UIHelper.ParseLong(ctlCompanyField.CompanyID)); } scgDocument.CreatorID = new SuUser(UIHelper.ParseLong(ctlCreatorData.UserID)); if (!string.IsNullOrEmpty(ctlRequesterData.UserID)) { scgDocument.RequesterID = new SuUser(UIHelper.ParseLong(ctlRequesterData.UserID)); } scgDocument.Subject = ctlSubject.Text; if (!string.IsNullOrEmpty(ctlApproverData.UserID)) { scgDocument.ApproverID = new SuUser(UIHelper.ParseLong(ctlApproverData.UserID)); } scgDocument.DocumentType = new SS.Standard.WorkFlow.DTO.DocumentType(DocumentTypeID.CADocument); scgDocument.Memo = ctlMemo.Text; scgDocument.Active = true; try { // Save SCG Document to Transaction. SCGDocumentService.UpdateTransactionDocument(this.TransactionID, scgDocument, false, true); } catch (ServiceValidationException ex) { errors.MergeErrors(ex.ValidationErrors); } #endregion SCGDocument #region CADocument CADocument caDocument = new CADocument(this.CADocumentID); caDocument.DocumentID = scgDocument; if (ctlSomeTime.Checked) { caDocument.IsTemporary = true; try { if (ctlStartDateSumtime.Value != null) { caDocument.StartDate = ctlStartDateSumtime.Value.Value; } if (ctlEndDateSumtime.Value != null) { caDocument.EndDate = ctlEndDateSumtime.Value.Value; } } catch (FormatException fex) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Invalid_Date_Format")); throw new ServiceValidationException(errors); } } else if (ctlRegular.Checked) { caDocument.IsTemporary = false; try { if (ctlStartDate.Value != null) { caDocument.StartDate = ctlStartDate.Value.Value; } if (ctlEndDate.Value != null) { caDocument.EndDate = ctlEndDate.Value.Value; } } catch (FormatException fex) { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Invalid_Date_Format")); throw new ServiceValidationException(errors); } } caDocument.CarLicenseNo = ctlCarLicenseNo.Text; caDocument.Brand = ctlBrand.Text; caDocument.Model = ctlModel.Text; switch (ctlDropDownListCategory.SelectedValue) { case "1": caDocument.OwnerType = OwnerMileage.Employee; break; case "2": caDocument.OwnerType = OwnerMileage.Company; break; default: break; } switch (ctlDropDownListType.SelectedValue) { case "1": caDocument.CarType = TypeOfCar.PrivateCar; break; case "2": caDocument.CarType = TypeOfCar.MotorCycle; break; case "3": caDocument.CarType = TypeOfCar.Pickup; break; default: break; } if (caDocument.IsTemporary) { if (ctlWorkInArea.Checked || ctlWorkOutOfArea.Checked) { if (ctlWorkInArea.Checked) { caDocument.IsWorkArea = true; } else if (ctlWorkOutOfArea.Checked) { caDocument.IsWorkArea = false; caDocument.Remark = ctlWorkOutOfAreatxt.Text; } } else { errors.AddError("Provider.Error", new Spring.Validation.ErrorMessage("Please Select Work Area.")); } } else { if (ctlWorkInArea.Checked) { caDocument.IsWorkArea = true; } else if (ctlWorkOutOfArea.Checked) { caDocument.IsWorkArea = false; caDocument.Remark = ctlWorkOutOfAreatxt.Text; } } caDocument.Active = true; try { // Get ta document information and save to transaction. CADocumentService.UpdateCADocumentTransaction(this.TransactionID, caDocument); } catch (ServiceValidationException ex) { errors.MergeErrors(ex.ValidationErrors); } if (!errors.IsEmpty) { throw new ServiceValidationException(errors); } #endregion CADocument try { ctlInitiator.Save(); DocumentInitiatorService.ValidateDocumentInitiator(this.TransactionID, this.CADocumentID); } catch (ServiceValidationException ex) { errors.MergeErrors(ex.ValidationErrors); } if (!errors.IsEmpty) { // If have some validation error then return error. throw new ServiceValidationException(errors); } else { return(this.SaveToDatabase()); } }