Beispiel #1
0
        //合并(测试)
        public string merge2()
        {
            List <CataItem> list     = new List <CataItem>();
            List <int>      parentid = new List <int>();

            using (var cmd = m_liteDB.CreateCommand())
            {
                cmd.CommandText = "SELECT id,name,parent FROM catalog where identifying =0";
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        //组装字典
                        CataItem item = new CataItem();
                        item.Id   = reader.GetInt32(0);
                        item.Name = reader.GetString(1);
                        parentid.Add(reader.GetInt32(2));
                        list.Add(item);
                    }
                }
            }

            //打开下载的文件
            LiteDB NewliteDB = new LiteDB(m_folder);

            NewliteDB.Open(0);
            using (var newcmd = NewliteDB.CreateCommand())
            {
                for (int j = 0; j < parentid.Count; j++)
                {
                    newcmd.CommandText = string.Format("SELECT id,name,parent FROM catalog where id='{0}'", parentid[j]);
                    using (var reader = newcmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            using (var addcom = NewliteDB.CreateCommand())
                            {
                                addcom.CommandText = string.Format("insert into catalog(id,name,parent,audit) values('{0}','{1}','{2}','{3}')", list[j].Id, list[j].Name, parentid[j], 1);
                                addcom.ExecuteScalar();
                            }
                        }
                        else
                        {
                            using (var cmd = m_liteDB.CreateCommand())
                            {
                                cmd.CommandText = string.Format("SELECT id,name,parent FROM catalog where id='{0}'", parentid[j]);
                                using (var readerparent = cmd.ExecuteReader())
                                {
                                    while (readerparent.Read())
                                    {
                                        using (var addcom = NewliteDB.CreateCommand())
                                        {
                                            addcom.CommandText = string.Format("insert into catalog(id,name,parent) values('{0}','{1}','{2}')", readerparent.GetInt32(0), readerparent.GetString(1), readerparent.GetInt32(2));
                                            addcom.ExecuteScalar();
                                        }
                                    }
                                }

                                using (var addcom = NewliteDB.CreateCommand())
                                {
                                    addcom.CommandText = string.Format("insert into catalog(id,name,parent,audit) values('{0}','{1}','{2}','{3}')", list[j].Id, list[j].Name, parentid[j], 1);
                                    addcom.ExecuteScalar();
                                }
                            }
                        }
                    }
                }
            }
            NewliteDB.Close();
            Updatetreeview();
            return("a");
        }
Beispiel #2
0
        //合并(测试)
        public void merge()
        {
            List <int>      parentid = new List <int>();
            List <CataItem> list     = new List <CataItem>();

            using (var cmd = m_liteDB.CreateCommand())
            {
                //查询所有修改过后的结点
                cmd.CommandText = "SELECT id,newname,parent FROM catalog where identifying =2";
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        //组装字典
                        CataItem item = new CataItem();
                        int      a    = reader.GetInt32(0);
                        string   ab   = reader.GetString(1);
                        item.Id   = reader.GetInt32(0);
                        item.Name = reader.GetString(1);
                        parentid.Add(reader.GetInt32(2));
                        list.Add(item);
                    }
                }
            }

            LiteDB NewliteDB = new LiteDB(m_folder);

            NewliteDB.Open(0);

            using (var newcmd = NewliteDB.CreateCommand())
            {
                for (int j = 0; j < list.Count; j++)
                {
                    newcmd.CommandText = string.Format("SELECT id,name,parent FROM catalog where id='{0}'", parentid[j]);
                    using (var updatereader = newcmd.ExecuteReader())
                    {
                        if (updatereader.Read())
                        {
                            using (var updatecom = NewliteDB.CreateCommand())
                            {
                                updatecom.CommandText = string.Format("UPDATE catalog set name='{0}',audit='{1}' where id={2}", list[j].Name, 1, list[j].Id);
                                updatecom.ExecuteScalar();
                            }
                        }
                        else
                        {
                            using (var cmd = m_liteDB.CreateCommand())
                            {
                                cmd.CommandText = string.Format("SELECT id,name,parent FROM catalog where id='{0}'", parentid[j]);
                                using (var readerparent = cmd.ExecuteReader())
                                {
                                    while (readerparent.Read())
                                    {
                                        using (var addcom = NewliteDB.CreateCommand())
                                        {
                                            addcom.CommandText = string.Format("insert into catalog(id,name,parent) values('{0}','{1}','{2}')", readerparent.GetInt32(0), readerparent.GetString(1), readerparent.GetInt32(2));
                                            addcom.ExecuteScalar();
                                        }
                                    }
                                }

                                using (var updatecom = NewliteDB.CreateCommand())
                                {
                                    updatecom.CommandText = string.Format("UPDATE catalog set name='{0}',audit='{1}' where id={2}", list[j].Name, 1, list[j].Id);
                                    updatecom.ExecuteScalar();
                                }
                            }
                        }
                    }
                }
            }
            NewliteDB.Close();
        }