| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace Core.LZMes.Client.UIB
- {
- class OperateConditionRecode
- {
- //读取操作条件
- public static string ReadCondition(string conStr)
- {
- string rowValue = "";//行值
- string conValue = null;//条件值
- try
- {
- //string sFile = System.IO.Directory.GetCurrentDirectory() + "\\" + "LzOperateCfg.ini";//当前路径
- string sFile = System.Windows.Forms.Application.StartupPath+ "\\" + "LzOperateCfg.ini";
- //string sFile = "C:\\WINDOWS\\LzOperateCfg.ini";
- string[] str = File.ReadAllLines(sFile);
-
- for (int i = 0; i < str.Length; i++)
- {
- rowValue = str[i];
- if (rowValue.Split('=')[0] == conStr)
- {
- conValue = rowValue.Split('=')[1];
- break;
- }
- }
-
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- return conValue;
- }
- //写入操作条件
- public static void WriteCondition(string conStr , string value)
- {
- try
- {
- string rowValue = "";//行值
- string conValue = "";//条件值
- // string sFile = System.IO.Directory.GetCurrentDirectory() + "\\" + "LzOperateCfg.ini";//当前路径
- string sFile = System.Windows.Forms.Application.StartupPath + "\\" + "LzOperateCfg.ini";
- if (!File.Exists(sFile))
- {
- File.Create(sFile).Close();
- File.AppendAllText(sFile, conStr + "=" + conValue+Environment.NewLine);
- return;
- }
- if (ReadCondition(conStr) == null)
- {
- File.AppendAllText(sFile, conStr + "=" + value + Environment.NewLine);
- }
- string[] str = File.ReadAllLines(sFile);
- File.WriteAllText(sFile , string.Empty);
- for (int i = 0; i < str.Length; i++ )
- {
- rowValue = str[i];
- if (rowValue.Split('=')[0] == conStr)
- {
- File.AppendAllText(sFile, conStr + "=" + value + Environment.NewLine);
- }
- else
- {
- File.AppendAllText(sFile, rowValue.Split('=')[0] + "=" + rowValue.Split('=')[1] + Environment.NewLine);
- }
-
- }
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.ToString());
- }
- }
- //删除行记录
- public void DeleteRow()
- {
- }
- }
- }
|