示例#1
0
        public CommandResult Insert(TInfo info)
        {
            CommandResult result;

            try
            {
                LDB_DataContext ldb = LDB_DataContextFactory.CreateLDB(ConnectStr);
                InsertingItem(info, ldb);
                ldb.SubmitChanges();
                result = new CommandResult(ResultCode.Successful, successMsg);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                if (ex.Number == 2627)
                {
                    result = new CommandResult(ResultCode.Fail, "不能插入重复ID的数据!");
                }
                else
                {
                    result = new CommandResult(ResultCode.Fail, "数据在写入数据库时发生错误!");
                }
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()");
            }
            catch (Exception ex)
            {
                result = new CommandResult(ResultCode.Fail, "数据在写入数据库时发生错误!");
                ExceptionPolicy.HandleException(ex, this.GetType().Name + "." + "Insert()");
            }
            return(result);
        }
示例#2
0
        public CommandResult Delete(TInfo info)
        {
            CommandResult result;

            try
            {
                LDB_DataContext ldb = LDB_DataContextFactory.CreateLDB(ConnectStr);
                DeletingItem(info, ldb);
                ldb.SubmitChanges();
                result = new CommandResult(ResultCode.Successful, successMsg);
            }
            catch (Exception ex)
            {
                result = new CommandResult(ResultCode.Fail, "从数据库删除数据时发生错误!");
                ExceptionPolicy.HandleException(ex, this.GetType().FullName + "." + "Delete()");
            }
            return(result);
        }
示例#3
0
        public CommandResult Update(TInfo newVal, TInfo original)
        {
            CommandResult result;

            try
            {
                LDB_DataContext ldb = LDB_DataContextFactory.CreateLDB(ConnectStr);
                UpdatingItem(newVal, original, ldb);
                ldb.SubmitChanges();
                result = new CommandResult(ResultCode.Successful, successMsg);
            }
            catch (Exception ex)
            {
                result = new CommandResult(ResultCode.Fail, "数据在写入数据库时发生错误!");
                ExceptionPolicy.HandleException(ex, this.GetType().FullName + "." + "Update()");
            }
            return(result);
        }