Beispiel #1
0
        /// <summary>
        /// 读取字符串数据
        /// </summary>
        /// <param name="segName">读取数据的段名</param>
        /// <param name="keyName">读取数据的键名</param>
        /// <returns>字符串数据</returns>
        public string ReadString(string segName, string keyName)
        {
            StringBuilder sbStr = new StringBuilder(512);

            HmzWin32App.GetPrivateProfileString(segName, keyName, "", sbStr, sbStr.Capacity, this.path);

            return(sbStr.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// 写入指定段名的整段数据
        /// </summary>
        /// <param name="segName">写入数据的段名</param>
        /// <param name="keys">写入数据的键集合</param>
        /// <param name="values">写入数据的值集合</param>
        public void WriteSection(string segName, string[] keys, string[] values)
        {
            if (keys.Length != values.Length)
            {
                throw new Exception("WriteSection(): 缺失参数");
            }

            for (int i = 0; i < keys.Length; i++)
            {
                HmzWin32App.WritePrivateProfileString(segName, keys[i], values[i], this.path);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 读取指定段名的整段数据
        /// </summary>
        /// <param name="segName">读取数据的段名</param>
        /// <param name="keys">读取数据的键集合</param>
        /// <returns>文件中获得的字符串数据集合</returns>
        public string[] ReadSection(string segName, string[] keys)
        {
            List <string> values = new List <string>();

            foreach (string item in keys)
            {
                StringBuilder sbStr = new StringBuilder();
                HmzWin32App.GetPrivateProfileString(segName, item, "", sbStr, sbStr.Capacity, this.path);
                values.Add(sbStr.ToString());
            }

            return(values.ToArray());
        }
Beispiel #4
0
        /// <summary>
        /// 读取浮点型数据
        /// </summary>
        /// <param name="segName">读取数据的段名</param>
        /// <param name="keyName">读取数据的键名</param>
        /// <returns>浮点型数据</returns>
        public double ReadDouble(string segName, string keyName)
        {
            double        value = 0;
            StringBuilder sbStr = new StringBuilder(128);

            HmzWin32App.GetPrivateProfileString(segName, keyName, "0", sbStr, sbStr.Capacity, this.path);

            if (!double.TryParse(sbStr.ToString(), out value))
            {
                value = 0;
            }

            return(value);
        }
Beispiel #5
0
 /// <summary>
 /// 写入浮点型数据
 /// </summary>
 /// <param name="segName">写入数据的段名</param>
 /// <param name="keyName">写入数据的键名</param>
 /// <param name="value">写入数据的值</param>
 public void WriteDouble(string segName, string keyName, double value)
 {
     HmzWin32App.WritePrivateProfileString(segName, keyName, value.ToString(), this.path);
 }
Beispiel #6
0
 /// <summary>
 /// 写入字符串数据
 /// </summary>
 /// <param name="segName">写入数据的段名</param>
 /// <param name="keyName">写入数据的键名</param>
 /// <param name="value">写入数据的值</param>
 public void WriteString(string segName, string keyName, string value)
 {
     HmzWin32App.WritePrivateProfileString(segName, keyName, value, this.path);
 }
Beispiel #7
0
 /// <summary>
 /// 删除指定段名的整段数据信息
 /// </summary>
 /// <param name="segName">需要删除的数据的段名</param>
 /// <returns>执行成功返回true</returns>
 public bool DeleteSection(string segName)
 {
     return(HmzWin32App.WritePrivateProfileString(segName, null, null, this.path));
 }
Beispiel #8
0
 /// <summary>
 /// 删除指定段名及键名的数据信息
 /// </summary>
 /// <param name="segName">需要删除的数据的段名</param>
 /// <param name="keyName">需要删除的数据的键名</param>
 /// <returns>执行成功返回true</returns>
 public bool DeleteKey(string segName, string keyName)
 {
     return(HmzWin32App.WritePrivateProfileString(segName, keyName, null, this.path));
 }
Beispiel #9
0
 /// <summary>
 /// 读取整数型数据
 /// </summary>
 /// <param name="segName">读取数据的段名</param>
 /// <param name="keyName">读取数据的键名</param>
 /// <returns>整型数据</returns>
 public int ReadInt(string segName, string keyName)
 {
     return(HmzWin32App.GetPrivateProfileInt(segName, keyName, 0, this.path));
 }