c#中“并非所有的代码路径都返回值”

呵呵112123 呵呵112123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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台机器上使用过该用户名登陆。登陆失败!
}
}

}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
呵呵112123
C# 111,129 成员 642,539 内容