Пример #1
0
        private Dictionary <string, object> GetDomainNameValuePair(IDomain pDomain)
        {
            Dictionary <string, object> myDic = new Dictionary <string, object>();
            ICodedValueDomain           cv    = pDomain as ICodedValueDomain;

            for (int i = 0; i < cv.CodeCount; i++)
            {
                myDic.Add(cv.GetCodeName(i), cv.GetCodeValue(i));
            }
            return(myDic);
        }
Пример #2
0
        private void SetDomainTree()
        {
            if (comboBoxDomains.SelectedIndex < 0 || fieldNamesHasDomain.Count == 0)
            {
                return;
            }

            string     fieldName    = fieldNamesHasDomain[comboBoxDomains.SelectedIndex];
            int        index        = fieldinfos.IndexOf(fieldName);
            IFieldInfo field        = fieldinfos.Get(index);
            IDomain    domainSelect = field.Domain;

            if (domainSelect == null)
            {
                return;
            }

            nodekeyMap.Clear();
            this.treeViewDomain.Nodes.Clear();
            if (domainSelect.DomainType == gviDomainType.gviDomainCodedValue)
            {
                ICodedValueDomain codedomain = domainSelect as ICodedValueDomain;
                int nCodes = codedomain.CodeCount;
                for (int c = 0; c < nCodes; c++)
                {
                    string codename  = codedomain.GetCodeName(c);
                    object codevalue = codedomain.GetCodeValue(c);
                    this.treeViewDomain.Nodes.Add(codevalue.ToString(), codename, 2, 2);
                    nodekeyMap.Add(codename, c);

                    TreeNode pNode = this.treeViewDomain.Nodes.Find(codevalue.ToString(), true)[0];
                    pNode.Checked = true;
                }

                //其它值
                {
                    this.treeViewDomain.Nodes.Add("other", "other", 2, 2);
                    nodekeyMap.Add("other", nCodes);

                    TreeNode pNode = this.treeViewDomain.Nodes.Find("other", true)[0];
                    pNode.Checked = true;
                }
            }
            else
            {
                IRangeDomain rangedomain = domainSelect as IRangeDomain;
                object       minValue    = rangedomain.MinValue;
                object       maxValue    = rangedomain.MaxValue;
            }
        }
Пример #3
0
        private void FillControls(IDataSource ds)
        {
            IDomain           domain           = null;
            IRangeDomain      rangeDomain      = null;
            ICodedValueDomain codedValueDomain = null;

            try
            {
                this.mt.Columns.Add("name", typeof(string));
                this.mt.Columns.Add("description", typeof(string));
                this.mt.Columns.Add("ft", typeof(string));
                this.mt.Columns.Add("dt", typeof(string));
                this.mt.Columns.Add("GUID", typeof(System.Guid));
                this.mt.Columns.Add("IsNew", typeof(bool));
                string[] domainNames = ds.GetDomainNames();
                if (domainNames != null)
                {
                    for (int i = 0; i < domainNames.Length; i++)
                    {
                        this.curtable = new System.Data.DataTable();
                        domain        = ds.GetDomainByName(domainNames[i].ToString());
                        if (domain != null)
                        {
                            string      text  = (domain.DomainType == gviDomainType.gviDomainRange) ? "值域型": "枚举型";
                            string      text2 = this.ConvertFieldTypeByString(domain.FieldType);
                            System.Guid guid  = System.Guid.NewGuid();
                            this.mt.Rows.Add(new object[]
                            {
                                domain.Name,
                                domain.Description,
                                text2,
                                text,
                                guid,
                                false
                            });
                            if (text == "值域型")
                            {
                                rangeDomain = (domain as IRangeDomain);
                                this.curtable.Columns.Add(this.fieldMin, this.GetColumnTypeByString(text2));
                                this.curtable.Columns.Add(this.fieldMax, this.GetColumnTypeByString(text2));
                                this.curtable.Rows.Add(new object[]
                                {
                                    rangeDomain.MinValue,
                                    rangeDomain.MaxValue
                                });
                            }
                            else
                            {
                                this.curtable    = new System.Data.DataTable();
                                codedValueDomain = (domain as ICodedValueDomain);
                                this.curtable.Columns.Add(this.fieldValue, this.GetColumnTypeByString(text2));
                                this.curtable.Columns.Add(this.fieldCode, typeof(string));
                                for (int j = 0; j < codedValueDomain.CodeCount; j++)
                                {
                                    this.curtable.Rows.Add(new object[]
                                    {
                                        codedValueDomain.GetCodeValue(j),
                                        codedValueDomain.GetCodeName(j)
                                    });
                                }
                                for (int k = 0; k < 200; k++)
                                {
                                    this.curtable.Rows.Add(new object[]
                                    {
                                        null,
                                        ""
                                    });
                                }
                            }
                            this.reftable.Add(guid, this.curtable);
                        }
                    }
                }
                for (int l = 0; l < 100; l++)
                {
                    this.mt.Rows.Add(new object[]
                    {
                        "",
                        "",
                        "",
                        "",
                        System.Guid.NewGuid(),
                        true
                    });
                }
                this.gridControl1.DataSource = this.mt;
            }
            catch (System.Exception)
            {
            }
            finally
            {
                if (codedValueDomain != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(codedValueDomain);
                    codedValueDomain = null;
                }
                if (rangeDomain != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rangeDomain);
                    rangeDomain = null;
                }
                if (domain != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(domain);
                    domain = null;
                }
            }
        }
