Files
2019-06-20 14:49:34 +01:00

198 lines
7.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sarand.Win.Forms.Controls;
using Sarand.Core.Bus;
using Sarand.Core.Base;
using Sarand.PatientMgr.Win.Forms.Base;
using Sarand.PatientMgr.Core.App;
using Sarand.Win.Forms.Utils;
namespace Sarand.PatientMgr.Win.Forms.Panels
{
//=======================================================================
public partial class SpmPanel_Items : SpmPanel
{
//-------------------------------------------------------------------
// Configuration.
public new class Config : SpmPanel.Config
{
}
//-------------------------------------------------------------------
// Data members.
private Config config;
//-------------------------------------------------------------------
// Construction.
private SpmPanel_Items() : this(new Config()) { }
protected SpmPanel_Items(Config config) : base()
{
SetConfig(config);
InitializeComponent();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null) components.Dispose();
}
base.Dispose(disposing);
}
//-------------------------------------------------------------------
// Properties.
[Browsable(false), ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual int ItemTotal { get { return 0; } }
[Browsable(false), ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual int ItemCount { get { return 0; } }
[Browsable(false), ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual int SelectedItemCount { get { return 0; } }
[Browsable(false), ReadOnly(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool DeletedItemsAreShown { get; protected set; } = false;
//-------------------------------------------------------------------
// Configure.
private void SetConfig(Config config)
{
base.SetConfig(config);
this.config = config;
}
//-------------------------------------------------------------------
// Initialisation.
protected override void OnCreateControl()
{
base.OnCreateControl();
if (this.IsDesignerHosted()) return;
}
//-------------------------------------------------------------------
// A c t i o n s
//-------------------------------------------------------------------
// Refresh.
protected void RefreshDataItems(object sender, EventArgs e) { RefreshDataItems(); }
public virtual void RefreshDataItems()
{
throw new NotSupportedException(GetType().Name + ".RefreshDataItems not implemented");
}
public virtual void RefreshDataItem(SysId id)
{
throw new NotSupportedException(GetType().Name + ".RefreshDataItem not implemented");
}
public virtual void RemoveDataItem(SysId id)
{
throw new NotSupportedException(GetType().Name + ".RemoveDataItem not implemented");
}
//-------------------------------------------------------------------
// Show/Hide deleted items.
protected void ShowDeletedItems(object sender, EventArgs e) { ShowDeletedItems(); }
public virtual void ShowDeletedItems()
{
DeletedItemsAreShown = true;
RefreshDataItems();
}
protected void HideDeletedItems(object sender, EventArgs e) { HideDeletedItems(); }
public virtual void HideDeletedItems()
{
DeletedItemsAreShown = false;
RefreshDataItems();
}
//-------------------------------------------------------------------
// Create item.
public virtual bool CanCreateItem() { return false; }
protected void CreateItem(object sender, EventArgs e) { CreateItem(); }
public virtual void CreateItem() { }
//-------------------------------------------------------------------
// View/Update item.
public virtual bool CanViewItem() { return false; }
protected void ViewItem(object sender, EventArgs e) { UpdateItem(false); }
public virtual bool CanUpdateItem() { return false; }
protected void UpdateItem(object sender, EventArgs e) { UpdateItem(true); }
public virtual void UpdateItem(bool updateItem = true) { }
//-------------------------------------------------------------------
// Delete item.
public virtual bool CanDeleteItem() { return false; }
protected void DeleteItem(object sender, EventArgs e) { DeleteItem(); }
public virtual void DeleteItem() { }
//-------------------------------------------------------------------
// Data import.
public virtual bool CanImportData() { return false; }
protected void ImportData(object sender, EventArgs e) { ImportData(); }
public virtual void ImportData() { }
//-------------------------------------------------------------------
// Data export.
public virtual bool CanExportData() { return false; }
protected void ExportData(object sender, EventArgs e) { ExportData(); }
public virtual void ExportData() { }
//-------------------------------------------------------------------
// P a n e l E v e n t s
//-------------------------------------------------------------------
// Item count changed.
public event EventHandler ItemCountChanged;
protected void InvokeItemCountChangedEvent(EventArgs e)
{
ItemCountChanged?.Invoke(this, e);
}
//-------------------------------------------------------------------
// Item selection changed.
public event EventHandler ItemSelectionChanged;
protected void InvokeItemSelectionChangedEvent(EventArgs e)
{
ItemSelectionChanged?.Invoke(this, e);
}
//-------------------------------------------------------------------
// Item created.
public class ItemModifiedEventArgs : EventArgs
{
public ItemModifiedEventArgs(Spm.DataItemType itemType, SysId itemId)
{
ItemType = itemType;
ItemId = itemId;
}
public Spm.DataItemType ItemType { get; private set; }
public SysId ItemId { get; private set; }
}
public event EventHandler<ItemModifiedEventArgs> ItemCreated;
protected void InvokeItemCreatedEvent(Spm.DataItemType itemType, SysId itemId)
{
ItemCreated?.Invoke(this, new ItemModifiedEventArgs(itemType, itemId));
}
//-------------------------------------------------------------------
// Item updated.
public event EventHandler<ItemModifiedEventArgs> ItemUpdated;
protected void InvokeItemUpdatedEvent(Spm.DataItemType itemType, SysId itemId)
{
ItemUpdated?.Invoke(this, new ItemModifiedEventArgs(itemType, itemId));
}
//-------------------------------------------------------------------
// Item deleted.
public event EventHandler<ItemModifiedEventArgs> ItemDeleted;
protected void InvokeItemDeletedEvent(Spm.DataItemType itemType, SysId itemId)
{
ItemDeleted?.Invoke(this, new ItemModifiedEventArgs(itemType, itemId));
}
//-------------------------------------------------------------------
}
//=======================================================================
}