예제 #1
0
        //根据fieldid, tabid,找出prop,前提是fieldid非零
        public DBCustomProperty FindPropByID(string fieldid, string tabid)
        {
            DBCustomClass dbClass = FindDbClassByTabid(tabid);

            if (dbClass == null)
            {
                return(null);
            }

            //每个字段
            foreach (DBCustomProperty prop in dbClass)
            {
                if (prop != null && prop.Key == fieldid)
                {
                    return(prop);
                }
                if (prop.Value != null && prop.Value is DBCustomClass)
                {
                    DBCustomProperty ret = FindPropInPropByFieldID(prop, fieldid);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }
            return(null);
        }
예제 #2
0
        //递归体
        private DBCustomProperty FindPropInPropByFieldID(DBCustomProperty prop, string fieldid)
        {
            if (prop.Value == null)
            {
                return(null);                     //修正在从表字段中不能保存脚本的问题
            }
            DBCustomClass cls = prop.Value as DBCustomClass;

            //找正常属性
            foreach (DBCustomProperty iprop in cls)
            {
                //找到了
                if (iprop.Key == fieldid)
                {
                    return(iprop);
                }
            }

            //找虚拟字段之类的
            foreach (DBCustomProperty iprop in cls)
            {
                if (iprop.Value != null && iprop.Value is DBCustomClass)
                {
                    DBCustomProperty ret = FindPropInPropByFieldID(iprop, fieldid);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }

            return(null);
        }
예제 #3
0
파일: ObjPool.cs 프로젝트: viticm/pap2
        public static void DelProperty(DBCustomProperty prop)
        {
            if (!m_bEnabled)
                return;

            string strkey = GetPropKey(prop.FieldID, prop.ID, prop.Name, prop.Value, prop.ReadOnly, prop.Visible, prop.ValueType);
            if (!m_poolprop.ContainsKey(strkey))
            {
                m_poolprop.Add(strkey, prop);
            }
        }
예제 #4
0
파일: ObjPool.cs 프로젝트: weimingtom/pap2
        public static void DelProperty(DBCustomProperty prop)
        {
            if (!m_bEnabled)
            {
                return;
            }

            string strkey = GetPropKey(prop.FieldID, prop.ID, prop.Name, prop.Value, prop.ReadOnly, prop.Visible, prop.ValueType);

            if (!m_poolprop.ContainsKey(strkey))
            {
                m_poolprop.Add(strkey, prop);
            }
        }
예제 #5
0
파일: ObjPool.cs 프로젝트: viticm/pap2
 public static DBCustomProperty GetProperty(int nFieldID, CustomClass parent, string strID, string sName, object value, bool bReadOnly, bool bVisible, enumValueType vtType)
 {
     if (!m_bEnabled)
         return new DBCustomProperty(parent, strID, sName, value, bReadOnly, bVisible, vtType);
     string strkey = GetPropKey(nFieldID, strID, sName, value, bReadOnly, bVisible, vtType);
     DBCustomProperty prop = null;
     if (m_poolprop.ContainsKey(strkey))
     {
         prop = m_poolprop[strkey];
         m_poolprop.Remove(strkey);
         prop.Init(parent, value);
     }
     else
         prop = new DBCustomProperty(parent, strID, sName, value, bReadOnly, bVisible, vtType);
     prop.FieldID = nFieldID;
     return prop;
 }
예제 #6
0
        /// <summary>
        /// 保存脚本到数据库和内存,如果内存中没有tab页,则只进数据库.此函数目前只被脚本调用
        /// </summary>
        /// <param name="fieldid"></param>
        /// <param name="tabid"></param>
        /// <param name="strCode"></param>
        /// <returns></returns>
        public string SaveScriptIntoDatabase(string fieldid, string tabid, string strCode)
        {
            DBCustomClass    dbclass = FindDbClassByTabid(tabid);
            DBCustomProperty prop    = FindPropByID(fieldid, tabid);

            if (fieldid == "0")
            {
                //是Tab页脚本
                //DBCustomClass dbclass = FindDbClassByTabid(tabid);
                if (dbclass != null)
                {
                    dbclass.SetScriptCode(null, strCode);
                    dbclass.SaveScript(null);
                    string logcomment = string.Format("PropertyName={0}, FieldID={1}", "#", fieldid);
                    //logscript.Log(TimeLog.enumLogType.ltend, null, null, logcomment + " 脚本被更改!");
                    dbclass.DoScript(null);
                    return("OK");
                }
            }
            else
            {
                //是属性脚本
                //DBCustomClass dbclass = FindDbClassByTabid(tabid);
                //DBCustomProperty prop = FindPropByID(fieldid, tabid);
                if (prop != null && dbclass != null)
                {
                    //内存中有脚本
                    dbclass.SetScriptCode(prop, strCode);
                    dbclass.SaveScript(prop);
                    string logcomment = string.Format("PropertyName={0}, FieldID={1}", prop.Name, prop.Key);
                    //logscript.Log(TimeLog.enumLogType.ltend, null, null, logcomment + " 脚本被更改!");
                    dbclass.DoScript(prop);
                    return("OK");
                }
            }

            //内存中没有脚本,直接进数据库
            string strMainTable = prop == null ? "" : (prop.Parent as DBCustomClass).MainTable;

            return(DBProcess.SaveScriptByID(strMainTable, fieldid, tabid, strCode) ? "OK" : "NG");
        }
예제 #7
0
파일: ObjPool.cs 프로젝트: weimingtom/pap2
        public static DBCustomProperty GetProperty(int nFieldID, CustomClass parent, string strID, string sName, object value, bool bReadOnly, bool bVisible, enumValueType vtType)
        {
            if (!m_bEnabled)
            {
                return(new DBCustomProperty(parent, strID, sName, value, bReadOnly, bVisible, vtType));
            }
            string           strkey = GetPropKey(nFieldID, strID, sName, value, bReadOnly, bVisible, vtType);
            DBCustomProperty prop   = null;

            if (m_poolprop.ContainsKey(strkey))
            {
                prop = m_poolprop[strkey];
                m_poolprop.Remove(strkey);
                prop.Init(parent, value);
            }
            else
            {
                prop = new DBCustomProperty(parent, strID, sName, value, bReadOnly, bVisible, vtType);
            }
            prop.FieldID = nFieldID;
            return(prop);
        }
예제 #8
0
파일: BaseForm.cs 프로젝트: viticm/pap2
 //根据指定的属性,展开,注意:可能对从表多个记录情况,会只能找到第1条记录的内容
 public bool ExpandProperty(DBCustomProperty prop)
 {            
     GridItem root = GetRoot(GetPropertyGrid(prop));
     GridItem item = GetItem(root, prop.ID);
     if (item != null)
     {
         item.Expanded = true;
         return item.Expanded;
     }
     return false;
 }
예제 #9
0
파일: BaseForm.cs 프로젝트: viticm/pap2
 private PropertyGrid GetPropertyGrid(DBCustomProperty prop)
 {
     DBCustomClass cls = prop.Parent as DBCustomClass;
     while (cls.Parent != null)
     {
         if (cls.Parent is DBCustomClass)
         {
             cls = (DBCustomClass)(cls.Parent);
         }
     }
     PropertyGrid pg = null;
     foreach (PageDesc pd in m_Pages)
     {
         if (pd.dbClass == cls)
         {
             pg = pd.pg;
             break;
         }
     }
     return pg;
 }
예제 #10
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;
        }
예제 #11
0
        /// <summary>
        /// 获取字段的全路径名
        /// </summary>
        /// <param name="dbClass">当前DBClass</param>
        /// <returns>全路径名</returns>
        private string GetFullDisplayName(DBCustomProperty prop)
        {
            
            string fullDisplayName = prop.Name.Trim(); // 完整的显示名称
            DBCustomClass parent = prop.Parent as DBCustomClass;

            while (parent != null && parent.Property != null && parent.ParentFieldID > 0) // 存在父字段且不为分类
            {
                fullDisplayName = string.Format("{0}.", parent.Property.Name.Trim()) + fullDisplayName;
                parent = parent.Parent as DBCustomClass;
            }

            return fullDisplayName;
        }
예제 #12
0
        private bool SavePropertyData(DataRow SaveRow, DBCustomProperty prop, object value, int savetype, string strRemarks, bool bMainSaveRow)
        {
            string oldValue = SaveRow[prop.ID].ToString(); // 旧值
            if (oldValue == "") // 为空,取默认值
            {
                DataRow defaultRow = CustomClassCache.GetPropDefaultValue(m_strMainTableName);
                if (defaultRow != null) // 默认行非空
                {
                    oldValue = defaultRow[prop.ID].ToString();
                }
            }

            //保存到数据表中
            if (prop.ValueType != enumValueType.vtUnknown)
            {
                try
                {
                    SaveRow[prop.ID] = value;

                    DataRow def_row = CustomClassCache.GetPropDefaultValue(m_strMainTableName);
                    if (def_row != null)
                    {
                        bool IsProcessingDefaultRow = true;

                        if (m_findkeys != null)
                        {
                            foreach (object obj in m_findkeys)
                            {
                                if (obj.ToString().Trim() != "0")
                                {
                                    IsProcessingDefaultRow = false;
                                    break;
                                }
                            }
                        }
                        else if (prop.Tag is object[])
                        {
                            foreach (object obj in (object[])(prop.Tag))
                            {
                                if (obj.ToString().Trim() != "0")
                                {
                                    IsProcessingDefaultRow = false;
                                    break;
                                }
                            }
                        }

                        if (!IsProcessingDefaultRow) // 如果保存的本来就是default row,可以不用处理。
                        {
                            object def_val = def_row[prop.ID];

                            bool bPropIsCat = false;
                            if (m_strCats != null)
                            {
                                foreach (string cat in m_strCats)
                                {
                                    if (prop.ID == cat)
                                    {
                                        bPropIsCat = true;
                                        break;
                                    }
                                }
                            }

                            // 如果是主键, 也不必和默认值比较了, 并存成 DBNull
                            bool bPropIsPrimaryKeys = false;
                            foreach (DataColumn col in m_tbl_MainData.PrimaryKey)
                            {
                                if (col.ColumnName.ToLower() == prop.ID.ToLower())
                                {
                                    bPropIsPrimaryKeys = true;
                                    break;
                                }
                            }

                            if (def_val.ToString() == value.ToString() && !bPropIsCat && savetype == 0 && !bPropIsPrimaryKeys)
                                SaveRow[prop.ID] = DBNull.Value;
                        }
                    }
                }
                catch (Exception ex)
                {
                    SaveRow[prop.ID] = DBNull.Value;
                    Helper.AddLog(ex.Message);
                }
            }


            // 将旧值和新值统一转换为true和false
            string newValue = value.ToString(); // 新值
            if (prop.ValueType == enumValueType.vtBool) // 检查是否是真假值,显示值统一换为是和否
            {
                oldValue = DataRecord.TranslateValue(oldValue);
                newValue = DataRecord.TranslateValue(newValue);
            }
            oldValue = oldValue.Replace("'", "''");
            newValue = newValue.Replace("'", "''");

            if (!bMainSaveRow)
            {

                DataTable tbl = SaveRow.Table;
                string sqlrow = tbl.ExtendedProperties["sql"] as string;
                if (Helper.SaveTable(tbl, sqlrow, MainForm.conn) < 1)
                {
                    return false;
                }

                //修改内存显示用的默认值
                /*if (prop.Value is DBCustomClass)
                    prop.DefaultValue = ((DBCustomClass)prop.Value).Value;
                else
                    prop.DefaultValue = prop.Value;
                */
                prop.UpdateDefaultValue();



                // 记录表的值
                DataRecord dataRecord = DataRecord.GetDataRecord();
                dataRecord.Conn = m_conn; // sql连接
                dataRecord.ModelID = m_nModlId; // 模块id
                dataRecord.TabID = m_nModlTabId; // tab页id
                dataRecord.CurrentNode = m_lua["SelectedNode"] as TreeNode; // 树结点
                dataRecord.Time = DateTime.Now; // 当前修改时间
                dataRecord.UserName = Helper.GetHostName(); // 当前用户名
                dataRecord.OldValue = oldValue; // 字段的旧值        
                dataRecord.NewValue = newValue; // 字段的新值
                dataRecord.FieldDisplayName = GetFullDisplayName(prop); // 字段的全路径
                dataRecord.FieldID = int.Parse(prop.Key); // 字段的id
                dataRecord.Remarks = strRemarks;
                dataRecord.Save();
            }
            else
            {
                mRecordProList.Add(prop);
                string[] record = new string[4];
                record[0] = oldValue;
                record[1] = newValue;
                record[2] = GetFullDisplayName(prop);
                record[3] = prop.Key;
                mRecordList.Add(record);
            }

            return true;
        }
예제 #13
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);                
            }
        }
예제 #14
0
        //递归体
        private DBCustomProperty FindPropInPropByFieldID(DBCustomProperty prop , string fieldid)
        {
            if (prop.Value == null ) return null; //修正在从表字段中不能保存脚本的问题

                DBCustomClass cls = prop.Value as DBCustomClass;
                
                //找正常属性
                foreach(DBCustomProperty iprop in cls)
                {
                    //找到了
                    if (iprop.Key == fieldid) return iprop;
                }

                //找虚拟字段之类的
                foreach(DBCustomProperty iprop in cls)
                {

                    if (iprop.Value != null && iprop.Value is DBCustomClass)
                    {
                        DBCustomProperty ret = FindPropInPropByFieldID(iprop, fieldid);
                        if (ret != null) return ret;
                    }

                }

                return null;
        }