Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. private void saveButton_Click(object sender, EventArgs e)
  2.         {
  3.             if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  4.             {
  5.                 pathToSave = saveFileDialog1.FileName;
  6.                 FileInfo newFile = new FileInfo(pathToSave);
  7.                 if (newFile.Exists)
  8.                 {
  9.                     if (MessageBox.Show("Файл с таким именем уже существует. Хотите перезаписать?", "Сообщение", MessageBoxButtons.YesNo)
  10.                         == DialogResult.Yes)
  11.                     {
  12.                         try
  13.                         {
  14.                             SaveFile.SaveThisInFile(pathToSave, allWeHave);
  15.                         }
  16.                         catch (Exception)
  17.                         {
  18.                             MessageBox.Show("Что-то пошло не так");
  19.                         }
  20.                     }
  21.                 } else
  22.                 {
  23.                     File.Create(pathToSave);
  24.                     try
  25.                     {
  26.                         SaveFile.SaveThisInFile(pathToSave, allWeHave);
  27.                     }
  28.                     catch (Exception)
  29.                     {
  30.                         MessageBox.Show(pathToSave);
  31.                     }
  32.                 }
  33.             }
  34.         }
  35.  
  36. public class SaveFile
  37.     {
  38.         public static void SaveThisInFile(string path, List<Tonnel> listToSave)
  39.         {
  40.             string[] list = new string[listToSave.Count + 1];
  41.             list[0] = $"ROWNUM;Name;Tunnel;AdmArea;District;Longitude_WGS84;Latitude_WGS84;global_id;";
  42.             for (int i = 1; i <= listToSave.Count + 1; ++i)
  43.             {
  44.                 list[i] = "";
  45.                 list[i] = $"{i};\"{listToSave[i].Name}\";\"{listToSave[i].Tunnel};{listToSave[i].District.AdmArea}\";\"{listToSave[i].District.Distr}\";\"{listToSave[i].Longtitude_WGS84}\";\"{listToSave[i].Latitude_WGS84}\";\"{listToSave[i].Global_id}\";";
  46.             }
  47.             File.WriteAllLines(path, list);
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement