Exemplo n.º 1
0
        void SaveRelationData()
        {
            m_sqlite = new MtSQLite(m_sqliteFilePath);

            string[]        _columnName      = m_columnName.Split(';');
            List <string[]> listColumnValues = new List <string[]>();

            foreach (var _switch in m_switchLightRelationDic)
            {
                foreach (var ctrlObj in _switch.Value)
                {
                    string switchCode  = "'" + _switch.Key + "'";
                    string ctrlObjCode = "'" + ctrlObj.Key + "'";
                    string typeCode    = "'" + ctrlObj.Value + "'";
                    listColumnValues.Add(new string[] { switchCode, ctrlObjCode, typeCode });
                }
            }
            m_sqlite.InsertIntoList(m_tableName, _columnName, listColumnValues);
        }
        public void DumpIntoDB2(string path, string systemName, string subSystem, string tunnelName,
                                string tableName, string columnName, bool isPositiveDir, bool isWaterReturnPipe)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            m_sqlite = new MtSQLite(path);

            string[] _columnKey = columnName.Split(';');

            List <string[]> listColumnValues = new List <string[]>();

            foreach (var Node in m_allTreeNodeList)
            {
                string info = Node.Info;

                string[] _columnValue = new string[_columnKey.Length];
                _columnValue[0] = ResetPipeId(Node, systemName, Node.Id.ToString());   //ID
                                                                                       //if (string.IsNullOrEmpty(tunnelName))
                                                                                       //    _columnValue[3] = "'" + "Default" + "'"; //TUNNEL 默认为Default
                                                                                       //else
                _columnValue[3] = "'" + GetTunnelName(tunnelName) + "'";

                _columnValue[5]  = Node.IsValve.ToString();                               //IsValve : 0 :非Valve  1: 是Valve
                _columnValue[6]  = "'" + subSystem + "'";                                 //SUBSYSTEM : 通过下拉框选择
                _columnValue[7]  = "'" + GetSubsystemCode(subSystem) + "'";               //subsystemCode
                _columnValue[8]  = "'" + (IsEncodeDevice(info) ? 1 : 0).ToString() + "'"; //设备是否有编码
                _columnValue[9]  = "'" + "0" + "'";                                       //是否是末端管道
                _columnValue[10] = ResetPipeId(m_startingElementNode, systemName, m_startingElementNode.Id.ToString());

                if (isPositiveDir)
                {
                    _columnValue[4] = "1"; //DIRECTION 1:正向 0:逆向

                    if (Node.Parent == null)
                    {
                        _columnValue[1] = "'" + string.Empty + "'";

                        foreach (var child in Node.ChildNodes)
                        {
                            //引用问题,所以用了临时变量
                            string[] tempColumnValue = CopyData(_columnValue);
                            tempColumnValue[2] = ResetPipeId(child, systemName, child.Id.ToString()); //DOWNSTREAM
                            listColumnValues.Add(tempColumnValue);
                        }
                    }
                    else
                    {
                        _columnValue[1] = ResetPipeId(Node.Parent, systemName, Node.Parent.Id.ToString());  //UPSTREAM
                        if (Node.ChildNodes != null && Node.ChildNodes.Count != 0)
                        {
                            foreach (var child in Node.ChildNodes)
                            {
                                string[] tempColumnValue = CopyData(_columnValue);
                                tempColumnValue[2] = ResetPipeId(child, systemName, child.Id.ToString()); //DOWNSTREAM
                                listColumnValues.Add(tempColumnValue);
                            }
                        }
                        else
                        {
                            _columnValue[2] = "'" + string.Empty + "'";
                            _columnValue[9] = "'" + "1" + "'";  //是否是末端管道 1:是 0:不是
                            listColumnValues.Add(_columnValue); //加入没有下游的记录
                        }
                    }
                }
                else
                {
                    _columnValue[4] = "0"; //DIRECTION 1:正向 0:逆向

                    if (Node.Parent == null)
                    {
                        _columnValue[2] = "'" + string.Empty + "'";

                        foreach (var child in Node.ChildNodes)
                        {
                            string[] tempColumnValue = CopyData(_columnValue);
                            tempColumnValue[1] = ResetPipeId(child, systemName, child.Id.ToString()); //加入逆向的初始管道
                            listColumnValues.Add(tempColumnValue);
                        }
                    }
                    else
                    {
                        _columnValue[2] = ResetPipeId(Node.Parent, systemName, Node.Parent.Id.ToString());  //DOWNSTREAM

                        if (Node.ChildNodes != null && Node.ChildNodes.Count != 0)
                        {
                            foreach (var child in Node.ChildNodes)
                            {
                                string[] tempColumnValue = CopyData(_columnValue);
                                tempColumnValue[1] = ResetPipeId(child, systemName, child.Id.ToString()); //UPSTREAM
                                listColumnValues.Add(tempColumnValue);
                            }
                        }
                        else
                        {
                            if (!isWaterReturnPipe) //回水的末端不加入数据库中,因为供水的管道已经写入
                            {
                                _columnValue[1] = "'" + string.Empty + "'";
                                _columnValue[9] = "'" + "1" + "'";
                                listColumnValues.Add(_columnValue);  //加入没有上游的记录
                            }
                        }
                    }
                }
            }
            m_sqlite.InsertIntoList(tableName, _columnKey, listColumnValues);
            m_isHide = true;
        }