Пример #1
0
        public TableCtl clone()
        {
            TableCtl tb = new TableCtl();
            List <List <string> > newData = new List <List <string> >();

            for (int i = 0; i < data.Count; ++i)
            {
                newData.Add(new List <string>(data[i].ToArray()));
            }
            tb.setData(newData);

            return(tb);
        }
Пример #2
0
        public void combine(TableCtl tb, string[] pkey, bool isCover = true, bool isCoverOnly = false)
        {
            if (data.Count == 0)
            {
                setData(tb.clone().data);
                //updateCol();
            }

            if (pkey.Length == 0)
            {
                for (int i = 1; i < tb.data.Count; ++i)
                {
                    data.Add(new List <string>(tb.data[i].ToArray()));
                }
                return;
            }

            //get pkey head
            List <int>            pHead   = headToCol(new List <string>(pkey));
            Dictionary <int, int> mapHead = new Dictionary <int, int>();

            for (int i = 0; i < pHead.Count; ++i)
            {
                mapHead[pHead[i]] = 0;
            }

            //create index
            Dictionary <string, int> pkeyIndex = new Dictionary <string, int>();

            for (int i = 1; i < data.Count; ++i)
            {
                string name = "";
                for (int j = 0; j < pHead.Count; ++j)
                {
                    name += data[i][pHead[j]];
                }
                pkeyIndex[name] = i;
            }

            //
            for (int i = 1; i < tb.data.Count; ++i)
            {
                string name = "";
                for (int j = 0; j < pHead.Count; ++j)
                {
                    name += tb.data[i][pHead[j]];
                }

                //pkey相同
                if (pkeyIndex.ContainsKey(name))
                {
                    if (isCover)
                    {
                        //覆盖
                        int idx = pkeyIndex[name];
                        for (int j = 0; j < data[idx].Count; ++j)
                        {
                            data[idx][j] = tb.data[i][j];
                        }
                    }
                    continue;
                }
                else
                {
                    if (isCoverOnly)
                    {
                        continue;
                    }
                }

                data.Add(new List <string>(tb.data[i]));
            }
        }