Exemplo n.º 1
0
 private void AddResult(CollectTable table, Dictionary <string, List <FieldValue> > result)
 {
     lock (_syncRoot)
     {
         _result.Add(table, result);
         _resullt2.Add(new Collect {
             XZQDM = XZQDM, XZQMC = XZQMC, Table = table, Values = result
         });
     }
 }
Exemplo n.º 2
0
        private static Dictionary <CollectTable, List <ExcelField> > GetFields(string queryString)
        {
            var dict  = new Dictionary <CollectTable, List <ExcelField> >();
            var nodes = XmlManager.GetList(queryString, XmlEnum.Field);
            var a     = 0;

            if (nodes != null)
            {
                foreach (System.Xml.XmlNode node in nodes)
                {
                    var table = new CollectTable
                    {
                        Name      = node.Attributes["Name"].Value,
                        Title     = node.Attributes["Title"].Value,
                        TableName = node.Attributes["TableName"].Value,
                        Model2    = node.Attributes["Model2"].Value,
                        Model3    = node.Attributes["Model3"].Value
                    };

                    if (node.Attributes["Regex"] != null)
                    {
                        table.Regex = node.Attributes["Regex"].Value;
                    }
                    if (node.Attributes["Model"] != null)
                    {
                        table.Model = node.Attributes["Model"].Value;
                    }
                    if (node.Attributes["CollectIndex"] != null)
                    {
                        if (int.TryParse(node.Attributes["CollectIndex"].Value, out a))
                        {
                            table.CollectIndex = a;
                        }
                    }
                    if (node.Attributes["StartIndex"] != null)
                    {
                        if (int.TryParse(node.Attributes["StartIndex"].Value, out a))
                        {
                            table.StartIndex = a;
                        }
                    }
                    var list = GetFields(node, table.TableName);
                    dict.Add(table, list);
                }
            }


            return(dict);
        }
Exemplo n.º 3
0
        private List <FieldValue> Program(CollectTable table, List <ExcelField> fields)
        {
            List <FieldValue> results = new List <FieldValue>();

            foreach (var field in fields)
            {
                var val = field.Indexs != null?GetValues(field, fields, table.TableName) : GetValue(field, table.TableName);

                if (val != null)
                {
                    results.Add(val);
                }
            }
            return(results);
        }
Exemplo n.º 4
0
        private Dictionary <string, List <FieldValue> > Program(CollectTable table, List <ExcelField> fields)
        {
            var XZDict = new Dictionary <string, List <FieldValue> >(); //乡镇对应的字段值列表

            foreach (var entry in XZCDict)                              //当前行政区 乡镇信息
            {
                var result = new List <FieldValue>();

                var value = entry.Value;
                foreach (var field in fields)//某一张表格的字段列表
                {
                    var val = field.Indexs != null?GetValues(field, value, fields, table.TableName) : GetValue(field, value, table.TableName);

                    if (val != null)
                    {
                        result.Add(val);
                    }
                }

                XZDict.Add(entry.Key, result);
            }
            return(XZDict);
        }
Exemplo n.º 5
0
        private void Program(CollectTable table, List <ExcelField> fields)
        {
            var resultdict = new Dictionary <string, List <FieldValue> >();
            var gg         = new List <Gather>();

            Console.WriteLine(table.Name);
            #region  获取数据
            foreach (var item in ExcelManager.Dict)//乡镇
            {
                _results = new List <FieldValue>();
                var array = item.Key.Split(',');
                var value = item.Value;
                gg.Add(new Gather {
                    Table = table, Fields = fields, Connection = Connection, XZC = item.Value, XZCDM = array[1]
                });
            }

            Parallel.ForEach(gg, g =>
            {
                g.Program();
            });

            foreach (var item in gg)
            {
                resultdict.Add(item.XZCDM, item.Results);
            }

            #endregion

            #region  写数据
            var filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Excels", table.Model);
            if (string.IsNullOrEmpty(filePath) || !System.IO.File.Exists(filePath))
            {
                LogManager.Log("模型Excel文件不存在,无法进行生成操作!");
                return;
            }

            IWorkbook workbook = filePath.OpenExcel();
            if (workbook == null)
            {
                LogManager.Log("未获取模型Excel文件,无法进行生成操作!");
                return;
            }
            ISheet sheet = workbook.GetSheetAt(0);
            if (sheet == null)
            {
                LogManager.Log("未获取模型Excel文件中的工作表");
                return;
            }

            var  modelrow = sheet.GetRow(table.StartIndex);
            IRow row      = null;
            sheet.ShiftRows(table.StartIndex + 1, table.StartIndex + 5, resultdict.Count - 1);
            var i    = table.StartIndex;
            var list = new List <FieldValue>();
            foreach (var entry in resultdict)
            {
                row = sheet.GetRow(i) ?? sheet.CreateRow(i);
                i++;
                row.Height = modelrow.Height;
                var cell = ExcelClass.GetCell(row, 0, modelrow);
                cell.SetCellValue(entry.Key);
                var item = ExcelManager.XZQ.FirstOrDefault(e => e.XZCDM == entry.Key);
                cell = ExcelClass.GetCell(row, 1, modelrow);
                if (item != null)
                {
                    cell.SetCellValue(item.XZCMC);
                }
                else
                {
                    cell.SetCellValue("未查询到名称");
                }
                list.AddRange(entry.Value);
                foreach (var field in entry.Value)
                {
                    ExcelClass.GetCell(row, field.Index - 2, modelrow).SetCellValue(field.Value);
                }
            }

            row        = sheet.GetRow(i);
            row.Height = modelrow.Height;
            var dict2 = list.GroupBy(e => e.Index).ToDictionary(e => e.Key, e => e.Where(k => k.Val != null && !string.IsNullOrEmpty(k.Val.ToString())));
            foreach (var field in fields)
            {
                var cell = ExcelClass.GetCell(row, field.Index - 2, modelrow);
                if (!dict2.ContainsKey(field.Index))
                {
                    continue;
                }
                var temp = dict2[field.Index];
                switch (field.Type)
                {
                case ExcelType.Double:
                    var a = temp.Sum(e => double.Parse(e.Val.ToString()));
                    cell.SetCellValue(a);
                    break;

                case ExcelType.Int:
                    var b = temp.Sum(e => int.Parse(e.Val.ToString()));
                    cell.SetCellValue(b);
                    break;
                }
            }
            using (var fs = new FileStream(System.IO.Path.Combine(SaveFolder, table.Name + "" + table.Title + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".xlsx"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                workbook.Write(fs);
            }


            #endregion
        }