private void load() { SortedDictionary <int, UserOrgStructTable> userGroupList = new SortedDictionary <int, UserOrgStructTable>(); string userQuery = "SELECT [PKEY],[DEPARTMENT_OR_STAFF],[VALUE],[PARENT_PKEY] FROM "; userQuery += "[dbo].[BASE_USER_ORG_STRUCT] ORDER BY PKEY"; if (m_UserOrgList.Count > 0) { m_UserOrgList.Clear(); } using (DataTable dataTable = DatabaseAccessFactoryInstance.Instance.QueryDataTable(FormMain.DB_NAME, userQuery)) { foreach (DataRow row in dataTable.Rows) { UserOrgStructTable record = new UserOrgStructTable(); record.pkey = DbDataConvert.ToInt32(row[0]); record.departmentOrStaff = DbDataConvert.ToInt32(row[1]); record.value = DbDataConvert.ToInt32(row[2]); record.parentPkey = DbDataConvert.ToInt32(row[3]); userGroupList.Add(record.pkey, record); } } m_UserOrgList = userGroupList; }
public int getChildNodesCount(int pkey) { int childNodesCount = 0; UserOrgStructTable record = new UserOrgStructTable(); foreach (KeyValuePair <int, UserOrgStructTable> index in m_UserOrgList) { record = index.Value; if (record.parentPkey == pkey) { childNodesCount++; } } return(childNodesCount); }
public ArrayList getNodesFormParentID(int parentID) { ArrayList nodes = new ArrayList(); UserOrgStructTable record = new UserOrgStructTable(); foreach (KeyValuePair <int, UserOrgStructTable> index in m_UserOrgList) { record = index.Value; if (record.parentPkey == parentID) { nodes.Add(record); } } return(nodes); }
public int getPkeyFromValue(int value) { int pkey = -1; UserOrgStructTable record = new UserOrgStructTable(); foreach (KeyValuePair <int, UserOrgStructTable> index in m_UserOrgList) { record = index.Value; if (record.value == value) { pkey = record.pkey; break; } } return(pkey); }
public void insert(UserOrgStructTable userOrgStruct) { string insert = "INSERT INTO [dbo].[BASE_USER_ORG_STRUCT] ([DEPARTMENT_OR_STAFF],[VALUE],[PARENT_PKEY]) VALUES ("; insert += Convert.ToString(userOrgStruct.departmentOrStaff) + ","; insert += Convert.ToString(userOrgStruct.value) + ","; insert += Convert.ToString(userOrgStruct.parentPkey); insert += ")"; try { DatabaseAccessFactoryInstance.Instance.ExecuteCommand(FormMain.DB_NAME, insert); MessageBoxExtend.messageOK("数据保存成功"); load(); } catch (Exception error) { MessageBoxExtend.messageWarning(error.Message); return; } }