一:截图
二:SettingDAL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace HRMSys.DAL
{
public class SettingDAL
{
/// <summary>
/// 赋值的公用方法
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
public void setValue(string name, string value)
{
int i = sqlhelper.ExecuteNon("update T_Setting set Value=@Value where Name=@Name",
new SqlParameter("@Value",value),
new SqlParameter("@Name",name));
if (i != 1)
{
throw new Exception("影响的行数不是1,而是"+i);
}
}
/// <summary>
/// bool重载赋值公用方法
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
public void setValue(string name, bool value)
{
setValue(name, value.ToString());
}
/// <summary>
/// int 重载赋值公用方法
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
public void SetValue(string name, int value)
{
setValue(name, value.ToString());
}
/// <summary>
/// 得到指定name的值
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string getValue(string name)
{
DataTable table = sqlhelper.datatable("select Value from T_Setting where Name=@Name",
new SqlParameter("@Name",name));
if(table.Rows.Count<=0)
{
throw new Exception(name +"不存在!");
}
if(table.Rows.Count>1)
{
throw new Exception("出现"+table.Rows.Count+"条Name="+"的Setting数据");
}
else
{
DataRow row=table.Rows[0];
return (string)row["Value"];
}
}
/// <summary>
/// 不是重载,又返回类型的得到指定的值
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public bool GetBoolValue(string name)
{
return Convert.ToBoolean(getValue(name));
}
public int GetIntValue(string name)
{
return Convert.ToInt32(getValue(name));
}
}
}
三:SettingWindow.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRMSys.DAL;
namespace HYMSys.UI.SystemMgr
{
public partial class SettingWindow : Form
{
public SettingWindow()
{
InitializeComponent();
}
/// <summary>
///保存时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_ok_Click(object sender, EventArgs e)
{
SettingDAL set = new SettingDAL();
set.setValue("公司网站", tb_companyWeb.Text);
set.setValue("公司名称", tb_CompanyName.Text);
set.setValue("启用生日提醒",(bool) chk_remind.Checked);//将是否选中转换为bool值
set.setValue("生日提醒天数",tb_remindDay.Text);
set.setValue("员工工号前缀",tb_employFirst.Text);
}
private void SettingWindow_Load(object sender, EventArgs e)
{
SettingDAL dal = new SettingDAL();
tb_CompanyName.Text = dal.getValue("公司名称");
tb_companyWeb.Text = dal.getValue("公司网站");
chk_remind.Checked = dal.GetBoolValue("启用生日提醒");
tb_remindDay.Text = dal.getValue("生日提醒天数");
tb_employFirst.Text = dal.getValue("员工工号前缀");
}
}
}
winform学习日志(十九)------系统设置,布布扣,bubuko.com
winform学习日志(十九)------系统设置