Beispiel #1
0
        /// <summary>
        /// 程序事务处理
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="trans"></param>
        /// <param name="cmdType"></param>
        /// <param name="cmdText"></param>
        /// <param name="commandParameters"></param>
        /// <returns></returns>
        public int ExecuteNonQuery(OracleConnection connection, OracleTransaction trans, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
        {
            int           val = 0;
            OracleCommand cmd = new OracleCommand();

            try
            {
                PrepareCommand(cmd, connection, trans, cmdType, cmdText, commandParameters);

                val = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
            }
            catch (System.Data.OracleClient.OracleException E)
            {
                if (trans != null)
                {
                    TextLog.Append("ERROR连接数据库异常,事务回滚," + E.Message + "\r\n cmdText" + cmdText + "\r\n tran" + trans.Connection.ConnectionString + "\r\n constr:" + connection.ConnectionString);

                    trans.Rollback();
                    connection.Close();
                }
                TextLog.Append("ERROR连接数据库异常," + E.Message + "\r\n constr:" + connection.ConnectionString);
                throw new Exception(E.Message);
            }
            finally
            {
                if (trans == null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
            return(val);
        }
Beispiel #2
0
 /// <summary>
 /// 执行SQL语句,返回影响的记录数
 /// </summary>
 /// <param name="SQLString">SQL语句</param>
 /// <returns>影响的记录数</returns>
 public int ExecuteSql(string SQLString, params OracleParameter[] cmdParms)
 {
     using (OracleConnection connection = new OracleConnection(ConnectionString))
     {
         using (OracleCommand cmd = new OracleCommand())
         {
             try
             {
                 PrepareCommand(cmd, connection, null, SQLString, cmdParms);
                 int rows = cmd.ExecuteNonQuery();
                 cmd.Parameters.Clear();
                 return(rows);
             }
             catch (System.Data.OracleClient.OracleException e)
             {
                 TextLog.Append(string.Format("sql:{0}\r\n error:{1}", SQLString, e.Message));
                 throw new Exception(e.Message);
             }
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// 执行SQL语句,返回影响的记录数
 /// </summary>
 /// <param name="SQLString">SQL语句</param>
 /// <returns>影响的记录数</returns>
 public int ExecuteSql(string SQLString)
 {
     using (OracleConnection connection = new OracleConnection(ConnectionString))
     {
         using (OracleCommand cmd = new OracleCommand(SQLString, connection))
         {
             try
             {
                 connection.Open();
                 int rows = cmd.ExecuteNonQuery();
                 return(rows);
             }
             catch (System.Data.SqlClient.SqlException e)
             {
                 connection.Close();
                 TextLog.Append(string.Format("sql:{0}\r\n error:{1}", SQLString, e.Message));
                 throw e;
             }
         }
     }
 }
Beispiel #4
0
        /// <summary>
        /// Checks the server.
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="second">The second.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public static bool CheckServer(string serviceName, double second)
        {
            try
            {
                int passMinute = 5;
                int.TryParse(AppConfigHelper.PassMinute, out passMinute);
                string serviceIp = NetUtil.GetHostIp();
                second = Math.Ceiling(second);

                var serverConfigBll  = new ServerConfigBll();
                var severConfigModel = serverConfigBll.GetModel(new ServerConfigModel()
                {
                    SERVICENAME = serviceName
                });
                //不存在记录,插入记录返回false
                if (severConfigModel == null)
                {
                    ServerConfigModel model = new ServerConfigModel();
                    model.SERVICENAME = serviceName;
                    model.SERVICEIP   = serviceIp;
                    model.PASSMINUTE  = passMinute;
                    model.SECOND      = second;
                    var bak = serverConfigBll.Add(model);
                    TextLog.Append("无服务配制,插入记录,返回F");
                    return(false);
                }
                else
                {
                    if (severConfigModel.PASSMINUTE > 0)
                    {
                        passMinute = severConfigModel.PASSMINUTE;
                    }
                    else
                    {
                        severConfigModel.PASSMINUTE = passMinute;
                    }
                    //存在记录IP相同
                    if (severConfigModel.SERVICEIP == serviceIp)
                    {
                        //存在记录IP相同,5分种内更新,返回true;
                        if (severConfigModel.SYSDATETIME < severConfigModel.LASTTIME.AddMinutes(passMinute).AddSeconds(severConfigModel.SECOND))
                        {
                            severConfigModel.SECOND = second;
                            var bak = serverConfigBll.UpdateLastTime(severConfigModel);
                            if (bolWriteLogFlag)
                            {
                                TextLog.Append(string.Format("IP相同,{0}分内,有权,返回T", passMinute));
                                bolWriteLogFlag = false;
                            }
                            return(bak);
                        }
                        else
                        {
                            severConfigModel.SECOND = second;
                            var bak = serverConfigBll.UpdateLastTime(severConfigModel);
                            //存在记录IP相同,5分种后主服务器收回权限,返回更新true;
                            TextLog.Append(string.Format("IP相同,{0}分后,获权,返回F", passMinute));
                            bolWriteLogFlag = true;
                            return(false);
                        }
                    }
                    else
                    {
                        //IP不同,5分种后返回true
                        if (severConfigModel.SYSDATETIME > severConfigModel.LASTTIME.AddMinutes(passMinute).AddSeconds(severConfigModel.SECOND))
                        {
                            TextLog.Append(string.Format("IP不同,{0}分种后,获权,返回F", passMinute));
                            bolWriteLogFlag = true;
                            severConfigModel.SERVICEIPPER = severConfigModel.SERVICEIP;
                            severConfigModel.SERVICEIP    = serviceIp;
                            severConfigModel.SECOND       = second;
                            var bak = serverConfigBll.UpdateLastIp(severConfigModel);
                            return(false);
                        }
                        else
                        {
                            //IP不同,5分种内返回false
                            TextLog.Append(string.Format("IP不同,{0}分种内,无权,返回F", passMinute));
                            bolWriteLogFlag = true;
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TextLog.Append(String.Format("检查服务配制失败: " + ex.Message));
                return(false);
            }
        }