示例#1
0
        /**
         * find any cycle happening in any refer o fletter between users
         * */
        private void checkForReferenceCycle(int letterId, int newFromUserId, int newToUserId)
        {
            ReferLetterEntity referEntity = getLastReferedEntity(letterId);

            if (referEntity == null)
            {
                return;
            }
            int lastFromUser = int.Parse(
                referEntity.Tables[0].Rows[0][ReferLetterEntity.FIELD_REFER_FROM_USER].ToString());

            if (lastFromUser == newToUserId)
            {
                //a cycle happened
                // persist it
                ReferenceCycleEntity cycleEntity = new ReferenceCycleEntity();
                DataRow dr = null;
                dr = cycleEntity.Tables[cycleEntity.TableName].NewRow();
                cycleEntity.FilledTableName = cycleEntity.TableName;


                dr[ReferenceCycleEntity.FIELD_FIRSTREFERDATE] = referEntity.Tables[0].Rows[0][ReferLetterEntity.FIELD_REFER_DATE];
                dr[ReferenceCycleEntity.FIELD_FIRSTFROMUSER]  = referEntity.Tables[0].Rows[0][ReferLetterEntity.FIELD_REFER_FROM_USER];
                dr[ReferenceCycleEntity.FIELD_FIRSTTOUSER]    = referEntity.Tables[0].Rows[0][ReferLetterEntity.FIELD_REFER_TO_USER];

                dr[ReferenceCycleEntity.FIELD_SECONDREFERDATE] = DateTime.Now;
                dr[ReferenceCycleEntity.FIELD_SECONDFROMUSER]  = newFromUserId;
                dr[ReferenceCycleEntity.FIELD_SECONDTOUSER]    = newToUserId;

                dr[ReferenceCycleEntity.FIELD_LETTERID] = letterId;

                cycleEntity.Tables[cycleEntity.TableName].Rows.Add(dr);

                ReferenceCycleBL referenceCycleBL = new ReferenceCycleBL();
                referenceCycleBL.add(cycleEntity);
            }
        }