Пример #1
0
        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;
            }
        }
Пример #2
0
        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;
            }
        }