Пример #1
0
        private void eventContainer_SortObjects(XmlDocument xmlDoc, Dictionary <object, object> context)
        {
            XmlElement root          = xmlDoc.DocumentElement;
            string     strParentGuid = root.GetAttribute("OrgGuid");

            string strSql = @"
				UPDATE ORGANIZATIONS SET MODIFY_TIME = GETDATE() WHERE GUID = {0};
				SELECT GLOBAL_SORT FROM ORGANIZATIONS WHERE GUID = {0};
				"                ;

            strSql = string.Format(strSql, TSqlBuilder.Instance.CheckQuotationMark(strParentGuid, true));
            object obj = InnerCommon.ExecuteScalar(strSql);

            ExceptionHelper.TrueThrow(obj is DBNull, "对不起,你要排序的父部门不存在!");
            string strParentGlobalSort = obj.ToString();
            int    iSort;

            for (iSort = 0; iSort < root.ChildNodes.Count; iSort++)
            {
                XmlNode elem = root.ChildNodes[iSort];
                strSql = SetSortDataSql(elem.LocalName, elem.InnerText, strParentGlobalSort, strParentGuid, iSort);
                InnerCommon.ExecuteNonQuery(strSql);
            }

            strSql = @"
				SELECT * 
				FROM( 
						(SELECT 'USERS' AS OBJECTCLASS, USER_GUID AS GUID, PARENT_GUID, GLOBAL_SORT FROM OU_USERS WHERE STATUS > 1 AND GLOBAL_SORT LIKE {0} + '______') 
							UNION
						(SELECT 'GROUPS' AS OBJECTCLASS, GUID, PARENT_GUID, GLOBAL_SORT FROM GROUPS WHERE STATUS > 1 AND GLOBAL_SORT LIKE {0} + '______')
							UNION
						(SELECT 'ORGANIZATIONS' AS OBJECTCLASS, GUID, PARENT_GUID, GLOBAL_SORT FROM ORGANIZATIONS WHERE STATUS > 1 AND GLOBAL_SORT LIKE {0} + '______')
					)TEMPDB
				ORDER BY GLOBAL_SORT				
				"                ;
            strSql = string.Format(strSql, TSqlBuilder.Instance.CheckQuotationMark(strParentGlobalSort, true));
            DataSet ds = InnerCommon.ExecuteDataset(strSql);

            StringBuilder builder = new StringBuilder(1024);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                strSql = SetSortDataSql(OGUCommonDefine.DBValueToString(row["OBJECTCLASS"]),
                                        OGUCommonDefine.DBValueToString(row["GUID"]),
                                        strParentGlobalSort,
                                        strParentGuid,
                                        iSort++,
                                        builder.Length == 0);

                builder.Append(strSql + Environment.NewLine);
            }
            if (builder.Length > 0)
            {
                InnerCommon.ExecuteNonQuery(builder.ToString());
            }
        }
