------- WindowsPhone 7手机开发、.Net培训、期待与您交流! -------
五、(例子2续)管理员管理的知识:
数据的软删除
bool:IsDeleted
一个表引用另一张表的时候最好引用主键
DeleteById(Guid id)
Insert(Operator op)
public Operator[] ListAll()
ToOperator()
(add,edit,delete)
Commhelper.cs
{
public static string GetPwdSale()
{
ConfigurationManager.AppSettings["pwdSalt"];
}
}
SqlHelper.cs
OperatorDAL.cs
{
public Operator GetById(Guid id)
Upublic void pdate(Guid id,string userName,string realName)//不更新密码泛型的方法
Upublic void Update(Guid id,string userName,string realName,string pwd)//重载更新密码
}
Operator.cs
HRMSys.UI:
LoginWindow.xaml
MainWindow.xaml.cs
{
miOperatorMgr_Click()
{}
}
app.config
{
<connectionString></connectionString>
<appSettings><add key="pwdSalt" value="love@baijnig"/></appSettings>
}
OperatorEditUI.xaml.cs
{
public bool IsInsert;
public int EditingId;
btnOK_Click()
{
新增:
略(密码加盐GetMD5值处理)
编辑:
密码为空则保留现有密码,反之则把密码重置为用户密码
}
Window_Load//
{
}
}
OperatorListUI.xaml.cs:
btnAdd_Click()
{}
btnDelete_Click()
{
获取删除行,软删除,重新加载数据
}
btnEdit_Click()
{}
private void LoadData()
{
//加载数据
}
Window_Load
{加载数据}
六、复合搜索
<GropBox Header="搜索条件" DockPanel.Dock="Top" Height="100">
<Grid>
<CheckBox Content="姓名"/><TextBox>
<CheckBox Content="入职时间"/>一个时间段
<CheckBox Content="部门"/><ComboBox>
</Grid>
</GropBox>
DateTime.Today.AddMonths(-1);一个月之前
btnSearch_Click()
{
//动态拼SQL
List<string> whereList=new List<string>();
List<SqlParameter> parametersList=new List<SqlParameter>();
if(cbSearchByName.IsChecked==true)
{
whereList.Add("Name=@Name");
parametersList.Add(new SqlParameter("@Name",txtName.Text))
}
if(cbSearchByInDate.IsChecked==true)
{
whereList.Add("InDate between @InDateStart and @InDateEnd");
parametersList.Add(new SqlParamete("@nDateStart",txtnDateStart.Text));
parametersList.Add(new SqlParamete("@nDateEnd",txtnDateEnd.Text));
}
if(cbSearchByDept.IsChecked==true)
{
whereList.Add("DeptId=@Dept");
parametersList.Add(new SqlParameter("@Dept",cmbDept.SelectedValue));
}
string whereSql=string.Join(" and ", whereList);
string sql="select * from T_Employee";
if(whereSql>0)//勾选有查询条件
{
sql=sql+" where "+whereSql;
}
}
未完待续。。。。。。