📄 branchinfoservice.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using MyOffice.Models;
using MyOffice.DBUtility;
using System.Data;
using System.Data.SqlClient;
namespace MyOffice.DAL
{
public class BranchInfoService
{
public BranchInfo GetBranchByID(int branchID)
{
string sql = string.Format(@"select * from branchinfo where branchid={0}",branchID);
using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null))
{
if (reader.Read())
{
BranchInfo branch = new BranchInfo();
branch.BranchID = reader.GetInt32(0);
branch.BranchName = reader.GetString(1);
branch.BranchShortName = reader.GetString(2);
return branch;
}
else
{
return null;
}
}
}
public IList<BranchInfo> GetAllBranchInfo()
{
IList<BranchInfo> list = new List<BranchInfo>();
string sql = string.Format(@"select * from branchinfo");
using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null))
{
while (reader.Read())
{
BranchInfo branch = new BranchInfo();
branch.BranchID = reader.GetInt32(0);
branch.BranchName = reader.GetString(1);
branch.BranchShortName = reader.GetString(2);
list.Add(branch);
}
}
return list;
}
public int AddNewBranch(BranchInfo branch)
{
int flag = -1;
string sql = string.Format(@"insert branchinfo (branchname,branchshortname)
values(@branchname,@branchshortname)");
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@branchname",branch.BranchName),
new SqlParameter("@branchshortname",branch.BranchShortName)
};
flag = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction,CommandType.Text,sql,para);
return flag;
}
public int DeleteBranchByID(int branchID)
{
int flag = -1;
string sql = string.Format(@"delete from branchinfo where branchid={0}",branchID);
flag = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction,CommandType.Text,sql,null);
return flag;
}
public int UpdateBranchInfoByID(int branchID)
{
int flag = -1;
return flag;
}
public IList<BranchInfo> SearchBranch(string content)
{
IList<BranchInfo> list = new List<BranchInfo>();
string sql = string.Format(@"select * from branchinfo where {0}",content);
using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null))
{
while (reader.Read())
{
BranchInfo branch = new BranchInfo();
branch.BranchID = reader.GetInt32(0);
branch.BranchName = reader.GetString(1);
branch.BranchShortName = reader.GetString(2);
list.Add(branch);
}
}
return list;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -