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()); } }
public void Initialize(string initFlag, long?documentID) { CADocumentDataSet caDocumentDS; long caDocumentID = 0; Guid txID = Guid.Empty; bool isCopy = false; //#region Visible Mode //ctlAddRequester.Visible = true; //this.isShowFooter = true; //#endregion Visible Mode if (initFlag.Equals(FlagEnum.NewFlag) && Request.QueryString["cp"] == null) { caDocumentDS = (CADocumentDataSet)CADocumentService.PrepareDS(); txID = TransactionService.Begin(caDocumentDS); caDocumentID = CADocumentService.AddCADocumentTransaction(txID); ctlCAFormHeader.Status = FlagEnum.NewFlag; } else if (((initFlag.Equals(FlagEnum.EditFlag) || (initFlag.Equals(FlagEnum.ViewFlag)))) && ((documentID.HasValue) && (documentID.Value != 0))) { caDocumentDS = (CADocumentDataSet)CADocumentService.PrepareDS(documentID.Value); txID = TransactionService.Begin(caDocumentDS); if (caDocumentDS.Document.Rows.Count > 0) { caDocumentID = UIHelper.ParseLong(caDocumentDS.CADocument.Rows[0]["CADocumentID"].ToString()); } } else if (Request.QueryString["cp"] != null && UIHelper.ParseLong(Request.QueryString["cp"]) == 1) { caDocumentDS = (CADocumentDataSet)CADocumentService.PrepareDataToDataset(UIHelper.ParseLong(Request.QueryString["docId"]), true); txID = TransactionService.Begin(caDocumentDS); isCopy = true; if (caDocumentDS.CADocument.Rows.Count > 0) { caDocumentID = UIHelper.ParseLong(caDocumentDS.CADocument.Rows[0]["CADocumentID"].ToString()); } } this.TransactionID = txID; this.CADocumentID = caDocumentID; this.InitialFlag = initFlag; // Define value to each DocumentEditor Property. // And store it in viewstate. this.VisibleFields = CADocumentService.GetVisibleFields(documentID); this.EditableFields = CADocumentService.GetEditableFields(documentID); this.InitializeControl(); this.BindControl(isCopy); #region Show Tab // ให้ Tab ที่มีข้อมูลโชว์ขึ้นมา ส่วน Tab ที่ไม่มีข้อมูล ไม่ต้องโชว์ string strCurrentState = ""; if (!string.IsNullOrEmpty(Request.Params["wfid"]) && UIHelper.ParseInt(Request.Params["wfid"]) > 0) { long workFlowID = UIHelper.ParseLong(Request.Params["wfid"]); SS.Standard.WorkFlow.DTO.WorkFlow wf = WorkFlowQueryProvider.WorkFlowQuery.FindByIdentity(workFlowID); if (wf != null && wf.CurrentState != null && wf.CurrentState.Name != null) { strCurrentState = wf.CurrentState.Name; } } if (strCurrentState == "Draft") { ctlTabMemo.Visible = true; ctlTabInitial.Visible = true; ctlTabAttachment.Visible = true; ctlTabHistory.Visible = true; ctlUpdatePanelTab.Update(); } else if (this.InitialFlag.Equals(FlagEnum.ViewFlag)) { if (string.IsNullOrEmpty(ctlMemo.Text)) { ctlTabMemo.Visible = false; } else { ctlTabMemo.Visible = true; } if (ctlInitiator.IsEmptyData) { ctlTabInitial.Visible = false; } else { ctlTabInitial.Visible = true; } if (ctlAttachment.IsEmptyData) { ctlTabAttachment.Visible = false; } else { ctlTabAttachment.Visible = true; } if (ctlHistory.IsEmptyData) { ctlTabHistory.Visible = false; } else { ctlTabHistory.Visible = true; } ctlUpdatePanelTab.Update(); } else { ctlTabMemo.Visible = true; ctlTabInitial.Visible = true; ctlTabAttachment.Visible = true; ctlTabHistory.Visible = true; ctlUpdatePanelTab.Update(); } #endregion Show Tab }