示例#1
0
        public bool OnLockRecord(bool bLock, DBCustomProperty prop, object[] findkeyvalues)
        {   
            RecordLock Lock;
            object[] keyvalue;
            int nLastServerVersion;
            if (prop == null || prop.Lock == null)
            {
                Lock = m_reclock;
                keyvalue = findkeyvalues;
                nLastServerVersion = m_reclock.LocalVersion;// m_nLastServerVersion;
            }
            else if (prop.Lock != null && prop.Tag != null)
            {
                Lock = prop.Lock;
                keyvalue = prop.Tag as object[];
                m_nRecordModifyCount = 0;
                nLastServerVersion = prop.LastVersion;
            }
            else
            {
                throw new Exception("系统内部错误,OnLockRecord 失败,请联系编辑器组相关同事。");
            }
      
            if (bLock)
            {
                if (m_nRecordModifyCount == 0 && (!Lock.Locked))// || Lock.UnLock(keyvalue)))
                {
                    if (Lock.Lock(keyvalue))
                    {
                        m_nRecordModifyCount++;
                        int serverver = Lock.GetServerLastVersion(keyvalue);
                        if (serverver != nLastServerVersion && serverver != 0)
                        {
                            MessageBox.Show("由于服务端数据已经更新,您当前修改的内容会被修正为服务端的内容。", "警告",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            //需要刷新当前数据才能开始编辑
                            //ReloadCurrentInfo();
                            OnAsynNotifyEvent(4, null);
                        }
                    }
                    else
                        return false;
                }
            }
            else //解锁
            {
                //先将从表中的锁全解了
                if (prop == null)
                {
                    foreach (DBCustomProperty subprop in this)
                    {
                        if (subprop.ValueType == enumValueType.vtExpandNode && subprop.Value is DBCustomClass)
                        {
                            DBCustomClass cls = ((DBCustomClass)subprop.Value);

                            if (!cls.ValueChanged) // 如果值没变的话就必要较进行重复的解锁操作 add by suntao
                            {
                                cls.OnLockRecord(bLock, null, cls.FindKeys);
                            }                            
                        }
                        else if (subprop.Tag != null && subprop.Tag is object[])
                        {
                            OnLockRecord(bLock, subprop, null);
                        }
                        //subprop.UpdateLastVersion();
                    }
                }
                if (Lock.Locked)
                {
                    if (Lock.UnLock(keyvalue) > 0)
                    {
                        m_nRecordModifyCount = 0;
                        if (prop != null && prop.Lock != null && prop.Tag != null)
                            prop.UpdateLastVersion();
                        //nLastServerVersion = Lock.GetServerLastVersion(keyvalue);//放在模块级,一次全更新,否则各TAB间的版本会不一致
                    }
                    else
                        return false;
                }
            }
            /*if (m_nRecordModifyCount > 0)
            {
                //解锁记录
            }
            m_nRecordModifyCount = 0;
             */
            return true;
        }
示例#2
0
        //按记录号排序:以记录号为父结点,以属性为叶结点组织显示
        //1对多另一种排序生成方式,以记录为虚拟字段,下属的为此记录相关的属性
        private void Load1MultipleRecordRecordMode(string[] parentKeys, object[] parentKeyValues, string[] primaryKeys)
        {
            object[] childKeys = null;

            // 遍历每条记录,并每条记录生成一个CustomClass,以记录号为名,将下面的内容包装起来
            DataRow[] rows = m_tbl_MainData.Select(GetFilter(parentKeys, parentKeyValues)); // "skillid = '28' and skilllevel = '1'");
            m_nRecordCound = rows.Length;

            for(int i = 0; i < rows.Length; i ++)
            {
                DataRow row = rows[i];
                DBCustomClass ChildNodes = new DBCustomClass(this, m_lua, m_nModlTabId, m_nParentFieldId); // 虚拟字段下第二级可展开字段
                childKeys = GetChildKeyValues(row, m_strDBPrimaryKeys);
                ChildNodes.Load1MultipleRecordRecordModeLine(m_strDBPrimaryKeys, childKeys); // 生成一对多的特殊情况,以记录号为树结点

                string strName = string.Format("{0}#", i + 1);
                DBCustomProperty p = new DBCustomProperty(this, strName, strName, ChildNodes, false, true, enumValueType.vtExpandNode); // 假属性暂不处理                

                bool lockRecord = false; // 默认行的子表记录是不能被修改的,所以加锁没意义,优化掉。

                foreach (object key in childKeys)
                {
                    if (key.ToString() != "0")
                    {
                        lockRecord = true;
                        break;
                    }
                }

                p.Lock = new RecordLockEx(Conn, MainTable, DBPrimaryKey, m_nModlId);

                if (lockRecord) // 只有在修改非默认行的子表记录时才加锁。
                {
                    p.UpdateLastVersion();
                }                

                p.Name = strName; // 中文名
                p.Description = "从表中的记录";
                p.Value = ChildNodes;
                p.Key = "-1";
                p.Tag = childKeys;
                p.IsCanHideNode = Parent != null; // 如果不是顶层结点,则是可以被隐藏的结点
                p.ReadOnly = true;
                this.Add(p);

                ChildNodes.Value = "...";
                ChildNodes.SetEvents(ChildNodes.AllEvents);                
            }
        }