c#中“并非所有的代码路径都返回值”
public string sqlexe(string sql)
{
cmd = new SqlCommand(sql,con);
con.Open();
string bbn = cmd.ExecuteScalar().ToString();
con.Close();
return bbn;
}
public void sqlexe2(string sql)
{
cmd = new SqlCommand(sql, con);
con.Open();
string bbn = cmd.ExecuteNonQuery().ToString();
con.Close();
}
public int loginlog(string a, string b,string c)
{
bool IsOverMaxLoginCount = true;
int custid=0;
//取CustomerID
string sql = "SELECT CustomerID FROM Customer where (LoginName = " + a + ") AND (PassWord = " + b + ")";
string bdf = sqlexe(sql);
if (bdf != null)
{
custid = Convert.ToInt32(bdf);
}
else
{
return 0;//0 用户名或密码不存在
}
//用户过期判断
string sql1 = "SELECT COUNT(*) FROM Customer where CustomerID= "+custid +" and (ExpiryTime>getdate() or ExpiryTime is null)";
string jkh= sqlexe(sql1);
if (jkh == null)
{
return 0;//0 用户名或密码不存在
}
else
{
string sql2 = "SELECT LoginLog.* FROM LoginLog where CustomerId="+custid ;
SqlDataAdapter custlog = new SqlDataAdapter(sql2, con);
DataSet ds = new DataSet();
custlog.Fill(ds, "custlog");
DataTable tblcust;
tblcust = ds.Tables["custlog"];
if(tblcust.Rows.Count< 2)
{
bool boltemp = false;//表示已经有此条数据
foreach( DataRow dr in tblcust.Rows )
{
if (dr["Mac"].ToString().ToUpper().Trim() == c.ToString().ToUpper().Trim())
{
boltemp = true;
return 1;//用户成功登陆
}
}
if (boltemp == false)
{
//llAdp.Insert(CustomerId, strmac, true);//插入MAC地址
string sql3 = "INSERT INTO LoginLog (CustomerId ,Mac) VALUES ("+custid+","+c+")";
sqlexe2(sql3);
return 1;//用户登录成功,并写入MAC
}
}
else if (tblcust.Rows.Count == 2)
{
bool boltemp = false;//表示已经有此条数据
foreach (DataRow dr in tblcust.Rows)
{
if (dr["Mac"].ToString().ToUpper().Trim() == c.ToString().ToUpper().Trim())
{
boltemp = true;
return 1;//用户成功登陆
}
}
if (boltemp)
IsOverMaxLoginCount = false;
else
IsOverMaxLoginCount = true;
}
else
{
IsOverMaxLoginCount = true;
}
if (IsOverMaxLoginCount)
{
return 2;//您已经在2台机器上使用过该用户名登陆。登陆失败!
}
}
}