110,538
社区成员
发帖
与我相关
我的任务
分享
public void SetDbType(int type)
{
this.type = type;
}
public IDataParameter Parameter(string name, DbType type, Object value)
{
DbParameter par = Factory().CreateParameter();
par.DbType = type;
par.Direction = ParameterDirection.Input;
par.ParameterName = name;
par.Value = value;
return par;
}
public DbProviderFactory Factory()
{
switch (type)
{
case 0:
return System.Data.OracleClient.OracleClientFactory.Instance;
case 1:
return Oracle.DataAccess.Client.OracleClientFactory.Instance;
default:
return null;
}
}
private void button1_Click_1(object sender, EventArgs e)
{
begin = DateTime.Now;
SetDbType(0);
LOGGER.Info("call sql by parameter...");
DbConnection connection = Factory().CreateConnection();
connection.ConnectionString = connectionString;
LOGGER.Debug(String.Format("get connection."));
connection.Open();
LOGGER.Debug(String.Format("oppend."));
int point = -1;
int promotedPoint = 0;
int perchasedPoint = 0;
int presentedPoint = 0;
int bound = 0;
DbDataAdapter adapter = null;
DbCommand command = null;
DataTable table = null;
try
{
DataRow row = null;
table = new DataTable();
string sql = "select BIND_FLAG,PROMOTE_SMS_POINT,BUY_SM_POINT,PRESENT_SM_NUM"+
" from im_mobile_maps where IM_ID=:imid";
command = Factory().CreateCommand();
command.Connection = connection;
command.CommandText = sql;
command.Parameters.Add(Parameter(":imid", DbType.String, imid));
adapter = Factory().CreateDataAdapter();
adapter.SelectCommand = command;
int rows = adapter.Fill(table);
if (rows == 0)
{
return;
}
row = table.Rows[0];
bound = (row["BIND_FLAG"] == DBNull.Value) ? 0 : (Decimal.ToInt32((Decimal)row["BIND_FLAG"]));
promotedPoint = Decimal.ToInt32((Decimal)row["PROMOTE_SMS_POINT"]);
perchasedPoint = Decimal.ToInt32((Decimal)row["BUY_SM_POINT"]);
presentedPoint = Decimal.ToInt32((Decimal)row["PRESENT_SM_NUM"]);
if (bound == 0)
{
if (LOGGER.IsDebugEnabled)
LOGGER.Debug(String.Format("GetCurrentSmPoint2 {0} is unbound.", imid));
return;
}
point = promotedPoint + perchasedPoint + presentedPoint;
LOGGER.Debug(String.Format("return value:{0}", point));
return;
}
catch (Exception exception)
{
LOGGER.Debug("error.", exception);
}
finally
{
if (adapter != null) adapter.Dispose();
if (command != null) command.Dispose();
if (table != null) table.Dispose();
LOGGER.Info("call sql by parameter end.\n");
}
}