110,571
社区成员
发帖
与我相关
我的任务
分享
public class DBHelper
{
//属性:数据库链接对象
private static SqlConnection conn;
public static SqlConnection Conn
{
get
{
string connstr =“server=192.168.1.10;database=rj;uid=sa;pwd=sa;”// ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString.ToString();
if (conn == null)
conn = new SqlConnection(connstr);
if (conn.State == ConnectionState.Closed)
conn.Open();
if (conn.State == ConnectionState.Broken)
{
conn.Close();
conn.Open();
}
return conn;
}
}
//方法:查询,DataReader
public static SqlDataReader GetReader(string SqlStr)
{
SqlCommand cmd = new SqlCommand(SqlStr, Conn);
return cmd.ExecuteReader();
}
public static SqlDataReader GetReader(string SqlStr, SqlParameter[] paras)
{
SqlCommand cmd = new SqlCommand(SqlStr, Conn);
cmd.Parameters.AddRange(paras);
return cmd.ExecuteReader();
}
//查询:DataTable
public static DataTable GetTable(string SqlStr)
{
SqlDataAdapter dap = new SqlDataAdapter(SqlStr, Conn);
DataSet ds = new DataSet();
dap.Fill(ds);
conn.Close();
return ds.Tables[0];
}
//增删改
public static bool Execute(string SqlStr)
{
SqlCommand cmd = new SqlCommand(SqlStr, Conn);
int result = cmd.ExecuteNonQuery();
conn.Close();
return result > 0;
}
//返回首行首列
public static object GetScalar(string SqlStr)
{
SqlCommand cmd = new SqlCommand(SqlStr, Conn);
object obj = cmd.ExecuteScalar();
conn.Close();
return obj;
}
private int maxi_serial()
{
/////取oplogs的i_serial的最大值
SqlConnection strcon = new SqlConnection("server=192.168.1.10;database=money;uid=sa;pwd=sa;");
strcon.Open();
SqlCommand scd = new SqlCommand("select max(i_serial)+1 as maxi_serial from now..oplogs", strcon);
int max_serial = Convert.ToInt32(scd.ExecuteScalar());
strcon.Close();
//
listBox1.Items.Add("取得最大值为" + Convert.ToString(max_serial));
return max_serial;
}
//
private void checksave(string bank, int userid, string orderno)
{
//////////now查询是否已经存入金额成功,rj成功则将是否成功标志置为1
SqlConnection cxcon = new SqlConnection("server=192.168.1.10;database=now;uid=sa;pwd=sa;");
cxcon.Open();
SqlCommand cxcd = new SqlCommand("select count(*) from oplogs where v_summary = '" + orderno + "'", cxcon);
int rescou = Convert.ToInt32(cxcd.ExecuteScalar());
cxcon.Close();
if (rescou == 1)
{
////已经存入,可将rj..successed置为1
SqlConnection updatecon = new SqlConnection("server=192.168.1.10;database=rj;uid=sa;pwd=sa;");
updatecon.Open();
SqlCommand updatecd;
if (bank == "ccb")
{
updatecd = new SqlCommand("update ccborder set successed = 1 where orderno='" + orderno + "'", updatecon);
}
else
{
updatecd = new SqlCommand("update abcorder set successed = 1 where orderno='" + orderno + "'", updatecon);
}
updatecd.ExecuteScalar();
updatecon.Close();
//
listBox1.Items.Add("更新完毕");
}
else if (rescou > 1)
{
listBox1.Items.Add("检测到编号为:" + orderno + "的订单有相同的存入记录");
}
}
//
private void checksave(string bank)
{
//////////////检测一下.是否有已经存入但是successed并没有置为1的记录
SqlConnection cfcon = new SqlConnection("server=192.168.1.10;database=rj;uid=sa;pwd=sa;");
SqlCommand cfcd;
if (bank == "ccb")
{
cfcd = new SqlCommand("update ccborder set successed = 1 where orderno in (select orderno from ccborder where successed = 0 and orderno in (select v_summary from now..oplogs))", cfcon);
}
else
{
cfcd = new SqlCommand("update abcorder set successed = 1 where orderno in (select orderno from abcorder where successed = 0 and orderno in (select v_summary from now..oplogs))", cfcon);
}
cfcd.ExecuteScalar();
cfcon.Close();
}