Пример #2
0
        private void MoveUsersToNewOrg(XmlElement elem, string strOrgGuid, Dictionary <object, object> context)
        {
            string strGuid          = elem.GetAttribute("GUID");
            string strOldParentGuid = elem.GetAttribute("PARENT_GUID");

            string strSql = @"
				DECLARE @ORG_ORIGINAL_SORT NVARCHAR(255);
				DECLARE @ORG_GLOBAL_SORT NVARCHAR(255);
				DECLARE @ORG_ALL_PATH_NAME NVARCHAR(255);

				DECLARE @NEW_INNER_SORT NVARCHAR(6);
				DECLARE @NEW_ALL_PATH_NAME NVARCHAR(255);

				/*获取被放入机构的相关数据*/
				UPDATE ORGANIZATIONS
					SET @ORG_ORIGINAL_SORT = ORIGINAL_SORT, 
						@ORG_GLOBAL_SORT = GLOBAL_SORT, 
						@NEW_INNER_SORT = REPLACE(STR(CHILDREN_COUNTER + 1, 6), ' ', '0'),
						@ORG_ALL_PATH_NAME = ALL_PATH_NAME, 
						CHILDREN_COUNTER = CHILDREN_COUNTER + 1
				WHERE GUID = {0};

				/*修改自身数据字段*/
				UPDATE OU_USERS
					SET PARENT_GUID = {0},
						INNER_SORT = @NEW_INNER_SORT, 
						ORIGINAL_SORT = @ORG_ORIGINAL_SORT + @NEW_INNER_SORT,
						GLOBAL_SORT = @ORG_GLOBAL_SORT + @NEW_INNER_SORT,
						ALL_PATH_NAME = @ORG_ALL_PATH_NAME + '\' + OBJ_NAME,
						@NEW_ALL_PATH_NAME = @ORG_ALL_PATH_NAME + '\' + OBJ_NAME
				WHERE USER_GUID = {1}
					AND PARENT_GUID = {2};

				/*获取新的数据值*/
				SELECT @ORG_ORIGINAL_SORT + @NEW_INNER_SORT AS ORIGINAL_SORT, 
					@ORG_GLOBAL_SORT + @NEW_INNER_SORT AS GLOBAL_SORT, 
					@NEW_INNER_SORT AS INNER_SORT, 
					@NEW_ALL_PATH_NAME AS ALL_PATH_NAME
				"                ;

            strSql = string.Format(strSql, TSqlBuilder.Instance.CheckQuotationMark(strOrgGuid, true),
                                   TSqlBuilder.Instance.CheckQuotationMark(strGuid, true),
                                   TSqlBuilder.Instance.CheckQuotationMark(strOldParentGuid, true));

            DataSet ds = InnerCommon.ExecuteDataset(strSql);

            SetMoveDataToXml(ds, elem, strOrgGuid);
        }
Пример #3
0
        /// <summary>
        /// 检测系统中是否存在相同All_PATH_NAME属性的对象,如果存在就得要抛出异常提醒。
        /// </summary>
        /// <param name="strAllPathName"></param>
        private static void CheckAllPathNameInSystem(string strAllPathName)
        {
            string strSql = @"
				SELECT * FROM ORGANIZATIONS WHERE ALL_PATH_NAME = {0};
				SELECT * FROM GROUPS WHERE ALL_PATH_NAME = {0};
				SELECT * FROM OU_USERS WHERE ALL_PATH_NAME = {0};"                ;

            strSql = string.Format(strSql, TSqlBuilder.Instance.CheckQuotationMark(strAllPathName, true));

            DataSet ds = InnerCommon.ExecuteDataset(strSql);

            foreach (DataTable table in ds.Tables)
            {
                ExceptionHelper.TrueThrow(table.Rows.Count > 0,
                                          "对不起,系统中已经存在您命名的对象"" + strAllPathName + ""!\n\n请修改"对象名称"后再保存!");
            }
        }
Пример #4
0
        private static void PrepareInsertOrgORGroups(XmlDocument xmlDoc, XmlDocument xsdDoc, Dictionary <object, object> context)
        {
            XmlNode nodeSet = xmlDoc.DocumentElement.SelectSingleNode(".//SET");

            CheckAllPathNameInSystem(nodeSet.SelectSingleNode(".//ALL_PATH_NAME").InnerText);

            string strSql = @"
				UPDATE ORGANIZATIONS 
					SET CHILDREN_COUNTER = CHILDREN_COUNTER + 1, MODIFY_TIME = GETDATE() 
				WHERE GUID = {0} ; 

				SELECT * 
				FROM ORGANIZATIONS 
				WHERE GUID = {0}"                ;

            strSql = string.Format(strSql, TSqlBuilder.Instance.CheckQuotationMark(nodeSet.SelectSingleNode("PARENT_GUID").InnerText, true));

            DataSet ds = InnerCommon.ExecuteDataset(strSql);

            ExceptionHelper.TrueThrow((ds == null) || (ds.Tables.Count == 0) || (ds.Tables[0].Rows.Count == 0), "对不起,系统中没有找到父部门对象!");
            DataRow row = ds.Tables[0].Rows[0];

            string strChildCounter = OGUCommonDefine.DBValueToString(row["CHILDREN_COUNTER"]);
            string strInnerSort    = CommonResource.OriginalSortDefault.Substring(0,
                                                                                  CommonResource.OriginalSortDefault.Length - strChildCounter.Length) + strChildCounter;

            XmlHelper.AppendNode(nodeSet, "INNER_SORT", strInnerSort);
            XmlHelper.AppendNode(nodeSet, "GLOBAL_SORT", OGUCommonDefine.DBValueToString(row["GLOBAL_SORT"]) + strInnerSort);
            XmlHelper.AppendNode(nodeSet, "ORIGINAL_SORT", OGUCommonDefine.DBValueToString(row["ORIGINAL_SORT"]) + strInnerSort);

            XmlHelper.AppendNode(nodeSet, "GUID", Guid.NewGuid().ToString());
            XmlHelper.AppendNode(nodeSet, "STATUS", "1");

            DataExtraCheck(xmlDoc, nodeSet.ParentNode.LocalName);//附加的数据检查

            strSql = InnerCommon.GetInsertSqlStr(xmlDoc, xsdDoc);

            context.Add("Sql", strSql);
        }
