当前位置: 代码迷 >> .NET分析设计 >> 评论一下内容优点和缺点,怎么做更好
  详细解决方案

评论一下内容优点和缺点,怎么做更好

热度:1151   发布时间:2016-05-01 22:43:18.0
评论一下内容优点和缺点,如何做更好~

    public interface ITrade
    {
        void UpdateTradeByTid(string Tid);
        bool CheckTrade(string Tid);
        void InsertTrade(TB_Trade trade);
        TB_Trade GetTrade(string Tid);
    }
    public class Trade : ITrade
    {
        public void UpdateTradeByTid(string Tid)
        {
            TB_Trade trade = GetTrade(Tid);
            if (trade == null)
            {
                trade = new TB_Trade();
                InsertTrade(trade);
            }
            else
            {
                using (GuoTBManageEntities context = new GuoTBManageEntities())
                {
                    context.Entry(trade).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
        public bool CheckTrade(string Tid)
        {
            TB_Trade trade=GetTrade(Tid);
            return trade == null ? false : true;
        }
        public void InsertTrade(TB_Trade trade)
        {
            try
            {
                using (GuoTBManageEntities context = new GuoTBManageEntities())
                {
                    context.TB_Trades.Add(trade);
                    context.SaveChanges();
                }
            }
  相关解决方案