Пример #4
0
        private void LoadDsDomains()
        {
            IDomain           d  = null;
            IRangeDomain      rd = null;
            ICodedValueDomain cv = null;

            try
            {
                string[] domainList = ds.GetDomainNames();
                if (domainList != null)
                {
                    for (int l = 0; l < domainList.Length; l++)
                    {
                        DataTable curtable = new DataTable();
                        d = ds.GetDomainByName(domainList[l].ToString());
                        if (d == null)
                        {
                            continue;
                        }
                        string dt = d.DomainType == gviDomainType.gviDomainRange ? "值域型" : "枚举型";
                        string ft = ConvertFieldTypeByString(d.FieldType);

                        int iRowIndex = this.dgv_DomainAttr.Rows.Add(new object[] { d.Name, d.Description, ft, dt, false });
                        if (dt == "值域型")
                        {
                            rd = d as IRangeDomain;
                            curtable.Columns.Add(sMinFieldName, GetColumnTypeByString(ft));
                            curtable.Columns.Add(sMaxFieldName, GetColumnTypeByString(ft));
                            curtable.Rows.Add(new object[] { rd.MinValue, rd.MaxValue });
                        }
                        else
                        {
                            cv = d as ICodedValueDomain;
                            curtable.Columns.Add(sEmunFieldName, GetColumnTypeByString(ft));
                            curtable.Columns.Add(sDscribFieldName, typeof(string));
                            for (int k = 0; k < cv.CodeCount; k++)
                            {
                                curtable.Rows.Add(new object[] { cv.GetCodeValue(k), cv.GetCodeName(k) });
                            }
                            //添加空行
                            for (int m = 0; m < 200; m++)
                            {
                                curtable.Rows.Add(new object[] { null, "" });
                            }
                        }
                        this.dgv_DomainAttr.Rows[iRowIndex].Tag = curtable;
                    }
                }
                for (int i = 0; i < 100; i++)
                {
                    this.dgv_DomainAttr.Rows.Add(new object[] { "", "", "", "", true });
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (cv != null)
                {
                    //Marshal.ReleaseComObject(cv);
                    cv = null;
                }
                if (rd != null)
                {
                    //Marshal.ReleaseComObject(rd);
                    rd = null;
                }
                if (d != null)
                {
                    //Marshal.ReleaseComObject(d);
                    d = null;
                }
            }
        }
Пример #5
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            IDomain           domain = null;
            IRangeDomain      rd     = null;
            ICodedValueDomain cv     = null;
            IDomainFactory    df     = new DomainFactory();
            DataTable         table  = null;

            try
            {
                //保存时,删除操作才生效
                foreach (string s in deletedomains)
                {
                    ds.DeleteDomain(s);
                }
                for (int i = 0; i < this.dgv_DomainAttr.Rows.Count; i++)
                {
                    DataGridViewRow myRow       = this.dgv_DomainAttr.Rows[i];
                    string          name        = myRow.Cells["name"].Value == null ? "" : myRow.Cells["name"].Value.ToString();
                    string          description = myRow.Cells["description"].Value == null ? "" : myRow.Cells["description"].Value.ToString();
                    string          ft          = myRow.Cells["fieldtype"].Value == null ? "" : myRow.Cells["fieldtype"].Value.ToString();
                    string          dt          = myRow.Cells["domaintype"].Value == null ? "" : myRow.Cells["domaintype"].Value.ToString();
                    if (name.Equals(""))
                    {
                        continue;                         //名称为空,不创建
                    }
                    if (myRow.Tag == null)
                    {
                        continue;
                    }
                    if (ft.Equals("String") && dt.Equals("值域型"))
                    {
                        continue;
                    }
                    table = myRow.Tag as DataTable;
                    if (!HasDomain(name, ds))
                    {
                        if (dt == "值域型")
                        {
                            rd             = df.CreateRangeDomain(name, GetFDEFieldTypeByString(ft));
                            rd.Description = description;
                            rd.MinValue    = table.Rows[0].IsNull(sMinFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMinFieldName];
                            rd.MaxValue    = table.Rows[0].IsNull(sMaxFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMaxFieldName];

                            ds.AddDomain(rd);
                        }
                        else if (dt == "枚举型")
                        {
                            cv             = df.CreateCodedValueDomain(name, GetFDEFieldTypeByString(ft));
                            cv.Description = description;
                            for (int j = 0; j < table.Rows.Count; j++)
                            {
                                if (table.Rows[j][sDscribFieldName].ToString() != "")
                                {
                                    if (table.Rows[j].IsNull(sEmunFieldName))
                                    {
                                        continue;
                                    }
                                    cv.AddCode(table.Rows[j][sEmunFieldName], table.Rows[j][sDscribFieldName].ToString());
                                }
                            }
                            ds.AddDomain(cv);
                        }
                    }
                    else
                    {
                        domain = ds.GetDomainByName(name);
                        if (dt == "值域型")
                        {
                            rd             = domain as IRangeDomain;
                            rd.Description = description;
                            rd.MaxValue    = table.Rows[0].IsNull(sMaxFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMaxFieldName];
                            rd.MinValue    = table.Rows[0].IsNull(sMinFieldName) ? GetColumnDefaultValue(ft) : table.Rows[0][sMinFieldName];
                            ds.ModifyDomain(rd);
                        }
                        else
                        {
                            cv             = domain as ICodedValueDomain;
                            cv.Description = description;
                            int codecount = cv.CodeCount;
                            for (int a = 0; a < codecount; a++)
                            {
                                cv.DeleteCode(cv.GetCodeValue(0));
                            }
                            for (int l = 0; l < table.Rows.Count; l++)
                            {
                                if (table.Rows[l][sDscribFieldName].ToString() != "")
                                {
                                    if (table.Rows[l].IsNull(sEmunFieldName))
                                    {
                                        continue;
                                    }
                                    cv.AddCode(table.Rows[l][sEmunFieldName], table.Rows[l][sDscribFieldName].ToString());
                                }
                            }
                            ds.ModifyDomain(cv);
                        }
                    }
                }
                MessageBox.Show("保存成功!");
            }
            catch (COMException comEx)
            {
                MessageBox.Show(comEx.Message);
                this.DialogResult = DialogResult.None;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = DialogResult.None;
            }
            finally
            {
                if (cv != null)
                {
                    //Marshal.ReleaseComObject(cv);
                    cv = null;
                }
                if (rd != null)
                {
                    //Marshal.ReleaseComObject(rd);
                    rd = null;
                }
                if (domain != null)
                {
                    //Marshal.ReleaseComObject(domain);
                    domain = null;
                }
            }
        }