📄 precontractservice.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:25:30
//============================================================
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 PreContractService
{
/// <summary>
///
/// </summary>
/// <param name="preContract"></param>
/// <returns></returns>
public static PreContract AddPreContract(PreContract preContract)
{
string sql =
"INSERT PreContract (ScheduleId, UserId)" +
"VALUES (@ScheduleId, @UserId)";
sql += " ; SELECT @@IDENTITY";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@ScheduleId", preContract.Schedule.ScheduleId), //FK
new SqlParameter("@UserId", preContract.UserId)
};
int newId = DBHelper.GetScalar(sql, para);
return GetPreContractByPreContractId(newId);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
///
/// </summary>
/// <param name="preContract"></param>
public static void DeletePreContract(PreContract preContract)
{
DeletePreContractByPreContractId( preContract.PreContractId );
}
/// <summary>
///
/// </summary>
/// <param name="preContractId"></param>
public static void DeletePreContractByPreContractId(int preContractId)
{
string sql = "DELETE PreContract WHERE PreContractId = @PreContractId";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@PreContractId", preContractId)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
///
/// </summary>
/// <param name="preContract"></param>
public static void ModifyPreContract(PreContract preContract)
{
string sql =
"UPDATE PreContract " +
"SET " +
"ScheduleId = @ScheduleId, " + //FK
"UserId = @UserId " +
"WHERE PreContractId = @PreContractId";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@PreContractId", preContract.PreContractId),
new SqlParameter("@ScheduleId", preContract.Schedule.ScheduleId), //FK
new SqlParameter("@UserId", preContract.UserId)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IList<PreContract> GetAllPreContracts()
{
string sqlAll = "SELECT * FROM PreContract";
return GetPreContractsBySql( sqlAll );
}
/// <summary>
///
/// </summary>
/// <param name="preContractId"></param>
/// <returns></returns>
public static PreContract GetPreContractByPreContractId(int preContractId)
{
string sql = "SELECT * FROM PreContract WHERE PreContractId = @PreContractId";
int scheduleId;
try
{
SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@PreContractId", preContractId));
if (reader.Read())
{
PreContract preContract = new PreContract();
preContract.PreContractId = (int)reader["PreContractId"];
preContract.UserId = (string)reader["UserId"];
scheduleId = (int)reader["ScheduleId"]; //FK
reader.Close();
preContract.Schedule = ScheduleService.GetScheduleByScheduleId(scheduleId);
return preContract;
}
else
{
reader.Close();
return null;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
public static List<PreContract> GetPreContractIdByScheduleId(int ScheduleId)
{
string sql = "SELECT * FROM PreContract WHERE ScheduleId = @ScheduleId";
try
{
List<PreContract> list = new List<PreContract>();
SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@ScheduleId", ScheduleId));
if (reader.Read())
{
PreContract preContract = new PreContract();
preContract.PreContractId = (int)reader["PreContractId"];
preContract.UserId = (string)reader["UserId"];
reader.Close();
preContract.Schedule = ScheduleService.GetScheduleByScheduleId(ScheduleId);
list.Add(preContract);
}
else
{
reader.Close();
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
///
/// </summary>
/// <param name="safeSql"></param>
/// <returns></returns>
private static IList<PreContract> GetPreContractsBySql( string safeSql )
{
List<PreContract> list = new List<PreContract>();
try
{
DataTable table = DBHelper.GetDataSet( safeSql );
foreach (DataRow row in table.Rows)
{
PreContract preContract = new PreContract();
preContract.PreContractId = (int)row["PreContractId"];
preContract.UserId = (string)row["UserId"];
preContract.Schedule = ScheduleService.GetScheduleByScheduleId((int)row["ScheduleId"]); //FK
list.Add(preContract);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
/// <summary>
///
/// </summary>
/// <param name="sql"></param>
/// <param name="values"></param>
/// <returns></returns>
private static IList<PreContract> GetPreContractsBySql( string sql, params SqlParameter[] values )
{
List<PreContract> list = new List<PreContract>();
try
{
DataTable table = DBHelper.GetDataSet( sql, values );
foreach (DataRow row in table.Rows)
{
PreContract preContract = new PreContract();
preContract.PreContractId = (int)row["PreContractId"];
preContract.UserId = (string)row["UserId"];
preContract.Schedule = ScheduleService.GetScheduleByScheduleId((int)row["ScheduleId"]); //FK
list.Add(preContract);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -