public void Activate() { string sql = "SELECT G3E_FID FROM WORKPOINT_N WHERE WR_NBR=:1 AND G3E_FNO=191"; Recordset rsValidate = null; int jFid = 0; short jFno = 0; IGTKeyObject jKeyObject = null; IGTJobManagementService oJobManagement = GTClassFactory.Create <IGTJobManagementService>(); oJobManagement.DataContext = m_ogtApplication.DataContext; try { if (ValidateCommand()) { ADODB.Recordset rsPendingEdits = oJobManagement.FindPendingEdits(); if (rsPendingEdits != null && rsPendingEdits.RecordCount > 0) { oJobManagement.DiscardJob(); //ALM 1321 - Automatically discard job at the start and assume that there are no unposted data m_oGTTransactionManager.RefreshDatabaseChanges(); m_ogtApplication.RefreshWindows(); } rsValidate = m_ogtApplication.DataContext.OpenRecordset(sql, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockReadOnly, (int)ADODB.CommandTypeEnum.adCmdText, new object[] { m_ogtApplication.DataContext.ActiveJob }); if (rsValidate == null || rsValidate.RecordCount == 0) { return; } m_oGTTransactionManager.Begin("Revert Job"); commonRevertAPI rFeature = new commonRevertAPI(m_ogtApplication); rsValidate.MoveFirst(); while (!rsValidate.EOF) { jFno = 191; jFid = Convert.ToInt32(rsValidate.Fields["G3E_FID"].Value); jKeyObject = m_ogtApplication.DataContext.OpenFeature(jFno, jFid); rFeature.m_FromJob = "JOB"; rFeature.RevertWPFeature(jKeyObject); rsValidate.MoveNext(); } if (rFeature.m_uProcessedCUs) { MessageBox.Show("Check remaining Work Points to make manual corrections.", "G/Technology", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } if (m_oGTTransactionManager.TransactionInProgress) { m_oGTTransactionManager.Commit(); m_oGTTransactionManager.RefreshDatabaseChanges(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "G/Technology", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); m_oGTTransactionManager.Rollback(); } finally { if (rsValidate != null) { if (rsValidate.State == 1) { rsValidate.Close(); rsValidate.ActiveConnection = null; } rsValidate = null; } } }
public void Activate() { IGTComponent cuComponent = null; short aFno = 0; int aFid = 0; int wpNotAssoFeaturesCount = 0; try { IGTDDCKeyObjects gtDDCKeyObjects = m_ogtApplication.Application.SelectedObjects.GetObjects(); activeFeatureDDCKey = gtDDCKeyObjects[0]; IGTJobHelper gTJobHelper = null; gTJobHelper = GTClassFactory.Create <IGTJobHelper>(); ADODB.Recordset myfeatures = gTJobHelper.FindPendingEdits(); if (myfeatures != null && myfeatures.RecordCount > 0) { myfeatures.MoveFirst(); myfeatures.Find("g3e_fid=" + activeFeatureDDCKey.FID + ""); if (!(myfeatures.BOF || myfeatures.EOF)) { MessageBox.Show("This command cannot be used on unposted features.", "G/Technology", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } } gTJobHelper = null; myfeatures = null; commonRevertAPI rFeature = new commonRevertAPI(m_ogtApplication); if (ValidateCommand()) { if (!rFeature.ValidateActiveFetature(m_oActiveKeyObject)) { //m_ogtApplication.SetStatusBarText(GTStatusPanelConstants.gtaspcMessage, "Feature has been edited by WR " + rFeature.m_WRID + "; cannot revert."); MessageBox.Show("Feature has been edited by WR " + rFeature.m_WRID + "; cannot revert.", "G/Technology", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } else { if (m_oActiveKeyObject.FNO == 191) { m_oGTTransactionManager.Begin("Revert Feature Fno=" + m_oActiveKeyObject.FNO + " FID=" + m_oActiveKeyObject.FID); cuComponent = m_oActiveKeyObject.Components.GetComponent(19104); if (cuComponent != null && cuComponent.Recordset != null && cuComponent.Recordset.RecordCount > 0) { cuComponent.Recordset.MoveFirst(); while (!cuComponent.Recordset.EOF) { aFno = Convert.ToInt16(cuComponent.Recordset.Fields["ASSOC_FNO"].Value); aFid = Convert.ToInt32(cuComponent.Recordset.Fields["ASSOC_FID"].Value); if (!rFeature.ValidateActiveFetature(m_ogtApplication.DataContext.OpenFeature(aFno, aFid))) { wpNotAssoFeaturesCount = wpNotAssoFeaturesCount + 1; } cuComponent.Recordset.MoveNext(); } } if (wpNotAssoFeaturesCount == 0) { rFeature.RevertWPFeature(m_oActiveKeyObject); if (m_oGTTransactionManager.TransactionInProgress) { m_oGTTransactionManager.Commit(); m_oGTTransactionManager.RefreshDatabaseChanges(); } } else if (wpNotAssoFeaturesCount == cuComponent.Recordset.RecordCount) { MessageBox.Show("All features associated with this Work Point have been edited by other WRs and cannot be reverted.", "G/Technology", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } else if (wpNotAssoFeaturesCount < cuComponent.Recordset.RecordCount) { DialogResult dResult = MessageBox.Show("One or more features associated with this Work Point have been edited by other WRs and cannot be reverted. Continue reverting other associated features?", "G/Technology", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dResult == DialogResult.OK) { rFeature.RevertWPFeature(m_oActiveKeyObject); if (m_oGTTransactionManager.TransactionInProgress) { m_oGTTransactionManager.Commit(); m_oGTTransactionManager.RefreshDatabaseChanges(); } } else { m_oGTTransactionManager.Rollback(); } } } else { if (m_oActiveKeyObject.Components["COMMON_N"].Recordset != null && m_oActiveKeyObject.Components["COMMON_N"].Recordset.RecordCount > 0) { m_oGTTransactionManager.Begin("Revert Feature Fno=" + m_oActiveKeyObject.FNO + " FID=" + m_oActiveKeyObject.FID); rFeature.RevertFeture(m_oActiveKeyObject.FNO, m_oActiveKeyObject.FID, m_ostrActFeatureState, 0, 0, 0); if (m_oGTTransactionManager.TransactionInProgress) { m_oGTTransactionManager.Commit(); m_oGTTransactionManager.RefreshDatabaseChanges(); } } } if (rFeature.m_uProcessedCUs) { MessageBox.Show("Command was unable to revert all activity.", "G/Technology", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "G/Technology", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); m_oGTTransactionManager.Rollback(); } }