📄 branchinfoservice.cs
字号:
//============================================================
// Producnt name: BoBoARTS.CodeMad
// Version: 1.0
// Coded by: Shen Bo (bo.shen@jb-aptech.com.cn)
// Auto generated at: 2008-9-18 16:21:20
//============================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Office.Model;
namespace Office.DAL
{
public static partial class BranchInfoService
{
/// <summary>
/// Method: Add branch
/// </summary>
/// <param name="branchInfo">BranchInfo</param>
/// <returns>BranchInfo</returns>
public static BranchInfo AddBranchInfo(BranchInfo branchInfo)
{
string sql =
"INSERT BranchInfo (BranchName, BranchShortName)" +
"VALUES (@BranchName, @BranchShortName)";
sql += " ; SELECT @@IDENTITY";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@BranchName", branchInfo.BranchName),
new SqlParameter("@BranchShortName", branchInfo.BranchShortName)
};
int newId = DBHelper.GetScalar(sql, para);
return GetBranchInfoByBranchId(newId);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
/// Method:delete branch
/// </summary>
/// <param name="branchInfo"></param>
public static void DeleteBranchInfo(BranchInfo branchInfo)
{
DeleteBranchInfoByBranchId( branchInfo.BranchId );
}
/// <summary>
/// Method:delete organization according to ID
/// </summary>
/// <param name="branchId">branchId</param>
public static void DeleteBranchInfoByBranchId(int branchId)
{
string sql = "DELETE BranchInfo WHERE BranchId = @BranchId";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@BranchId", branchId)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
/// Method:modification organization
/// </summary>
/// <param name="branchInfo"></param>
public static void ModifyBranchInfo(BranchInfo branchInfo)
{
string sql =
"UPDATE BranchInfo " +
"SET " +
"BranchName = @BranchName, " +
"BranchShortName = @BranchShortName " +
"WHERE BranchId = @BranchId";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@BranchId", branchInfo.BranchId),
new SqlParameter("@BranchName", branchInfo.BranchName),
new SqlParameter("@BranchShortName", branchInfo.BranchShortName)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
/// Method: Get all organization
/// </summary>
/// <returns></returns>
public static IList<BranchInfo> GetAllBranchInfos()
{
string sqlAll = "SELECT * FROM BranchInfo";
return GetBranchInfosBySql( sqlAll );
}
/// <summary>
///
/// </summary>
/// <param name="branchId"></param>
/// <returns></returns>
public static BranchInfo GetBranchInfoByBranchId(int branchId)
{
string sql = "SELECT * FROM BranchInfo WHERE BranchId = @BranchId";
try
{
SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@BranchId", branchId));
if (reader.Read())
{
BranchInfo branchInfo = new BranchInfo();
branchInfo.BranchId = (int)reader["BranchId"];
branchInfo.BranchName = (string)reader["BranchName"];
branchInfo.BranchShortName = (string)reader["BranchShortName"];
reader.Close();
return branchInfo;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
/// Method:get all organization according to safe T-SQL
/// </summary>
/// <param name="safeSql"></param>
/// <returns></returns>
private static IList<BranchInfo> GetBranchInfosBySql( string safeSql )
{
List<BranchInfo> list = new List<BranchInfo>();
try
{
DataTable table = DBHelper.GetDataSet( safeSql );
foreach (DataRow row in table.Rows)
{
BranchInfo branchInfo = new BranchInfo();
branchInfo.BranchId = (int)row["BranchId"];
branchInfo.BranchName = (string)row["BranchName"];
branchInfo.BranchShortName = (string)row["BranchShortName"];
list.Add(branchInfo);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
/// Over loading Method:Get all organization according to safe T-SQL and parameter
/// </summary>
/// <param name="sql"></param>
/// <param name="values"></param>
/// <returns></returns>
private static IList<BranchInfo> GetBranchInfosBySql( string sql, params SqlParameter[] values )
{
List<BranchInfo> list = new List<BranchInfo>();
try
{
DataTable table = DBHelper.GetDataSet( sql, values );
foreach (DataRow row in table.Rows)
{
BranchInfo branchInfo = new BranchInfo();
branchInfo.BranchId = (int)row["BranchId"];
branchInfo.BranchName = (string)row["BranchName"];
branchInfo.BranchShortName = (string)row["BranchShortName"];
list.Add(branchInfo);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -