Note.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using static System.Net.WebRequestMethods;
  13. namespace MOTINOVA_Motor_Factory_Set
  14. {
  15. public partial class Note : Form
  16. {
  17. public string LocalPath = "/Note";
  18. public string FileName = "Note.txt";
  19. public Note()
  20. {
  21. InitializeComponent();
  22. }
  23. private void Note_Load(object sender, EventArgs e)
  24. {
  25. //检查本地文件删除
  26. if (System.IO.File.Exists(StartForm.UserPath + "\\" + FileName))
  27. System.IO.File.Delete(StartForm.UserPath + "\\" + FileName);
  28. //下载远程文件
  29. StartForm.myFtp.DownloadFile(LocalPath + "/" + FileName, StartForm.UserPath);
  30. //显示文件
  31. StreamReader objReader = new StreamReader(StartForm.UserPath + "\\" + FileName);
  32. string sLine = "";
  33. ArrayList arrText = new ArrayList();//创建一个动态数组
  34. while (sLine != null)
  35. {
  36. sLine = objReader.ReadLine();
  37. arrText.Add(sLine);
  38. }
  39. objReader.Close();
  40. richTextBox_Note.Clear();
  41. foreach (string sOutput in arrText)
  42. {
  43. richTextBox_Note.AppendText(sOutput + "\r\n");
  44. }
  45. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  46. }
  47. private void button_NoteRead_Click(object sender, EventArgs e)
  48. {
  49. //检查本地文件删除
  50. if (System.IO.File.Exists(StartForm.UserPath + "\\" + FileName))
  51. System.IO.File.Delete(StartForm.UserPath + "\\" + FileName);
  52. //下载远程文件
  53. StartForm.myFtp.DownloadFile(LocalPath + "/" + FileName, StartForm.UserPath);
  54. //显示文件
  55. StreamReader objReader = new StreamReader(StartForm.UserPath + "\\" + FileName);
  56. string sLine = "";
  57. ArrayList arrText = new ArrayList();//创建一个动态数组
  58. while (sLine != null)
  59. {
  60. sLine = objReader.ReadLine();
  61. arrText.Add(sLine);
  62. }
  63. objReader.Close();
  64. richTextBox_Note.Clear();
  65. foreach (string sOutput in arrText)
  66. {
  67. richTextBox_Note.AppendText(sOutput + "\r\n");
  68. }
  69. richTextBox_Note.Text = richTextBox_Note.Text.Remove(richTextBox_Note.Text.Length - 1);
  70. }
  71. private void button_NoteWrite_Click(object sender, EventArgs e)
  72. {
  73. //检查本地并删除
  74. if (System.IO.File.Exists(StartForm.UserPath + "\\" + FileName))
  75. System.IO.File.Delete(StartForm.UserPath + "\\" + FileName);
  76. //保存
  77. System.IO.File.WriteAllText(StartForm.UserPath + "\\" + FileName, richTextBox_Note.Text);
  78. //上传服务器
  79. if (!StartForm.myFtp.DirectoryExist("/", "Note"))
  80. StartForm.myFtp.MakeDir("/Note");
  81. bool result = StartForm.myFtp.UploadFile(StartForm.UserPath + "\\" + FileName, "/Note");
  82. if (result)
  83. MessageBox.Show("上传完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  84. else
  85. MessageBox.Show("上传失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  86. }
  87. private void Note_FormClosing(object sender, FormClosingEventArgs e)
  88. {
  89. richTextBox_Note.Clear();
  90. }
  91. }
  92. }