⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 operation.cs

📁 基于C#语言的一个企业客户管理数据库系统开发案例的源代码 ,很实用
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Operation 的摘要说明
/// </summary>
public class ReRecord
{
    public string  ID;
    public string RecordID;
    public  string ReReordContent;
    public string EngineerName;
    public  DateTime RevertDate;
    public int  Flag;
 }
public class Count
{
    public int All;
    public int Good;
    public int Bad;
    public int Common;
}
public class Records
{
    public int RecordID;
    public string RecordTitle;
    public string RecordDetails;
    public string UserName;
    public string  Allot;
    public DateTime CreateDate;
    public string EngineerName;
}
public class Research
{
    public string UserName;
    public DateTime ResearchDate;
    public string Appraise;
    public int ReIdea;
}
/// <summary>
/// 
/// </summary>
public class Operation
{
    public int Count;
    public static string userName;
	public Operation()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    /// <summary>
    /// 该方法返回一个SqlConnection对象
    /// </summary>
    /// <returns></returns>
    public static SqlConnection GetCon()
    {
        return new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["DNS"]);
       
    }
    public static int UserID;
    public static bool FindPeople(string UserName,string Password,int Type)
    {
        try
        {
            SqlConnection con = Operation.GetCon();
            SqlCommand comm = new SqlCommand("SelUsers", con);
            comm.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
            SqlParameter paraUserName = new SqlParameter("@UserName", SqlDbType.VarChar, 20);//给存储过程添加参数
            paraUserName.Value = UserName;
            comm.Parameters.Add(paraUserName);
            SqlParameter paraPassword = new SqlParameter("@Password", SqlDbType.VarChar, 20);
            paraPassword.Value = Password;
            comm.Parameters.Add(paraPassword);
            SqlParameter paraType = new SqlParameter("@Type", SqlDbType.Int, 4);
            paraType.Value = Type;
            comm.Parameters.Add(paraType);
            //指出该参数是存储过程的Output参数
            SqlParameter paraID = new SqlParameter("@ID", SqlDbType.Int, 4);
            paraID.Direction = ParameterDirection.Output;
            comm.Parameters.Add(paraID);
            con.Open();
            comm.ExecuteNonQuery();
            con.Close();
            UserID = (int)paraID.Value;//根据存储过程的输出参数的值对该方法的参数UserID赋值
            if (UserID != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch
        {

            return false;

        }
    }
    public static bool InsertUserInfo(string UserName,string Password,int Sex,string Telephone,int Type)
    {
        try
        {
            SqlConnection con = Operation.GetCon();
            SqlCommand comm = new SqlCommand("AddUsersInfo", con);
            comm.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
            SqlParameter paraUserName = new SqlParameter("@UserName", SqlDbType.VarChar, 20);//给存储过程添加参数
            paraUserName.Value = UserName;
            comm.Parameters.Add(paraUserName);
           SqlParameter paraPassword = new SqlParameter("@Password", SqlDbType.VarChar, 20);
            paraPassword.Value = Password;
            comm.Parameters.Add(paraPassword);
            SqlParameter paraSex = new SqlParameter("@Sex", SqlDbType.Int, 4);
            paraSex.Value = Sex;
            comm.Parameters.Add(paraSex);
            SqlParameter paraTelephone = new SqlParameter("@Telephone", SqlDbType.VarChar, 50);
            paraTelephone.Value = Telephone;
            comm.Parameters.Add(paraTelephone);
            SqlParameter paraType = new SqlParameter("@Type", SqlDbType.Int, 4);
            paraType.Value = Type;
            comm.Parameters.Add(paraType);
            con.Open();//打开数据库连接
            comm.ExecuteNonQuery();//进行数据库操作
            con.Close();//关闭连接
            return true;
        }
        catch 
        {
            return false;
        }
    }
    public static DataSet ReDataSet(string  StoreName)
    {
        SqlConnection con = Operation.GetCon();
        SqlDataAdapter sda = new SqlDataAdapter(StoreName, con);
        sda.SelectCommand.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
        con.Open();//打开数据库连接
        DataSet ds = new DataSet();
        sda.Fill(ds, "Records");//进行数据库操作
        con.Close();//关闭连接
        return ds;
    }
    public static void ExSql(string StoreName,int ID)
    {
        SqlConnection con = Operation.GetCon();

        SqlCommand comm = new SqlCommand(StoreName, con);
        comm.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
        SqlParameter para = new SqlParameter("@ID", SqlDbType.Int, 4);//给存储过程添加参数
        para.Value = ID;
        comm.Parameters.Add(para);        
        con.Open();//打开数据库连接
        comm.ExecuteNonQuery();//进行数据库操作
        con.Close();//关闭连接
    }
    public static bool ReDataReader(int RecordID,Records Re)
    {
        SqlConnection con = Operation.GetCon();
        SqlCommand comm = new SqlCommand("ReaderRecords", con);
        comm.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
        SqlParameter paraRecordID = new SqlParameter("@RecordID", SqlDbType.Int, 4);//给存储过程添加参数
        paraRecordID.Value = RecordID;
        comm.Parameters.Add(paraRecordID);
        SqlParameter paraRecordTitle = new SqlParameter("@RecordTitle", SqlDbType.VarChar, 50);
        paraRecordTitle.Direction = ParameterDirection.Output;
        comm.Parameters.Add(paraRecordTitle);
        SqlParameter paraRecordDetails = new SqlParameter("@RecordDetails", SqlDbType.VarChar, 200);
        paraRecordDetails.Direction = ParameterDirection.Output;
        comm.Parameters.Add(paraRecordDetails);
        SqlParameter paraCreateDate = new SqlParameter("@CreateDate", SqlDbType.DateTime, 8);
        paraCreateDate.Direction = ParameterDirection.Output;
        comm.Parameters.Add(paraCreateDate);
        SqlParameter paraUserName = new SqlParameter("@UserName", SqlDbType.VarChar, 20);
        paraUserName.Direction = ParameterDirection.Output;
        comm.Parameters.Add(paraUserName);
        try
        {
            con.Open();//打开数据库连接
            comm.ExecuteNonQuery();//进行数据库操作
            con.Close();//关闭连接
            //根据存储过程的输出参数的值 Re对象赋值
            Re.RecordTitle = paraRecordTitle.Value.ToString();
            Re.RecordDetails = paraRecordDetails.Value.ToString();
            Re.CreateDate = (DateTime)(paraCreateDate.Value);
            Re.UserName = paraUserName.Value.ToString();
            return true;
        }
        catch
        {
            return false;
        }
    }
    public static bool updateRecords(int ID,string EngineerName)
    {
        try
        {
            SqlConnection con = Operation.GetCon();
      
            SqlCommand comm = new SqlCommand("UpdateUserName", con);
            comm.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
            SqlParameter paraID = new SqlParameter("@RecordID", SqlDbType.Int, 4);//给存储过程添加参数
            paraID.Value = ID;
            comm.Parameters.Add(paraID);
            SqlParameter paraEngineerName = new SqlParameter("@EngineerName", SqlDbType.VarChar, 20);
            paraEngineerName.Value = EngineerName;
            comm.Parameters.Add(paraEngineerName);
            con.Open();//打开数据库连接
            comm.ExecuteNonQuery();//进行数据库操作
            con.Close();//关闭连接
            return true;
        }
        catch 
        {
            return false;
        }
    }
   
    public bool  SelRecordReRecord(int RecordID,Records Re,ReRecord Red )
    {
        SqlConnection con = Operation.GetCon();
        SqlCommand comm = new SqlCommand ("SelRecordReRecord", con);
        comm.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
        SqlParameter paraRecordID = new SqlParameter("@RecordID", SqlDbType.Int, 4);//给存储过程添加参数
        paraRecordID.Value = RecordID;
        comm.Parameters.Add(paraRecordID);
        SqlParameter paraID = new SqlParameter("@ID", SqlDbType.Int, 4);
        Operation oper = new Operation();//生成Operation类对象
        int ID=oper.Judge(RecordID);//调用Judge方法返回int类型的值
        paraID.Value = ID;
        comm.Parameters.Add(paraID);
        con.Open();//打开数据库连接
        SqlDataReader dr = comm.ExecuteReader();//进行数据库操作
        int id = (int)(paraID.Value);
        if (id==0)
        {
            dr.Read();
            Re.RecordID = (int)(dr["RecordID"]);//返回SqlDataReader数据集给Re对象赋值
            Re.RecordTitle = dr["RecordTitle"].ToString();
            Re.RecordDetails = dr["RecordDetails"].ToString();
            Re.UserName = dr["UserName"].ToString();
            Re.EngineerName = dr["EngineerName"].ToString();
            Re.CreateDate = (DateTime)(dr["CreateDate"]);
            con.Close();//关闭连接
            return true;
        }
        else
        {
            dr.Read();
            Re.RecordID = (int)(dr["RecordID"]);//返回SqlDataReader数据集给Red对象赋值
            Re.RecordTitle = dr["RecordTitle"].ToString();
            Re.RecordDetails = dr["RecordDetails"].ToString();
            Re.EngineerName = dr["EngineerName"].ToString();
            Re.UserName = dr["UserName"].ToString();
            Re.CreateDate = (DateTime)(dr["CreateDate"]);
            Red.ReReordContent = dr["ReRecordContent"].ToString();
            Red.RevertDate = (DateTime)(dr["RevertDate"]);
            Red.Flag =(int)(dr["Flag"]);
            con.Close();//关闭连接
            return false;
        } 
    }
    public static bool UpdateUsers(int ID,string Password,string NewPassword)
    {
        try
        {
            SqlConnection con = Operation.GetCon();
            SqlCommand comm = new SqlCommand("UpdateUserInfo", con);
            comm.CommandType = CommandType.StoredProcedure;//指明Sql命令的操作类型是使用存储过程
            SqlParameter paraID = new SqlParameter("@ID", SqlDbType.Int, 4);//给存储过程添加参数
            paraID.Value = ID;
            comm.Parameters.Add(paraID);
            SqlParameter paraPassword = new SqlParameter("@Password", SqlDbType.VarChar, 20);
            paraPassword.Value = Password;
            comm.Parameters.Add(paraPassword);
            SqlParameter paraNewPassword = new SqlParameter("@NewPassword", SqlDbType.VarChar, 20);
            paraNewPassword.Value = NewPassword;
            comm.Parameters.Add(paraNewPassword);
            con.Open();//打开数据库连接
            comm.ExecuteNonQuery();//进行数据库操作

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -