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台机器上使用过该用户名登陆。登陆失败!
}
}
}
{
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台机器上使用过该用户名登陆。登陆失败!
}
}
}
...全文
相关推荐
C#绝对路径拼接相对路径的实例代码
C#绝对路径拼接相对路径的实例代码,需要的朋友可以参考一下
C#批量删除指定文件(路径,后缀名,大小) 代码
自己写的文件删除工具,根据路径,后缀名和文件大小来批量删除文件
C# 获取系统路径如“我的文档”
c# 获取相对路径,操作环境变量. 一、获取当前文件的路径 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 获取模块的完整路径,包括文件名。 2. System.Environment.CurrentDirectory 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。 ...... C# 如何获取某用户的“我的文档”的目录 System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)); System.Environment.GetFolderPath 方法 获取指向由指定枚举标识的系统特殊文件夹的路径。 ......
C#弹出窗口返回值,下载文件
winform 弹出子窗口,子窗口填写完毕,将值传递给父窗口;选择电脑中的文件,下载到另一份额盘符当中。源代码
C#调用Rar文件及获取Rar返回值的方法
主要介绍了C#调用Rar文件及获取Rar返回值的方法,实例分析了C#调用rar文件实现文件的压缩与解压相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下


