/// <summary> /// 插入和更新 /// </summary> /// <param name="deptInfo"></param> /// <returns></returns> public long Save(SYSDeptInfo deptInfo) { long id = deptInfo.ID.Value; base.Save(deptInfo); if (deptInfo.IsUnit == 1) { deptInfo.UnitID = deptInfo.ID; deptInfo.ParentID = 0; deptInfo.Layer = 0; deptInfo.Path = ",-1," + deptInfo.ID + ","; } else { DeptInfo tempInfo = GetInfo <DeptInfo>(deptInfo.ParentID.Value); deptInfo.Layer = tempInfo.Layer + 1; deptInfo.Path = tempInfo.Path + deptInfo.ID + ","; } base.Save(deptInfo); if (id != 0) { //更新user表 string strSql = "UPDATE " + DBHelperProxy.FormatTable("User") + " SET DeptName = " + DBHelperProxy.FormatParameter("Name") + " WHERE DeptID=" + DBHelperProxy.FormatParameter("ID") + ";UPDATE " + DBHelperProxy.FormatTable("User") + " SET SLDeptName = " + DBHelperProxy.FormatParameter("Name") + " WHERE SLDeptID=" + DBHelperProxy.FormatParameter("ID") + ";"; DBHelperProxy.ExecuteScalar(strSql, DBHelperProxy.CreateParameter("Name", deptInfo.Name), DBHelperProxy.CreateParameter("ID", deptInfo.ID.Value)); } if (id == 0 && deptInfo.IsUnit == 1) { //新增单位时自动增加一个单位管理员 NewAdminOfUnit(deptInfo.ID.Value, deptInfo.ID.Value, deptInfo.Name); } return(deptInfo.ID.Value); }
public bool ImportDictXml(XmlDocument doc) { //因为专用数据字典表的,不想再建数据字典的数据实体了,所以用sql语句写死了 XmlElement root = doc.DocumentElement; foreach (XmlNode nodeDictType in root.ChildNodes) { if (nodeDictType.Attributes.Count == 0) { continue; } string attDictTypeNameValue = nodeDictType.Attributes["Name"].Value; string strSql = "select ID from DictType where name=" + DBHelperProxy.FormatParameter("DictTypeName"); var parDictTypeName = DBHelperProxy.CreateParameter("DictTypeName", attDictTypeNameValue); long dictTypeID = Convert.ToInt32(DBHelperProxy.ExecuteScalar(strSql, parDictTypeName)); var parDictTypeID = DBHelperProxy.CreateParameter("DictTypeID", dictTypeID); if (dictTypeID <= 0)//if no exists then add 'DictType ' { dictTypeID = DBHelperProxy.GetMaxID("DictType"); parDictTypeID.Value = dictTypeID; strSql = "insert into DictType(ID,Name) values (" + DBHelperProxy.FormatParameter("DictTypeID") + "," + DBHelperProxy.FormatParameter("DictTypeName") + ");"; if (DBHelperProxy.ExecuteNonQuery(strSql, parDictTypeID, parDictTypeName) == 0) { return(false); } } foreach (XmlNode nodeDictDir in nodeDictType.ChildNodes) { if (nodeDictDir.Attributes.Count == 0) { continue; } strSql = "if exists(select ID from DictDir where name=" + DBHelperProxy.FormatParameter("DictDirName") + " and TypeID=" + DBHelperProxy.FormatParameter("DictTypeID") + ")begin delete DictItem where DirID in (select ID from DictDir where name=" + DBHelperProxy.FormatParameter("DictDirName") + " and TypeID=" + DBHelperProxy.FormatParameter("DictTypeID") + ");delete DictDir where name=" + DBHelperProxy.FormatParameter("DictDirName") + " and TypeID=" + DBHelperProxy.FormatParameter("DictTypeID") + ";end;";//if exists then delete 'DictDir' and 'DictItem' strSql += "insert into DictDir(ID,UnitID,Name,TypeID,Remark) values (" + DBHelperProxy.FormatParameter("DictDirID") + "," + DBHelperProxy.FormatParameter("UnitID") + "," + DBHelperProxy.FormatParameter("DictDirName") + "," + DBHelperProxy.FormatParameter("DictTypeID") + "," + DBHelperProxy.FormatParameter("Remark") + ");"; var parDictDirID = DBHelperProxy.CreateParameter("DictDirID", DBHelperProxy.GetMaxID("DictDir")); var parDictDirName = getSqlParameter("DictDirName", nodeDictDir.Attributes["Name"]); var parUnitID = getSqlParameter("UnitID", nodeDictDir.Attributes["UnitID"]); var parDictDirRemark = getSqlParameter("Remark", nodeDictDir.Attributes["Remark"]); if (DBHelperProxy.ExecuteNonQuery(strSql, parDictDirName, parDictDirID, parUnitID, parDictTypeID, parDictDirRemark) == 0) { return(false); } foreach (XmlNode nodeDictItem in nodeDictDir.ChildNodes) { if (nodeDictItem.Attributes.Count == 0) { continue; } strSql = "insert into DictItem (ID,DirID,Name,Code,Sequence) values (" + DBHelperProxy.FormatParameter("DictItemID") + "," + DBHelperProxy.FormatParameter("DictDirID") + "," + DBHelperProxy.FormatParameter("DictItemName") + "," + DBHelperProxy.FormatParameter("DictItemCode") + "," + DBHelperProxy.FormatParameter("DictItemSequence") + ");"; var parDictItemID = DBHelperProxy.CreateParameter("DictItemID", DBHelperProxy.GetMaxID("DictItem")); var parDictItemName = getSqlParameter("DictItemName", nodeDictItem.Attributes["Name"]); var parDictItemCode = getSqlParameter("DictItemCode", nodeDictItem.Attributes["Code"]); var parDictItemSequence = getSqlParameter("DictItemSequence", nodeDictItem.Attributes["Sequence"]); if (DBHelperProxy.ExecuteNonQuery(strSql, parDictItemID, parDictItemName, parDictDirID, parDictItemCode, parDictItemSequence) == 0) { return(false); } } } } return(true); }