- using HRMDAL;
- using HRMTest.Model;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace HRMTest.DAL
- {
- public class DepartmentDAL
- {
- //ListAll(),GetById(),DeleteById(),Insert(),Update()
-
- public Department GetById(Guid id)
- {
- string sql = "select ID, Name,IsDeleted from T_Department where ID=@ID";
- DataTable table = SqlHelper.ExecuteDataTable(sql,
- new SqlParameter("@ID",id));
-
- if(table.Rows.Count<=0)
- {
- //此处不可以加入messageBox为什么?
-
- return null;
- }
- else if(table.Rows.Count>1)
- {
- throw new Exception("存在Id相同的记录");
- }
- else
- {
- DataRow row = table.Rows[0];
- Department depart = new Department();
- depart.ID = (Guid)row["ID"];
- depart.Name = (string)row["Name"];
- depart.IsDeleted = (bool)row["IsDeleted"];
- return depart;
- }
- }
- }
- }
复制代码 |