示例#1
0
        public object[] UpdateOrAdd(object[] items, bool convertToDynamic = true)
        {
            if (items == null || items.Length == 0)
            {
                return(null);
            }
            string dbName = items[0].GetType().Name;

            DataFile db = GetDF(dbName);

            if (db != null && db.Opened)
            {
                return(db.AddItems(items, convertToDynamic));
            }
            return(null);
        }
示例#2
0
        public void Start()
        {
            //new Thread(() =>
            //{
            string   dbUSER = typeof(USER).Name;
            DataFile dfUSER = null;

            string[] fs = Directory.GetFiles(m_PathData, "*.df");
            if (fs.Length > 0)
            {
                for (int k = 0; k < fs.Length; k++)
                {
                    DataFile df = new DataFile(fs[k]);
                    if (df.Opened)
                    {
                        if (df.Model.Name == dbUSER)
                        {
                            dfUSER = df;
                        }

                        string name = df.Model.Name;
                        if (m_dataFile.TryAdd(name, df))
                        {
                            m_listDataName.Add(name);
                        }
                    }
                }
            }

            if (dfUSER == null)
            {
                dfUSER = DataFile.Open(typeof(USER));
                if (dfUSER.Opened)
                {
                    if (m_dataFile.TryAdd(dbUSER, dfUSER))
                    {
                        m_listDataName.Add(dbUSER);
                    }
                }
            }

            if (dfUSER != null && dfUSER.Count == 0)
            {
                var ra = dfUSER.AddItems(new USER[] {
                    new USER()
                    {
                        FULLNAME = "Admin", PASSWORD = "******", USERNAME = "******"
                    },
                    new USER()
                    {
                        FULLNAME = "user", PASSWORD = "******", USERNAME = "******"
                    },
                    //new USER() { FULLNAME = "free", PASSWORD = "******", USERNAME = "******" },
                });
                //var ra2 = dfUSER.AddItems(new USER[] { new USER() { FULLNAME = "user", PASSWORD = "******", USERNAME = "******" }, });
                if (ra[0] != EditStatus.SUCCESS)
                {
                    if (OnOpen != null)
                    {
                        OnOpen(m_listDataName.ToArray());
                    }
                    return;
                }
            }

            Open = true;
            if (OnOpen != null)
            {
                OnOpen(m_listDataName.ToArray());
            }
            //}).Start();
        }