Пример #5
0
        /// <summary>
        /// 因为更新了机构的对象名称,要求同步修改其子孙的ALL_PATH_NAME
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <returns></returns>
        private static string UpdataOrganizationsChildrens(XmlDocument xmlDoc)
        {
            string strResult = string.Empty;

            XmlNode root = xmlDoc.DocumentElement.FirstChild;

            if (root.SelectSingleNode("SET/OBJ_NAME") != null)
            {
                string strNewOrgAPN = root.SelectSingleNode("SET/ALL_PATH_NAME").InnerText;
                string strGuid      = root.SelectSingleNode("WHERE/GUID").InnerText;
                ExceptionHelper.TrueThrow(strGuid.Length == 0, "对不起,没有找到确定修改的目标!");

                string  strSql = "SELECT * FROM ORGANIZATIONS WHERE GUID = " + TSqlBuilder.Instance.CheckQuotationMark(strGuid, true);
                DataSet ds     = InnerCommon.ExecuteDataset(strSql);
                ExceptionHelper.TrueThrow(ds.Tables[0].Rows.Count == 0, "对不起,没有找到确定修改的目标!");

                string strOldOrgAPN = OGUCommonDefine.DBValueToString(ds.Tables[0].Rows[0]["ALL_PATH_NAME"]);
                string strOrgOS     = OGUCommonDefine.DBValueToString(ds.Tables[0].Rows[0]["ORIGINAL_SORT"]);

                strResult = @"
				UPDATE ORGANIZATIONS 
					SET ALL_PATH_NAME = {0} + SUBSTRING(ALL_PATH_NAME, LEN({2}) + 1, LEN(ALL_PATH_NAME) - LEN({2})) 
				WHERE ORIGINAL_SORT LIKE {1} + '_%';  

				UPDATE GROUPS 
					SET ALL_PATH_NAME = {0} +  SUBSTRING(ALL_PATH_NAME, LEN({2}) + 1, LEN(ALL_PATH_NAME) - LEN({2})) 
				WHERE ORIGINAL_SORT LIKE {1} + '_%'; 

				UPDATE OU_USERS 
					SET ALL_PATH_NAME = {0} +  SUBSTRING(ALL_PATH_NAME, LEN({2}) + 1, LEN(ALL_PATH_NAME) - LEN({2})) 
				WHERE ORIGINAL_SORT LIKE {1} + '_%';"                ;

                strResult = string.Format(strResult, TSqlBuilder.Instance.CheckQuotationMark(strNewOrgAPN, true),
                                          TSqlBuilder.Instance.CheckQuotationMark(strOrgOS, true),
                                          TSqlBuilder.Instance.CheckQuotationMark(strOldOrgAPN, true));
            }

            return(strResult);
        }
