Example #1
0
        public Form1()
        {
            //string abc = "dzyslx= \"'>  d+ \" </ div > \"";
            //Regex reg = new Regex("(?<=dzyslx=.*>).{1,10}(?=</div>)");
            //var numberCollection = reg.Matches(abc);

            InitializeComponent();

            //string a = "https://msjw.gat.shandong.gov.cn/zayw/hkzd/stbb/zzsb.jsp?data=pVC3T2lZmIc4jlXXaJyILe5mZPxaaeqx9L43ge5lIGEZynQ860PsjuB9O9RTeDRDDd7uGjeiovBVYWXnFq7eP9BbvWenwLF4GtiXgcdDRyjwT42sYSdvrIEumJkdNvmzWajK9tYQDXfa7nbpvKwtQ11FBaTHxyEVYr1c1mefBapa9FyqcyMhKVGfcbYd%2BL5v58KJHHTREyHElKceWNCgQUd7IhmaglLkaiTu2Awqjq0%3D";
            //Process.Start(a);

            CensusContext.Connect();
            currentVillageList = CensusContext.GetVillages();
        }
Example #2
0
 public DataForm()
 {
     InitializeComponent();
     allVillageList = CensusContext.GetVillages();
 }
Example #3
0
        private void parseVillage()
        {
            StreamReader    reader    = null;
            List <MoveFile> moveFiles = new List <MoveFile>();

            try
            {
                int           newVillageCount = 0, newBuildCount = 0, oldVillageCount = 0, oldBuildCount = 0, fileCount = 0;
                StringBuilder sb = new StringBuilder();

                int ic = 0, size = dragFiles.Length;
                foreach (var dragFile in dragFiles)
                {
                    ic++;
                    this.Invoke(new FormControlInvoker(() =>
                    {
                        statusLabel.Text = $"{dragFile},{ic}/{size}";
                    }));
                    reader = File.OpenText(dragFile);
                    string content = reader.ReadToEnd();
                    Regex  reg     = new Regex("(?<=guid=)[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}");
                    var    villageGuidCollection = reg.Matches(content);
                    reg = new Regex("(?<=guid=\")[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}");
                    var guidCollection = reg.Matches(content);
                    reg = new Regex("(?<=dzyslx=[^>]{1,10}>)[^<]{0,10}");
                    var numberCollection = reg.Matches(content);
                    reg = new Regex("(?<=mid=\")[0-9]{21}");
                    var midCollection = reg.Matches(content);
                    reg = new Regex("(?<=<span>)[\u4E00-\u9FA5]+(?=</span>)");
                    var villageNameCollection = reg.Matches(content);

                    string fileNameEx = Path.GetFileName(dragFile), fileName = Path.GetFileNameWithoutExtension(dragFile);
                    if (!(numberCollection.Count == midCollection.Count && midCollection.Count == guidCollection.Count && villageGuidCollection.Count == 1 && villageNameCollection.Count == 1))
                    {
                        MessageBox.Show($"file : {fileName};village guid count : {villageGuidCollection.Count} ;village name count : {villageNameCollection.Count} ;guid count : {guidCollection.Count}; number count : {numberCollection.Count} ;mid count : {midCollection.Count} . ");
                        throw new Exception("【" + fileName + "】的房屋数据不平衡。");
                    }

                    if (numberCollection.Count == 0)
                    {
                        MessageBox.Show($"file : {dragFile}");
                        throw new Exception("【" + fileName + "】不存在数据。");
                    }

                    /**
                     * 解析村庄
                     * */
                    string villageName = villageNameCollection[0].Value.Trim();
                    string villageGuid = villageGuidCollection[0].Value.Trim();

                    Village village = CensusContext.GetVillage(villageName);
                    if (village == null)
                    {
                        village = new Village(villageGuid, villageName);
                        CensusContext.AddVillage(village);
                        newVillageCount++;
                    }
                    else
                    {
                        oldVillageCount++;
                    }

                    FileInfo fi = new FileInfo(dragFile);
                    MoveFile mf = new MoveFile();
                    mf.oldPath = dragFile;
                    mf.newPath = fi.Directory.FullName + "\\" + villageName.Replace("鲁权屯镇", "") + ".html";
                    moveFiles.Add(mf);

                    /**
                     * 解析房屋
                     * */
                    for (int i = 0; i < numberCollection.Count; i++)
                    {
                        string guid   = guidCollection[i].Value.Trim();
                        string mid    = midCollection[i].Value.Trim();
                        string number = numberCollection[i].Value.Trim();
                        if (!CensusContext.IsExistBuild(guid))
                        {
                            newBuildCount++;
                            //allBuildList.Add(new Build(guid, mid, Regex.Match(number, "[0-9]{1,4}号").Value, village.guid));
                            CensusContext.AddBuild(new Build(guid, mid, number, village.guid));
                        }
                        else
                        {
                            oldBuildCount++;
                        }
                    }

                    //saveBuild(allBuildList);
                    //sb.Append(village.name + "导入新数据 " + newCount + " 条,重复数据 " + redo + " 条\n\r");
                    fileCount++;
                }
                currentVillageList = CensusContext.GetVillages();
                this.Invoke(new FormControlInvoker(() =>
                {
                    listBoxVillage.Items.Clear();
                }));
                foreach (var v in currentVillageList)
                {
                    this.Invoke(new FormControlInvoker(() =>
                    {
                        this.listBoxVillage.Items.Add(new Village(v.guid, v.name.Replace("鲁权屯镇", "")));
                    }));
                }

                MessageBox.Show(sb.Append($"共导入{fileCount}个文件。\r\n{newVillageCount}个村庄新数据,{oldVillageCount}个已存在村庄数据。\r\n{newBuildCount}个房屋新数据,{oldBuildCount}个已存在房屋数据。").ToString());
            }
            catch (Exception e)
            {
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }

                foreach (var f in moveFiles)
                {
                    FileInfo fi = new FileInfo(f.oldPath);
                    if (!f.oldPath.Equals(f.newPath))
                    {
                        fi.MoveTo(f.newPath);
                    }
                }
                this.Invoke(new FormControlInvoker(() =>
                {
                    statusLabel.Text = "";
                }));
            }
            //
        }