⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 framevalue.cs

📁 结构很好的三层数据访问组件。开放源码。是微软企业库数据访问的替代产品之一。
💻 CS
字号:
namespace FrameCountry
{
    using System;
    using System.Reflection;
    using System.Runtime.InteropServices;

    internal class FrameValue
    {
        private string ClassAlias = "VA";
        private int count = 0;
        private string DBType = "";
        private FrameCity frameCity = new FrameCity();
        private ValueList[] pList;

        public FrameValue(string dBType)
        {
            this.DBType = dBType;
        }

        public bool AddValue(int index, string Name, string Depiction, string DataType, string Col, ref string ErrorInfo)
        {
            string functionAlias = "04";
            try
            {
                if (((DataType.ToLower() != "string") && (DataType.ToLower() != "datetime")) && (DataType.ToLower() != "number"))
                {
                    throw new Exception("不支持数据类型:" + DataType.ToString() + " !");
                }
                this.pList[index].Name = Name;
                this.pList[index].Depiction = Depiction;
                this.pList[index].DataType = DataType;
                this.pList[index].Col = Col;
            }
            catch (Exception exception)
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "加载 Value 项错误:\n\r" + exception.Message);
                return false;
            }
            return true;
        }

        public void Clear()
        {
            for (int i = 0; i < this.count; i++)
            {
                this.pList[i].Value = null;
            }
        }

        public void CreatNew(int thecount)
        {
            this.count = thecount;
            this.pList = new ValueList[thecount];
        }

        public bool ReplaceValue(ref string returnSQL, string CommandName, ref string ErrorInfo)
        {
            string functionAlias = "02";
            string str2 = "";
            string str3 = "";
            int index = 0;
            try
            {
                switch (CommandName.ToLower())
                {
                    case "insert":
                        str2 = "(";
                        index = 0;
                        goto Label_01A3;

                    case "update":
                        index = 0;
                        goto Label_0280;

                    case "delete":
                    case "select":
                    case "other":
                    case "procedure":
                    case "procedurequery":
                    case "extendselect":
                    case "table":
                        goto Label_0309;

                    default:
                        throw new Exception("数据库操作类型 " + CommandName + " 不存在");
                }
            Label_0130:
                if (this.pList[index].Value != null)
                {
                    str2 = str2 + ", " + this.pList[index].Col;
                    str3 = str3 + ", " + this.frameCity.GetValueData(this.pList[index].Value, this.DBType, this.pList[index].DataType);
                }
                index++;
            Label_01A3:
                if (index < this.count)
                {
                    goto Label_0130;
                }
                if (index == 0)
                {
                    throw new Exception("操作类型 Insert 不存在 ValueList 项!");
                }
                returnSQL = str2.Replace("(,", "(") + ") values (" + str3.Substring(1, str3.Length - 1) + ")";
                goto Label_0309;
            Label_01F6:
                if (this.pList[index].Value != null)
                {
                    str2 = str2 + ", " + this.pList[index].Col + "=" + this.frameCity.GetValueData(this.pList[index].Value, this.DBType, this.pList[index].DataType);
                }
                index++;
            Label_0280:
                if (index < this.count)
                {
                    goto Label_01F6;
                }
                if (index == 0)
                {
                    throw new Exception("操作类型 Update 不存在 ValueList 项!");
                }
                returnSQL = " set " + str2.Substring(1, str2.Length - 1);
            }
            catch (Exception exception)
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "处理Value时出错:\n\r" + exception.Message);
                return false;
            }
        Label_0309:
            return true;
        }

        public int Count
        {
            get
            {
                return this.count;
            }
        }

        public string this[string index]
        {
            get
            {
                string functionAlias = "06";
                int num = -1;
                for (int i = 0; i < this.count; i++)
                {
                    if (this.pList[i].Name == index)
                    {
                        num = i;
                    }
                }
                if (-1 == num)
                {
                    throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "Value属性:" + index + " 项不存在!"));
                }
                return this.pList[num].Value;
            }
            set
            {
                string functionAlias = "06";
                int num = -1;
                for (int i = 0; i < this.count; i++)
                {
                    if (this.pList[i].Name == index)
                    {
                        num = i;
                    }
                }
                if (-1 == num)
                {
                    throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "Value属性:" + index + " 项不存在!"));
                }
                this.pList[num].Value = value;
            }
        }

        public string this[int index]
        {
            get
            {
                string functionAlias = "05";
                if ((index < 0) || (index > (this.count - 1)))
                {
                    throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, " Value属性:共存在 " + this.count.ToString() + " 项,索引 " + index.ToString() + " 越界!"));
                }
                return this.pList[index].Value;
            }
            set
            {
                string functionAlias = "06";
                if ((index < 0) || (index > (this.count - 1)))
                {
                    throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, " Value属性:共存在 " + this.count.ToString() + " 项,索引 " + index.ToString() + " 越界!"));
                }
                this.pList[index].Value = value;
            }
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct ValueList
        {
            public string Name;
            public string Depiction;
            public string DataType;
            public string Col;
            public string Value;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -