public static void ShowProgressDialog(string message, Delegate action, params object[] args) { // Create a CancelTracker ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor var int32_hWnd = ArcMap.Application.hWnd; var stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.Hide(); // Create the ProgressDialog. This automatically displays the dialog var progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Set the properties of the ProgressDialog progressDialog2.CancelEnabled = false; progressDialog2.Description = message; progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; progressDialog2.ShowDialog(); progressDialog2.CancelEnabled = false; action.DynamicInvoke(args); progressDialog2.CancelEnabled = false; trackCancel = null; stepProgressor = null; progressDialog2.HideDialog(); progressDialog2 = null; }
/// <summary> /// 保存当前ActiveView为图片 /// </summary> /// <param name="SaveFilePath">图片路径</param> /// <param name="ActiveView">Map ActiveView</param> public static void ExportMap(string SaveFilePath,IActiveView ActiveView) { IExport export = ExportBase(SaveFilePath); double IScreenResolution = ActiveView.ScreenDisplay.DisplayTransformation.Resolution; export.ExportFileName = SaveFilePath; export.Resolution = IScreenResolution; ESRI.ArcGIS.esriSystem.tagRECT deviceRECT = ActiveView.ExportFrame; IEnvelope envelope = new EnvelopeClass(); deviceRECT.right = deviceRECT.right * 10; deviceRECT.bottom = deviceRECT.bottom * 10; envelope.PutCoords(deviceRECT.left, deviceRECT.top, deviceRECT.right, deviceRECT.bottom); export.PixelBounds = envelope; ITrackCancel Cancel=new ESRI.ArcGIS.Display.CancelTrackerClass(); ActiveView.Output(export.StartExporting(), (int)IScreenResolution*10, ref deviceRECT, ActiveView.Extent, Cancel); export.FinishExporting(); export.Cleanup(); //MessageBox.Show("OK"); }
private void PrintAuto(IActiveView pActiveView) { IPaper pPaper = new Paper(); IPrinter pPrinter = new EmfPrinterClass(); System.Drawing.Printing.PrintDocument sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument(); pPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName; pPrinter.Paper = pPaper; int Resolution = pPrinter.Resolution; double w, h; IEnvelope PEnvelope = pActiveView.Extent; w = PEnvelope.Width; h = PEnvelope.Height; double pw, ph; //纸张 pPrinter.QueryPaperSize(out pw, out ph); tagRECT userRECT = pActiveView.ExportFrame; userRECT.left = (int)(pPrinter.PrintableBounds.XMin * Resolution); userRECT.top = (int)(pPrinter.PrintableBounds.YMin * Resolution); if ((w / h) > (pw / ph))//以宽度来调整高度 { userRECT.right = userRECT.left + (int)(pPrinter.PrintableBounds.Width * Resolution); userRECT.bottom = userRECT.top + (int)((pPrinter.PrintableBounds.Width * Resolution) * h / w); } else { userRECT.bottom = userRECT.top + (int)(pPrinter.PrintableBounds.Height * Resolution); userRECT.right = userRECT.left + (int)(pPrinter.PrintableBounds.Height * Resolution * w / h); } IEnvelope pDriverBounds = new EnvelopeClass(); pDriverBounds.PutCoords(userRECT.left, userRECT.top, userRECT.right, userRECT.bottom); ITrackCancel pCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); int hdc = pPrinter.StartPrinting(pDriverBounds, 0); pActiveView.Output(hdc, pPrinter.Resolution, ref userRECT, pActiveView.Extent, pCancel); pPrinter.FinishPrinting(); }
public void RunCreateRules() { ICursor cursor = null; IFeatureCursor fCursor = null; bool ran = false; try { //Get list of editable layers IEditor editor = _editor; IEditLayers eLayers = (IEditLayers)editor; long lastOID = -1; string lastLay = ""; if (_editor.EditState != esriEditState.esriStateEditing) return; IMap map = editor.Map; IActiveView activeView = map as IActiveView; IStandaloneTable stTable; ITableSelection tableSel; IStandaloneTableCollection stTableColl = (IStandaloneTableCollection)map; long rowCount = stTableColl.StandaloneTableCount; long rowSelCount = 0; for (int i = 0; i < stTableColl.StandaloneTableCount; i++) { stTable = stTableColl.get_StandaloneTable(i); tableSel = (ITableSelection)stTable; if (tableSel.SelectionSet != null) { rowSelCount = rowSelCount + tableSel.SelectionSet.Count; } } long featCount = map.SelectionCount; int totalCount = (Convert.ToInt32(rowSelCount) + Convert.ToInt32(featCount)); if (totalCount >= 1) { if (MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantAsk_4a") + totalCount + A4LGSharedFunctions.Localizer.GetString("AttributeAssistantAsk_2b"), A4LGSharedFunctions.Localizer.GetString("Confirm"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = ArcMap.Application.hWnd; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 1; stepProgressor.MaxRange = totalCount; stepProgressor.StepValue = 1; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_2a"); // Create the ProgressDialog. This automatically displays the dialog ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog2.CancelEnabled = true; progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantDesc_2a") + totalCount.ToString() + "."; progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantTitle_2a"); progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; // Step. Do your big process here. System.Boolean boolean_Continue = false; boolean_Continue = true; System.Int32 progressVal = 0; ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar; ran = true; editor.StartOperation(); //bool test = false; //Get list of feature layers UID geoFeatureLayerID = new UIDClass(); geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; IEnumLayer enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true); IFeatureLayer fLayer; IFeatureSelection fSel; ILayer layer; // Step through each geofeature layer in the map enumLayer.Reset(); // Create an edit operation enabling undo/redo try { // AAState.StopCreateMonitor(); while ((layer = enumLayer.Next()) != null) { // Verify that this is a valid, visible layer and that this layer is editable fLayer = (IFeatureLayer)layer; bool bIsEditableFabricLayer = (fLayer is ICadastralFabricSubLayer2); if (bIsEditableFabricLayer) { IDataset pDS = (IDataset)fLayer.FeatureClass; IWorkspace pFabWS = pDS.Workspace; bIsEditableFabricLayer = (bIsEditableFabricLayer && pFabWS.Equals(editor.EditWorkspace)); } if (fLayer.Valid && (eLayers.IsEditable(fLayer) || bIsEditableFabricLayer))//fLayer.Visible && { // Verify that this layer has selected features IFeatureClass fc = fLayer.FeatureClass; fSel = (IFeatureSelection)fLayer; if ((fc != null) && (fSel.SelectionSet.Count > 0)) { fSel.SelectionSet.Search(null, false, out cursor); fCursor = cursor as IFeatureCursor; IFeature feat; feat = (IFeature)fCursor.NextFeature(); while (feat != null) { progressVal++; progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantProc_2a") + progressVal + A4LGSharedFunctions.Localizer.GetString("Of") + totalCount.ToString() + "."; stepProgressor.Step(); statusBar.set_Message(0, progressVal.ToString()); lastOID = feat.OID; lastLay = fLayer.Name; IObject pObj = feat as IObject; AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_5a")); AAState._editEvents.OnCreateFeature -= AAState.FeatureCreate; AAState._editEvents.OnChangeFeature -= AAState.FeatureChange; try { //AAState.FeatureCreate(pObj); Debug.WriteLine("Feature with " + feat.OID); Debug.WriteLine(progressVal.ToString() + " : Count is " + fSel.SelectionSet.Count); feat.Store(); } catch { } AAState._editEvents.OnCreateFeature += AAState.FeatureCreate; AAState._editEvents.OnChangeFeature += AAState.FeatureChange; AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_5b")); //Check if the cancel button was pressed. If so, stop process boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { break; } feat = (IFeature)fCursor.NextFeature(); } if (feat != null) Marshal.ReleaseComObject(feat); } } else { if (fLayer.Valid) { // Verify that this layer has selected features IFeatureClass fc = fLayer.FeatureClass; fSel = (IFeatureSelection)fLayer; if (fSel.SelectionSet.Count > 0) { progressVal = progressVal + fSel.SelectionSet.Count; stepProgressor.OffsetPosition(progressVal); stepProgressor.Step(); } } } } activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { editor.AbortOperation(); ran = false; MessageBox.Show("RunCreateRule\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source); return; } finally { // AAState.StartCreateMonitor(); try { // Stop the edit operation editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantDone_5a")); } catch (Exception ex) { } } editor.StartOperation(); try { AAState.StopChangeMonitor(); for (int i = 0; i < stTableColl.StandaloneTableCount; i++) { stTable = stTableColl.get_StandaloneTable(i); tableSel = (ITableSelection)stTable; if (tableSel.SelectionSet != null) { if (tableSel.SelectionSet.Count > 0) { tableSel.SelectionSet.Search(null, false, out cursor); IRow pRow; while ((pRow = (IRow)cursor.NextRow()) != null) { progressVal++; progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantProc_2a") + progressVal + A4LGSharedFunctions.Localizer.GetString("Of") + totalCount.ToString() + "."; stepProgressor.Step(); statusBar.set_Message(0, progressVal.ToString()); lastOID = pRow.OID; lastLay = stTable.Name; IObject pObj = pRow as IObject; AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_5a")); AAState._editEvents.OnCreateFeature -= AAState.FeatureCreate; try { AAState.FeatureCreate(pObj); pRow.Store(); } catch { } AAState._editEvents.OnCreateFeature += AAState.FeatureCreate; AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_5b")); //Check if the cancel button was pressed. If so, stop process boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { break; } } if (pRow != null) Marshal.ReleaseComObject(pRow); } } } } catch (Exception ex) { editor.AbortOperation(); MessageBox.Show("RunCreateRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source); ran = false; return; } finally { AAState.StartChangeMonitor(); try { // Stop the edit operation editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantDone_5a")); } catch (Exception ex) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorWarn_14a") + " " + ex.Message); } } // Done trackCancel = null; stepProgressor = null; progressDialog2.HideDialog(); progressDialog2 = null; } } else { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantError_2a")); } } catch (Exception ex) { MessageBox.Show(ex.Message + " \n" + "RunCreateRules", ex.Source); ran = false; return; } finally { if (ran) // MessageBox.Show("Process has completed successfully"); if (cursor != null) Marshal.ReleaseComObject(cursor); if (fCursor != null) Marshal.ReleaseComObject(fCursor); } }
/// <summary> /// Sets the buffer tube and strand counts based on the given configuration. If IPID and/or CABLEID are null, it also /// takes care of them /// </summary> /// <param name="feature">The FiberCable feature to configure</param> /// <param name="configuration">The tube/strand counts</param> /// <param name="isExistingOperation">Flag to control whether this method is being called from within an existing /// edit operation</param> /// <returns>Success</returns> protected bool ConfigureCable(ESRI.ArcGIS.Geodatabase.IFeature feature, FiberCableConfiguration configuration, bool isExistingOperation) { bool isComplete = false; bool isOurOperationOpen = false; // The following assignments are defaults for the case where they are not already populated on the feature string fiberCableIpid = Guid.NewGuid().ToString("B").ToUpper(); // The following will be set during Validation ESRI.ArcGIS.Geodatabase.IObjectClass ftClass = null; ESRI.ArcGIS.Geodatabase.IFields fields = null; int ipidIdx = -1; int bufferCountIdx = -1; int strandCountIdx = -1; #region Validation if (null == feature) { throw new ArgumentNullException("feature"); } if (null == configuration) { throw new ArgumentNullException("configuration"); } if (_editor.EditState == ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing) { throw new InvalidOperationException("You must be editing the workspace to perform this operation."); } ftClass = feature.Class; fields = ftClass.Fields; string missingFieldFormat = "Field {0} is missing."; ipidIdx = fields.FindField(ConfigUtil.IpidFieldName); if (-1 == ipidIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.IpidFieldName)); } bufferCountIdx = fields.FindField(ConfigUtil.NumberOfBuffersFieldName); if (-1 == bufferCountIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.NumberOfBuffersFieldName)); } strandCountIdx = fields.FindField(ConfigUtil.NumberOfFibersFieldName); if (-1 == strandCountIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.NumberOfFibersFieldName)); } #endregion ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = _hookHelper.CreateProgressDialog(trackCancel, "Preparing to configure cable...", 1, configuration.TotalFiberCount, 1, "Starting edit operation...", "Fiber Configuration"); ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; progressDialog.ShowDialog(); stepProgressor.Step(); if (!isExistingOperation) { _editor.StartOperation(); isOurOperationOpen = true; } try { if (DBNull.Value == feature.get_Value(ipidIdx)) { feature.set_Value(ipidIdx, fiberCableIpid); } else { fiberCableIpid = feature.get_Value(ipidIdx).ToString(); } feature.set_Value(bufferCountIdx, configuration.BufferCount); feature.set_Value(strandCountIdx, configuration.TotalFiberCount); isComplete = GenerateUnits(feature, configuration, progressDialog, trackCancel); progressDialog.Description = "Completing configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { if (isComplete) { feature.Store(); _editor.StopOperation("Configure Fiber"); } else { _editor.AbortOperation(); } } } catch { if (isOurOperationOpen) { _editor.AbortOperation(); } } progressDialog.HideDialog(); return isComplete; }
public void ExportSelectedRecordsToExcel() { ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null; ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null; IMxDocument mxdoc = null; IMap map = null; IStandaloneTableCollection standTabColl = null; IStandaloneTable standTable = null; ITableSelection tableSel = null; IEnumFeature enumFeat = null; IFeature feat = null; IFeatureSelection featSel = null; ITable openTable = null; object missing = null; //object fileName = null; object newTemplate = null; object docType = null; object isVisible = null; UID geoFeatureLayerID = null; IEnumLayer enumLayer = null; IFeatureLayer featlayer = null; try { mxdoc = (IMxDocument)_app.Document; map = mxdoc.FocusMap; long standTableCnt; int i = 0; bool selectionInTable = false; missing = System.Reflection.Missing.Value; // fileName = "normal.dot"; newTemplate = false; docType = 0; isVisible = true; //Get enumeration of feature layers geoFeatureLayerID = new UIDClass(); geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; enumLayer = map.get_Layers(geoFeatureLayerID, true); enumLayer.Reset(); standTabColl = (IStandaloneTableCollection)map; standTableCnt = standTabColl.StandaloneTableCount; enumFeat = (IEnumFeature)map.FeatureSelection; enumFeat.Reset(); feat = enumFeat.Next(); if (standTableCnt > 0) { for (int j = 0; j < standTableCnt; j++) { standTable = standTabColl.get_StandaloneTable(j); if (standTable.Valid) { openTable = (ITable)standTable; tableSel = (ITableSelection)openTable; if (tableSel.SelectionSet.Count > 0) { selectionInTable = true; break; } } } } if ((selectionInTable == false) && (feat == null)) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("DataToolsMess_1") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("DataToolsMess_2"), messageBoxHeader); return; } // Create a CancelTracker ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = _app.hWnd; progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; stepProgressor.MaxRange = mxdoc.FocusMap.SelectionCount; stepProgressor.StepValue = 1; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("ExportXL"); // Create the ProgressDialog. This automatically displays the dialog progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = true; progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + "1" + A4LGSharedFunctions.Localizer.GetString("Of") + mxdoc.FocusMap.SelectionCount.ToString() + "."; progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("ExportXL"); progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; progressDialog.ShowDialog(); if ((feat != null) && (selectionInTable == true)) { ExcelApp = new Excel.ApplicationClass(); //Delete default worksheets ExcelApp.DisplayAlerts = false; objBook = ExcelApp.Workbooks.Add(missing); //objBook = ExcelApp.Workbooks.get_Item(1); for (int m = objBook.Sheets.Count; m > 1; m--) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m); objSheet.Delete(); } featlayer = (IFeatureLayer)enumLayer.Next(); while (featlayer != null) { if ((featlayer.Valid) && (featlayer.Selectable)) { featSel = (IFeatureSelection)featlayer; if (featSel.SelectionSet.Count > 0) { if (ExportLayer(objBook, mxdoc, featlayer, ref progressDialog, ref stepProgressor, ref trackCancel) == false) { return; } } } featlayer = (IFeatureLayer)enumLayer.Next(); } for (i = 0; i < standTableCnt; i++) { standTable = standTabColl.get_StandaloneTable(i); if (standTable.Valid) { openTable = (ITable)standTable; tableSel = (ITableSelection)openTable; if (tableSel.SelectionSet.Count > 0) { if (ExportTable(objBook, mxdoc, standTable, ref progressDialog, ref stepProgressor, ref trackCancel) == false) { return; } } } } } else if ((feat != null) && (selectionInTable == false)) { ExcelApp = new Excel.ApplicationClass(); //Delete default worksheets ExcelApp.DisplayAlerts = false; objBook = ExcelApp.Workbooks.Add(missing); //objBook = ExcelApp.Workbooks.get_Item(1); for (int m = objBook.Sheets.Count; m > 1; m--) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m); objSheet.Delete(); } ILayer pTLay = enumLayer.Next(); while (pTLay != null) { if (pTLay is IFeatureLayer) { featlayer = (IFeatureLayer)pTLay; if ((featlayer.Valid)) { featSel = (IFeatureSelection)featlayer; if (featSel.SelectionSet.Count > 0) { if (ExportLayer(objBook, mxdoc, featlayer, ref progressDialog, ref stepProgressor, ref trackCancel) == false) { return; } } } } pTLay = enumLayer.Next(); } pTLay = null; } else if ((feat == null) && (selectionInTable == true)) { ExcelApp = new Excel.ApplicationClass(); //Delete default worksheets ExcelApp.DisplayAlerts = false; objBook = ExcelApp.Workbooks.Add(missing); //objBook = ExcelApp.Workbooks.get_Item(1); for (int m = objBook.Sheets.Count; m > 1; m--) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m); objSheet.Delete(); } for (i = 0; i < standTableCnt; i++) { standTable = standTabColl.get_StandaloneTable(i); if (standTable.Valid) { openTable = (ITable)standTable; tableSel = (ITableSelection)openTable; if (tableSel.SelectionSet.Count > 0) { if (ExportTable(objBook, mxdoc, standTable, ref progressDialog, ref stepProgressor, ref trackCancel) == false) { return; } } } } } if (objBook.Sheets.Count > 1) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(1); objSheet.Delete(); } //objSheet = (Excel.Worksheet)objBook.Sheets["Sheet2"]; //objSheet.Delete(); //objSheet = (Excel.Worksheet)objBook.Sheets["Sheet3"]; //objSheet.Delete(); ExcelApp.DisplayAlerts = true; //Make the first sheet active objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(1) as Excel.Worksheet; (objSheet as Microsoft.Office.Interop.Excel._Worksheet).Activate(); //Make Excel visible ExcelApp.Visible = true; return; } catch (Exception ex) { if (ExcelApp != null) { ExcelApp = null; } //ExcelApp.Visible = true; MessageBox.Show("ExportSelectedRecordsToExcel\n" + ex.Message, ex.Source); return; } finally { if (progressDialog != null) { progressDialog.HideDialog(); } progressDialogFactory = null; stepProgressor = null; progressDialog = null; mxdoc = null; map = null; standTabColl = null; standTable = null; tableSel = null; enumFeat = null; feat = null; featSel = null; openTable = null; missing = null; //fileName = null; newTemplate = null; docType = null; isVisible = null; geoFeatureLayerID = null; enumLayer = null; featlayer = null; } }
public void ThreadMain() { this.Temp = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp/"+System.IO.Path.GetFileName(this.FilePath)); IExport export = ExportBase(); double IScreenResolution = ActiveView.ScreenDisplay.DisplayTransformation.Resolution; export.ExportFileName = this.Temp; export.Resolution = IScreenResolution; ESRI.ArcGIS.esriSystem.tagRECT deviceRECT = ActiveView.ExportFrame; IEnvelope envelope = new EnvelopeClass(); deviceRECT.right = deviceRECT.right * DPI; deviceRECT.bottom = deviceRECT.bottom * DPI; envelope.PutCoords(deviceRECT.left, deviceRECT.top, deviceRECT.right, deviceRECT.bottom); export.PixelBounds = envelope; ITrackCancel Cancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ActiveView.Output(export.StartExporting(), (int)IScreenResolution * DPI, ref deviceRECT, ActiveView.Extent, Cancel); export.FinishExporting(); export.Cleanup(); Merge(); }
private bool RemoveFiberCableConfigDomains(IWorkspace wksp) { bool result = true; if(wksp == null || ((wksp as IWorkspaceDomains3) == null)) return false; try { // get Handles to everything we need first or bail. IFeatureClass cableFc = FindFeatureClass(ConfigUtil.FiberCableFtClassName); if (cableFc == null) { return false; } ISubtypes subs = cableFc as ISubtypes; if (subs == null) { return false; } IClassSchemaEdit4 schEdit = cableFc as IClassSchemaEdit4; if (schEdit == null) { return false; } // ---------------------------------------------------- // First we have to unassign the domains from the FC fields // ---------------------------------------------------- schEdit.AlterDomain(ConfigUtil.NumberOfFibersFieldName, null); schEdit.AlterDomain(ConfigUtil.NumberOfBuffersFieldName, null); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Unassigned FiberCable domains", "NumberOfFibers + NumberOfBuffers"); // ---------------------------------------------------- // Also have to remove domain from the subtypes (arghh) // 1 & 2 are overhead and underground. // ---------------------------------------------------- IEnumSubtype types = subs.Subtypes; subs.set_Domain(1, ConfigUtil.NumberOfFibersFieldName, null); subs.set_Domain(2, ConfigUtil.NumberOfFibersFieldName, null); subs.set_Domain(1, ConfigUtil.NumberOfBuffersFieldName, null); subs.set_Domain(2, ConfigUtil.NumberOfBuffersFieldName, null); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Removed FiberCable subtype domains", "NumberOfFibers + NumberOfBuffers"); // ---------------------------------------------------- // Now we can remove the domains // ---------------------------------------------------- IWorkspaceDomains3 wkspDomains = wksp as IWorkspaceDomains3; if (wkspDomains.get_CanDeleteDomain("NumberOfFibers") && wkspDomains.get_CanDeleteDomain("NumberOfBuffers")) { wkspDomains.DeleteDomain("NumberOfFibers"); wkspDomains.DeleteDomain("NumberOfBuffers"); MessageBox.Show("Domains successfully deleted"); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Domains successfully deleted", "NumberOfFibers + NumberOfBuffers"); } else { MessageBox.Show("Upgrade failed. \nCould not get exclusive access to this database. \nPLEASE RESTORE FROM YOUR BACKUP"); _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Cannot delete domains.","Non-Exclusive access?"); return false; } // ---------------------------------------------------- // Recalculate the fields based on the count of actual // related objects found. We'll use this code later // for integrity checking. // ---------------------------------------------------- IRelationshipClass bufferRelationship = GdbUtils.GetRelationshipClass(cableFc, ConfigUtil.FiberCableToBufferRelClassName); IRelationshipClass strandRelationship = GdbUtils.GetRelationshipClass(cableFc, ConfigUtil.FiberCableToFiberRelClassName); IFeature ft; int bufferIdx = cableFc.Fields.FindField(ConfigUtil.NumberOfBuffersFieldName); int strandIdx = cableFc.Fields.FindField(ConfigUtil.NumberOfFibersFieldName); if (bufferIdx == -1 || strandIdx == -1) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Cannot find buffer or strand fields.", ConfigUtil.NumberOfBuffersFieldName + " " + ConfigUtil.NumberOfFibersFieldName); MessageBox.Show("Upgrade failed. \nCould not find appropriate fields based on current config settings. \nPLEASE RESTORE FROM YOUR BACKUP."); return false; } _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Recalculating buffer and strand counts..."); // Start edit session do the updates.... ArcMap.Editor.StartEditing(wksp); IFeatureCursor cables = cableFc.Update(null, false); int count = cableFc.FeatureCount(null); //ProgressBar ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); // Set the properties of the Step Progressor ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, ArcMap.Application.hWnd); stepProgressor.MinRange = 1; stepProgressor.MaxRange = count; stepProgressor.StepValue = 1; stepProgressor.Message = "Updating cable config for " + count + " cables"; // Create the ProgressDialog. This automatically displays the dialog ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = false; progressDialog.Description = ""; progressDialog.Title = "Workspace Upgrade"; progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; progressDialog.ShowDialog(); int i = 1; while ((ft = cables.NextFeature()) != null) { progressDialog.Description = string.Format("Updating cable {0} of {1}", i, count); stepProgressor.Step(); ISet buffers = bufferRelationship.GetObjectsRelatedToObject(ft); ft.set_Value(bufferIdx,buffers.Count); ISet strands = strandRelationship.GetObjectsRelatedToObject(ft); ft.set_Value(strandIdx, strands.Count); ft.Store(); i++; } progressDialog.HideDialog(); ArcMap.Editor.StopEditing(true); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Upgrade Completed Successfully."); MessageBox.Show("Upgrade Completed Successfully."); } catch (Exception e) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "RemoveFiberCableConfigDomains", e.Message); result = false; } return result; }
private bool RemoveFiberCableConfigDomains(IWorkspace wksp) { bool result = true; if (wksp == null || ((wksp as IWorkspaceDomains3) == null)) { return(false); } try { // get Handles to everything we need first or bail. IFeatureClass cableFc = FindFeatureClass(ConfigUtil.FiberCableFtClassName); if (cableFc == null) { return(false); } ISubtypes subs = cableFc as ISubtypes; if (subs == null) { return(false); } IClassSchemaEdit4 schEdit = cableFc as IClassSchemaEdit4; if (schEdit == null) { return(false); } // ---------------------------------------------------- // First we have to unassign the domains from the FC fields // ---------------------------------------------------- schEdit.AlterDomain(ConfigUtil.NumberOfFibersFieldName, null); schEdit.AlterDomain(ConfigUtil.NumberOfBuffersFieldName, null); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Unassigned FiberCable domains", "NumberOfFibers + NumberOfBuffers"); // ---------------------------------------------------- // Also have to remove domain from the subtypes (arghh) // 1 & 2 are overhead and underground. // ---------------------------------------------------- IEnumSubtype types = subs.Subtypes; subs.set_Domain(1, ConfigUtil.NumberOfFibersFieldName, null); subs.set_Domain(2, ConfigUtil.NumberOfFibersFieldName, null); subs.set_Domain(1, ConfigUtil.NumberOfBuffersFieldName, null); subs.set_Domain(2, ConfigUtil.NumberOfBuffersFieldName, null); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Removed FiberCable subtype domains", "NumberOfFibers + NumberOfBuffers"); // ---------------------------------------------------- // Now we can remove the domains // ---------------------------------------------------- IWorkspaceDomains3 wkspDomains = wksp as IWorkspaceDomains3; if (wkspDomains.get_CanDeleteDomain("NumberOfFibers") && wkspDomains.get_CanDeleteDomain("NumberOfBuffers")) { wkspDomains.DeleteDomain("NumberOfFibers"); wkspDomains.DeleteDomain("NumberOfBuffers"); MessageBox.Show("Domains successfully deleted"); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Domains successfully deleted", "NumberOfFibers + NumberOfBuffers"); } else { MessageBox.Show("Upgrade failed. \nCould not get exclusive access to this database. \nPLEASE RESTORE FROM YOUR BACKUP"); _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Cannot delete domains.", "Non-Exclusive access?"); return(false); } // ---------------------------------------------------- // Recalculate the fields based on the count of actual // related objects found. We'll use this code later // for integrity checking. // ---------------------------------------------------- IRelationshipClass bufferRelationship = GdbUtils.GetRelationshipClass(cableFc, ConfigUtil.FiberCableToBufferRelClassName); IRelationshipClass strandRelationship = GdbUtils.GetRelationshipClass(cableFc, ConfigUtil.FiberCableToFiberRelClassName); IFeature ft; int bufferIdx = cableFc.Fields.FindField(ConfigUtil.NumberOfBuffersFieldName); int strandIdx = cableFc.Fields.FindField(ConfigUtil.NumberOfFibersFieldName); if (bufferIdx == -1 || strandIdx == -1) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "Cannot find buffer or strand fields.", ConfigUtil.NumberOfBuffersFieldName + " " + ConfigUtil.NumberOfFibersFieldName); MessageBox.Show("Upgrade failed. \nCould not find appropriate fields based on current config settings. \nPLEASE RESTORE FROM YOUR BACKUP."); return(false); } _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Recalculating buffer and strand counts..."); // Start edit session do the updates.... ArcMap.Editor.StartEditing(wksp); IFeatureCursor cables = cableFc.Update(null, false); int count = cableFc.FeatureCount(null); //ProgressBar ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); // Set the properties of the Step Progressor ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, ArcMap.Application.hWnd); stepProgressor.MinRange = 1; stepProgressor.MaxRange = count; stepProgressor.StepValue = 1; stepProgressor.Message = "Updating cable config for " + count + " cables"; // Create the ProgressDialog. This automatically displays the dialog ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = false; progressDialog.Description = ""; progressDialog.Title = "Workspace Upgrade"; progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; progressDialog.ShowDialog(); int i = 1; while ((ft = cables.NextFeature()) != null) { progressDialog.Description = string.Format("Updating cable {0} of {1}", i, count); stepProgressor.Step(); ISet buffers = bufferRelationship.GetObjectsRelatedToObject(ft); ft.set_Value(bufferIdx, buffers.Count); ISet strands = strandRelationship.GetObjectsRelatedToObject(ft); ft.set_Value(strandIdx, strands.Count); ft.Store(); i++; } progressDialog.HideDialog(); ArcMap.Editor.StopEditing(true); _logHelper.addLogEntry(DateTime.Now.ToString(), "INFO", "Upgrade Completed Successfully."); MessageBox.Show("Upgrade Completed Successfully."); } catch (Exception e) { _logHelper.addLogEntry(DateTime.Now.ToString(), "ERROR", "RemoveFiberCableConfigDomains", e.Message); result = false; } return(result); }
/// <summary> /// Sets the buffer tube and strand counts based on the given configuration. If IPID and/or CABLEID are null, it also /// takes care of them /// </summary> /// <param name="feature">The FiberCable feature to configure</param> /// <param name="configuration">The tube/strand counts</param> /// <param name="isExistingOperation">Flag to control whether this method is being called from within an existing /// edit operation</param> /// <returns>Success</returns> protected bool ConfigureCable(ESRI.ArcGIS.Geodatabase.IFeature feature, FiberCableConfiguration configuration, bool isExistingOperation) { bool isComplete = false; bool isOurOperationOpen = false; // The following assignments are defaults for the case where they are not already populated on the feature string fiberCableIpid = Guid.NewGuid().ToString("B").ToUpper(); // The following will be set during Validation ESRI.ArcGIS.Geodatabase.IObjectClass ftClass = null; ESRI.ArcGIS.Geodatabase.IFields fields = null; int ipidIdx = -1; int bufferCountIdx = -1; int strandCountIdx = -1; #region Validation if (null == feature) { throw new ArgumentNullException("feature"); } if (null == configuration) { throw new ArgumentNullException("configuration"); } if (_editor.EditState == ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing) { throw new InvalidOperationException("You must be editing the workspace to perform this operation."); } ftClass = feature.Class; fields = ftClass.Fields; string missingFieldFormat = "Field {0} is missing."; ipidIdx = fields.FindField(ConfigUtil.IpidFieldName); if (-1 == ipidIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.IpidFieldName)); } bufferCountIdx = fields.FindField(ConfigUtil.NumberOfBuffersFieldName); if (-1 == bufferCountIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.NumberOfBuffersFieldName)); } strandCountIdx = fields.FindField(ConfigUtil.NumberOfFibersFieldName); if (-1 == strandCountIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.NumberOfFibersFieldName)); } #endregion ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = _hookHelper.CreateProgressDialog(trackCancel, "Preparing to configure cable...", 1, configuration.TotalFiberCount, 1, "Starting edit operation...", "Fiber Configuration"); ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; progressDialog.ShowDialog(); stepProgressor.Step(); if (!isExistingOperation) { _editor.StartOperation(); isOurOperationOpen = true; } try { if (DBNull.Value == feature.get_Value(ipidIdx)) { feature.set_Value(ipidIdx, fiberCableIpid); } else { fiberCableIpid = feature.get_Value(ipidIdx).ToString(); } feature.set_Value(bufferCountIdx, configuration.BufferCount); feature.set_Value(strandCountIdx, configuration.FibersPerTube); isComplete = GenerateUnits(feature, configuration, progressDialog, trackCancel); progressDialog.Description = "Completing configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { if (isComplete) { feature.Store(); _editor.StopOperation("Configure Fiber"); } else { _editor.AbortOperation(); } } } catch (Exception e) { if (isOurOperationOpen) { _editor.AbortOperation(); } } progressDialog.HideDialog(); return(isComplete); }
public void ExportSelectedRecordsToExcel() { ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null; ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = null; IMxDocument mxdoc = null; IMap map = null; IStandaloneTableCollection standTabColl = null; IStandaloneTable standTable = null; ITableSelection tableSel = null; IEnumFeature enumFeat = null; IFeature feat = null; IFeatureSelection featSel = null; ITable openTable = null; object missing = null; //object fileName = null; object newTemplate = null; object docType = null; object isVisible = null; UID geoFeatureLayerID = null; IEnumLayer enumLayer = null; IFeatureLayer featlayer = null; try { mxdoc = (IMxDocument)_app.Document; map = mxdoc.FocusMap; long standTableCnt; int i = 0; bool selectionInTable = false; missing = System.Reflection.Missing.Value; // fileName = "normal.dot"; newTemplate = false; docType = 0; isVisible = true; //Get enumeration of feature layers geoFeatureLayerID = new UIDClass(); geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; enumLayer = map.get_Layers(geoFeatureLayerID, true); enumLayer.Reset(); standTabColl = (IStandaloneTableCollection)map; standTableCnt = standTabColl.StandaloneTableCount; enumFeat = (IEnumFeature)map.FeatureSelection; enumFeat.Reset(); feat = enumFeat.Next(); if (standTableCnt > 0) { for (int j = 0; j < standTableCnt; j++) { standTable = standTabColl.get_StandaloneTable(j); if (standTable.Valid) { openTable = (ITable)standTable; tableSel = (ITableSelection)openTable; if (tableSel.SelectionSet.Count > 0) { selectionInTable = true; break; } } } } if ((selectionInTable == false) && (feat == null)) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("DataToolsMess_1") + Environment.NewLine + A4LGSharedFunctions.Localizer.GetString("DataToolsMess_2"), messageBoxHeader); return; } // Create a CancelTracker ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = _app.hWnd; progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; stepProgressor.MaxRange = mxdoc.FocusMap.SelectionCount; stepProgressor.StepValue = 1; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("ExportXL"); // Create the ProgressDialog. This automatically displays the dialog progressDialog = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog.CancelEnabled = true; progressDialog.Description = A4LGSharedFunctions.Localizer.GetString("ExportAsset") + "1" + A4LGSharedFunctions.Localizer.GetString("Of") + mxdoc.FocusMap.SelectionCount.ToString() + "."; progressDialog.Title = A4LGSharedFunctions.Localizer.GetString("ExportXL"); progressDialog.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe; progressDialog.ShowDialog(); if ((feat != null) && (selectionInTable == true)) { ExcelApp = new Excel.ApplicationClass(); //Delete default worksheets ExcelApp.DisplayAlerts = false; objBook = ExcelApp.Workbooks.Add(missing); //objBook = ExcelApp.Workbooks.get_Item(1); for (int m = objBook.Sheets.Count; m > 1; m--) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m); objSheet.Delete(); } featlayer = (IFeatureLayer)enumLayer.Next(); while (featlayer != null) { if ((featlayer.Valid) && (featlayer.Selectable)) { featSel = (IFeatureSelection)featlayer; if (featSel.SelectionSet.Count > 0) { ExportLayer(objBook, mxdoc, featlayer, ref progressDialog, ref stepProgressor); } } featlayer = (IFeatureLayer)enumLayer.Next(); } for (i = 0; i < standTableCnt; i++) { standTable = standTabColl.get_StandaloneTable(i); if (standTable.Valid) { openTable = (ITable)standTable; tableSel = (ITableSelection)openTable; if (tableSel.SelectionSet.Count > 0) { ExportTable(objBook, mxdoc, standTable, ref progressDialog, ref stepProgressor); } } } } else if ((feat != null) && (selectionInTable == false)) { ExcelApp = new Excel.ApplicationClass(); //Delete default worksheets ExcelApp.DisplayAlerts = false; objBook = ExcelApp.Workbooks.Add(missing); //objBook = ExcelApp.Workbooks.get_Item(1); for (int m = objBook.Sheets.Count; m > 1; m--) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m); objSheet.Delete(); } ILayer pTLay = enumLayer.Next(); while (pTLay != null) { if (pTLay is IFeatureLayer) { featlayer = (IFeatureLayer)pTLay; if ((featlayer.Valid) ) { featSel = (IFeatureSelection)featlayer; if (featSel.SelectionSet.Count > 0) { ExportLayer(objBook, mxdoc, featlayer, ref progressDialog, ref stepProgressor); } } } pTLay = enumLayer.Next(); } pTLay = null; } else if ((feat == null) && (selectionInTable == true)) { ExcelApp = new Excel.ApplicationClass(); //Delete default worksheets ExcelApp.DisplayAlerts = false; objBook = ExcelApp.Workbooks.Add(missing); //objBook = ExcelApp.Workbooks.get_Item(1); for (int m = objBook.Sheets.Count; m > 1; m--) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(m); objSheet.Delete(); } for (i = 0; i < standTableCnt; i++) { standTable = standTabColl.get_StandaloneTable(i); if (standTable.Valid) { openTable = (ITable)standTable; tableSel = (ITableSelection)openTable; if (tableSel.SelectionSet.Count > 0) { ExportTable(objBook, mxdoc, standTable, ref progressDialog, ref stepProgressor); } } } } if (objBook.Sheets.Count > 1) { objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(1); objSheet.Delete(); } //objSheet = (Excel.Worksheet)objBook.Sheets["Sheet2"]; //objSheet.Delete(); //objSheet = (Excel.Worksheet)objBook.Sheets["Sheet3"]; //objSheet.Delete(); ExcelApp.DisplayAlerts = true; //Make the first sheet active objSheet = (Excel.Worksheet)objBook.Sheets.get_Item(1) as Excel.Worksheet; (objSheet as Microsoft.Office.Interop.Excel._Worksheet).Activate(); //Make Excel visible ExcelApp.Visible = true; return; } catch (Exception ex) { if (ExcelApp != null) ExcelApp = null; //ExcelApp.Visible = true; MessageBox.Show("ExportSelectedRecordsToExcel\n" + ex.Message, ex.Source); return; } finally { if (progressDialog != null) progressDialog.HideDialog(); progressDialogFactory = null; stepProgressor = null; progressDialog = null; mxdoc = null; map = null; standTabColl = null; standTable = null; tableSel = null; enumFeat = null; feat = null; featSel = null; openTable = null; missing = null; //fileName = null; newTemplate = null; docType = null; isVisible = null; geoFeatureLayerID = null; enumLayer = null; featlayer = null; } }
/// <summary> /// Sets the input and output ports based on the given configuration. If IPID and/or CABLEID are null, it also /// takes care of them /// </summary> /// <param name="feature">The device feature to configure</param> /// <param name="inputPorts">Number of input ports</param> /// <param name="outputPorts">Number of output ports</param> /// <param name="isExistingOperation">Flag to control whether this method is being called from within an existing /// edit operation -- the default behavior is "false" in which case it adds an operation of its own</param> /// <returns>True if the configuration is complete</returns> public bool ConfigureDevice(ESRI.ArcGIS.Geodatabase.IFeature feature, int inputPorts, int outputPorts, bool isExistingOperation) { bool isComplete = false; bool isOurOperationOpen = false; string deviceIpid = string.Empty; #region Validation string missingFieldFormat = "Field {0} is missing."; // The following will be set during Validation ESRI.ArcGIS.Geodatabase.IObjectClass ftClass = null; ESRI.ArcGIS.Geodatabase.IFields fields = null; ftClass = feature.Class; fields = ftClass.Fields; if (null == feature) { throw new ArgumentNullException("feature"); } if (_editor.EditState == ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing) { throw new InvalidOperationException("You must be editing the workspace to perform this operation."); } if (0 > inputPorts) { throw new ArgumentOutOfRangeException("inputPorts"); } if (0 > outputPorts) { throw new ArgumentOutOfRangeException("outputPorts"); } int ipidIdx = fields.FindField(ConfigUtil.IpidFieldName); if (-1 == ipidIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.IpidFieldName)); } int inPortsIdx = fields.FindField(ConfigUtil.InputPortsFieldName); if (-1 == inPortsIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.InputPortsFieldName)); } int outPortsIdx = fields.FindField(ConfigUtil.OutputPortsFieldName); if (-1 == outPortsIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.OutputPortsFieldName)); } #endregion // Are we RE-configuring? // int? oldInputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.InputPortsFieldName); // int? oldOutputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.OutputPortsFieldName); // int inputPortDifference = oldInputPorts.HasValue ? Math.Abs(inputPorts - oldInputPorts.Value) : inputPorts; // int outputPortDifference = oldOutputPorts.HasValue ? Math.Abs(outputPorts - oldOutputPorts.Value) : outputPorts; ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = _hookHelper.CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPorts + outputPorts, 1, "Starting edit operation...", "Device Configuration"); // ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPortDifference + outputPortDifference + 2, 1, "Starting edit operation...", "Device Configuration"); ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; progressDialog.ShowDialog(); stepProgressor.Step(); if (!isExistingOperation) { try { _editor.StartOperation(); isOurOperationOpen = true; } catch (Exception ex) { throw new Exception("Failed to start edit operation.", ex); } } try { feature.set_Value(inPortsIdx, inputPorts); feature.set_Value(outPortsIdx, outputPorts); if (DBNull.Value == feature.get_Value(ipidIdx)) { Guid g = Guid.NewGuid(); deviceIpid = g.ToString("B").ToUpper(); feature.set_Value(ipidIdx, deviceIpid); } else { deviceIpid = feature.get_Value(ipidIdx).ToString(); } // if (!oldOutputPorts.HasValue && !oldInputPorts.HasValue) // { isComplete = GeneratePorts(feature, 1, inputPorts, 1, outputPorts, progressDialog, trackCancel); // } // else // { // bool additionsComplete = false; // bool deletionsComplete = false; // // additionsComplete = GeneratePorts(feature, oldInputPorts.Value + 1, oldInputPorts.Value + inputPortDifference, oldOutputPorts.Value + 1, oldOutputPorts.Value + outputPortDifference, progressDialog, trackCancel); // deletionsComplete = DeletePorts(feature, inputPorts, outputPorts, progressDialog, trackCancel); // // isComplete = additionsComplete && deletionsComplete; // } if (isComplete) { stepProgressor.Message = "Finishing configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { feature.Store(); _editor.StopOperation("Configure Device"); } } else { stepProgressor.Message = "Cancelling configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { _editor.AbortOperation(); } } } catch { if (isOurOperationOpen) { _editor.AbortOperation(); } } if (null != progressDialog) { progressDialog.HideDialog(); } return(isComplete); }
/// <summary> /// Sets the input and output ports based on the given configuration. If IPID and/or CABLEID are null, it also /// takes care of them /// </summary> /// <param name="feature">The device feature to configure</param> /// <param name="inputPorts">Number of input ports</param> /// <param name="outputPorts">Number of output ports</param> /// <param name="isExistingOperation">Flag to control whether this method is being called from within an existing /// edit operation -- the default behavior is "false" in which case it adds an operation of its own</param> /// <returns>True if the configuration is complete</returns> public bool ConfigureDevice(ESRI.ArcGIS.Geodatabase.IFeature feature, int inputPorts, int outputPorts, bool isExistingOperation) { bool isComplete = false; bool isOurOperationOpen = false; string deviceIpid = string.Empty; #region Validation string missingFieldFormat = "Field {0} is missing."; // The following will be set during Validation ESRI.ArcGIS.Geodatabase.IObjectClass ftClass = null; ESRI.ArcGIS.Geodatabase.IFields fields = null; ftClass = feature.Class; fields = ftClass.Fields; if (null == feature) { throw new ArgumentNullException("feature"); } if (_editor.EditState == ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing) { throw new InvalidOperationException("You must be editing the workspace to perform this operation."); } if (0 > inputPorts) { throw new ArgumentOutOfRangeException("inputPorts"); } if (0 > outputPorts) { throw new ArgumentOutOfRangeException("outputPorts"); } int ipidIdx = fields.FindField(ConfigUtil.IpidFieldName); if (-1 == ipidIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.IpidFieldName)); } int inPortsIdx = fields.FindField(ConfigUtil.InputPortsFieldName); if (-1 == inPortsIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.InputPortsFieldName)); } int outPortsIdx = fields.FindField(ConfigUtil.OutputPortsFieldName); if (-1 == outPortsIdx) { throw new InvalidOperationException(string.Format(missingFieldFormat, ConfigUtil.OutputPortsFieldName)); } #endregion // Are we RE-configuring? // int? oldInputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.InputPortsFieldName); // int? oldOutputPorts = GdbUtils.GetDomainedIntName(feature, ConfigUtil.OutputPortsFieldName); // int inputPortDifference = oldInputPorts.HasValue ? Math.Abs(inputPorts - oldInputPorts.Value) : inputPorts; // int outputPortDifference = oldOutputPorts.HasValue ? Math.Abs(outputPorts - oldOutputPorts.Value) : outputPorts; ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = _hookHelper.CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPorts + outputPorts, 1, "Starting edit operation...", "Device Configuration"); // ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog = CreateProgressDialog(trackCancel, "Configuring device...", 1, inputPortDifference + outputPortDifference + 2, 1, "Starting edit operation...", "Device Configuration"); ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = (ESRI.ArcGIS.esriSystem.IStepProgressor)progressDialog; progressDialog.ShowDialog(); stepProgressor.Step(); if (!isExistingOperation) { try { _editor.StartOperation(); isOurOperationOpen = true; } catch (Exception ex) { throw new Exception("Failed to start edit operation.", ex); } } try { feature.set_Value(inPortsIdx, inputPorts); feature.set_Value(outPortsIdx, outputPorts); if (DBNull.Value == feature.get_Value(ipidIdx)) { Guid g = Guid.NewGuid(); deviceIpid = g.ToString("B").ToUpper(); feature.set_Value(ipidIdx, deviceIpid); } else { deviceIpid = feature.get_Value(ipidIdx).ToString(); } // if (!oldOutputPorts.HasValue && !oldInputPorts.HasValue) // { isComplete = GeneratePorts(feature, 1, inputPorts, 1, outputPorts, progressDialog, trackCancel); // } // else // { // bool additionsComplete = false; // bool deletionsComplete = false; // // additionsComplete = GeneratePorts(feature, oldInputPorts.Value + 1, oldInputPorts.Value + inputPortDifference, oldOutputPorts.Value + 1, oldOutputPorts.Value + outputPortDifference, progressDialog, trackCancel); // deletionsComplete = DeletePorts(feature, inputPorts, outputPorts, progressDialog, trackCancel); // // isComplete = additionsComplete && deletionsComplete; // } if (isComplete) { stepProgressor.Message = "Finishing configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { feature.Store(); _editor.StopOperation("Configure Device"); } } else { stepProgressor.Message = "Cancelling configuration..."; stepProgressor.Step(); if (isOurOperationOpen) { _editor.AbortOperation(); } } } catch { if (isOurOperationOpen) { _editor.AbortOperation(); } } if (null != progressDialog) { progressDialog.HideDialog(); } return isComplete; }