OperateConditionRecode.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. namespace Core.LZMes.Client.UIB
  7. {
  8. class OperateConditionRecode
  9. {
  10. //读取操作条件
  11. public static string ReadCondition(string conStr)
  12. {
  13. string rowValue = "";//行值
  14. string conValue = null;//条件值
  15. try
  16. {
  17. //string sFile = System.IO.Directory.GetCurrentDirectory() + "\\" + "LzOperateCfg.ini";//当前路径
  18. string sFile = System.Windows.Forms.Application.StartupPath+ "\\" + "LzOperateCfg.ini";
  19. //string sFile = "C:\\WINDOWS\\LzOperateCfg.ini";
  20. string[] str = File.ReadAllLines(sFile);
  21. for (int i = 0; i < str.Length; i++)
  22. {
  23. rowValue = str[i];
  24. if (rowValue.Split('=')[0] == conStr)
  25. {
  26. conValue = rowValue.Split('=')[1];
  27. break;
  28. }
  29. }
  30. }
  31. catch (Exception ex)
  32. {
  33. System.Diagnostics.Debug.WriteLine(ex.ToString());
  34. }
  35. return conValue;
  36. }
  37. //写入操作条件
  38. public static void WriteCondition(string conStr , string value)
  39. {
  40. try
  41. {
  42. string rowValue = "";//行值
  43. string conValue = "";//条件值
  44. // string sFile = System.IO.Directory.GetCurrentDirectory() + "\\" + "LzOperateCfg.ini";//当前路径
  45. string sFile = System.Windows.Forms.Application.StartupPath + "\\" + "LzOperateCfg.ini";
  46. if (!File.Exists(sFile))
  47. {
  48. File.Create(sFile).Close();
  49. File.AppendAllText(sFile, conStr + "=" + conValue+Environment.NewLine);
  50. return;
  51. }
  52. if (ReadCondition(conStr) == null)
  53. {
  54. File.AppendAllText(sFile, conStr + "=" + value + Environment.NewLine);
  55. }
  56. string[] str = File.ReadAllLines(sFile);
  57. File.WriteAllText(sFile , string.Empty);
  58. for (int i = 0; i < str.Length; i++ )
  59. {
  60. rowValue = str[i];
  61. if (rowValue.Split('=')[0] == conStr)
  62. {
  63. File.AppendAllText(sFile, conStr + "=" + value + Environment.NewLine);
  64. }
  65. else
  66. {
  67. File.AppendAllText(sFile, rowValue.Split('=')[0] + "=" + rowValue.Split('=')[1] + Environment.NewLine);
  68. }
  69. }
  70. }
  71. catch (Exception ex)
  72. {
  73. System.Diagnostics.Debug.WriteLine(ex.ToString());
  74. }
  75. }
  76. //删除行记录
  77. public void DeleteRow()
  78. {
  79. }
  80. }
  81. }