public static void DelDBClass(DBCustomClass cls) { if (!m_bEnabled) return; string strkey = GetDBClassKey(cls.ParentFieldID); if (!m_pooldbclass.ContainsKey(strkey)) { m_pooldbclass.Add(strkey, cls); } }
public static DBCustomClass GetDBClass(object parent, LuaEx lua, int nTabId, int nParentFieldId, int nParentFieldType) { if (!m_bEnabled) return new DBCustomClass(parent, lua, nTabId, nParentFieldId, nParentFieldType); string strkey = GetDBClassKey(nParentFieldId); DBCustomClass cls = null; if (m_pooldbclass.ContainsKey(strkey)) { cls = m_pooldbclass[strkey]; m_pooldbclass.Remove(strkey); cls.ReInit(parent, nParentFieldType); } else cls = new DBCustomClass(parent, lua, nTabId, nParentFieldId, nParentFieldType); return cls; }
public static Hashtable[] GetComboCaches(string key, DBCustomClass dbClass) { if (m_htComboCaches[key] == null) { Hashtable[] htReturn = new Hashtable[3]; string[] keys = key.Split(new Char[] {','}); string strlisttable = keys[0]; string strliscondition = keys[1]; string strlistf = keys[2]; string strlistk = keys[3]; string strlistfex = keys[4]; string sql = "SELECT * FROM " + strlisttable; if (strliscondition.Length > 0) sql += " WHERE " + strliscondition; /*DataTable tbl = Helper.GetDataTable(sql, Conn);*/ DataTable tbl = GetDataTableWithKeyProxy(strlisttable, strliscondition, null); Hashtable comhashkeys = new Hashtable(); Hashtable comhashvalues = new Hashtable(); Hashtable comhashfieldsex = dbClass.GetListFieldExArray(strlistfex); // 下拉框可以获取一些额外的字段,以便于脚本访问从表字段内容 Hashtable modihash = comhashfieldsex == null ? null : (Hashtable)comhashfieldsex.Clone(); Hashtable comfieldsexContainer = new Hashtable(); foreach (DataRow comborow in tbl.Rows) { string strkey = dbClass.GetFieldStrNoLower(comborow, strlistk); string newStrListF = dbClass.GetFieldStr(comborow, strlistf) + "[" + strkey + "]"; comhashkeys[newStrListF] = strkey; comhashvalues[strkey] = newStrListF; if (comhashfieldsex != null) { foreach (string eachkey in comhashfieldsex.Keys) { if (comborow[eachkey] != null) { modihash[eachkey] = comborow[eachkey].ToString(); } else modihash[eachkey] = ""; } if (comhashfieldsex.Count > 0 && !comfieldsexContainer.ContainsKey(strkey)) comfieldsexContainer[strkey] = modihash.Clone(); // 每一行形成一个HASHTABLE } } htReturn[0] = comhashkeys; htReturn[1] = comhashvalues; htReturn[2] = comfieldsexContainer; // 每一行记录形成一个HASHTABLE,容器的KEY值中listfieldID值 if (m_htComboCaches.Keys.Count > comboCacheSize) { m_htComboCaches.Clear(); } m_htComboCaches[key] = htReturn; } return (Hashtable[])(m_htComboCaches[key]); }
// 把某个页的默认值设置为当前显示的值 private void SetPageValueIntoDefault(DBCustomClass dbClass) { foreach (DBCustomProperty prop in dbClass) { prop.UpdateDefaultValue(); if (prop.ValueType == enumValueType.vtExpandNode && prop.Value is DBCustomClass) { SetPageValueIntoDefault(prop.Value as DBCustomClass); } } }
/// <summary> /// 强制DBCustomClass在保存时刷新 /// </summary> /// <param name="dbCustomClass">当前DBCustomClass</param> private void ForceReloadOnSave(DBCustomClass dbCustomClass) { dbCustomClass.ReloadDataOnSave = true; foreach (CustomProperty customProperty in dbCustomClass) { if (customProperty.ValueType == enumValueType.vtExpandNode) { DBCustomClass childDBCustomClass = customProperty.Value as DBCustomClass; if (childDBCustomClass != null) { ForceReloadOnSave(childDBCustomClass); } } } }
private void Init(CustomProperty prop, DBCustomClass cls) { m_keyvaluehelper = new NewRowKeyValueHelper(m_keyvalue); m_newrowkeyvaluehelper = new NewRowKeyValueHelper(m_htnewrow); //用于在 onnewrecord事件中让用户可以有机会更改新记录的内容 DBCustomClass dbclass = cls; if (dbclass.ParentFieldType == 2) //如果是真实字段,要找到虚拟字段 { NewRecordForm frm = new NewRecordForm(); ArrayList arr = new ArrayList(); foreach (CustomProperty subprop in dbclass) { if (subprop.ValueType == enumValueType.vtExpandNode && subprop.Value is DBCustomClass) { DBCustomClass subdbclass = subprop.Value as DBCustomClass; if (subdbclass.ParentFieldType != 2) { //m_key = subprop.Key; //m_dbclass = subprop.Value as DBCustomClass; int nAddIdx = frm.listBox1.Items.Add(subprop.Name); arr.Add(subprop); //break; } } } if (frm.listBox1.Items.Count > 1) frm.listBox1.SelectedIndex = 0; if (frm.listBox1.Items.Count == 1 || (frm.listBox1.Items.Count > 1 && frm.listBox1.SelectedIndex >= 0 && frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)) { CustomProperty subprop = (frm.listBox1.Items.Count == 1 ? arr[0] : arr[frm.listBox1.SelectedIndex]) as CustomProperty; m_key = subprop.Key; m_dbclass = subprop.Value as DBCustomClass; m_opprop = subprop; } else throw new Exception("新建动作被取消。"); } else { m_opprop = prop; //m_key = null;//暂时置空 m_key = prop.Key; m_dbclass = cls; } if (m_dbclass == null || m_key == null) throw new Exception("不能在此字段中新建子表记录。"); m_findkeyvalues = new object[m_dbclass.DBPrimaryKey.Length]; for (int i = 0; i < m_findkeyvalues.Length; i++) { m_findkeyvalues[i] = null; } foreach (string strKeyField in m_dbclass.DBPrimaryKey) { m_keyvalue[strKeyField] = null; } }
private object selectObject(DBCustomClass dbClass, object[] tags) { CustomClass selectedObj = dbClass.ReloadDBData(tags); return selectedObj; }
public NewRowHelper(DBCustomClass cls) { Init(null, cls); }
//找到有效的父结点,用于1对多时,每条记录的脚本存储位置应该是属于虚拟字段结点, 而不是以字段名为名的结点中 private DBCustomClass _GetTopParent(DBCustomClass cls) { if (cls.IsVirtualField) return cls; if (cls.Parent is DBCustomClass) { return _GetTopParent((DBCustomClass)cls.Parent); } else { return null; } }
//按记录号排序:以记录号为父结点,以属性为叶结点组织显示 //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); } }
// 按字段名排序:以字段名为父结点,记录号为叶结点组织显示 // 一对多时,需要特殊处理,通过虚拟父结点(1,2,3为名的虚拟属性,一个属性代表一条唯一的记录) // 生成最子表中最低层的叶子结点 private void Load1MultipleRecord(object[] keyvalues) { bool lockRecord = false; // 默认行的子表记录是不能被修改的,所以加锁没意义,优化掉。 foreach (object key in keyvalues) { if (key.ToString() != "0") { lockRecord = true; break; } } foreach (string strcolname in m_listSortedCol) { // 虚拟字段,以子表一个字段名为名字 DBCustomClass ChildNodes = new DBCustomClass(this, m_lua, m_nModlTabId, m_nParentFieldId); // 虚拟字段下第二级可展开字段 ChildNodes.Load1MultipleRecordLine(strcolname, m_strPrimaryKeys, keyvalues, m_strDBPrimaryKeys, lockRecord); // 生成一对多的特殊情况 object[] args = (object[])(m_colName[strcolname]); int nFieldID = args[9] == DBNull.Value ? 0 : Convert.ToInt32(args[9]); DBCustomProperty p = ObjPool.GetProperty(nFieldID, this, strcolname, (string)args[0], ChildNodes, false, true, enumValueType.vtExpandNode); p.Name = (string)args[0]; // 中文名 p.Description = (string)args[1]; p.Category = (string)args[2]; // 类别名 p.Value = ChildNodes; p.Key = (string)args[9]; p.IsCanHideNode = (Parent != null); // 如果不是顶层结点,则是可以被隐藏的结点 p.ReadOnly = true; this.Add(p); //生成子记录的详细key值 ChildNodes.Value = "..."; ChildNodes.SetEvents(ChildNodes.AllEvents); } }
public queryCommand(DBCustomClass dc, object[] ao) { this.ao = ao; this.dc = dc; }