日期:2014-05-17  浏览次数:20443 次

该怎样实现“当数据库中的条目+1时,触发一系列条件使得数据库内数值改变”?
我是这样想的:
  int grade, point;
  long size1;

  string sql1 = "select point,size,grade from users where login='1'";
  classDB nb = new classDB();
  DataSet sd = nb.TDataSet(sql1);
  DataTable dt = sd.Tables[0];

  string sql3 = "select count(files.ID) from files,users where files.ID=users.ID and users.login='1'";
  classDB cc = new classDB();
  DataSet cds = cc.TDataSet(sql3);
  DataTable cdtb = cds.Tables[0];

  CRules ri = new CRules();
  ri.grade = Convert.ToInt32(dt.Rows[0]["grade"]);
  ri.point = Convert.ToInt32(dt.Rows[0]["point"]);
  ri.i = cdtb.Rows.Count;
  grade = ri.levelup();
  point = ri.pointc();
  size1 = ri.rules();

然后用一个update值送回数据库。
但是现在出现了一个问题,就是送回的值还是原封不动的原值,等于说类CRules中的方法完全无效,求解

以下为CRules:

public class CRules
{
  public int grade;
  public int size;
  public int point;
  public int i;
   

  public int pointc()
  {
  int u;
  u = i + 1;
  if (i == u)
  {
  point = point + 3;
  }
  return point;
  }

  public int levelup()
  {
  switch (point)
  {
  case 9:grade=1;break;
  case 15:grade=2;break;
  case 21:grade=3;break;
  case 39:grade=4;break;
  case 51:grade=5;break;
  case 78:grade=6;break;
  case 99:grade=7;break;
  default: break;
  } 
  return grade;
  }

  public long rules()
  {
  if (grade == 1)
  {
  size = 10485760;
  }
  else if (grade == 2)
  {
  size = 20971520;
  }
  else if (grade == 3)
  {
  size = 41943040;
  }
  else if (grade == 4)
  {
  size = 83886080;
  }
  else if (grade == 5)
  {
  size = 167772160;
  }
  else if (grade == 6)
  {
  size = 335544320;
  }
  else
  {
  size = 671088640;
  }
  return size;

  }
}

------解决方案--------------------
用数据库触发器实现吧
------解决方案--------------------
http://www.cnblogs.com/xianqingzh/archive/2009/04/30/1447143.html