/// <summary> /// 增加一条数据 /// </summary> public string Add(Model.department model, string username, string realname) { if (model.de_type == 0) { return("请选择机构类别"); } if (string.IsNullOrEmpty(model.de_name)) { return("请填写机构全称"); } if (Exists(model.de_name, model.de_parentid.Value)) { return("同一个上级机构下不能存在相同的机构"); } if (model.de_isGroup.Value && ExistsGroup()) { return("已经存在总部的机构,不能再添加总部机构"); } if (model.de_type == 1) { if (string.IsNullOrEmpty(model.de_subname)) { return("请填写公司简称"); } if (string.IsNullOrEmpty(model.de_area)) { return("请填写公司简码"); } } else { model.de_subname = ""; model.de_area = ""; } Model.department depart = GetModel(model.de_parentid.Value); if (depart != null) { if (model.de_type == 1)//机构类别为公司时 { if (!depart.de_isGroup.Value) { return("上级机构为总公司时才能添加公司"); } } else { if (model.de_parentid == 0) { return("机构类别为部门或岗位时,上级机构必填"); } else { model.de_area = depart.de_area; } } } int id = dal.Add(model); if (id > 0) { if (model.de_type == 1) { Dictionary <string, string> dic = new Dictionary <string, string>(); DataTable dt = dal.GetList(0, "de_type=1", "de_sort asc,de_id asc").Tables[0]; if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { dic.Add(dr["de_area"].ToString(), dr["de_subname"].ToString()); } CacheHelper.Remove(DTKeys.COMPANY_AREA); CacheHelper.Insert(DTKeys.COMPANY_AREA, dic, 10);//重新写入缓存 } } Model.business_log logmodel = new Model.business_log(); logmodel.ol_relateID = id; logmodel.ol_title = "添加部门岗位"; logmodel.ol_content = "机构类别:" + Common.BusinessDict.departType()[model.de_type.Value] + "<br/>上级机构ID:" + model.de_parentid + "<br/>机构全称:" + model.de_name + "<br/>机构简称:" + model.de_subname + "<br/>名称简码:" + model.de_area + "<br/>是否总部:" + (model.de_isGroup.Value ? "是" : "否") + ""; logmodel.ol_operateDate = DateTime.Now; new business_log().Add(DTEnums.ActionEnum.Add.ToString(), logmodel, username, realname); return(""); } return("添加失败"); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Model.department model) { return(dal.Add(model)); }