📄 company.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Security.Cryptography;
using System.Text;
namespace Hr.component
{
public class Company:Hr.component.DatabaseOperation
{
private string m_Password;
private string m_Mail;
public string Password
{
get
{
return m_Password;
}
set
{
m_Password = value;
}
}
public string Mail
{
get
{
return m_Mail;
}
set
{
m_Mail = value;
}
}
public Company()
{
}
public void Add()
{
if(IsExist())
{
throw new Exception("该公司已经注册了!");
}
else
{
strSQL = "Insert into company (Name,Password,Mail) Values("
+ "'" + this.Name + "',"
+ "'" + publicfunc.Encrypt(this.Password,1) + "',"
+ "'" + this.Mail + "')";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("注册失败!");
}
}
strSQL = "Select Max(companyID) From company";
int companyId;
try
{
companyId = ExecuteReturnValue(strSQL);
}
catch
{
throw new Exception("返回公司注册编号失败!");
}
strSQL = "Insert into CompanyOffer (companyID) Values("+"'"+ companyId.ToString() +"')";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("注册失败!");
}
}
public static void Add(string name,string password,string mail)
{
if(IsExist(name))
{
throw new Exception("This name was registered!");
}
else
{
strSQL = "Insert into company (Name,Password,Mail) Values("
+ "'" + name + "',"
+ "'" + publicfunc.Encrypt(password,1) + "',"
+ "'" + mail + "')";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("注册失败!");
}
}
strSQL = "Select Max(companyID) From company";
int companyId;
try
{
companyId = ExecuteReturnValue(strSQL);
}
catch
{
throw new Exception("注册失败!");
}
strSQL = "Insert into CompanyOffer (companyID) Values("+"'"+ companyId.ToString() +"')";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("注册失败!");
}
}
public void ChangePassword(string newPassword)
{
strSQL = "Update company Set "
+ "Password='" + publicfunc.Encrypt(newPassword,1) + "'"
+ " Where Name='" + this.Name + "'"
+ " And Password='" + publicfunc.Encrypt(this.Password,1) + "'";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("Change password FAILED!");
}
}
public static void ChangePassword(string name,string oldPassword,string newPassword)
{
strSQL = "Update company Set "
+ "Password='" + publicfunc.Encrypt(newPassword,1) + "'"
+ " Where Name='" + name + "'"
+ " And Password='" + publicfunc.Encrypt(oldPassword,1) + "'";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("Change password FAILED!");
}
}
public bool Check()
{
strSQL = "Select companyID from company Where Name='"
+ Name + "'"
+ " And Mail='" + Mail +"'";
try
{
ExecuteReturnValue(strSQL);
return true;
}
catch
{
return false;
}
}
public static bool Check(string name,string mail)
{
strSQL = "Select companyID from company Where Name='"
+ name + "'"
+ " And Mail='" + mail +"'";
try
{
ExecuteReturnValue(strSQL);
return true;
}
catch
{
return false;
}
}
public static void Delete(int id)
{
strSQL = "Delete From company Where companyID="+id;
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("Delete user FAILED!");
}
}
public void Delete()
{
strSQL = "Delete From company Where Name="+Name;
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("Delete user FAILED!");
}
}
public static void Delete(string name)
{
strSQL = "Delete From company Where Name="+name;
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("Delete user FAILED!");
}
}
public static void DeleteGroup(string names)
{
strSQL = "Delete From company Where Name in ('" + names + "')";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
throw new Exception("Delete user FAILED!");
}
}
public bool IsExist()
{
strSQL = "Select companyID from company Where Name='"
+ this.Name + "'";
try
{
ExecuteReturnValue(strSQL);
return true;
}
catch
{
return false;
}
}
public static bool IsExist(string name)
{
strSQL = "Select companyID from company Where Name='"
+ name + "'";
try
{
ExecuteReturnValue(strSQL);
return true;
}
catch
{
return false;
}
}
public string GetPassword()
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
int i;
for(i=0;i<32;i++)
{
sb.Append(rnd.Next(0,9).ToString());
}
string Password = sb.ToString();
string EnPassword = publicfunc.Encrypt(Password,1);
strSQL = "Update company Set Password = '"
+ EnPassword + "'"
+ " Where Name='" + Name + "'";
try
{
ExecuteNonQuery(strSQL);
return Password;
}
catch
{
throw new Exception("读取密码失败");
}
}
public static string GetPassword(string name)
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
int i;
for(i=0;i<32;i++)
{
sb.Append(rnd.Next(0,9).ToString());
}
string Password = sb.ToString();
string EnPassword = publicfunc.Encrypt(Password,1);
strSQL = "Update company Set Password = '"
+ EnPassword + "'"
+ " Where Name='" + name + "'";
try
{
ExecuteNonQuery(strSQL);
return Password;
}
catch
{
throw new Exception("读取密码失败");
}
}
public bool Login()
{
strSQL = "Select companyID from company Where Name='"
+ this.Name + "'"
+ " And Password='" + publicfunc.Encrypt(this.Password,1) +"'";
try
{
ExecuteReturnValue(strSQL);
return true;
}
catch
{
return false;
}
}
public static bool Login(string name,string password)
{
strSQL = "Select companyID from company Where Name='"
+ name + "'"
+ " And Password='" + publicfunc.Encrypt(password,1) +"'";
try
{
ExecuteReturnValue(strSQL);
return true;
}
catch
{
return false;
}
}
public bool Update()
{
strSQL = "Update company Set "
+ "Mail='" + this.Mail
+"' Where Name='"+this.Name + "'"
+ " And Password='" + publicfunc.Encrypt(this.Password,1) +"'";
try
{
ExecuteNonQuery(strSQL);
return true;
}
catch
{
throw new Exception("Update failed!");
}
}
public static bool Update(string mail,string name,string password)
{
strSQL = "Update company Set "
+ "Mail='" + mail
+"' Where Name='"+name + "'"
+ " And Password='" + publicfunc.Encrypt(password,1) +"'";
try
{
ExecuteNonQuery(strSQL);
return true;
}
catch
{
throw new Exception("Update failed!");
}
}
public static DataSet GetUsers()
{
strSQL = "SELECT * FROM company";
try
{
return ExecuteReturnDS(strSQL);
}
catch
{
throw new Exception("读取所有公司信息失败!");
}
}
public bool GetUserInfo()
{
strSQL = "Select * from company Where Name='"
+ this.Name + "'";
SqlConnection myConn = new SqlConnection(strConn);
myConn.Open();
SqlCommand myCmd = new SqlCommand(strSQL,myConn);
try
{
myCmd.ExecuteNonQuery();
SqlDataReader reader = myCmd.ExecuteReader();
if(reader.Read())
{
this.ID = reader.GetInt32(0);
this.Mail = reader.GetString(3);
return true;
}
else
{
return false;
}
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
myCmd.Dispose();
myConn.Close();
}
}
public static DataSet GetCompanyStore(int CompanyId)
{
strSQL = "Select * from CompanyStoreV Where CompanyId=" + CompanyId.ToString();
try
{
return ExecuteReturnDS(strSQL);
}
catch
{
throw new Exception("Get Company store failed!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -