コード例 #1
0
        private void ButtonChangeFile_Copy_Click(object sender, RoutedEventArgs e)
        {
            if (listBoxChange.Items.Count == 0)
            {
                MessageBox.Show("Не выбраны файлы для разбора", "Нет файлов", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            int CountNum = Convert.ToInt32(TextBoxCount.Text.Trim()) + 1;

            foreach (string name in listBoxChange.Items)
            {
                ParseFile(name);

                if (ComboBoxItem.Text == "*.TXT")
                {
                    listBoxCreate.Items.Add("*** Результаты разбора файла : " + name + " в " + DateTime.Now + " ***");

                    #region ZU
                    if (LZu.Count != 0)
                    {
                        int          i   = 0;
                        int          j   = 0;
                        int          n   = 1;
                        StreamWriter FZu = new StreamWriter(FileName + "_ЗУ_" + n + ".txt");
                        listBoxCreate.Items.Add(FileName + "_ЗУ_" + n + ".txt");
                        foreach (string ZU in LZu)
                        {
                            if (i == CountNum)
                            {
                                FZu.WriteLine(ZU);
                                FZu.Close();
                                n++;
                                FZu = new StreamWriter(FileName + "_ЗУ_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ЗУ_" + n + ".txt");


                                i = 0;
                            }
                            else
                            {
                                if (j == LZu.Count() - 1)
                                {
                                    FZu.Write(ZU);
                                }
                                else
                                {
                                    FZu.Write(ZU + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        FZu.Close();
                    }
                    #endregion ZU

                    if (CheckBoxDel.IsChecked == true)
                    {
                        if (LOks.Count != 0)
                        {
                            int          i    = 0;
                            int          j    = 0;
                            int          n    = 1;
                            StreamWriter FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                            listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                            foreach (string OKS in LOks)
                            {
                                if (i == CountNum)
                                {
                                    FOks.WriteLine(OKS);
                                    FOks.Close();
                                    n++;
                                    FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");


                                    i = 0;
                                }
                                else
                                {
                                    if (j == LOks.Count() - 1)
                                    {
                                        FOks.Write(OKS);
                                    }
                                    else
                                    {
                                        FOks.Write(OKS + ";");
                                    }
                                }

                                i++;
                                j++;
                            }
                            FOks.Close();
                        }
                        if (LUn.Count != 0)
                        {
                            int          i   = 0;
                            int          j   = 0;
                            int          n   = 1;
                            StreamWriter Fun = new StreamWriter(FileName + "_НД_" + n + ".txt");
                            listBoxCreate.Items.Add(FileName + "_НД_" + n + ".txt");
                            foreach (string Un in LUn)
                            {
                                if (i == CountNum)
                                {
                                    Fun.WriteLine(Un);

                                    Fun.Close();
                                    n++;
                                    Fun = new StreamWriter(FileName + "_НД_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_НД_" + n + ".txt");


                                    i = 0;
                                }
                                else
                                {
                                    if (j == LUn.Count() - 1)
                                    {
                                        Fun.Write(Un);
                                    }
                                    else
                                    {
                                        Fun.Write(Un + ";");
                                    }
                                }

                                i++;
                                j++;
                            }
                            Fun.Close();
                        }
                        if (LFlat.Count != 0)
                        {
                            int          i     = 0;
                            int          j     = 0;
                            int          n     = 1;
                            StreamWriter FFlat = new StreamWriter(FileName + "_КВ_" + n + ".txt");
                            listBoxCreate.Items.Add(FileName + "_КВ_" + n + ".txt");
                            foreach (string Flat in LFlat)
                            {
                                if (i == CountNum)
                                {
                                    FFlat.WriteLine(Flat);
                                    FFlat.Close();
                                    n++;
                                    FFlat = new StreamWriter(FileName + "_КВ_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_КВ_" + n + ".txt");


                                    i = 0;
                                }
                                else
                                {
                                    if (j == LFlat.Count() - 1)
                                    {
                                        FFlat.Write(Flat);
                                    }
                                    else
                                    {
                                        FFlat.Write(Flat + ";");
                                    }
                                }

                                i++;
                                j++;
                            }
                            FFlat.Close();
                        }
                        if (LCnst.Count != 0)
                        {
                            int          i      = 0;
                            int          j      = 0;
                            int          n      = 1;
                            StreamWriter FCnstr = new StreamWriter(FileName + "_СР_" + n + ".txt");
                            listBoxCreate.Items.Add(FileName + "_СР_" + n + ".txt");
                            foreach (string Cnstr in LCnst)
                            {
                                if (i == CountNum)
                                {
                                    FCnstr.WriteLine(Cnstr);

                                    FCnstr.Close();
                                    n++;
                                    FCnstr = new StreamWriter(FileName + "_СР_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_СР_" + n + ".txt");


                                    i = 0;
                                }
                                else
                                {
                                    if (j == LCnst.Count() - 1)
                                    {
                                        FCnstr.Write(Cnstr);
                                    }
                                    else
                                    {
                                        FCnstr.Write(Cnstr + ";");
                                    }
                                }

                                i++;
                                j++;
                            }
                            FCnstr.Close();
                        }
                    }
                    else
                    {
                        int          i    = 0;
                        int          j    = 0;
                        int          n    = 1;
                        StreamWriter FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                        listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                        foreach (string OKS in LOks)
                        {
                            if (i == CountNum)
                            {
                                FOks.WriteLine(OKS);

                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");


                                i = 0;
                            }
                            else
                            {
                                if (j == LOks.Count() - 1)
                                {
                                    FOks.Write(OKS);
                                }
                                else
                                {
                                    FOks.Write(OKS + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        foreach (string Un in LUn)
                        {
                            if (i == CountNum)
                            {
                                FOks.WriteLine(Un);

                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");


                                i = 0;
                            }
                            else
                            {
                                if (j == LUn.Count() - 1)
                                {
                                    FOks.Write(Un);
                                }
                                else
                                {
                                    FOks.Write(Un + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        foreach (string Flat in LFlat)
                        {
                            if (i == CountNum)
                            {
                                FOks.WriteLine(Flat);

                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");


                                i = 0;
                            }
                            else
                            {
                                if (j == LFlat.Count() - 1)
                                {
                                    FOks.Write(Flat);
                                }
                                else
                                {
                                    FOks.Write(Flat + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        foreach (string Cnstr in LCnst)
                        {
                            if (i == CountNum)
                            {
                                FOks.WriteLine(Cnstr);

                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");


                                i = 0;
                            }
                            else
                            {
                                if (j == LCnst.Count() - 1)
                                {
                                    FOks.Write(Cnstr);
                                }
                                else
                                {
                                    FOks.Write(Cnstr + ";");
                                }
                            }

                            i++;
                            j++;
                        }

                        FOks.Close();
                    }
                    LOks.Clear();
                    LUn.Clear();
                    LFlat.Clear();
                    LCnst.Clear();
                    LZu.Clear();
                }
            }

            if (ComboBoxItem.Text == "*.CSV")
            {
                var excel = new ExcelPackage();

                int i  = 1;
                int k  = 1;
                int j  = 1;
                var ws = excel.Workbook.Worksheets.Add("ЗУ");
                foreach (var Num in LZu)
                {
                    if (i == CountNum)
                    {
                        excel.SaveAs(new FileInfo("ZU_" + j + ".csv"));
                        listBoxCreate.Items.Add("Файл ZU_" + j + ".csv получен в " + DateTime.Now);
                        i = 1;
                        j++;
                        excel = new ExcelPackage();
                        ws    = excel.Workbook.Worksheets.Add("ЗУ");
                    }
                    ws.Cells[i, 1].Value = Num + ",," + k;
                    k++;
                    i++;
                }
                excel.SaveAs(new FileInfo("ZU_" + j + ".csv"));
                listBoxCreate.Items.Add("Файл ZU_" + j + ".csv получен в " + DateTime.Now);
                if (i > 1)
                {
                    listBoxCreate.Items.Add("Все ЗУ разобраны в " + DateTime.Now);
                }

                excel = new ExcelPackage();

                i  = 1;
                j  = 1;
                k  = 1;
                ws = excel.Workbook.Worksheets.Add("OKS");
                foreach (string OKS in LOks)
                {
                    if (i == CountNum)
                    {
                        excel.SaveAs(new FileInfo("OKS_" + j + ".csv"));
                        listBoxCreate.Items.Add("Файл OKS_" + j + ".csv получен в " + DateTime.Now);
                        i = 1;
                        j++;
                        excel = new ExcelPackage();
                        ws    = excel.Workbook.Worksheets.Add("ОКС");
                    }
                    ws.Cells[i, 1].Value = OKS + ",," + k;
                    k++;
                    i++;
                }
                foreach (string Un in LUn)
                {
                    if (i == CountNum)
                    {
                        excel.SaveAs(new FileInfo("OKS_" + j + ".csv"));
                        listBoxCreate.Items.Add("Файл OKS_" + j + ".csv получен в " + DateTime.Now);
                        i = 1;
                        j++;
                        excel = new ExcelPackage();
                        ws    = excel.Workbook.Worksheets.Add("ОКС");
                    }
                    ws.Cells[i, 1].Value = Un + ",," + k;
                    k++;
                    i++;
                }
                foreach (string Flat in LFlat)
                {
                    if (i == CountNum)
                    {
                        excel.SaveAs(new FileInfo("OKS" + j + ".csv"));
                        listBoxCreate.Items.Add("Файл OKS_" + j + ".csv получен в " + DateTime.Now);
                        i = 1;
                        j++;
                        excel = new ExcelPackage();
                        ws    = excel.Workbook.Worksheets.Add("ОКС");
                    }
                    ws.Cells[i, 1].Value = Flat + ",," + k;
                    k++;
                    i++;
                }
                foreach (string Cnstr in LCnst)
                {
                    if (i == CountNum)
                    {
                        excel.SaveAs(new FileInfo("OKS_" + j + ".csv"));
                        i = 1;
                        j++;
                        excel = new ExcelPackage();
                        ws    = excel.Workbook.Worksheets.Add("ОКС");
                        listBoxCreate.Items.Add("Файл OKS_" + j + ".csv получен в " + DateTime.Now);
                    }
                    ws.Cells[i, 1].Value = Cnstr + ",," + k;
                    k++;
                    i++;
                }

                excel.SaveAs(new FileInfo("OKS_" + j + ".csv"));
                listBoxCreate.Items.Add("Файл OKS_" + j + ".csv получен в " + DateTime.Now);
                if (i > 1)
                {
                    listBoxCreate.Items.Add("Все ОКС разобраны в " + DateTime.Now);
                }
            }
            CountCad.Visibility = Visibility.Visible;
            CountCad.Content    = "Получено кадастровых номеров: " + Count;
            Count = 0;
        }
コード例 #2
0
        private void ButtonChangeFile_Copy_Click(object sender, RoutedEventArgs e)
        {
            foreach (string name in listBoxChange.Items)
            {
                listBoxCreate.Items.Add("*** Результаты разбора файла : " + name + " в " + DateTime.Now + " ***");
                ParseFile(name);
                #region ZU
                if (LZu.Count != 0)
                {
                    int          i   = 0;
                    int          j   = 0;
                    int          n   = 1;
                    StreamWriter FZu = new StreamWriter(FileName + "_ЗУ_" + n + ".txt");
                    listBoxCreate.Items.Add(FileName + "_ЗУ_" + n + ".txt");
                    foreach (string ZU in LZu)
                    {
                        if (i == 50)
                        {
                            FZu.WriteLine(ZU);
                            if (CheckBoxVal.IsChecked == true)
                            {
                                FZu.Close();
                                n++;
                                FZu = new StreamWriter(FileName + "_ЗУ_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ЗУ_" + n + ".txt");
                            }
                            i = 0;
                        }
                        else
                        {
                            if (j == LZu.Count() - 1)
                            {
                                FZu.Write(ZU);
                            }
                            else
                            {
                                FZu.Write(ZU + ";");
                            }
                        }

                        i++;
                        j++;
                    }
                    FZu.Close();
                }
                #endregion ZU

                if (CheckBoxDel.IsChecked == true)
                {
                    if (LOks.Count != 0)
                    {
                        int          i    = 0;
                        int          j    = 0;
                        int          n    = 1;
                        StreamWriter FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                        listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                        foreach (string OKS in LOks)
                        {
                            if (i == 50)
                            {
                                FOks.WriteLine(OKS);
                                if (CheckBoxVal.IsChecked == true)
                                {
                                    FOks.Close();
                                    n++;
                                    FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                                }
                                i = 0;
                            }
                            else
                            {
                                if (j == LOks.Count() - 1)
                                {
                                    FOks.Write(OKS);
                                }
                                else
                                {
                                    FOks.Write(OKS + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        FOks.Close();
                    }
                    if (LUn.Count != 0)
                    {
                        int          i   = 0;
                        int          j   = 0;
                        int          n   = 1;
                        StreamWriter Fun = new StreamWriter(FileName + "_НД_" + n + ".txt");
                        listBoxCreate.Items.Add(FileName + "_НД_" + n + ".txt");
                        foreach (string Un in LUn)
                        {
                            if (i == 50)
                            {
                                Fun.WriteLine(Un);
                                if (CheckBoxVal.IsChecked == true)
                                {
                                    Fun.Close();
                                    n++;
                                    Fun = new StreamWriter(FileName + "_НД_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_НД_" + n + ".txt");
                                }
                                i = 0;
                            }
                            else
                            {
                                if (j == LUn.Count() - 1)
                                {
                                    Fun.Write(Un);
                                }
                                else
                                {
                                    Fun.Write(Un + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        Fun.Close();
                    }
                    if (LFlat.Count != 0)
                    {
                        int          i     = 0;
                        int          j     = 0;
                        int          n     = 1;
                        StreamWriter FFlat = new StreamWriter(FileName + "_КВ_" + n + ".txt");
                        listBoxCreate.Items.Add(FileName + "_КВ_" + n + ".txt");
                        foreach (string Flat in LFlat)
                        {
                            if (i == 50)
                            {
                                FFlat.WriteLine(Flat);
                                if (CheckBoxVal.IsChecked == true)
                                {
                                    FFlat.Close();
                                    n++;
                                    FFlat = new StreamWriter(FileName + "_КВ_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_КВ_" + n + ".txt");
                                }
                                i = 0;
                            }
                            else
                            {
                                if (j == LFlat.Count() - 1)
                                {
                                    FFlat.Write(Flat);
                                }
                                else
                                {
                                    FFlat.Write(Flat + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        FFlat.Close();
                    }
                    if (LCnst.Count != 0)
                    {
                        int          i      = 0;
                        int          j      = 0;
                        int          n      = 1;
                        StreamWriter FCnstr = new StreamWriter(FileName + "_СР_" + n + ".txt");
                        listBoxCreate.Items.Add(FileName + "_СР_" + n + ".txt");
                        foreach (string Cnstr in LCnst)
                        {
                            if (i == 50)
                            {
                                FCnstr.WriteLine(Cnstr);
                                if (CheckBoxVal.IsChecked == true)
                                {
                                    FCnstr.Close();
                                    n++;
                                    FCnstr = new StreamWriter(FileName + "_СР_" + n + ".txt");
                                    listBoxCreate.Items.Add(FileName + "_СР_" + n + ".txt");
                                }
                                i = 0;
                            }
                            else
                            {
                                if (j == LCnst.Count() - 1)
                                {
                                    FCnstr.Write(Cnstr);
                                }
                                else
                                {
                                    FCnstr.Write(Cnstr + ";");
                                }
                            }

                            i++;
                            j++;
                        }
                        FCnstr.Close();
                    }
                }
                else
                {
                    int          i    = 0;
                    int          j    = 0;
                    int          n    = 1;
                    StreamWriter FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                    listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                    foreach (string OKS in LOks)
                    {
                        if (i == 50)
                        {
                            FOks.WriteLine(OKS);
                            if (CheckBoxVal.IsChecked == true)
                            {
                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                            }
                            i = 0;
                        }
                        else
                        {
                            if (j == LOks.Count() - 1)
                            {
                                FOks.Write(OKS);
                            }
                            else
                            {
                                FOks.Write(OKS + ";");
                            }
                        }

                        i++;
                        j++;
                    }
                    foreach (string Un in LUn)
                    {
                        if (i == 50)
                        {
                            FOks.WriteLine(Un);
                            if (CheckBoxVal.IsChecked == true)
                            {
                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                            }
                            i = 0;
                        }
                        else
                        {
                            if (j == LUn.Count() - 1)
                            {
                                FOks.Write(Un);
                            }
                            else
                            {
                                FOks.Write(Un + ";");
                            }
                        }

                        i++;
                        j++;
                    }
                    foreach (string Flat in LFlat)
                    {
                        if (i == 50)
                        {
                            FOks.WriteLine(Flat);
                            if (CheckBoxVal.IsChecked == true)
                            {
                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                            }
                            i = 0;
                        }
                        else
                        {
                            if (j == LFlat.Count() - 1)
                            {
                                FOks.Write(Flat);
                            }
                            else
                            {
                                FOks.Write(Flat + ";");
                            }
                        }

                        i++;
                        j++;
                    }
                    foreach (string Cnstr in LCnst)
                    {
                        if (i == 50)
                        {
                            FOks.WriteLine(Cnstr);
                            if (CheckBoxVal.IsChecked == true)
                            {
                                FOks.Close();
                                n++;
                                FOks = new StreamWriter(FileName + "_ОКС_" + n + ".txt");
                                listBoxCreate.Items.Add(FileName + "_ОКС_" + n + ".txt");
                            }
                            i = 0;
                        }
                        else
                        {
                            if (j == LCnst.Count() - 1)
                            {
                                FOks.Write(Cnstr);
                            }
                            else
                            {
                                FOks.Write(Cnstr + ";");
                            }
                        }

                        i++;
                        j++;
                    }

                    FOks.Close();
                }



                LOks.Clear();
                LUn.Clear();
                LFlat.Clear();
                LCnst.Clear();
                LZu.Clear();
            }
            CountCad.Visibility = Visibility.Visible;
            CountCad.Content    = "Получено кадастровых номеров: " + Count;
            Count = 0;
        }