Пример #1
0
        private static void UpdateCodedValueDomain(IWorkspace theWorkspace, string DomainName, string SourceClassName, string CodeFieldName, string ValueFieldName)
        {
            // Get reference to the table to read codes and values from
            ITable theTable = commonFunctions.OpenTable(theWorkspace, SourceClassName);

            // Get reference to the domain itself
            IWorkspaceDomains wsDomains = (IWorkspaceDomains)theWorkspace;
            ICodedValueDomain theDomain = (ICodedValueDomain)wsDomains.get_DomainByName(DomainName);

            // Requires exclusive schema lock
            ISchemaLock schemaLock = (ISchemaLock)theDomain;

            try
            {
                // Get an exclusive lock
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock);

                // Clear everything out of the domain first
                int codedValues = theDomain.CodeCount;
                for (int i = 0; i <= codedValues - 1; i++)
                {
                    theDomain.DeleteCode(theDomain.Value[0]);
                }

                // Sort the table
                ITableSort tableSorter = new TableSortClass();
                tableSorter.Fields = ValueFieldName;
                tableSorter.set_Ascending(ValueFieldName, true);
                tableSorter.Table = theTable;
                tableSorter.Sort(null);

                // Loop through the sorted rows, add to the domain
                int codeFld  = theTable.FindField(CodeFieldName);
                int valueFld = theTable.FindField(ValueFieldName);

                ICursor theCursor = tableSorter.Rows;
                IRow    theRow    = theCursor.NextRow();

                while (theRow != null)
                {
                    theDomain.AddCode(theRow.get_Value(codeFld), theRow.get_Value(valueFld).ToString());
                    theRow = theCursor.NextRow();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(DomainName + " was not updated. This is likely because an exclusive schema lock could not be obtained.", "NCGMP Tools");
            }
            finally
            {
                // Release the exclusive lock, if it was acquired.
                //  This block of code (finally) is called whether or not there is a problem
                schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            // s = ArcZona.AZUtil.ParseGeoDBName(@"sde:sqlserver:DPU-PBU-GIS77\sqlexpress");
            // s = ArcZona.AZUtil.ParseGeoDBName("sde:oracle10g:/:dpu_admin");
            // s = ArcZona.AZUtil.ParseGeoDBName("5151:dpu_admin");

            /* Sample Command Line Params:
             *  -n  ssDomainOwner -v -g "\OWNEDBY_Example.gdb"
             *
             * */
            try
            {
                ESRILicenseProductCode = esriLicenseProductCode.esriLicenseProductCodeArcView;
                ArgParser = new CommandLine.Utility.CommandArguments(System.Environment.GetCommandLineArgs());

                // display the usage when
                if (System.Environment.CommandLine.IndexOf("-h", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0 |
                    System.Environment.CommandLine.IndexOf("--help", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0 |
                    System.Environment.CommandLine.IndexOf("/?", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0 |
                    System.Environment.CommandLine.IndexOf("-help", 0, System.StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    Usage();
                    return;
                }

                if (ValidateArgs() == true)
                {
                    ESRILicenseInitializer = new GeoprocessingInDotNet.LicenseInitializer();

                    ConsoleWriteLine("Arguments Validated!!");
                    ConsoleWriteLine("Initializing ArcObjects License...");

                    ESRILicenseInitializer.InitializeApplication(ESRILicenseProductCode);

                    if (ESRILicenseInitializer.InitializedProduct > 0)
                    {
                        ConsoleWriteLine("License Initialized.");

                        IWorkspace         ws = UmbrielArcGISHelper.GetWorkspace(ArgParser);
                        IWorkspaceDomains2 workspaceDomains = (IWorkspaceDomains2)ws;


                        IDomain           domain      = workspaceDomains.get_DomainByName(DomainName);
                        ICodedValueDomain codedDomain = (ICodedValueDomain)domain;


                        Stack <string> domainValues = new Stack <string>();

                        for (int i = codedDomain.CodeCount - 1; i >= 0; i--)
                        {
                            codedDomain.DeleteCode(codedDomain.get_Value(i));
                        }

                        workspaceDomains.AlterDomain(domain);
                    }
                    else
                    {
                        Console.WriteLine("\a");
                        Console.WriteLine("Could not initialize ESRI License.");
                    }

                    // Do not make any call to ArcObjects after ShutDownApplication()
                    ConsoleWriteLine("Releasing ArcObjects License...");
                    ESRILicenseInitializer.ShutdownApplication();
                    ConsoleWriteLine("ArcObjects License Released.");
                }
                else
                {
                    Usage();
                    return;
                }
            }
            catch (Exception ex)
            {
                // beep!
                Console.WriteLine("\a");
                Console.WriteLine("An error has occurred: \n\n");
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                // try to shut down the ESRI license
                if (ESRILicenseInitializer != null)
                {
                    if (ESRILicenseInitializer.InitializedProduct > 0)
                    {
                        ESRILicenseInitializer.ShutdownApplication();
                    }
                }
            }



            /* SDEMeta sleeps for 2000 milliseconds by default,
             * so that when called from a batch, the license manager has a chance to return
             * the license to the pool before the next SDEMeta attempts to check it out.
             */
            if (!ArgParser.Contains("-nosleep"))
            {
                string sleep = ArgParser.GetValue("sleep");

                try
                {
                    int sleepDuration = 2000;
                    if (!String.IsNullOrEmpty(sleep))
                    {
                        sleepDuration = Convert.ToInt32(sleep);
                    }

                    System.Threading.Thread.Sleep(sleepDuration);
                }
                catch
                {
                }
            }
        }
Пример #3
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            IDomain           domain = null;
            IRangeDomain      rd     = null;
            ICodedValueDomain cv     = null;
            IDomainFactory    df     = new DomainFactory();
            DataTable         table  = null;

            try
            {
                //保存时,删除操作才生效
                foreach (string s in deletedomains)
                {
                    ds.DeleteDomain(s);
                }
                for (int i = 0; i < this.dgv_DomainAttr.Rows.Count; i++)
                {
                    DataGridViewRow myRow       = this.dgv_DomainAttr.Rows[i];
                    string          name        = myRow.Cells["name"].Value == null ? "" : myRow.Cells["name"].Value.ToString();
                    string          description = myRow.Cells["description"].Value == null ? "" : myRow.Cells["description"].Value.ToString();
                    string          ft          = myRow.Cells["fieldtype"].Value == null ? "" : myRow.Cells["fieldtype"].Value.ToString();
                    string          dt          = myRow.Cells["domaintype"].Value == null ? "" : myRow.Cells["domaintype"].Value.ToString();
                    if (name.Equals(""))
                    {
                        continue;                         //名称为空,不创建
                    }
                    if (myRow.Tag == null)
                    {
                        continue;
                    }
                    if (ft.Equals("String") && dt.Equals("值域型"))
                    {
                        continue;
                    }
                    table = myRow.Tag as DataTable;
                    if (!HasDomain(name, ds))
                    {
                        if (dt == "值域型")
                        {
                            rd             = df.CreateRangeDomain(name, GetFDEFieldTypeByString(ft));
                            rd.Description = description;
                            rd.MinValue    = table.Rows[0].IsNull(sMinFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMinFieldName];
                            rd.MaxValue    = table.Rows[0].IsNull(sMaxFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMaxFieldName];

                            ds.AddDomain(rd);
                        }
                        else if (dt == "枚举型")
                        {
                            cv             = df.CreateCodedValueDomain(name, GetFDEFieldTypeByString(ft));
                            cv.Description = description;
                            for (int j = 0; j < table.Rows.Count; j++)
                            {
                                if (table.Rows[j][sDscribFieldName].ToString() != "")
                                {
                                    if (table.Rows[j].IsNull(sEmunFieldName))
                                    {
                                        continue;
                                    }
                                    cv.AddCode(table.Rows[j][sEmunFieldName], table.Rows[j][sDscribFieldName].ToString());
                                }
                            }
                            ds.AddDomain(cv);
                        }
                    }
                    else
                    {
                        domain = ds.GetDomainByName(name);
                        if (dt == "值域型")
                        {
                            rd             = domain as IRangeDomain;
                            rd.Description = description;
                            rd.MaxValue    = table.Rows[0].IsNull(sMaxFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMaxFieldName];
                            rd.MinValue    = table.Rows[0].IsNull(sMinFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMinFieldName];
                            ds.ModifyDomain(rd);
                        }
                        else
                        {
                            cv             = domain as ICodedValueDomain;
                            cv.Description = description;
                            int codecount = cv.CodeCount;
                            for (int a = 0; a < codecount; a++)
                            {
                                cv.DeleteCode(cv.GetCodeValue(0));
                            }
                            for (int l = 0; l < table.Rows.Count; l++)
                            {
                                if (table.Rows[l][sDscribFieldName].ToString() != "")
                                {
                                    if (table.Rows[l].IsNull(sEmunFieldName))
                                    {
                                        continue;
                                    }
                                    cv.AddCode(table.Rows[l][sEmunFieldName], table.Rows[l][sDscribFieldName].ToString());
                                }
                            }
                            ds.ModifyDomain(cv);
                        }
                    }
                }
                MessageBox.Show("保存成功!");
            }
            catch (COMException comEx)
            {
                MessageBox.Show(comEx.Message);
                this.DialogResult = DialogResult.None;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = DialogResult.None;
            }
            finally
            {
                if (cv != null)
                {
                    //Marshal.ReleaseComObject(cv);
                    cv = null;
                }
                if (rd != null)
                {
                    //Marshal.ReleaseComObject(rd);
                    rd = null;
                }
                if (domain != null)
                {
                    //Marshal.ReleaseComObject(domain);
                    domain = null;
                }
            }
        }