public string InsertCategory(string name, string parentId) { if (string.IsNullOrEmpty(name)) { return("类型名称不能为空"); } if (string.IsNullOrEmpty(parentId)) { return("所属名称对应值不正确,请检查"); } Guid pId = Guid.Empty; if (!Guid.TryParse(parentId, out pId)) { return("所属名称对应值格式不正确"); } Model.Category model = new Model.Category(); model.CategoryName = name; model.ParentID = pId; model.Title = "All"; model.Sort = 0; model.Remark = string.Empty; model.LastUpdatedDate = DateTime.Now; BLL.Category cBll = new BLL.Category(); int effect = cBll.Insert(model); if (effect == 110) { return("已存在相同记录"); } if (effect > 0) { return("操作成功"); } else { return("操作失败"); } }
/// <summary> /// 保存数据 /// </summary> private void OnSave() { hBackToN.Value = (int.Parse(hBackToN.Value) + 1).ToString();; #region 获取输入并验证 string sName = txtCategoryname.Value.Trim(); string sParentID = "0"; string sRemark = txtCategoryname.Value.Trim(); if (ddlCategory.SelectedIndex > -1) { sParentID = ddlCategory.SelectedValue; } if (string.IsNullOrEmpty(sName)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "分类名称不能为空", "操作错误", "error"); return; } #endregion if (cBll == null) { cBll = new BLL.Category(); } Model.Category model = new Model.Category(); model.CategoryName = sName; model.ParentID = sParentID; model.Remark = sRemark; model.Sort = 0; model.CreateDate = DateTime.Now; model.Title = title; int result = -1; if (!string.IsNullOrEmpty(cId)) { model.NumberID = cId; result = cBll.Update(model); } else { result = cBll.Insert(model); } if (result == 110) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "分类名称已存在,请换一个再重试!"); return; } if (result > 0) { WebHelper.MessageBox.MessagerShow(this.Page, lbtnSave, "提交成功!"); //重新加载所属分类 InitCategoryList(ddlCategory); } else { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "提交失败,系统异常!", "系统提示"); } }