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

📄 frameship.cs

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

    public class FrameShip
    {
        private string ClassAlias;
        private FrameCity frameCity;
        private int itemColumnCount;
        private DataSet ItemDS;
        private int recordType;
        private DataSet shipDS;

        public FrameShip()
        {
            this.ClassAlias = "SH";
            this.frameCity = new FrameCity();
            this.recordType = 1;
            string functionAlias = "11";
            string shipXML = "<?xml version = '1.0' encoding = 'UTF-8'?><Request><Info><ParamInfo><ValueList></ValueList><WhereList></WhereList></ParamInfo></Info></Request>";
            string errorInfo = "";
            if (!this.SetShip(shipXML, ref errorInfo))
            {
                throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "◇" + errorInfo));
            }
            if ((1 == this.recordType) && !this.WriteLog(shipXML, ref errorInfo))
            {
                throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "◇" + errorInfo));
            }
        }

        public FrameShip(string ShipXML)
        {
            this.ClassAlias = "SH";
            this.frameCity = new FrameCity();
            this.recordType = 1;
            string functionAlias = "00";
            string errorInfo = "";
            if (!this.SetShip(ShipXML, ref errorInfo))
            {
                throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "◇" + errorInfo));
            }
            if ((1 == this.recordType) && !this.WriteLog(ShipXML, ref errorInfo))
            {
                throw new Exception(this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "◇" + errorInfo));
            }
        }

        public string GetItem(int ItemIndex, string ParamName)
        {
            try
            {
                return this.ItemDS.Tables["ValueList"].Rows[ItemIndex][ParamName].ToString().Trim();
            }
            catch
            {
                return null;
            }
        }

        public int GetItemColumnCount()
        {
            try
            {
                return this.itemColumnCount;
            }
            catch
            {
                return 0;
            }
        }

        public string GetItemColumnName(int ItemIndex)
        {
            try
            {
                return this.ItemDS.Tables["ValueList"].Columns[ItemIndex].ColumnName;
            }
            catch
            {
                return null;
            }
        }

        public int GetItemCount()
        {
            try
            {
                return this.ItemDS.Tables["ValueList"].Rows.Count;
            }
            catch
            {
                return 0;
            }
        }

        public string GetParam(string ListName, string ParamName)
        {
            try
            {
                return this.shipDS.Tables[ListName].Rows[0][ParamName].ToString().Trim();
            }
            catch
            {
                return null;
            }
        }

        public int GetParamCount(string ListName)
        {
            try
            {
                return this.shipDS.Tables[ListName].Columns.Count;
            }
            catch
            {
                return 0;
            }
        }

        public string GetParamName(string ListName, int ParamIndex)
        {
            try
            {
                return this.shipDS.Tables[ListName].Columns[ParamIndex].ColumnName;
            }
            catch
            {
                return null;
            }
        }

        public bool SetShip(string ShipXML, ref string ErrorInfo)
        {
            string functionAlias = "01";
            this.shipDS = new DataSet();
            this.ItemDS = new DataSet();
            XmlDocument document = new XmlDocument();
            this.itemColumnCount = 0;
            string errorInfo = "";
            try
            {
                document.LoadXml(ShipXML);
            }
            catch (Exception exception)
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "加载访问字符串错误!\n\r错误信息如下:\n\r" + exception.Message);
                return false;
            }
            if (!this.WriteLog(ShipXML, ref errorInfo))
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "◇" + errorInfo);
                return false;
            }
            try
            {
                this.shipDS.Tables.Add("Request");
                DataRow row = this.shipDS.Tables["Request"].NewRow();
                for (int i = 0; i < document.SelectNodes("./Request")[0].ChildNodes.Count; i++)
                {
                    if (document.SelectNodes("./Request")[0].ChildNodes[i].Name != "Info")
                    {
                        this.shipDS.Tables["Request"].Columns.Add(document.SelectNodes("./Request")[0].ChildNodes[i].Name);
                        row[document.SelectNodes("./Request")[0].ChildNodes[i].Name] = document.SelectNodes("./Request")[0].ChildNodes[i].InnerText;
                    }
                }
                this.shipDS.Tables["Request"].Rows.Add(row);
            }
            catch (Exception exception2)
            {
                ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "加载访问字符串 Request 错误!\n\r错误信息如下:\n\r" + exception2.Message);
                return false;
            }
            try
            {
                this.shipDS.Tables.Add("ValueList");
                DataRow row2 = this.shipDS.Tables["ValueList"].NewRow();
                for (int j = 0; j < document.SelectNodes("./Request/Info/ParamInfo/ValueList")[0].ChildNodes.Count; j++)
                {
                    this.shipDS.Tables["ValueList"].Columns.Add(document.SelectNodes("./Request/Info/ParamInfo/ValueList")[0].ChildNodes[j].Name);
                    row2[document.SelectNodes("./Request/Info/ParamInfo/ValueList")[0].ChildNodes[j].Name] = document.SelectNodes("./Request/Info/ParamInfo/ValueList")[0].ChildNodes[j].InnerText;
                }
                this.shipDS.Tables["ValueList"].Rows.Add(row2);
            }
            catch (Exception exception3)
            {
                if (exception3.GetType().ToString() == "System.NullReferenceException")
                {
                    this.shipDS.Tables["ValueList"].Columns.Clear();
                }
                else
                {
                    ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "加载访问字符串 ValueList 错误!\n\r错误信息如下:\n\r" + exception3.Message);
                    return false;
                }
            }
            try
            {
                this.shipDS.Tables.Add("WhereList");
                DataRow row3 = this.shipDS.Tables["WhereList"].NewRow();
                for (int k = 0; k < document.SelectNodes("./Request/Info/ParamInfo/WhereList")[0].ChildNodes.Count; k++)
                {
                    this.shipDS.Tables["WhereList"].Columns.Add(document.SelectNodes("./Request/Info/ParamInfo/WhereList")[0].ChildNodes[k].Name);
                    row3[document.SelectNodes("./Request/Info/ParamInfo/WhereList")[0].ChildNodes[k].Name] = document.SelectNodes("./Request/Info/ParamInfo/WhereList")[0].ChildNodes[k].InnerText;
                }
                this.shipDS.Tables["WhereList"].Rows.Add(row3);
            }
            catch (Exception exception4)
            {
                if (exception4.GetType().ToString() == "System.NullReferenceException")
                {
                    this.shipDS.Tables["WhereList"].Columns.Clear();
                }
                else
                {
                    ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "加载访问字符串 WhereList 错误!\n\r错误信息如下:\n\r" + exception4.Message);
                    return false;
                }
            }
            bool flag = true;
            try
            {
                string s = "<?xml version = '1.0' encoding = 'GB2312'?><Items>" + document.SelectNodes("./Request/Info/ParamInfo/Items")[0].InnerXml + "</Items>";
                flag = false;
                StringReader reader = new StringReader(s);
                this.ItemDS.ReadXml(reader, XmlReadMode.Auto);
                this.itemColumnCount = this.ItemDS.Tables["ValueList"].Columns.Count;
            }
            catch (Exception exception5)
            {
                if (flag)
                {
                    this.ItemDS.Tables.Add("ValueList");
                    this.itemColumnCount = 0;
                }
                else
                {
                    ErrorInfo = this.frameCity.DealErrorInfo(this.ClassAlias, functionAlias, "加载访问字符串 Items 错误!\n\r错误信息如下:\n\r" + exception5.Message);
                }
            }
            return true;
        }

        private bool WriteLog(string TransXML, ref string ErrorInfo)
        {
            string functionAlias = "09";
            string errorInfo = "";
            FrameCity city = new FrameCity();
            int num = 0x3e8 + DateTime.Now.Millisecond;
            string str4 = DateTime.Now.ToString() + "." + num.ToString().Substring(1, 3);
            switch (this.recordType)
            {
                case 1:
                {
                    string writeStr = "┏━━━━━━━━━━ FrameShip Record ━━━━━━━━━━┓\n";
                    writeStr = ((writeStr + "┣DateTime: " + str4 + "\n") + "┣━━━━━━┫Information\n" + TransXML + "\n") + "┗━━━━━━━━━━━━━ End ━━━━━━━━━━━━━━┛";
                    if (!city.WriteFrameShipLog(writeStr, ref errorInfo))
                    {
                        ErrorInfo = city.DealErrorInfo(this.ClassAlias, functionAlias, "◇" + errorInfo);
                        return false;
                    }
                    break;
                }
            }
            return true;
        }

        public int RecordType
        {
            get
            {
                return this.recordType;
            }
            set
            {
                if ((value == 0) || (value == 1))
                {
                    this.recordType = value;
                }
                else
                {
                    this.recordType = 1;
                }
            }
        }
    }
}

⌨️ 快捷键说明

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