Ejemplo n.º 1
0
        /// <summary>
        /// 保存到数据库
        /// </summary>
        /// <param name="entity">针对的实体对象</param>
        /// <param name="ResultMsg">返回的消息</param>
        /// <returns>返回是否成功标志</returns>
        public static bool saveData(Landlord2Entities context, object entity, out string ResultMsg)
        {
            bool flag = false;
            int  num;

            try
            {
                num  = context.SaveChanges();
                flag = true;

#if DEBUG
                ResultMsg = string.Format("成功操作{0}条记录。", num);
#else
                ResultMsg = string.Format("数据操作成功。");
#endif
            }
            catch (OptimisticConcurrencyException)
            {
                ((IObjectContextAdapter)context).ObjectContext.Refresh(RefreshMode.ClientWins, entity);
                num  = context.SaveChanges();
                flag = true;

#if DEBUG
                ResultMsg = string.Format("成功处理开放式并发异常,并操作{0}条记录。", num);
#else
                ResultMsg = string.Format("数据操作成功。");
#endif
            }
            catch (Exception ex)
            {
                string msg = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;

#if DEBUG
                ResultMsg = string.Format("数据操作失败:{0}", msg);
#else
                ResultMsg = string.Format("数据操作失败,详细信息请查看日志文件。");
                PrintLog(string.Format("数据操作失败:{0}", msg));
#endif
            }
            return(flag);
        }
Ejemplo n.º 2
0
 public UC源房详细(bool isReadOnly, Landlord2Entities context)
 {
     InitializeComponent();
     IsReadOnly    = isReadOnly;
     parentContext = context;
 }