Example #1
0
        /// <summary>
        /// 主机接替备机时 更新资源表
        /// </summary>
        /// <param name="dbInfo">数据库连接信息</param>
        /// <param name="strRelpaceModuleNumber">要接替的主机key</param>
        /// <param name="strResourceKey">备机key</param>
        /// <returns></returns>
        public static OperationReturn UpdateReplaceModuleNumberInDB(DatabaseInfo dbInfo, string strRelpaceModuleNumber, string strResourceKey)
        {
            OperationReturn optReturn = new OperationReturn();

            try
            {
                string strConnectString = dbInfo.GetConnectionString();
                //先找到备机对应的资源ID
                string strSql = string.Empty;
                switch (dbInfo.TypeID)
                {
                case 2:
                    strSql    = "select * from t_11_101_{0} where C001 >2210000000000000000 and C001 <2220000000000000000 and C002 =1 and C014 in( {1},{2})";
                    strSql    = string.Format(strSql, "00000", strResourceKey, strRelpaceModuleNumber);
                    optReturn = MssqlOperation.GetDataSet(strConnectString, strSql);
                    break;

                case 3:
                    strSql    = "select * from t_11_101_{0} where C001 >2210000000000000000 and C001 <2220000000000000000 and C002 =1 and C014 in( {1},{2})";
                    strSql    = string.Format(strSql, "00000", strResourceKey, strRelpaceModuleNumber);
                    optReturn = OracleOperation.GetDataSet(strConnectString, strSql);
                    break;
                }

                if (!optReturn.Result)
                {
                    return(optReturn);
                }
                DataSet ds = optReturn.Data as DataSet;
                if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
                {
                    optReturn.Result = false;
                    return(optReturn);
                }
                //定义两个变量 来保存主备机器的资源ID
                string strMainResID   = string.Empty;
                string strBackupResID = string.Empty;
                string strKey         = string.Empty;
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    strKey = row["C012"].ToString();
                    if (strKey == strResourceKey)
                    {
                        strBackupResID = row["C001"].ToString();
                        continue;
                    }
                    else if (strKey == strRelpaceModuleNumber)
                    {
                        strMainResID = row["C001"].ToString();
                    }
                }

                //判断备机资源的standbyrole是不是3
                switch (dbInfo.TypeID)
                {
                case 2:
                    strSql    = "select * from t_11_101_{0} where C001 ={1} and C002 = 2";
                    strSql    = string.Format(strSql, "00000", strBackupResID);
                    optReturn = MssqlOperation.GetDataSet(strConnectString, strSql);
                    break;

                case 3:
                    strSql    = "select * from t_11_101_{0} where C001 ={1} and C002 = 2";
                    strSql    = string.Format(strSql, "00000", strBackupResID);
                    optReturn = OracleOperation.GetDataSet(strConnectString, strSql);
                    break;
                }
                if (!optReturn.Result)
                {
                    return(optReturn);
                }
                ds = optReturn.Data as DataSet;
                if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0)
                {
                    optReturn.Result = false;
                    return(optReturn);
                }
                string strStandbyrole = ds.Tables[0].Rows[0]["C012"].ToString();
                if (strStandbyrole != "3")
                {
                    optReturn.Result = false;
                    return(optReturn);
                }
                //更新备机的RelpaceModuleNumber
                switch (dbInfo.TypeID)
                {
                case 2:
                    strSql    = "update t_11_101_{0} set C011 = '{1}' where C001 = {2} and C002 = 3";
                    strSql    = string.Format(strSql, "00000", strRelpaceModuleNumber, strBackupResID);
                    optReturn = MssqlOperation.ExecuteSql(strConnectString, strSql);
                    break;

                case 3:
                    strSql    = "UPDATE t_11_101_{0} SET C011 = '{1}' where C001 = {2} and C002 = 3";
                    strSql    = string.Format(strSql, "00000", strRelpaceModuleNumber, strBackupResID);
                    optReturn = OracleOperation.ExecuteSql(strConnectString, strSql);
                    break;
                }
                if (!optReturn.Result)
                {
                    return(optReturn);
                }

                //更新主机的RelpaceModuleNumber
                switch (dbInfo.TypeID)
                {
                case 2:
                    strSql    = "update t_11_101_{0} set C011 = '{1}' where C001 = {2} and C002 = 3";
                    strSql    = string.Format(strSql, "00000", strResourceKey, strMainResID);
                    optReturn = MssqlOperation.ExecuteSql(strConnectString, strSql);
                    break;

                case 3:
                    strSql    = "UPDATE t_11_101_{0} SET C011 = '{1}' where C001 = {2} and C002 = 3";
                    strSql    = string.Format(strSql, "00000", strResourceKey, strMainResID);
                    optReturn = OracleOperation.ExecuteSql(strConnectString, strSql);
                    break;
                }
                if (!optReturn.Result)
                {
                    return(optReturn);
                }

                optReturn.Result = true;
                optReturn.Code   = Defines.RET_SUCCESS;
            }
            catch (Exception ex)
            {
                optReturn.Result  = false;
                optReturn.Code    = Defines.RET_FAIL;
                optReturn.Message = ex.Message;
            }

            return(optReturn);
        }
Example #2
0
        private OperationReturn ExtDBCommand(List <string> listParams)
        {
            OperationReturn optReturn = new OperationReturn();

            optReturn.Result = true;
            optReturn.Code   = 0;
            try
            {
                //ListParams
                //参考S000A1Codes中的定义
                if (listParams == null || listParams.Count < 2)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Request param is null or count invalid");
                    return(optReturn);
                }
                string strUserID = listParams[0];
                string strSql    = listParams[1];
                WriteOperationLog(
                    string.Format("GetDBInfo:\tUserID:{0};Sql:{1}",
                                  strUserID,
                                  strSql));
                strSql    = DecryptFromClient(strSql);
                optReturn = ReadDatabaseInfo();
                if (!optReturn.Result)
                {
                    return(optReturn);
                }
                DatabaseInfo dbInfo = optReturn.Data as DatabaseInfo;
                if (dbInfo == null)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_OBJECT_NULL;
                    optReturn.Message = string.Format("DatabaseInfo is null");
                    return(optReturn);
                }
                string strConn = dbInfo.GetConnectionString();
                switch (dbInfo.TypeID)
                {
                case 2:
                    optReturn = MssqlOperation.ExecuteSql(strConn, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    break;

                case 3:
                    optReturn = OracleOperation.ExecuteSql(strConn, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    break;

                default:
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("DBType invalid.\t{0}", dbInfo.TypeID);
                    return(optReturn);
                }
            }
            catch (Exception ex)
            {
                optReturn.Result  = false;
                optReturn.Code    = Defines.RET_FAIL;
                optReturn.Message = ex.Message;
                return(optReturn);
            }
            return(optReturn);
        }