Пример #1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            ErecordInfo ei = new ErecordInfo();

            ei.drive   = cbxDrives.Text;
            ei.oldroot = txtPath.Text;
            DataRowView dr = cbxRegionCode.SelectedItem as DataRowView;

            ei.regioncode = dr["code"].ToString();

            if (rbnShidaidianzi.Checked)
            {
                ei.type = 1;
            }
            else
            {
                ei.type = 0;
            }
            if (string.IsNullOrEmpty(txtPath.Text))
            {
                MessageBox.Show("请输入路径!");
                return;
            }
            bgwImport.RunWorkerAsync(ei);
        }
Пример #2
0
        private void bgwImport_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            ErecordInfo      ei     = e.Argument as ErecordInfo;

            lblStatus.Invoke(appendMessage, "开始导入...");
            string idcard;

            //   SqlCommand cmd = new SqlCommand();

            //DataRowView dr = cbxRegionCode.SelectedItem as DataRowView;
            //string regioncode = dr["code"].ToString();
            //string drive = cbxDrives.Text;
            //string oldERecordRoot = txtPath.Text;

            string newpath;
            string newroot;


            int wuxianRegionCount = 0;
            int wuxianRootCount   = 0;
            int wuxianCount       = 0;
            int wuxianTotal       = 0;


            int ageRegionCount = 0;
            int ageRootCount   = 0;
            int ageCount       = 0;
            int ageTotal       = 0;

            int          total  = 0;
            StreamWriter sw     = new StreamWriter("log.csv", true);
            Random       rd     = new Random();
            string       region = "";
            int          year;
            const int    yearMax = 1965;

            string[]      regions    = new string[] { "市本级", "内丘电子档案-城镇职工-20671", "内丘新农保电子档案-时代提取-114987", "邢台县电子档案-时代提取-170512", "任县电子档案-时代提取-179537", "沙河档案交接分拣196038" };
            List <string> regionList = new List <string>();

            for (int i = 0; i < regions.Length; i++)
            {
                regionList.Add(regions[i]);
            }

            try
            {
                foreach (string path in Directory.EnumerateFiles(ei.oldroot + @"\", "*.jpg", SearchOption.AllDirectories))
                {
                    if (path.Split('\\').Length > 3)
                    {
                        idcard = Path.GetFileNameWithoutExtension(path).Trim();
                        year   = Convert.ToInt32(idcard.Substring(6, 4));
                        region = path.Split('\\')[2];
                        if (year >= yearMax && !Idcard.CheckIDCard15(idcard))
                        {
                            if (region != path.Split('\\')[2])
                            {
                                ageRegionCount++;
                                ageCount     = 0;
                                ageRootCount = 0;
                            }
                            if (ageCount == 5000)
                            {
                                ageCount = 0;
                                ageRootCount++;
                            }
                            newpath = ERecordPath.GetERecordPathTemp(ei.drive, "五十岁以下", region, ageRootCount.ToString(), idcard);
                            newroot = Path.GetDirectoryName(newpath);
                            if (!Directory.Exists(newroot))
                            {
                                Directory.CreateDirectory(newroot);
                            }
                            if (!File.Exists(newpath))
                            {
                                ageCount++;
                                ageTotal++;
                                File.Copy(path, newpath, true);
                                WriteLogToCSV(sw, idcard + "," + path + "," + region);// + ei.type.ToString() + "," + ei.regioncode);
                            }
                        }
                        //if (year < yearMax || Idcard.CheckIDCard15(idcard))
                        //{
                        //    if (region != path.Split('\\')[2])
                        //    {
                        //        ageRegionCount++;
                        //        ageCount = 0;
                        //        ageRootCount = 0;
                        //    }
                        //    if (ageCount == 5000)
                        //    {
                        //        ageCount = 0;
                        //        ageRootCount++;
                        //    }
                        //    newpath = ERecordPath.GetERecordPathTemp(ei.drive, "50岁和15位", region, ageRootCount.ToString(), idcard);
                        //    newroot = Path.GetDirectoryName(newpath);
                        //    if (!Directory.Exists(newroot))
                        //    {
                        //        Directory.CreateDirectory(newroot);
                        //    }
                        //    if (!File.Exists(newpath))
                        //    {
                        //        ageCount++;
                        //        ageTotal++;
                        //        File.Copy(path, newpath, true);
                        //        WriteLogToCSV(sw, idcard + "," + path + "," + region);// + ei.type.ToString() + "," + ei.regioncode);
                        //    }

                        //}
                        //else if (regionList.Contains(region) && Idcard.IsIdcard(idcard) && IsGet(rd))
                        //{
                        //    if (region != path.Split('\\')[2])
                        //    {
                        //        wuxianRegionCount++;
                        //        wuxianRootCount = 0;
                        //        wuxianCount = 0;
                        //    }
                        //    if (wuxianCount == 5000)
                        //    {
                        //        wuxianCount = 0;
                        //        wuxianRootCount++;
                        //    }

                        //    newpath = ERecordPath.GetERecordPathTemp(ei.drive, "五县抽调", region, wuxianRootCount.ToString(), idcard);
                        //    newroot = Path.GetDirectoryName(newpath);
                        //    if (!Directory.Exists(newroot))
                        //    {
                        //        Directory.CreateDirectory(newroot);
                        //    }
                        //    if (!File.Exists(newpath))
                        //    {
                        //        wuxianCount++;
                        //        wuxianTotal++;
                        //        File.Copy(path, newpath, true);
                        //        WriteLogToCSV(sw, idcard + "," + path + "," + region);// + ei.type.ToString() + "," + ei.regioncode);
                        //    }
                        //}

                        total++;
                        lblStatus.Invoke(appendMessage, "50岁:" + ageRegionCount + "/" + ageRootCount + "/" + ageCount + "/" + ageTotal +
                                         "。\n五县:" + wuxianRegionCount + "/" + wuxianRootCount + "/" + wuxianCount + "/" + wuxianTotal + "\t" + "总数:" + total);
                    }
                }
                lblStatus.Invoke(appendMessage, "完成" + total);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                sw.Close();
            }
        }