Exemplo n.º 1
0
        /// <summary>
        /// 将实体对象从数据库中删除,调用该方法时实体对象必须具备主键属性
        /// </summary>
        /// <param name="object">实体对象</param>
        public virtual int Delete(object @object)
        {
            Type elementType = @object.GetType();

            if (@object.GetType().IsAssignableFrom(typeof(IEntityObject)))
            {
                elementType = @object.GetType().BaseType;
            }

            IDeleteable deleteable = this.factory.CreateDeleteProvider(this).CreateDelete(elementType);

            var properties = elementType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            properties.Where(property => property.IsPrimaryKey()).Each(property =>
            {
                ParameterExpression pe = Expression.Parameter(@object.GetType(), "s");
                MemberExpression me    = Expression.MakeMemberAccess(pe, property);
                ConstantExpression ce  = Expression.Constant(property.EmitGetValue(@object), property.PropertyType);
                BinaryExpression be    = Expression.Equal(me, ce);

                deleteable = deleteable.Where(be);
            });

            return(deleteable.Execute(elementType));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Validates the AntiForgery token and calls delete for the id on the Repository
 /// </summary>
 /// <typeparam name="T">A type that implements INameable and IIdentifiable</typeparam>
 /// <param name="controller">The controller being extended</param>
 /// <param name="id">The id of the object to be deleted</param>
 /// <returns>A redirect to the Index</returns>
 public static ActionResult Delete <T>(this IDeleteable <T> controller, int id)
     where T : class,
 INameable,
 IIdentifiable
 {
     return(Delete(controller, controller.Repository.Find(id)));
 }
Exemplo n.º 3
0
 // ---------------------------------------------------------------------
 // Delete
 // ---------------------------------------------------------------------
 public void Delete <T>(T model, String statement, IDeleteable <T> traits)
 {
     using (SqlCommand cmd = new SqlCommand(statement, m_connection))
     {
         traits.ApplyDelete(model, cmd);
         cmd.ExecuteNonQuery();
     }
 }
Exemplo n.º 4
0
 protected virtual void ApplyDeleteFilterList(IDeleteable <TEntity> deleteable)
 {
     if (_filters[GetFilterIndex(nameof(ISoftDelete))].IsEnabled && GetInterfacesOfTEntity().Contains(typeof(ISoftDelete)))
     {
         var dbColumnName = Context.EntityMaintenance.GetDbColumnName <TEntity>(nameof(ISoftDelete.IsDeleted));
         deleteable = deleteable.Where($"{dbColumnName} = 0");
     }
 }
Exemplo n.º 5
0
 // ---------------------------------------------------------------------
 // Delete
 // ---------------------------------------------------------------------
 public void Delete <T>(T model, String statement, IDeleteable <T> traits)
 {
     using (IDbCommand command = m_connection.CreateCommand())
     {
         command.CommandText = statement;
         traits.ApplyDelete(model, command);
         command.ExecuteNonQuery();
     }
 }
Exemplo n.º 6
0
        public static void Delete(this IDeleteable deleteable)
        {
            if (deleteable is IDeleteAware)
            {
                ((IDeleteAware)deleteable).OnPreDelete();
            }

            deleteable.DeletedKey = SystemDateTime.Now;
        }
Exemplo n.º 7
0
        /// <inheritdoc/>
        public virtual bool DeleteWithConfirmation(IDeleteable deleteable)
        {
            deleteable.DeleteInDatabase();

            if (deleteable is DatabaseEntity d)
            {
                Publish(d);
            }

            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 按条件删除(物理删除)
        /// </summary>
        /// <typeparam name="T">表实体</typeparam>
        /// <param name="where">条件语句,如:"id=@id"</param>
        /// <param name="parameters">参数,如:new{id=0}</param>
        /// <returns>int</returns>
        public int Delete <T>(string where, object parameters) where T : class, new()
        {
            IDeleteable <T> r = _db.Deleteable <T>();

            if (!string.IsNullOrEmpty(where))
            {
                r = r.Where(where, parameters);
            }

            return(r.ExecuteCommand());
        }
Exemplo n.º 9
0
        public override bool DeleteWithConfirmation(IDeleteable deleteable)
        {
            if (deleteable is DatabaseEntity d && !d.Exists())
            {
                throw new Exception("Attempt made to delete an object which didn't exist");
            }

            deleteable.DeleteInDatabase();
            RefreshBus.Publish(this, new RefreshObjectEventArgs((DatabaseEntity)deleteable));
            return(true);
        }
Exemplo n.º 10
0
        public Task <bool> ExecuteCommandHasChangeAsync()
        {
            Task <bool> result = new Task <bool>(() =>
            {
                IDeleteable <T> asyncDeleteable = CopyDeleteable();
                return(asyncDeleteable.ExecuteCommand() > 0);
            });

            TaskStart(result);
            return(result);
        }
Exemplo n.º 11
0
        public Task <int> ExecuteCommandAsync()
        {
            Task <int> result = new Task <int>(() =>
            {
                IDeleteable <T> asyncDeleteable = CopyDeleteable();
                return(asyncDeleteable.ExecuteCommand());
            });

            TaskStart(result);
            return(result);
        }
Exemplo n.º 12
0
 public void Remove(Product entity)
 {
     if (entity is IDeleteable)//control
     {
         IDeleteable item = (IDeleteable)entity;
         item.IsDeleted = true;
         Update(entity);
     }
     else
     {
         _db.Products.Remove(entity);
     }
 }
Exemplo n.º 13
0
 public void Remove(Product product)
 {
     if (product is IDeleteable)
     {
         IDeleteable item = (IDeleteable)product;
         item.IsDeleted = true;
         Update(product);
     }
     else
     {
         _db.Products.Remove(product);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Validates the AntiForgery token and calls delete for the id on the Repository
        /// </summary>
        /// <typeparam name="T">A type that implements INameable and IIdentifiable</typeparam>
        /// <param name="controller">The controller being extended</param>
        /// <param name="id">The id of the object to be deleted</param>
        /// <returns>A redirect to the Index</returns>
        public static ActionResult Delete <T>(this IDeleteable <T> controller, T model)
            where T : class,
        INameable,
        IIdentifiable
        {
            AntiForgeryHelperAdapter.Validate();

            controller.Repository.Delete(model);
            controller.Repository.SaveChanges();

            return(new RedirectToRouteResult("Default",
                                             new RouteValueDictionary(new { action = "Index" })));
        }
Exemplo n.º 15
0
        private void DoDelete()
        {
            IDeleteable del = tvProjects.SelectedNode.Tag as IDeleteable;

            if (del == null)
            {
                return;
            }

            string text = tvProjects.SelectedNode.Text;

            if (MessageBox.Show("確定要刪除『" + text + "』?", "確定", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                del.Delete();
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 设置筛选函数
        /// </summary>
        /// <param name="source">IDeleteable 对象</param>
        /// <param name="predicate">用于测试每个源元素是否满足条件的函数</param>
        public static IDeleteable Where(this IDeleteable source, Expression predicate)
        {
            if (predicate == null)
            {
                return(source);
            }

            if (source.Predicate == null)
            {
                source.Predicate = predicate;
            }
            else
            {
                source.Predicate = Expression.AndAlso(source.Predicate, predicate);
            }

            return(source);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 设置筛选函数
        /// </summary>
        /// <param name="source">IDeleteable<T> 对象</param>
        /// <param name="predicate">用于测试每个源元素是否满足条件的函数</param>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public static IDeleteable <T> Where <T>(this IDeleteable <T> source, Expression <Func <T, bool> > predicate)
        {
            if (predicate == null)
            {
                return(source);
            }

            if (source.Predicate == null)
            {
                source.Predicate = predicate.Body;
            }
            else
            {
                source.Predicate = Expression.AndAlso(source.Predicate, predicate.Body);
            }

            return(source);
        }
Exemplo n.º 18
0
        /// <inheritdoc/>
        public virtual bool DeleteWithConfirmation(IDeleteable deleteable)
        {
            if (IsInteractive && InteractiveDeletes)
            {
                bool didDelete = InteractiveDelete(deleteable);

                if (didDelete)
                {
                    PublishNearest(deleteable);
                }

                return(didDelete);
            }
            else
            {
                deleteable.DeleteInDatabase();
                PublishNearest(deleteable);

                return(true);
            }
        }
Exemplo n.º 19
0
 public ExecuteCommandDelete(IBasicActivateItems activator,
                             [DemandsInitialization("The object you want to delete", Mandatory = true)]
                             IDeleteable deletable) : this(activator, new [] { deletable })
 {
 }
Exemplo n.º 20
0
 public static void UnDelete(this IDeleteable deleteable)
 {
     deleteable.DeletedKey = null;
 }
Exemplo n.º 21
0
 public static bool IsDeleted(this IDeleteable deleteable)
 {
     return(deleteable.DeletedKey.HasValue);
 }
Exemplo n.º 22
0
 public void Delete <T>(T model, IDeleteable <T> traits)
 {
     Delete(model, traits.DeleteSql(), traits);
 }
Exemplo n.º 23
0
        public override bool DeleteWithConfirmation(IDeleteable deleteable)
        {
            var databaseObject = deleteable as DatabaseEntity;

            //If there is some special way of describing the effects of deleting this object e.g. Selected Datasets
            var customMessageDeletable = deleteable as IDeletableWithCustomMessage;

            if (databaseObject is Catalogue c)
            {
                if (c.GetExtractabilityStatus(RepositoryLocator.DataExportRepository).IsExtractable)
                {
                    if (YesNo("Catalogue must first be made non extractable before it can be deleted, mark non extractable?", "Make Non Extractable"))
                    {
                        var cmd = new ExecuteCommandChangeExtractability(this, c);
                        cmd.Execute();
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (databaseObject is AggregateConfiguration ac && ac.IsJoinablePatientIndexTable())
            {
                var users = ac.JoinableCohortAggregateConfiguration?.Users?.Select(u => u.AggregateConfiguration);
                if (users != null)
                {
                    users = users.ToArray();
                    if (users.Any())
                    {
                        WideMessageBox.Show("Cannot Delete", $"Cannot Delete '{ac.Name}' because it is linked to by the following AggregateConfigurations:{Environment.NewLine}{string.Join(Environment.NewLine,users)}");
                        return(false);
                    }
                }
            }

            string overrideConfirmationText = null;

            if (customMessageDeletable != null)
            {
                overrideConfirmationText = "Are you sure you want to " + customMessageDeletable.GetDeleteMessage() + "?";
            }

            //it has already been deleted before
            if (databaseObject != null && !databaseObject.Exists())
            {
                return(false);
            }

            string idText = "";

            if (databaseObject != null)
            {
                idText = " ID=" + databaseObject.ID;
            }

            if (databaseObject != null)
            {
                var exports = RepositoryLocator.CatalogueRepository.GetReferencesTo <ObjectExport>(databaseObject).ToArray();
                if (exports.Any(e => e.Exists()))
                {
                    if (YesNo("This object has been shared as an ObjectExport.  Deleting it may prevent you loading any saved copies.  Do you want to delete the ObjectExport definition?", "Delete ObjectExport"))
                    {
                        foreach (ObjectExport e in exports)
                        {
                            e.DeleteInDatabase();
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (
                YesNo(
                    overrideConfirmationText ?? ("Are you sure you want to delete '" + deleteable + "'?")
                    + Environment.NewLine + "(" + deleteable.GetType().Name + idText + ")",
                    "Delete " + deleteable.GetType().Name))
            {
                deleteable.DeleteInDatabase();

                if (databaseObject == null)
                {
                    var descendancy = CoreChildProvider.GetDescendancyListIfAnyFor(deleteable);
                    if (descendancy != null)
                    {
                        databaseObject = descendancy.Parents.OfType <DatabaseEntity>().LastOrDefault();
                    }
                }

                if (deleteable is IMasqueradeAs)
                {
                    databaseObject = databaseObject ?? ((IMasqueradeAs)deleteable).MasqueradingAs() as DatabaseEntity;
                }

                if (databaseObject == null)
                {
                    throw new NotSupportedException("IDeletable " + deleteable +
                                                    " was not a DatabaseObject and it did not have a Parent in it's tree which was a DatabaseObject (DescendancyList)");
                }

                RefreshBus.Publish(this, new RefreshObjectEventArgs(databaseObject)
                {
                    DeletedObjectDescendancy = CoreChildProvider.GetDescendancyListIfAnyFor(databaseObject)
                });

                return(true);
            }

            return(false);
        }
Exemplo n.º 24
0
 public static void RegisterDelete <T>(IDeleteable <T> converter)
 {
     Init();
     m_delete_register[typeof(T)] = converter;
 }
Exemplo n.º 25
0
        private void tvProjects_AfterSelect(object sender, TreeViewEventArgs e)
        {
            INodeHandler handler = e.Node.Tag as INodeHandler;

            if (handler != null)
            {
                if (handler.IsFirstClick)
                {
                    handler.OnFirstClick();
                }
                else
                {
                    handler.OnClick();
                }
            }
            splitContainer1.Panel2.Controls.Clear();

            IDeleteable del = handler as IDeleteable;

            tsbtnDelete.Enabled = false;
            if (del != null)
            {
                tsbtnDelete.Enabled     = true;
                tsbtnDelete.ToolTipText = del.TitleOfDelete;
                menuProject.Items.Add(del.TitleOfDelete, actImgs.Images["delete"], cmDelete_Click);
            }

            IAddable add = handler as IAddable;

            tsbtnAdd.Enabled = false;
            if (add != null)
            {
                tsbtnAdd.Enabled     = true;
                tsbtnAdd.ToolTipText = add.TitleOfAdd;
                menuProject.Items.Add(add.TitleOfAdd, actImgs.Images["add"], cmAdd_Click);
            }

            IReloadable reload = handler as IReloadable;

            tsbtnReload.Enabled = false;
            if (reload != null)
            {
                tsbtnReload.Enabled = true;
            }

            ITestable test = handler as ITestable;

            tsbtnTest.Enabled = false;
            if (test != null)
            {
                tsbtnTest.Image   = actImgs.Images[test.TestImageKey];
                tsbtnTest.Enabled = true;
            }

            IRenameable rename = handler as IRenameable;

            tsbtnRename.Enabled = false;
            if (rename != null)
            {
                tsbtnRename.Enabled = true;
            }

            IExportable export = handler as IExportable;

            tsbtnExport.Enabled = false;
            if (export != null)
            {
                tsbtnExport.Enabled = true;
            }

            ISetupable setup = handler as ISetupable;

            cmSetup.Enabled = false;
            if (setup != null)
            {
                cmSetup.Enabled = true;
            }

            IDeployable deploy = handler as IDeployable;

            cmDeploy.Enabled = false;
            if (deploy != null)
            {
                cmDeploy.Enabled = true;
            }

            IDeployToPhysical phyDeploy = handler as IDeployToPhysical;

            tsbtnDeployToPhysical.Enabled = false;
            if (phyDeploy != null)
            {
                tsbtnDeployToPhysical.Enabled = true;
            }

            IImportFromPhysical phyImport = handler as IImportFromPhysical;

            tsbtnImportFromPhysical.Enabled = false;
            if (phyImport != null)
            {
                tsbtnImportFromPhysical.Enabled = true;
            }

            IImportable import = handler as IImportable;

            tsbtnImport.Enabled = false;
            if (import != null)
            {
                tsbtnImport.Enabled = true;
            }

            IJoinProject joinProject = handler as IJoinProject;

            tsbtnJoinProject.Enabled = false;
            if (joinProject != null)
            {
                tsbtnJoinProject.Enabled = true;
            }

            ILeaveProject leaveProject = handler as ILeaveProject;

            tsbtnLeaveProject.Enabled = false;
            if (leaveProject != null)
            {
                tsbtnLeaveProject.Enabled = true;
            }

            ISyncUpload syncUplaod = handler as ISyncUpload;

            cmUpload.Enabled = false;
            if (syncUplaod != null)
            {
                cmUpload.Enabled = true;
            }

            ISyncUpload syncDownload = handler as ISyncUpload;

            cmDownload.Enabled = false;
            if (syncDownload != null)
            {
                cmDownload.Enabled = true;
            }

            tsEditMode.Items.Clear();
            rsbtnSave.Enabled = false;
            IEditorManager manager = handler as IEditorManager;

            if (manager != null)
            {
                rsbtnSave.Enabled = false;
                foreach (IEditable editable in manager.Editors)
                {
                    ToolStripItem item = tsEditMode.Items.Add(editable.ModeTitle, actImgs.Images[editable.ImageKey], cmEdit_Click);
                    item.ToolTipText = editable.ModeTitle;
                    item.Text        = string.Empty;
                    item.Tag         = editable;
                }
            }
        }
Exemplo n.º 26
0
 /// <summary>
 /// 执行删除操作
 /// </summary>
 /// <param name="source">IDeleteable 对象</param>
 /// <typeparam name="T">元素类型</typeparam>
 public static int Execute <T>(this IDeleteable <T> source)
 {
     return(source.Provider.Execute <T>(source.Predicate));
 }
Exemplo n.º 27
0
        private void tvProjects_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                tvProjects.SelectedNode = e.Node;

                menuProject.Items.Clear();

                //判斷是否可以開啟
                IEditorManager editorManager = e.Node.Tag as IEditorManager;
                if (editorManager != null)
                {
                    if (editorManager.Editors.Count == 1)
                    {
                        IEditable     editable = editorManager.Editors[0];
                        ToolStripItem item     = menuProject.Items.Add(editable.DocumentTitle, actImgs.Images[editable.ImageKey], cmEdit_Click);
                        item.Tag = editable;
                    }
                    else if (editorManager.Editors.Count > 0)
                    {
                        ToolStripMenuItem menuItem = new ToolStripMenuItem("開啟");
                        menuProject.Items.Add(menuItem);

                        foreach (IEditable editable in editorManager.Editors)
                        {
                            ToolStripItem item = menuItem.DropDownItems.Add(editable.DocumentTitle, actImgs.Images[editable.ImageKey], cmEdit_Click);
                            item.Tag = editable;
                        }
                    }
                }

                //判斷是否可以改名
                ToolStripMenuItem cmRename = new ToolStripMenuItem("重新命名(&N)");
                this.CheckMenuItemVisiable(typeof(IRenameable), cmRename);
                cmRename.Click += new EventHandler(cmRename_Click);
                cmRename.Image  = actImgs.Images["rename"];

                //判斷是否可以新增
                IAddable addable = e.Node.Tag as IAddable;
                if (addable != null)
                {
                    menuProject.Items.Add(addable.TitleOfAdd, actImgs.Images["add"], cmAdd_Click);
                }

                //判斷是否可以重新整理
                ToolStripMenuItem cmReload = new ToolStripMenuItem("重新整理(&R)");
                this.CheckMenuItemVisiable(typeof(IReloadable), cmReload);
                cmReload.Click += new EventHandler(cmReload_Click);
                cmReload.Image  = actImgs.Images["reload"];

                //判斷是否可以刪除
                IDeleteable deleteable = e.Node.Tag as IDeleteable;
                if (deleteable != null)
                {
                    menuProject.Items.Add(deleteable.TitleOfDelete, actImgs.Images["delete"], cmDelete_Click);
                }

                //判斷是否可以測試
                ITestable testable = e.Node.Tag as ITestable;
                if (testable != null)
                {
                    menuProject.Items.Add(testable.TitleOfTest, actImgs.Images[testable.TestImageKey], cmTest_Click);
                }

                //判斷是否可以匯出
                ToolStripMenuItem cmExport = new ToolStripMenuItem("匯出(&E)");
                this.CheckMenuItemVisiable(typeof(IExportable), cmExport);
                cmExport.Click += new EventHandler(cmExport_Click);
                cmExport.Image  = actImgs.Images["export"];

                //判斷是否可以匯入
                ToolStripMenuItem cmImport = new ToolStripMenuItem("匯入(&I)");
                this.CheckMenuItemVisiable(typeof(IImportable), cmImport);
                cmImport.Click += new EventHandler(cmImport_Click);
                cmImport.Image  = actImgs.Images["import"];

                //判斷是否可以加入專案
                IJoinProject join = e.Node.Tag as IJoinProject;
                if (join != null)
                {
                    menuProject.Items.Add("加入專案(&J)", actImgs.Images["join"], cmJoinProject_Click);
                }

                //判斷是否可以匯入
                ILeaveProject leave = e.Node.Tag as ILeaveProject;
                if (leave != null)
                {
                    menuProject.Items.Add("從專案卸載(&L)", actImgs.Images["leave"], cmLeaveProject_Click);
                }

                //判斷是否可以上傳
                ISyncUpload upload = e.Node.Tag as ISyncUpload;
                if (upload != null)
                {
                    menuProject.Items.Add("同步至伺服器(&U)", actImgs.Images["upload"], cmUpload_Click);
                }

                //判斷是否可以下載
                ISyncDownload download = e.Node.Tag as ISyncDownload;
                if (download != null)
                {
                    menuProject.Items.Add("自伺服器同步(&D)", actImgs.Images["download"], cmDownload_Click);
                }

                //判斷是否可以設定
                ISetupable setup = e.Node.Tag as ISetupable;
                if (setup != null)
                {
                    menuProject.Items.Add(setup.SetupTitle + "(&S)", actImgs.Images["setup"], cmSetup_Click);
                }

                //判斷是否可以佈署
                IDeployable deploy = e.Node.Tag as IDeployable;
                if (deploy != null)
                {
                    menuProject.Items.Add("佈署(&L)", actImgs.Images["deploy"], cmDeploy_Click);
                }

                //判斷是否可以佈署到實體
                IDeployToPhysical deployToPhysical = e.Node.Tag as IDeployToPhysical;
                if (deployToPhysical != null)
                {
                    menuProject.Items.Add("佈署到實體(&P)", actImgs.Images["deployToPhysical"], tsbtnDeployToPhysical_Click);
                }

                //判斷是否可以從實體 Service 載入
                IImportFromPhysical importFromPhysical = e.Node.Tag as IImportFromPhysical;
                if (importFromPhysical != null)
                {
                    menuProject.Items.Add("實體 Service 載入(&X)", actImgs.Images["importFromPhysical"], tsbtnImportFromPhysical_Click);
                }

                menuProject.Show(e.Location);
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// 执行删除操作
 /// </summary>
 /// <param name="source">IDeleteable 对象</param>
 /// <param name="elementType">元素类型</param>
 public static int Execute(this IDeleteable source, Type elementType)
 {
     return(source.Provider.Execute(elementType, source.Predicate));
 }
Exemplo n.º 29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="able"></param>
 public SugarWDeletable(IDeleteable <T> able)
 {
     _deletable = able;
 }
Exemplo n.º 30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="client"></param>
 public SugarWDeletable(SqlSugarClient client)
 {
     _deletable = client.Deleteable <T>();
 }