Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 11k
Category:

ADO-ODBC

Development Platform:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.IO;
  8. namespace ch3_3
  9. {
  10. /// <summary>
  11. /// Form1 的摘要说明。
  12. /// </summary>
  13. public class Form1 : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Button button1;
  16. private System.Windows.Forms.Label label1;
  17. private System.Windows.Forms.Label label3;
  18. private System.Windows.Forms.Label label5;
  19. private System.Windows.Forms.OpenFileDialog openFileDialog1;
  20. private System.Windows.Forms.TextBox textBox1;
  21. private System.Windows.Forms.TextBox textBox2;
  22. private System.Windows.Forms.TextBox textBox3;
  23. private System.Windows.Forms.Label label2;
  24. private System.Windows.Forms.TextBox textBox4;
  25. private System.Windows.Forms.Label label4;
  26. private System.Windows.Forms.TextBox textBox5;
  27. private System.Windows.Forms.GroupBox groupBox1;
  28. private System.Windows.Forms.CheckBox checkBox1;
  29. private System.Windows.Forms.CheckBox checkBox2;
  30. private System.Windows.Forms.CheckBox checkBox3;
  31. private System.Windows.Forms.CheckBox checkBox4;
  32. private System.Windows.Forms.CheckBox checkBox5;
  33. private System.Windows.Forms.CheckBox checkBox6;
  34. /// <summary>
  35. /// 必需的设计器变量。
  36. /// </summary>
  37. private System.ComponentModel.Container components = null;
  38. public Form1()
  39. {
  40. //
  41. // Windows 窗体设计器支持所必需的
  42. //
  43. InitializeComponent();
  44. //
  45. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  46. //
  47. }
  48. /// <summary>
  49. /// 清理所有正在使用的资源。
  50. /// </summary>
  51. protected override void Dispose( bool disposing )
  52. {
  53. if( disposing )
  54. {
  55. if (components != null) 
  56. {
  57. components.Dispose();
  58. }
  59. }
  60. base.Dispose( disposing );
  61. }
  62. #region Windows Form Designer generated code
  63. /// <summary>
  64. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  65. /// 此方法的内容。
  66. /// </summary>
  67. private void InitializeComponent()
  68. {
  69. this.button1 = new System.Windows.Forms.Button();
  70. this.label1 = new System.Windows.Forms.Label();
  71. this.label3 = new System.Windows.Forms.Label();
  72. this.label5 = new System.Windows.Forms.Label();
  73. this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
  74. this.textBox1 = new System.Windows.Forms.TextBox();
  75. this.textBox2 = new System.Windows.Forms.TextBox();
  76. this.textBox3 = new System.Windows.Forms.TextBox();
  77. this.label2 = new System.Windows.Forms.Label();
  78. this.textBox4 = new System.Windows.Forms.TextBox();
  79. this.label4 = new System.Windows.Forms.Label();
  80. this.textBox5 = new System.Windows.Forms.TextBox();
  81. this.groupBox1 = new System.Windows.Forms.GroupBox();
  82. this.checkBox1 = new System.Windows.Forms.CheckBox();
  83. this.checkBox2 = new System.Windows.Forms.CheckBox();
  84. this.checkBox3 = new System.Windows.Forms.CheckBox();
  85. this.checkBox4 = new System.Windows.Forms.CheckBox();
  86. this.checkBox5 = new System.Windows.Forms.CheckBox();
  87. this.checkBox6 = new System.Windows.Forms.CheckBox();
  88. this.groupBox1.SuspendLayout();
  89. this.SuspendLayout();
  90. // 
  91. // button1
  92. // 
  93. this.button1.Location = new System.Drawing.Point(24, 224);
  94. this.button1.Name = "button1";
  95. this.button1.TabIndex = 0;
  96. this.button1.Text = "选定文件";
  97. this.button1.Click += new System.EventHandler(this.button1_Click);
  98. // 
  99. // label1
  100. // 
  101. this.label1.Location = new System.Drawing.Point(24, 24);
  102. this.label1.Name = "label1";
  103. this.label1.Size = new System.Drawing.Size(56, 23);
  104. this.label1.TabIndex = 1;
  105. this.label1.Text = "文件名";
  106. // 
  107. // label3
  108. // 
  109. this.label3.Location = new System.Drawing.Point(24, 64);
  110. this.label3.Name = "label3";
  111. this.label3.Size = new System.Drawing.Size(64, 24);
  112. this.label3.TabIndex = 3;
  113. this.label3.Text = "文件路径";
  114. // 
  115. // label5
  116. // 
  117. this.label5.Location = new System.Drawing.Point(24, 104);
  118. this.label5.Name = "label5";
  119. this.label5.Size = new System.Drawing.Size(64, 23);
  120. this.label5.TabIndex = 5;
  121. this.label5.Text = "创建时间";
  122. // 
  123. // textBox1
  124. // 
  125. this.textBox1.Location = new System.Drawing.Point(112, 24);
  126. this.textBox1.Name = "textBox1";
  127. this.textBox1.Size = new System.Drawing.Size(120, 21);
  128. this.textBox1.TabIndex = 7;
  129. this.textBox1.Text = "";
  130. // 
  131. // textBox2
  132. // 
  133. this.textBox2.Location = new System.Drawing.Point(112, 64);
  134. this.textBox2.Name = "textBox2";
  135. this.textBox2.Size = new System.Drawing.Size(120, 21);
  136. this.textBox2.TabIndex = 8;
  137. this.textBox2.Text = "";
  138. // 
  139. // textBox3
  140. // 
  141. this.textBox3.Location = new System.Drawing.Point(112, 104);
  142. this.textBox3.Name = "textBox3";
  143. this.textBox3.Size = new System.Drawing.Size(120, 21);
  144. this.textBox3.TabIndex = 9;
  145. this.textBox3.Text = "";
  146. // 
  147. // label2
  148. // 
  149. this.label2.Location = new System.Drawing.Point(24, 144);
  150. this.label2.Name = "label2";
  151. this.label2.Size = new System.Drawing.Size(72, 23);
  152. this.label2.TabIndex = 10;
  153. this.label2.Text = "修改时间";
  154. // 
  155. // textBox4
  156. // 
  157. this.textBox4.Location = new System.Drawing.Point(112, 144);
  158. this.textBox4.Name = "textBox4";
  159. this.textBox4.Size = new System.Drawing.Size(120, 21);
  160. this.textBox4.TabIndex = 11;
  161. this.textBox4.Text = "";
  162. // 
  163. // label4
  164. // 
  165. this.label4.Location = new System.Drawing.Point(24, 184);
  166. this.label4.Name = "label4";
  167. this.label4.Size = new System.Drawing.Size(72, 23);
  168. this.label4.TabIndex = 12;
  169. this.label4.Text = "上次访问";
  170. // 
  171. // textBox5
  172. // 
  173. this.textBox5.Location = new System.Drawing.Point(112, 184);
  174. this.textBox5.Name = "textBox5";
  175. this.textBox5.Size = new System.Drawing.Size(120, 21);
  176. this.textBox5.TabIndex = 13;
  177. this.textBox5.Text = "";
  178. // 
  179. // groupBox1
  180. // 
  181. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  182. this.checkBox6,
  183. this.checkBox5,
  184. this.checkBox4,
  185. this.checkBox3,
  186. this.checkBox2,
  187. this.checkBox1});
  188. this.groupBox1.Location = new System.Drawing.Point(264, 16);
  189. this.groupBox1.Name = "groupBox1";
  190. this.groupBox1.Size = new System.Drawing.Size(224, 232);
  191. this.groupBox1.TabIndex = 14;
  192. this.groupBox1.TabStop = false;
  193. this.groupBox1.Text = "文件属性";
  194. // 
  195. // checkBox1
  196. // 
  197. this.checkBox1.Location = new System.Drawing.Point(40, 24);
  198. this.checkBox1.Name = "checkBox1";
  199. this.checkBox1.TabIndex = 0;
  200. this.checkBox1.Text = "是否只读文件";
  201. // 
  202. // checkBox2
  203. // 
  204. this.checkBox2.Location = new System.Drawing.Point(40, 56);
  205. this.checkBox2.Name = "checkBox2";
  206. this.checkBox2.TabIndex = 1;
  207. this.checkBox2.Text = "是否系统文件";
  208. // 
  209. // checkBox3
  210. // 
  211. this.checkBox3.Location = new System.Drawing.Point(40, 88);
  212. this.checkBox3.Name = "checkBox3";
  213. this.checkBox3.TabIndex = 2;
  214. this.checkBox3.Text = "是否隐藏文件";
  215. // 
  216. // checkBox4
  217. // 
  218. this.checkBox4.Location = new System.Drawing.Point(40, 120);
  219. this.checkBox4.Name = "checkBox4";
  220. this.checkBox4.TabIndex = 3;
  221. this.checkBox4.Text = "是否目录";
  222. // 
  223. // checkBox5
  224. // 
  225. this.checkBox5.Location = new System.Drawing.Point(40, 152);
  226. this.checkBox5.Name = "checkBox5";
  227. this.checkBox5.Size = new System.Drawing.Size(128, 24);
  228. this.checkBox5.TabIndex = 4;
  229. this.checkBox5.Text = "上次备份后已更改";
  230. // 
  231. // checkBox6
  232. // 
  233. this.checkBox6.Location = new System.Drawing.Point(40, 184);
  234. this.checkBox6.Name = "checkBox6";
  235. this.checkBox6.TabIndex = 5;
  236. this.checkBox6.Text = "是否临时文件";
  237. // 
  238. // Form1
  239. // 
  240. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  241. this.ClientSize = new System.Drawing.Size(520, 269);
  242. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  243.   this.groupBox1,
  244.   this.textBox5,
  245.   this.label4,
  246.   this.textBox4,
  247.   this.label2,
  248.   this.textBox3,
  249.   this.textBox2,
  250.   this.textBox1,
  251.   this.label5,
  252.   this.label3,
  253.   this.label1,
  254.   this.button1});
  255. this.Name = "Form1";
  256. this.Text = "文件信息读取";
  257. this.groupBox1.ResumeLayout(false);
  258. this.ResumeLayout(false);
  259. }
  260. #endregion
  261. /// <summary>
  262. /// 应用程序的主入口点。
  263. /// </summary>
  264. [STAThread]
  265. static void Main() 
  266. {
  267. Application.Run(new Form1());
  268. }
  269. private void button1_Click(object sender, System.EventArgs e)
  270. {
  271. //checkBox初始化
  272. this.checkBox1.Checked=false;
  273. this.checkBox2.Checked=false;
  274. this.checkBox3.Checked=false;
  275. this.checkBox4.Checked=false;
  276. this.checkBox5.Checked=false;
  277. this.checkBox6.Checked=false;
  278. if (this.openFileDialog1.ShowDialog()==DialogResult.OK)
  279. {
  280. //获取文件详细路径和文件名
  281. string fileName=this.openFileDialog1.FileName;
  282. //获取文件名
  283. string shortName=fileName.Substring(fileName.LastIndexOf("\")+1);
  284. //获取文件路径
  285. string filePath=fileName.Substring(0,fileName.Length-shortName.Length);
  286.             
  287. this.textBox1.Text=shortName;
  288. this.textBox2.Text=filePath;
  289. //读取文件创建时间
  290. string creatTime=File.GetCreationTime(fileName).ToLongDateString();
  291. this.textBox3.Text=creatTime;
  292. //读取文件修改时间
  293. string amendTime=File.GetLastWriteTime(fileName).ToLongDateString();
  294. this.textBox4.Text=amendTime;
  295. //读取文件上次访问时间
  296. string lastTime=File.GetLastAccessTime(fileName).ToLongDateString();
  297. this.textBox5.Text=lastTime;
  298.     //获取文件属性信息
  299. FileAttributes fAttris=File.GetAttributes(fileName);
  300.  
  301. string fileType=fAttris.ToString();
  302. //因为一个文件可能同时有多种属性。所有每一种情况都要分析
  303. //判断是否是只读文件
  304. if ( fileType.LastIndexOf("ReadOnly")!=-1)
  305. {
  306. this.checkBox1.Checked=true;
  307. }
  308. //判断是否是系统文件
  309. if (fileType.LastIndexOf("System")!=-1)
  310. {
  311. this.checkBox2.Checked=true;
  312. }
  313. //判断是否是隐藏文件
  314. if (fileType.LastIndexOf("Hidden")!=-1)
  315. {
  316. this.checkBox3.Checked=true;
  317. }
  318. //判断是否是目录
  319. if (fileType.LastIndexOf("Directory")!=-1)
  320. {
  321. this.checkBox4.Checked=true;
  322. }
  323. //判断是否上次备份后已更改
  324. if (fileType.LastIndexOf("Archive")!=-1)
  325. {
  326. this.checkBox5.Checked=true;
  327. }
  328. //判断是否是临时文件
  329. if (fileType.LastIndexOf("Temporary")!=-1)
  330. {
  331. this.checkBox5.Checked=true;
  332. }
  333. }
  334. }
  335. }
  336. }