PrintExpressCode/Common/Common.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Security.Cryptography;

namespace PrintExpressCode
{
    public class Common
    {
        /// <summary>
        /// 更新appSettings
        /// </summary>
        /// <param name="name">key名称</param>
        /// <param name="value">值</param>
        public void UpdateAppSettings(string name,string value)
        {
            //获取Configuration对象
            Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            string path = System.Windows.Forms.Application.UserAppDataPath;
            string path1 = System.Windows.Forms.Application.ExecutablePath;
            string path2 = System.Windows.Forms.Application.CommonAppDataPath;
            string path3 = System.Windows.Forms.Application.LocalUserAppDataPath;
            string path4 = System.Windows.Forms.Application.StartupPath;
            //根据Key读取<add>元素的Value
            KeyValueConfigurationElement keyname = config.AppSettings.Settings[name];
            if (keyname != null)
            {
                //写入<add>元素的Value
                config.AppSettings.Settings[name].Value = value;
            }
            else
            {
                //增加<add>元素
                config.AppSettings.Settings.Add(name, value);
            }
            ////删除<add>元素
            //config.AppSettings.Settings.Remove("name");

            //一定要记得保存,写不带参数的config.Save()也可以
            config.Save(ConfigurationSaveMode.Modified);
            //刷新,否则程序读取的还是之前的值(可能已装入内存)
            System.Configuration.ConfigurationManager.RefreshSection("appSettings");
        }

        /// <summary>
        /// 获取相关的配置文件
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetappSettings(string name)
        {
            //获取Configuration对象
            Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            return config.AppSettings.Settings[name].Value;
        }


        /// <summary>
后面还有 12 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。