//检查 唯一约束Name
//检查 唯一约束Name int count = new BLL.Funcs().GetRecordCount(string.Format("Name={0}", model.Name)); if (!CheckUniqueFieldByCount(EditID, count, preName, model.Name)) { FineUI.Alert.Show(Resources.WebResource.SaveFailed); return; }
//新增和编辑的唯一验证不一样,必须分别判断:
/// <summary> /// 检查唯一约束 /// </summary> /// <param name="editId">编辑id</param> /// <param name="count">根据当前Name查询的数量</param> /// <param name="preName">原Name值</param> /// <param name="newName">新Name值</param> /// <returns>是否唯一</returns> protected bool CheckUniqueFieldByCount(int editId, int count, string preName, string newName) { if (editId > 0) { //如果已存在 不是本身的Name if (count > 1 || (count == 1 && newName != preName)) { return false; } } else { //如果已存在Name if (count > 0) { return false; } } return true; }
时间: 2024-10-12 16:11:29