Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void writeFile()
- {
- System.IO.FileInfo fi;
- System.IO.StreamWriter sw;
- System.IO.StreamReader sr;
- List<string> lines = new List<string>();
- try
- {
- fi = new System.IO.FileInfo(textBox3.Text);
- }
- catch
- {
- MessageBox.Show("Путь имеет неверный формат.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- if(!textBox3.Text.StartsWith(Application.StartupPath) &&
- MessageBox.Show("Файл не находится в папке приложения, продолжить?", "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
- {
- return;
- }
- if(fi.Exists)
- {
- sr = new System.IO.StreamReader(textBox3.Text, Encoding.GetEncoding(1251));
- lines = sr.ReadToEnd().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
- sr.Close();
- }
- sw = fi.CreateText();
- double temp = Convert.ToDouble(textBox1.Text);
- DateTime date = monthCalendar1.SelectionStart;
- while(monthCalendar1.SelectionEnd >= date)
- {
- int cloneIndex = lines.FindIndex(v => v.StartsWith(date.ToString("d")));
- if(cloneIndex > -1)
- {
- if(MessageBox.Show("Запись на дату " + date.ToString("d") + " уже существует.\nЗаменить?", "Совданение", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- lines.RemoveAt(cloneIndex);
- }
- else
- {
- continue;
- }
- }
- lines.Add(date.ToString("d")+" "+temp.ToString("N"));
- date = date.AddDays(1);
- }
- foreach(string line in lines)
- {
- sw.WriteLine(line);
- }
- sw.Close();
- textBox1.Text = "";
- readFile();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement