41-4장 답변형 게시판(Biz)
ReplyBiz.Cs |
using System; using Reply.Entity; using Reply.Dsl; using System.Transactions; using System.Collections.Generic; using System.Data; namespace Reply.Bsl { //트랜잭션 처리 관련 public class ReplyBiz { #region 입력 : InsertReply() public int InsertReply(ReplyEntity re) { int result = -1; using (TransactionScope scope = new TransactionScope { ReplyDac rd = new ReplyDac(); result = rd.InsertReply(re); scope.Complete(); } return result; } #endregion #region 출력 public List<ReplyEntity> SelectReply() { //반환 용도로 리스트네네릭 클래스 변수 선언 List<ReplyEntity> lst = new List<ReplyEntity>(); //Dac단에서 DataSet받기 DataSet ds = (new ReplyDac()).SelectReply(); DataTable dt = ds.Tables[0]; //반환된 레코드 수 만큼 반복 ReplyEntity re = new ReplyEntity(); re.Num = Convert.ToInt32(dt.Rows[i]["Num"]); re.Name = dt.Rows[i]["Name"].ToString(); re.Email = dt.Rows[i]["Email"].ToString(); re.Title = dt.Rows[i]["Tilte"].ToString(); re.PostDate = Convert.ToDateTime(dt.Rows[i]["PostData"].ToString()); re.PostIP = dt.Rows[i]["PostIP"].ToString(); re.Content = dt.Rows[i]["Content"].ToString(); re.Password = dt.Rows[i]["Password"].ToString(); re.ReadCount = Convert.ToInt32(dt.Rows[i]["ReadCount"].ToString()); re.Encoding = dt.Rows[i]["Encoding"].ToString(); re.Homepage = dt.Rows[i]["Homepage"].ToString(); re.Ref = Convert.ToInt32(dt.Rows[i]["Ref"].ToString()); re.Step = Convert.ToInt32(dt.Rows[i]["Step"].ToString()); re.RefOrder = Convert.ToInt32(dt.Rows[i]["RefOrder"].ToString()); lst.Add(re); } return lst; } #endregion public ReplyEntity SelectReplyByNum(int num) { ReplyEntity re = new ReplyEntity(); //데이터가 있으면, 엔터디 담기 using (IDataReader dr = (new ReplyDac()).SelectReplyByNum(num)) { if (dr.Read()) { re.Num = Convert.ToInt32(dr["Num"]); re.Name = dr["Name"].ToString(); re.Email = dr["Email"].ToString(); re.Title = dr["Tilte"].ToString(); re.PostDate = Convert.ToDateTime(dr["PostData"].ToString()); re.PostIP = dr["PostIP"].ToString(); re.Content = dr["Content"].ToString(); re.Password = dr["Password"].ToString(); re.ReadCount = Convert.ToInt32(dr["ReadCount"].ToString()); re.Encoding = dr["Encoding"].ToString(); re.Homepage = dr["Homepage"].ToString(); re.Ref = Convert.ToInt32(dr["Ref"].ToString()); re.Step = Convert.ToInt32(dr["Step"].ToString()); re.RefOrder = Convert.ToInt32(dr["RefOrder"].ToString()); } dr.Close(); } //결과값 반환 return re; } } } |