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

📄 labelsql.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace PowerEasy.SqlServerDal.TemplateProc
{
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using PowerEasy.IDal.TemplateProc;
    using PowerEasy.Model.TemplateProc;
    using System;
    using System.Data;
    using System.Data.Common;
    using System.Data.Odbc;
    using System.Data.OleDb;
    using System.Data.OracleClient;
    using System.Data.SqlClient;
    using System.IO;
    using System.Text;
    using System.Xml;

    public sealed class LabelSql : ILabelProc
    {
        public LabelInfo GetOdbcQuery(LabelInfo labelInfo)
        {
            string str = labelInfo.LabelDefineData["LabelDataSource"];
            string str2 = labelInfo.LabelDefineData["LabelSqlString"];
            if (string.IsNullOrEmpty(str))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"数据源连接为空!]");
                return labelInfo;
            }
            if (string.IsNullOrEmpty(str2))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"查询语句为空!]");
                return labelInfo;
            }
            str = PareProc(str, labelInfo);
            str2 = PareProc(str2, labelInfo);
            if (labelInfo.PageSize > 0)
            {
                OdbcDataAdapter adapter;
                string istr = labelInfo.LabelDefineData["LabelSqlPage"];
                string str4 = labelInfo.LabelDefineData["LabelSqlCount"];
                istr = PareProc(istr, labelInfo);
                str4 = PareProc(str4, labelInfo);
                if (string.IsNullOrEmpty(istr))
                {
                    labelInfo.Error = 1;
                    labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"分页查询语句为空!]");
                    return labelInfo;
                }
                if (string.IsNullOrEmpty(str4))
                {
                    labelInfo.Error = 1;
                    labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"统计查询语句为空!]");
                    return labelInfo;
                }
                str = str.Replace("@page", labelInfo.Page.ToString());
                str2 = str2.Replace("@pagesize", labelInfo.PageSize.ToString());
                istr = istr.Replace("@pagesize", labelInfo.PageSize.ToString());
                int num = (labelInfo.Page - 1) * labelInfo.PageSize;
                if (num < 0)
                {
                    num = 0;
                }
                istr = istr.Replace("@startrow", Convert.ToString(num));
                OdbcConnection connection = new OdbcConnection(str);
                connection.Open();
                if (!string.IsNullOrEmpty(str4))
                {
                    try
                    {
                        OdbcCommand command = new OdbcCommand(str4, connection);
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (reader[0] != DBNull.Value)
                                {
                                    labelInfo.TotalPub = reader.GetInt32(0);
                                }
                            }
                            else
                            {
                                labelInfo.TotalPub = 0;
                            }
                        }
                    }
                    catch
                    {
                        labelInfo.TotalPub = 0;
                    }
                }
                else
                {
                    labelInfo.TotalPub = 0;
                }
                if ((labelInfo.Page > 1) && !string.IsNullOrEmpty(istr))
                {
                    adapter = new OdbcDataAdapter(istr, connection);
                }
                else
                {
                    adapter = new OdbcDataAdapter(str2, connection);
                }
                DataSet dataSet = new DataSet();
                try
                {
                    adapter.Fill(dataSet);
                    if (labelInfo.TotalPub == 0)
                    {
                        DataTable table = dataSet.Tables[0];
                        labelInfo.TotalPub = table.Rows.Count;
                    }
                    labelInfo.LabelContent = new StringBuilder(dataSet.GetXml());
                }
                catch (OdbcException exception)
                {
                    labelInfo.Error = 2;
                    labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"ODBC数据源错误,原因:" + exception.Message + "]");
                }
                finally
                {
                    adapter.Dispose();
                }
                connection.Dispose();
                return labelInfo;
            }
            str2 = str2.Replace("@pagesize", "500");
            OdbcConnection selectConnection = new OdbcConnection(str);
            selectConnection.Open();
            OdbcDataAdapter adapter2 = new OdbcDataAdapter(str2, selectConnection);
            try
            {
                DataSet set2 = new DataSet();
                adapter2.Fill(set2);
                DataTable table2 = set2.Tables[0];
                labelInfo.TotalPub = table2.Rows.Count;
                labelInfo.LabelContent = new StringBuilder(set2.GetXml());
            }
            catch (OdbcException exception2)
            {
                labelInfo.Error = 2;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"ODBC数据源读取错误,原因:" + exception2.Message + "]");
            }
            finally
            {
                adapter2.Dispose();
                selectConnection.Dispose();
            }
            return labelInfo;
        }

        public LabelInfo GetOleQuery(LabelInfo labelInfo)
        {
            string istr = labelInfo.LabelDefineData["LabelDataSource"];
            string str2 = labelInfo.LabelDefineData["LabelSqlString"];
            istr = PareProc(istr, labelInfo);
            str2 = PareProc(str2, labelInfo);
            if (string.IsNullOrEmpty(istr))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"数据源连接为空!]");
                return labelInfo;
            }
            if (string.IsNullOrEmpty(str2))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"查询语句为空!]");
                return labelInfo;
            }
            if (labelInfo.PageSize > 0)
            {
                OleDbDataAdapter adapter;
                string str3 = labelInfo.LabelDefineData["LabelSqlPage"];
                string str4 = labelInfo.LabelDefineData["LabelSqlCount"];
                str3 = PareProc(str3, labelInfo);
                str4 = PareProc(str4, labelInfo);
                if (string.IsNullOrEmpty(str3))
                {
                    labelInfo.Error = 1;
                    labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"分页查询语句为空!]");
                    return labelInfo;
                }
                if (string.IsNullOrEmpty(str4))
                {
                    labelInfo.Error = 1;
                    labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"统计查询语句为空!]");
                    return labelInfo;
                }
                istr = istr.Replace("@page", labelInfo.Page.ToString());
                str2 = str2.Replace("@pagesize", labelInfo.PageSize.ToString());
                str3 = str3.Replace("@pagesize", labelInfo.PageSize.ToString());
                int num = (labelInfo.Page - 1) * labelInfo.PageSize;
                if (num < 0)
                {
                    num = 0;
                }
                str3 = str3.Replace("@startrow", Convert.ToString(num));
                OleDbConnection connection = new OleDbConnection(istr);
                connection.Open();
                if (!string.IsNullOrEmpty(str4))
                {
                    try
                    {
                        OleDbCommand command = new OleDbCommand(str4, connection);
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (reader[0] != DBNull.Value)
                                {
                                    labelInfo.TotalPub = reader.GetInt32(0);
                                }
                            }
                            else
                            {
                                labelInfo.TotalPub = 0;
                            }
                        }
                    }
                    catch
                    {
                        labelInfo.TotalPub = 0;
                    }
                }
                else
                {
                    labelInfo.TotalPub = 0;
                }
                if (labelInfo.Page > 1)
                {
                    adapter = new OleDbDataAdapter(str3, connection);
                }
                else
                {
                    adapter = new OleDbDataAdapter(str2, connection);
                }
                DataSet dataSet = new DataSet();
                try
                {
                    adapter.Fill(dataSet);
                    if (labelInfo.TotalPub == 0)
                    {
                        DataTable table = dataSet.Tables[0];
                        labelInfo.TotalPub = table.Rows.Count;
                    }
                    labelInfo.LabelContent = new StringBuilder(dataSet.GetXml());
                }
                catch (OleDbException exception)
                {
                    labelInfo.Error = 2;
                    labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"错误,原因:" + exception.Message + "]");
                }
                finally
                {
                    adapter.Dispose();
                }
                connection.Dispose();
                return labelInfo;
            }
            str2 = str2.Replace("@pagesize", "500");
            OleDbConnection selectConnection = new OleDbConnection(istr);
            selectConnection.Open();
            OleDbDataAdapter adapter2 = new OleDbDataAdapter(str2, selectConnection);
            try
            {
                DataSet set2 = new DataSet();
                adapter2.Fill(set2);
                DataTable table2 = set2.Tables[0];
                labelInfo.TotalPub = table2.Rows.Count;
                labelInfo.LabelContent = new StringBuilder(set2.GetXml());
            }
            catch (OleDbException exception2)
            {
                labelInfo.Error = 2;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"数据源[" + istr + "]错误,原因:" + exception2.Message + "]");
            }
            finally
            {
                adapter2.Dispose();
                selectConnection.Dispose();
            }
            return labelInfo;
        }

        public LabelInfo GetOracleQuery(LabelInfo labelInfo)
        {
            string istr = labelInfo.LabelDefineData["LabelDataSource"];
            string str2 = labelInfo.LabelDefineData["LabelSqlString"];
            istr = PareProc(istr, labelInfo);
            str2 = PareProc(str2, labelInfo);
            if (string.IsNullOrEmpty(istr))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"数据源连接为空!]");
                return labelInfo;
            }
            if (string.IsNullOrEmpty(str2))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"查询语句为空!]");
                return labelInfo;
            }
            OracleConnection connection = new OracleConnection(istr);
            connection.Open();
            if (labelInfo.PageSize > 0)
            {
                string str3 = labelInfo.LabelDefineData["LabelSqlCount"];
                str3 = PareProc(str3, labelInfo);
                if (string.IsNullOrEmpty(str3))
                {
                    labelInfo.Error = 1;
                    labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"统计查询语句为空!]");
                    return labelInfo;
                }
                str2 = str2.Replace("@pagesize", labelInfo.PageSize.ToString());
                str3 = str3.Replace("@pagesize", labelInfo.PageSize.ToString());
                int num = (labelInfo.Page - 1) * labelInfo.PageSize;
                if (num < 0)
                {
                    num = 0;
                }
                str2 = str2.Replace("@startrow", num.ToString());
                OracleCommand command = new OracleCommand(str3.Replace("@startrow", num.ToString()), connection);
                if (labelInfo.PageSize > 0)
                {
                    try
                    {
                        using (IDataReader reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (reader[0] != DBNull.Value)

⌨️ 快捷键说明

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