示例#1
0
        private void AddFillValue(FillValue3C fillValue, TreeValue value, Hashtable set)
        {
            string[]  values = string.IsNullOrEmpty(fillValue.Value) ? new string[] { fillValue.Value } : fillValue.Value.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
            TreeValue temp   = null;

            if (values.Length == 1 || value == null || value.Parent == null)
            {
                fillValue.SetValue(values[0]);
                InitFilesFullName(fillValue);
                set.Add(fillValue.Key, fillValue);
            }
            else
            {
                int appendIndex = 1000;
                for (int i = 0; i < values.Length; i++)
                {
                    if (i == 0)
                    {
                        temp = value;
                    }
                    else
                    {
                        temp = value.Parent.FindChild(value.Name, string.Format("{0}{1}", value.Suffix, appendIndex));
                    }
                    if (temp == null)
                    {
                        temp = new TreeValue(value.Name, string.Format("{0}{1}", value.Suffix, appendIndex));
                        temp.CopyFrom(value);
                        value.Parent.AddChild(temp);
                    }
                    FillValue3C tempValue = new FillValue3C();
                    tempValue.CopyFrom(fillValue);
                    tempValue.SetValue(values[i]);
                    InitFilesFullName(tempValue);
                    temp.Values.Add(tempValue.Key, tempValue);
                    appendIndex++;
                }
            }
            if (value.Parent == null)
            {
                return;
            }
            // 设置新增节点默认值
            int index = 1001;

            temp = value.Parent.FindChild(value.Name, string.Format("{0}{1}", value.Suffix, index));
            while (temp != null)
            {
                foreach (DictionaryEntry entry in value.Values)
                {
                    object val = temp.Values[entry.Key];
                    if (val == null)
                    {
                        temp.Values[entry.Key] = entry.Value;
                    }
                }
                index++;
                temp = value.Parent.FindChild(value.Name, string.Format("{0}{1}", value.Suffix, index));
            }
        }
示例#2
0
        /// <summary>
        /// 从指定文件中读取需填报的参数值。
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private TreeValue ReadData(string fileName, Hashtable data, Hashtable fillParameters)
        {
            try
            {
                TreeValue root         = InitTreeNode();
                Hashtable treeDir      = GetTreeDir(root);
                Hashtable current      = null;
                TreeValue lastTreeNode = root;
                Hashtable columnHeader = new Hashtable();
                using (Office.Excel.ForwardExcelReader reader = new Office.Excel.ForwardExcelReader(fileName))
                {
                    reader.Open();
                    Office.Excel.ForwardReadWorksheet sheet = reader.Activate(1) as Office.Excel.ForwardReadWorksheet;
                    if (sheet != null)
                    {
                        object header = null;
                        if (sheet.ReadNextRow() && sheet.CurrentRowIndex == 1)
                        {
                            while (sheet.ReadNextCell(false))
                            {
                                header = sheet.GetContent();
                                columnHeader.Add(sheet.CurrentCell.ColumnIndex, header == null ? "" : header.ToString());
                            }
                        }
                        FillValue3C fillValue = null;
                        object      content   = null;
                        string      str       = null;
                        bool        nextRow   = false;
                        while (sheet.ReadNextRow())
                        {
                            fillValue = new FillValue3C();
                            while (sheet.ReadNextCell(false))
                            {
                                content = sheet.GetContent();
                                str     = content == null ? "" : content.ToString();
                                switch (columnHeader[sheet.CurrentCell.ColumnIndex] as string)
                                {
                                case "序号":
                                    fillValue.Key = str;
                                    break;

                                case "参数项的值":
                                    fillValue.SetValue(string.Format("{0}{1}", string.IsNullOrEmpty(fillValue.Value) ? "" : string.Format("{0}\t", fillValue.Value), str));
                                    break;

                                case "参数项名称":
                                    Match match = paraNameMatcher.Match(str);
                                    if (match.Success && match.Groups["name"].Success)
                                    {
                                        str = match.Groups["name"].Value.Trim();
                                    }
                                    else
                                    {
                                        str = str.Trim();
                                    }
                                    if (treeDir.ContainsKey(str))
                                    {
                                        TreeValue parent = lastTreeNode;
                                        TreeValue child  = null;
                                        while (parent != null)
                                        {
                                            child = parent.FindChild(str, null);
                                            if (child == null)
                                            {
                                                parent = parent.Parent;
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                        if (child == null)
                                        {
                                            child  = treeDir[str] as TreeValue;
                                            parent = child.Parent;
                                        }
                                        System.Diagnostics.Trace.Assert(child != null && parent != null);
                                        match = suffixMatcher.Match(fillValue.Key);
                                        if (match.Success)
                                        {
                                            string    suffix = match.Groups["suffix"].Value;
                                            TreeValue temp   = new TreeValue(child.Name, suffix);
                                            temp.CopyFrom(child);
                                            parent.AddChild(temp);
                                            child = temp;
                                        }
                                        current      = child.Values;
                                        lastTreeNode = child;
                                        nextRow      = true; // 当前行为目录行,忽略其它内容
                                    }
                                    break;

                                case "附件":
                                    fillValue.PublicAttachFile = str;
                                    break;
                                }
                                if (nextRow)
                                {
                                    break;
                                }
                            }
                            if (string.IsNullOrEmpty(fillValue.Key) == false)
                            {
                                if (nextRow)
                                {
                                    nextRow = false;
                                    continue;
                                }
                                AddFillValue(fillValue, lastTreeNode, current == null ? data : current);
                                //if (current == null)                                    //  若当前值为树节点下的值则将其添加到当前树节点的Values中,
                                //    _data.Add(fillValue.Key, fillValue);        //  否则(如证书名称、厂商关系)添加到管理器的数据中。
                                //else
                                //    current.Add(fillValue.Key, fillValue);
                            }
                        }
                    }
                }
                return(root);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.StackTrace + ex.Message);
                throw;
            }
        }
示例#3
0
文件: CCCFiller.cs 项目: qwdingyu/C-
        /// <summary>
        /// 从指定文件中读取需填报的参数值。
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private TreeValue ReadData(string fileName)
        {
            TreeValue root         = InitTreeNode();
            Hashtable treeDir      = GetTreeDir(root);
            Hashtable current      = null;
            TreeValue lastTreeNode = root;
            Hashtable columnHeader = new Hashtable();

            using (Office.Excel.ForwardExcelReader reader = new Office.Excel.ForwardExcelReader(fileName))
            {
                reader.Open();
                Office.Excel.ForwardReadWorksheet sheet = reader.Activate(1) as Office.Excel.ForwardReadWorksheet;
                if (sheet != null)
                {
                    object header = null;
                    if (sheet.ReadNextRow() && sheet.CurrentRowIndex == 1)
                    {
                        while (sheet.ReadNextCell(false))
                        {
                            header = sheet.GetContent();
                            columnHeader.Add(sheet.CurrentCell.ColumnIndex, header == null ? "" : header.ToString());
                        }
                    }
                    FillValue3C fillValue = null;
                    object      content   = null;
                    string      str       = null;
                    bool        nextRow   = false;
                    while (sheet.ReadNextRow())
                    {
                        fillValue = new FillValue3C();
                        while (sheet.ReadNextCell(false))
                        {
                            content = sheet.GetContent();
                            str     = content == null ? "" : content.ToString();
                            switch (columnHeader[sheet.CurrentCell.ColumnIndex] as string)
                            {
                            case "序号":
                                fillValue.Key = str;
                                break;

                            case "参数项的值":
                                fillValue.SetValue(str);
                                break;

                            case "参数项名称":
                                str = str.Trim();
                                if (treeDir.ContainsKey(str))
                                {
                                    TreeValue parent = lastTreeNode;
                                    TreeValue child  = null;
                                    while (parent != null)
                                    {
                                        child = parent.FindChild(str, null);
                                        if (child == null)
                                        {
                                            parent = parent.Parent;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (child == null)
                                    {
                                        child  = treeDir[str] as TreeValue;
                                        parent = child.Parent;
                                    }
                                    System.Diagnostics.Trace.Assert(child != null && parent != null);
                                    Match match = Main_3C.suffixMatcher.Match(fillValue.Key);
                                    if (match.Success)
                                    {
                                        string    suffix = match.Groups["suffix"].Value;
                                        TreeValue temp   = new TreeValue(child.Name, suffix);
                                        temp.CopyFrom(child);
                                        parent.AddChild(temp);
                                        child = temp;
                                    }
                                    current      = child.Values;
                                    lastTreeNode = child;
                                    nextRow      = true; // 当前行为目录行,忽略其它内容
                                }
                                break;

                            case "附件":
                                fillValue.AttachFile = str;
                                break;
                            }
                            if (nextRow)
                            {
                                break;
                            }
                        }
                        if (string.IsNullOrEmpty(fillValue.Key) == false)
                        {
                            if (nextRow)
                            {
                                nextRow = false;
                                continue;
                            }
                            if (current == null)
                            {
                                _data.Add(fillValue.Key, fillValue);
                            }
                            else
                            {
                                current.Add(fillValue.Key, fillValue);
                            }
                        }
                    }
                }
            }
            return(root);
        }