settingdbfunc.cs

来自「是一款式CSDN阅读器,可以方便CSDN用户阅读自己感兴趣的内容!」· CS 代码 · 共 76 行

CS
76
字号
using System;
using System.Collections.Generic;
using System.Text;

using System.Data;

namespace feiyun0112.cnblogs.com.CSDNReader.Functions
{
    class SettingDBFunc
    {
        public DataView GetSetting()
        {
            DataView dvw = null;
            DBFunc db = new DBFunc(false, false);
            try
            {                
                string strSql = "select * from Settings";
                dvw = db.GetDataSet(strSql).Tables[0].DefaultView;
                
            }
            catch (Exception e)
            {
                dvw = null;
                MsgFunc.ShowWarning(e.Message);
                return dvw;
            }
            finally
            {
                db.CloseCon();
            }
            return dvw;
        }

        public string GetSettingValue(string strID)
        {
            DataView dvwSetting = GetSetting();
            string strValue = "";
            dvwSetting.RowFilter = "ID='" + strID + "'";
            if (dvwSetting.Count > 0)
            {
                strValue = dvwSetting[0]["Value"].ToString();
            }

            return strValue;
        }


        public void SetSetting(string strID, string strNewValue)
        {
            DBFunc db = new DBFunc(false, false);

            
            try
            {
                string strSql = "delete * from Settings where Id='" + strID + "'";
                db.ExecuteSql(strSql);

                strSql = "insert into Settings([ID],[Value]) values('" + strID + "','" + db.SpecialChar(strNewValue) + "')";
                db.ExecuteSql(strSql);
            }
            catch (Exception e)
            {
                
                MsgFunc.ShowWarning(e.Message);
                return ;
            }
            finally
            {
                db.CloseCon();
            }


        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?