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

📄 labelsql.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
                                {
                                    labelInfo.TotalPub = reader.GetInt32(0);
                                }
                            }
                            else
                            {
                                labelInfo.TotalPub = 0;
                            }
                        }
                    }
                    catch
                    {
                        labelInfo.TotalPub = 0;
                    }
                }
            }
            else
            {
                str2 = str2.Replace("@pagesize", "1000").Replace("@startrow", "0");
            }
            OracleDataAdapter adapter = new OracleDataAdapter(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 (OracleException exception)
            {
                labelInfo.Error = 2;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"Oracle数据源读取错,原因:" + exception.Message + "]");
            }
            finally
            {
                adapter.Dispose();
            }
            connection.Dispose();
            return labelInfo;
        }

        public LabelInfo GetOutSqlQuery(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;
            }
            SqlConnection connection = new SqlConnection(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());
                SqlCommand command = new SqlCommand(str3.Replace("@startrow", num.ToString()), connection);
                if (labelInfo.PageSize > 0)
                {
                    try
                    {
                        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
            {
                str2 = str2.Replace("@pagesize", "1000").Replace("@startrow", "0");
            }
            SqlDataAdapter adapter = new SqlDataAdapter(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 (SqlException exception)
            {
                labelInfo.Error = 2;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"SQL数据源读取错,原因:" + exception.Message + "]");
            }
            finally
            {
                adapter.Dispose();
            }
            connection.Dispose();
            return labelInfo;
        }

        public int GetSqlCommand(LabelInfo labelInfo)
        {
            string str = labelInfo.LabelDefineData["LabelSqlString"];
            if (string.IsNullOrEmpty(str))
            {
                return -999;
            }
            str = PareProc(str, labelInfo);
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand sqlStringCommand = database.GetSqlStringCommand(str);
            try
            {
                return database.ExecuteNonQuery(sqlStringCommand);
            }
            catch (SqlException)
            {
                return -999;
            }
        }

        public LabelInfo GetSqlQuery(LabelInfo labelInfo)
        {
            DbCommand command2;
            string istr = labelInfo.LabelDefineData["LabelSqlString"];
            istr = PareProc(istr, labelInfo);
            if (string.IsNullOrEmpty(istr))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"查询命令为空!]");
            }
            Database database = DatabaseFactory.CreateDatabase();
            if (labelInfo.PageSize > 0)
            {
                string str2 = labelInfo.LabelDefineData["LabelSqlCount"];
                str2 = PareProc(str2, labelInfo);
                istr = istr.Replace("@pagesize", labelInfo.PageSize.ToString());
                str2 = str2.Replace("@pagesize", labelInfo.PageSize.ToString());
                int num = (labelInfo.Page - 1) * labelInfo.PageSize;
                if (num < 0)
                {
                    num = 0;
                }
                istr = istr.Replace("@startrow", num.ToString());
                str2 = str2.Replace("@startrow", num.ToString());
                DbCommand sqlStringCommand = database.GetSqlStringCommand(str2);
                if (labelInfo.PageSize <= 0)
                {
                    goto Label_016A;
                }
                using (IDataReader reader = database.ExecuteReader(sqlStringCommand))
                {
                    if (reader.Read())
                    {
                        if (reader[0] != DBNull.Value)
                        {
                            labelInfo.TotalPub = reader.GetInt32(0);
                        }
                    }
                    else
                    {
                        labelInfo.TotalPub = 0;
                    }
                    goto Label_016A;
                }
            }
            istr = istr.Replace("@pagesize", "1000").Replace("@startrow", "0");
        Label_016A:
            command2 = database.GetSqlStringCommand(istr);
            try
            {
                using (DataSet set = database.ExecuteDataSet(command2))
                {
                    if (labelInfo.TotalPub == 0)
                    {
                        DataTable table = set.Tables[0];
                        labelInfo.TotalPub = table.Rows.Count;
                    }
                    labelInfo.LabelContent = new StringBuilder(set.GetXml());
                    return labelInfo;
                }
            }
            catch (SqlException exception)
            {
                labelInfo.Error = 2;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"数据源读取错,原因:" + exception.Message + "]");
            }
            return labelInfo;
        }

        public int GetStoreCommand(LabelInfo labelInfo)
        {
            string str = labelInfo.LabelDefineData["LabelSqlString"];
            if (string.IsNullOrEmpty(str))
            {
                labelInfo.Error = 1;
                return -999;
            }
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand storedProcCommand = database.GetStoredProcCommand(str);
            foreach (string str2 in labelInfo.AttributesData.AllKeys)
            {
                database.AddInParameter(storedProcCommand, "@" + str2, DbType.String, labelInfo.AttributesData[str2]);
            }
            try
            {
                return database.ExecuteNonQuery(storedProcCommand);
            }
            catch (SqlException)
            {
                labelInfo.Error = 2;
                return -999;
            }
        }

        public LabelInfo GetStoreQuery(LabelInfo labelInfo)
        {
            string str = labelInfo.LabelDefineData["LabelSqlString"];
            if (string.IsNullOrEmpty(str))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"请指定存储过程]");
            }
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand storedProcCommand = database.GetStoredProcCommand(str);
            foreach (string str2 in labelInfo.AttributesData.AllKeys)
            {
                database.AddInParameter(storedProcCommand, "@" + str2, DbType.String, labelInfo.AttributesData[str2]);
            }
            try
            {
                using (DataSet set = database.ExecuteDataSet(storedProcCommand))
                {
                    labelInfo.LabelContent = new StringBuilder();
                    foreach (DataTable table in set.Tables)
                    {
                        labelInfo.TotalPub = table.Rows.Count;
                        labelInfo.LabelContent.Append(set.GetXml());
                    }
                    return labelInfo;
                }
            }
            catch (SqlException exception)
            {
                labelInfo.Error = 2;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"存储过程没有取得正确的数据,原因:" + exception.Message + "]");
            }
            return labelInfo;
        }

        public LabelInfo GetXmlQuery(LabelInfo labelInfo)
        {
            string path = labelInfo.LabelDefineData["LabelDataSource"];
            if (string.IsNullOrEmpty(path.ToString()))
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"XML地址为空!]");
                return labelInfo;
            }
            if ((path.ToLower().IndexOf("http://", 0, 7) < 0) && !Path.IsPathRooted(path))
            {
                path = Path.Combine(labelInfo.RootPath, path);
            }
            foreach (string str2 in labelInfo.AttributesData.AllKeys)
            {
                path = path.Replace("@" + str2, labelInfo.AttributesData[str2]);
            }
            path = path.Replace("@page", labelInfo.Page.ToString());
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(path.ToString());
                labelInfo.LabelContent = new StringBuilder(document.OuterXml);
            }
            catch (XmlException exception)
            {
                labelInfo.Error = 1;
                labelInfo.LabelContent = new StringBuilder("[err:标签\"" + labelInfo.OriginalData["id"] + "\"XML源\"" + path + "\"读取错误,原因:" + exception.Message);
            }
            return labelInfo;
        }

        private static string PareProc(string istr, LabelInfo labelInfo)
        {
            foreach (string str in labelInfo.AttributesData.AllKeys)
            {
                istr = istr.Replace("@" + str, labelInfo.AttributesData[str]);
            }
            return istr;
        }
    }
}

⌨️ 快捷键说明

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