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)); } }
private void WriteExcelRow(TreeValue value, ISheet source, ISheet dest, Hashtable valueColumns, int lastValueIndex) { foreach (DictionaryEntry entry in value.Values) { FillValue3C fillValue = entry.Value as FillValue3C; } }
/// <summary> /// 使用用户输入的文件名初始化文件的绝对路径。 /// </summary> /// <param name="fillValue"></param> private void InitFilesFullName(FillValue3C fillValue) { FillParameter3C fillParameter = fillParameters[fillValue.Key] as FillParameter3C; if (fillParameter == null) { fillValue.Separators = FillParameter3C.DefaultSeparators; } else { fillValue.Separators = fillParameter.Separators; } if (fillValue == null || fillValue.AttachFile == null || fillValue.Separators == null || fillValue.Separators.Length < 1) { return; } string[] fileNames = fillValue.AttachFile.Split(fillValue.Separators[0]); StringBuilder buffer = new StringBuilder(); foreach (string fileName in fileNames) { string file = GetRealFile(fileName); buffer.Append(file); buffer.Append(fillValue.Separators[0]); } if (buffer.Length > 1) { buffer.Remove(buffer.Length - 1, 1); } fillValue.SetAttachFile(buffer.ToString()); }
private void InnerConvert(FillValue3C fillValue, ConverterParameter parameter) { StringBuilder builder = new StringBuilder(fillValue.Value); if (string.IsNullOrEmpty(parameter.ValueReplaceGroup) == false) { string[] replaceGroup = parameter.ValueReplaceGroup.Split('|'); foreach (var group in replaceGroup) { string[] keyAndValue = group.Split(':'); if (keyAndValue.Length >= 2) { builder.Replace(keyAndValue[0], keyAndValue[1]); } } } fillValue.Value = builder.ToString(); }
private void FillWorker(object state) { FillDialog_3C.BeginListen(); string windowType = null; FillDialog_3C fill = FillDialog_3C.GetFillDialog(out windowType); try { _fillParameters = this.ReadFillParameter(@"..\..\..\演示数据\CCC\CCC填报规则.xlsx"); TreeValue root = this.ReadData(DataFile); FillDialog_3C.BeginListen(); windowType = null; fill = FillDialog_3C.GetFillDialog(out windowType); if (fill != null) { if (windowType == CCCWindowType.LoginWindow) { fill.FillValue = _data["厂商关系"] as FillValue3C; fill.DoFillWork(_data["登录证书"]); } else if (windowType == CCCWindowType.FirmWindow) { FillValue3C value = _data["厂商关系"] as FillValue3C; fill.DoFillWork(value == null ? "" : value.Value); } } main = Main_3C.GetMainWindow(this.DataFile); //this.SetWindowPos(); main.FillParameters = this._fillParameters; this.GetTreeView(); main.TreeValue = root; while (main.SelectNextNode(true)) { main.FillPage(); } } catch { this.EndFill(); } }
private void InitFilesFullName(FillValue3C fillValue) { FillParameter3C fillParameter = fillParameters[fillValue.Key] as FillParameter3C; if (fillParameter == null) { fillValue.Separators = FillParameter3C.DefaultSeparators; } else { fillValue.Separators = fillParameter.Separators; } if (fillValue == null || fillValue.AttachFile == null || fillValue.Separators == null || fillValue.Separators.Length < 1) { return; } string[] fileNames = fillValue.AttachFile.Split(fillValue.Separators[0]); bool flag = fillValue.AttachFile == fillValue.PublicAttachFile; StringBuilder buffer = new StringBuilder(); foreach (string fileName in fileNames) { List <string> files = CheckFile(fileName, flag); if (files != null) { foreach (var file in files) { buffer.Append(file); buffer.Append(fillValue.Separators[0]); } } } if (buffer.Length > 1) { buffer.Remove(buffer.Length - 1, 1); } fillValue.SetAttachFile(buffer.ToString()); }
/// <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; } }
/// <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); }