private void button2_Click(object sender, EventArgs e) { List <string> Files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + @"\PIA\Reports\", "*.txt") .Select(Path.GetFileName) .ToList <string>(); string txtname; if (textBox1.Text != "") { txtname = Interface1.CurRepSend(); if (Files.Contains(txtname + ".txt")) { if (checkBox1.Text == "") { checkBox1.Checked = false; checkBox1.Visible = false; } checkBox1.Visible = true; checkBox1.Text = "Are you sure you want" + Environment.NewLine + "to overwrite the old Report:" + Environment.NewLine + txtname + ".txt"; button2.Text = "Confirm Save"; if (checkBox1.Text == "Are you sure you want" + Environment.NewLine + "to overwrite the old Report:" + Environment.NewLine + txtname + ".txt" && checkBox1.Checked == true) { string Name = AppDomain.CurrentDomain.BaseDirectory + @"\PIA\Reports\" + txtname + ".txt"; Interface1.RepSave(textBox1.Text, Name); Interface1.clear(); checkBox1.Text = ""; checkBox1.Checked = false; checkBox1.Visible = false; button2.Text = "Save"; textBox1.ReadOnly = true; save++; } } else { File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\PIA\Reports\" + txtname + ".txt", textBox1.Text); textBox1.ReadOnly = true; save++; } } else { textBox1.Text = "Generate report first"; } }
private void button2_Click(object sender, EventArgs e) { if (checkBox1.Text == "") { checkBox1.Checked = false; checkBox1.Visible = false; } checkBox1.Visible = true; checkBox1.Text = "Are you sure you want" + Environment.NewLine + "to overwrite the old Report:" + Environment.NewLine + Interface1.CurRepViewSend(); button2.Text = "Confirm Save"; if (checkBox1.Text == "Are you sure you want" + Environment.NewLine + "to overwrite the old Report:" + Environment.NewLine + Interface1.CurRepViewSend() && checkBox1.Checked == true) { string Name = AppDomain.CurrentDomain.BaseDirectory + @"\PIA\Reports\" + Interface1.CurRepViewSend(); Interface1.RepSave(textBox4.Text, Name); Interface1.clear(); checkBox1.Text = ""; checkBox1.Checked = false; checkBox1.Visible = false; button2.Text = "Save"; textBox4.ReadOnly = true; button4.Visible = false; button5.Visible = false; } }