Пример #6
0
        private static void PrepareInsertUserToOrganization(XmlDocument xmlDoc, XmlDocument userXsd, XmlDocument orgUserXsd, Dictionary <object, object> context)
        {
            XmlNode nodeSet = xmlDoc.DocumentElement.SelectSingleNode(".//SET");

            XmlNode tNode = nodeSet.SelectSingleNode(".//IC_CARD");

            if (tNode != null)
            {
                ExceptionHelper.FalseThrow(tNode.InnerText.Trim() == string.Empty || tNode.InnerText.Trim().Length == 16, "请注意,系统中要求“IC卡号”只能是16位!");
            }

            CheckAllPathNameInSystem(nodeSet.SelectSingleNode(".//ALL_PATH_NAME").InnerText);

            string strSql = @"
				UPDATE ORGANIZATIONS 
					SET CHILDREN_COUNTER = CHILDREN_COUNTER + 1, MODIFY_TIME = GETDATE() 
				WHERE GUID = {0} ; 

				SELECT * 
				FROM ORGANIZATIONS 
				WHERE GUID = {0}"                ;

            strSql = string.Format(strSql, TSqlBuilder.Instance.CheckQuotationMark(nodeSet.SelectSingleNode("PARENT_GUID").InnerText, true));

            DataSet ds = InnerCommon.ExecuteDataset(strSql);

            ExceptionHelper.TrueThrow((ds == null) || (ds.Tables.Count == 0) || (ds.Tables[0].Rows.Count == 0), "对不起,系统中没有找到父部门对象!");
            DataRow row = ds.Tables[0].Rows[0];

            string strChildCounter = OGUCommonDefine.DBValueToString(row["CHILDREN_COUNTER"]);
            string strInnerSort    = CommonResource.OriginalSortDefault.Substring(0,
                                                                                  CommonResource.OriginalSortDefault.Length - strChildCounter.Length) + strChildCounter;

            XmlHelper.AppendNode(nodeSet, "INNER_SORT", strInnerSort);
            XmlHelper.AppendNode(nodeSet, "GLOBAL_SORT", OGUCommonDefine.DBValueToString(row["GLOBAL_SORT"]) + strInnerSort);
            XmlHelper.AppendNode(nodeSet, "ORIGINAL_SORT", OGUCommonDefine.DBValueToString(row["ORIGINAL_SORT"]) + strInnerSort);

            XmlHelper.AppendNode(nodeSet, "STATUS", "1");
            string strUserGuid = Guid.NewGuid().ToString();

            XmlHelper.AppendNode(nodeSet, "GUID", strUserGuid);
            XmlHelper.AppendNode(nodeSet, "USER_GUID", strUserGuid);
            // 默认初始化登录口令[cgac\yuan_yong--2004/07/20]
            object oPwdGuid = InnerCommon.ExecuteScalar("SELECT TOP 1 GUID FROM PWD_ARITHMETIC WHERE VISIBLE = 1 ORDER BY SORT_ID");

            XmlHelper.AppendNode(nodeSet, "PWD_TYPE_GUID", oPwdGuid.ToString());
            XmlHelper.AppendNode(nodeSet, "USER_PWD", SecurityCalculate.PwdCalculate(oPwdGuid.ToString(), CommonResource.OriginalSortDefault));

            DataExtraCheck(xmlDoc, "USERS", "OU_USERS");//附加数据检查

            XmlDocument userXml = new XmlDocument();

            userXml.LoadXml("<Insert><USERS><SET/></USERS></Insert>");
            XmlDocument orgUserXml = new XmlDocument();

            orgUserXml.LoadXml("<Insert><OU_USERS><SET/></OU_USERS></Insert>");
            XmlDocToUsersAndOrgUsers(xmlDoc, userXml, userXsd, orgUserXml, orgUserXsd);

            strSql = InnerCommon.GetInsertSqlStr(userXml, userXsd);
            Debug.WriteLine(strSql, "USERS");

            strSql += " \n ; \n " + InnerCommon.GetInsertSqlStr(orgUserXml, orgUserXsd);
            Debug.WriteLine(strSql, "OU_USERS");

            context.Add("Sql", strSql);
        }