/// <summary>
        /// Creates a new error message and adds it to the collection.
        /// </summary>
        /// <param name="self">The collection to add the message to.</param>
        /// <param name="message">The human readable error message as text for string formatting.</param>
        /// <param name="parms">Paramters for formatting the message text.</param>
        /// <returns>Returns the error message object that was created.</returns>
        public static ErrorMessage CreateMessage(this IDataCollection <ErrorMessage> self, string message, params object[] parms)
        {
            ErrorMessage msg = new ErrorMessage(string.Format(message, parms));

            self.Add(msg);
            return(msg);
        }
        /// <summary>
        /// Creates a new error message and adds it to the collection.
        /// </summary>
        /// <param name="self">The collection to add the message to.</param>
        /// <param name="message">The human readable error message.</param>
        /// <returns>Returns the error message object that was created.</returns>
        public static ErrorMessage CreateMessage(this IDataCollection <ErrorMessage> self, string message)
        {
            ErrorMessage msg = new ErrorMessage(message);

            self.Add(msg);
            return(msg);
        }
        private void ComboBoxAddClick(object sender, EventArgs e)
        {
            ButtonSpecAny   item  = (ButtonSpecAny)sender;
            KryptonComboBox combo = (KryptonComboBox)item.Owner;
            Field           field = (Field)combo.Tag;
            ObjectClass     c     = ReferenceProperty.Get(field).Reference;
            ObjectData      d     = collection.Add(c, false);

            if (d != null)
            {
                combo.Items.Add(d);
                combo.SelectedItem = d;
                this.AddDataItem(field, d);
            }
        }
Example #4
0
        private void SaveAction(object obj)
        {
            var item = this;

            if (status == ChangeStatus.New)
            {
                var id = handphoneCollection.Add(item);
                if (id > 0)
                {
                    item.Id = id;
                    MessageBox.Show("Data Berhasil Disimpan");
                    item.ProducentName = ProducentSelected.Name;


                    this.source.Add(item);
                    this.sourceView.Refresh();
                    this.WindowClose();
                }
                else
                {
                    MessageBox.Show("Data Gagal Disimpan");
                }
            }
            else
            {
                var isUpdated = handphoneCollection.Update(item);
                if (isUpdated)
                {
                    MessageBox.Show("Data Berhasil Disimpan");
                    item.ProducentName = ProducentSelected.Name;
                    this.sourceView.Refresh();
                    this.WindowClose();
                }
                else
                {
                    MessageBox.Show("Data Gagal Disimpan");
                }
            }
        }
Example #5
0
        internal static void ToAsset(string savePath, Dictionary <int, List <Cell> > dic, string tableName = null)
        {
            string           className = tableName ?? new FileInfo(savePath).Name.Replace(".asset", "");
            ScriptableObject table     = EditorUtils.CreateAsset <ScriptableObject>(className, savePath.Replace(EditorUtils.DataPath, ""));

            IDataCollection db = table as IDataCollection;

            if (db == null)
            {
                return;
            }
            db.Clear();
            var type = EditorUtils.GetType(tableName.Replace("Table", "Info"));

            foreach (var pair in dic)
            {
                var classInstance = type.Assembly.CreateInstance(type.FullName);
                foreach (var cell in pair.Value)
                {
                    var fileInfo = type.GetField(cell.name);
                    if (fileInfo == null)
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(cell.value))
                    {
                        continue;
                    }
                    fileInfo.SetValue(classInstance, cell.value, fileInfo.FieldType);
                }
                db.Add(classInstance);
            }

            EditorUtility.SetDirty(table);
            AssetDatabase.SaveAssets();
        }
Example #6
0
    void TableParseMethod(TableProcessInfo _tableInfo)
    {
        ScriptableObject table
            = EditorHelper.CreateNewEditorProfile <ScriptableObject>(_tableInfo.ouput_asset_name,
                                                                     assetOutputPath,
                                                                     _tableInfo.table_class_name);

        if (table == null)
        {
            Debug.LogError("create table " + _tableInfo.table_class_name + " failed! output path : " + assetOutputPath + ", table class name : " + _tableInfo.table_class_name);
            return;
        }

        foreach (Dictionary <string, string> row in excelData.Values)
        {
            int index = 0;

            Type          t = asm.GetType(_tableInfo.data_class_name);
            System.Object c = Activator.CreateInstance(t);
            foreach (string title in row.Keys)
            {
                int len = title.Length - 1;
                while (title[len] >= '0' && title[len] <= '9')
                {
                    --len;
                }
                string name = title.Substring(0, len + 1);

                FieldInfo mInfo = t.GetField(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                if (mInfo != null)
                {
                    object param = EditorHelper.GetTableValue(type[index], row[title]);
                    if (param != null)
                    {
                        if (name.Length == title.Length)
                        {
                            t.InvokeMember(mInfo.Name, BindingFlags.SetField | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, c, new object[] { param });
                        }
                        else
                        {
                            SetValue(type[index], mInfo, c, param);
                        }
                    }
                }
                else
                {
                    PropertyInfo pInfo = t.GetProperty(name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                    if (pInfo != null)
                    {
                        object param = EditorHelper.GetTableValue(type[index], row[title]);
                        if (param != null)
                        {
                            t.InvokeMember(pInfo.Name, BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.Public, null, c, new object[] { param });
                        }
                    }
                    else
                    {
                        Debug.LogError("cannot find field " + header[index]);
                    }
                }

                index++;
            }

            IDataCollection lst = table as IDataCollection;
            if (lst != null)
            {
                lst.Add(c);
            }
            else
            {
                Debug.LogError(table.GetType() + " " + "isn't implemente IDataList interface!");
            }
        }
        EditorUtility.SetDirty(table);
        AssetDatabase.SaveAssets();
    }
 public static bool Add(IMonitoredCity city)
 {
     return(_cities.Add(city));
 }