/// <summary> /// 行的数据转为实体 /// </summary> /// <param name="row">行</param> /// <returns>OilTableColEntity实体</returns> private S_UserEntity rowToEntity(DataGridViewRow row) { S_UserEntity user = new S_UserEntity(); user.ID = int.Parse(row.Cells["ID"].Value.ToString()); if (user.ID != 0) { S_UserBll s_UserBll = new S_UserBll(); S_UserEntity userOld = s_UserBll.getUser(user.ID); user.password = RIPP.Lib.Security.SecurityTool.BuildPassword(row.Cells["password"].Value.ToString().Trim() == "******" ? userOld.password : row.Cells["password"].Value.ToString().Trim()); } else { user.password = RIPP.Lib.Security.SecurityTool.BuildPassword(row.Cells["password"].Value.ToString().Trim()); } user.loginName = row.Cells["loginName"].Value.ToString(); user.realName = row.Cells["realName"].Value == null ? "": row.Cells["realName"].Value.ToString(); user.sex = row.Cells["sex"].Value == null ? false : (bool)row.Cells["sex"].Value; user.tel = row.Cells["tel"].Value == null ? "" : row.Cells["tel"].Value.ToString(); user.email = row.Cells["email"].Value == null ? "" : row.Cells["email"].Value.ToString(); user.addTime = DateTime.Now; user.role = row.Cells["role"].Value == null ? "role1" : (row.Cells["role"].Value.ToString().Trim() == "管理员" ? "role1" : "role2"); return(user); }
public int updateUser(S_UserEntity item) { List <S_UserEntity> itemTemps = this._access.Get(" loginName='" + item.loginName + "' and ID!=" + item.ID); if (itemTemps.Count != 0) //用户名不能重复 { return(-1); } return(this._access.Update(item, item.ID.ToString())); }
/// <summary> /// 添加用户 /// </summary> /// <param name="item"></param> /// <returns>-1,用户名重复</returns> public int addUser(S_UserEntity item) { List <S_UserEntity> itemTemps = this._access.Get(" loginName='" + item.loginName + "'"); if (itemTemps.Count() != 0) //用户名不能重复 { return(-1); } return(this._access.Insert(item)); }
/// <summary> /// 更新数据库,如果是新添加的行则添加数据库,否则更新数据库 /// </summary> /// <param name="col">OilTableColEntity实体</param> private void updateRow(S_UserEntity user) { S_UserBll s_UserBll = new S_UserBll(); if (user.ID != 0) //如果行在数据库中存在(即ID字段不为0)则从更新数据库,否则(该行是才添加的还没存到数据库)添加到数据库 { if (s_UserBll.updateUser(user) == -1) { MessageBox.Show("用户名重复!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } else { if (s_UserBll.addUser(user) == -1) { MessageBox.Show("用户名重复!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } }