示例#1
0
        public static void init()
        {
            //connects to DB
            if (Editor.sqlConnection != null)
            {
                string selectString = "SELECT [ClassHash],[PropertyHash],[Description],[Editor] FROM ClassPropertyDescription";

                try
                {
                    SqlCommand    myCommand = new SqlCommand(selectString, Editor.sqlConnection);
                    SqlDataReader myReader  = myCommand.ExecuteReader();

                    while (myReader.Read())
                    {
                        GodzClassProperty cp = new GodzClassProperty();

                        Int64 tempclass = (Int64)myReader["ClassHash"];
                        uint  classhash = (uint)tempclass;

                        if (mClassMap[classhash] == null)
                        {
                            GodzClassInfo gclass = new GodzClassInfo();
                            mClassMap[classhash] = gclass;
                        }

                        Int64 temp = (Int64)myReader["PropertyHash"];
                        cp.property    = (uint)temp;
                        cp.Description = (String)myReader["Description"];
                        object type = myReader["Editor"];

                        if (type != null)
                        {
                            cp.Type = (GodzClassPropertyType)type;
                        }
                        else
                        {
                            cp.Type = GodzClassPropertyType.Default;
                        }

                        GodzClassInfo godzClass = (GodzClassInfo)mClassMap[classhash];
                        godzClass.cpList.Add(cp);
                    }

                    myReader.Close();
                }
                catch (System.Data.SqlClient.SqlException exception)
                {
                    Console.WriteLine(exception.ToString());
                }
            }
        }
        private void propertyListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (propertyListBox1.SelectedItem != null)
            {
                uint hash = props[propertyListBox1.SelectedIndex].mPropertyNameHash;

                foreach (GodzClassProperty cp in dbProperties)
                {
                    if (cp.property == hash)
                    {
                        propertyGrid1.SelectedObject = cp;
                        return;
                    }
                }

                //we never found an entry, so create one....
                GodzClassProperty newProperty = new GodzClassProperty();
                newProperty.property         = hash;
                newProperty.Type             = GodzClassPropertyType.Default;
                propertyGrid1.SelectedObject = newProperty;
                dbProperties.Add(newProperty);

                //update the class definition in memory as well....
                classInfo.cpList.Add(newProperty);

                //INSERT INTO ClassPropertyDescription Table....
                if (Editor.sqlConnection != null)
                {
                    try
                    {
                        String     value         = "Values (" + activeClass.getObjectName() + "," + hash + ",'" + newProperty.Description + "'," + (int)newProperty.Type + ")";
                        SqlCommand insertCommand = new SqlCommand("INSERT INTO ClassPropertyDescription (ClassHash, PropertyHash, Description, Editor) " + value, Editor.sqlConnection);
                        insertCommand.ExecuteNonQuery();
                    }
                    catch (SqlException sqlerror)
                    {
                        Console.WriteLine(sqlerror.ToString());
                    }
                }
            }
        }