This commit is contained in:
227
source/Plugins/AyaNova.Plugin.ClientRemover/ClientRemover.cs
Normal file
227
source/Plugins/AyaNova.Plugin.ClientRemover/ClientRemover.cs
Normal file
@@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Reflection;
|
||||
using AyaNova.PlugIn;
|
||||
using GZTW.AyaNova.BLL;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
//using Newtonsoft.Json;
|
||||
//using Newtonsoft.Json.Serialization;
|
||||
//using ICSharpCode.SharpZipLib.Zip;
|
||||
|
||||
namespace AyaNova.PlugIn.ClientRemover
|
||||
{
|
||||
class ClientRemover : IAyaNovaPlugin
|
||||
{
|
||||
|
||||
#region Plugin interface
|
||||
System.Resources.ResourceManager resman = null;
|
||||
private static List<RootObjectTypes> ObjectsWeCanDealWith = null;
|
||||
|
||||
|
||||
public string PluginName
|
||||
{
|
||||
get { return "ClientRemover"; }
|
||||
}
|
||||
|
||||
public string PluginVersion
|
||||
{
|
||||
get { return "7.5"; }
|
||||
}
|
||||
|
||||
public string About
|
||||
{
|
||||
get
|
||||
{
|
||||
return "AyaNova ClientRemover plugin\r\n" +
|
||||
"Built " + AyaNova.PlugIn.ClientRemover.Timestamp.BuildAt.ToString() + "\r\n" +
|
||||
"Copyright 2018 Ground Zero Tech-Works Inc.";
|
||||
}
|
||||
}
|
||||
|
||||
public Guid PluginID
|
||||
{
|
||||
get { return new Guid("{37486FF1-3F9B-4B37-880E-75B934174ACB}"); }
|
||||
}
|
||||
|
||||
public System.Drawing.Image PluginSmallIcon
|
||||
{
|
||||
get { return Resource1.ClientRemover16; }
|
||||
}
|
||||
|
||||
public System.Drawing.Image PluginLargeIcon
|
||||
{
|
||||
get { return Resource1.ClientRemover32; }
|
||||
}
|
||||
|
||||
public System.Resources.ResourceManager AyaNovaResourceManager
|
||||
{
|
||||
set { resman = value; }
|
||||
get { return resman; }
|
||||
}
|
||||
|
||||
public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText)
|
||||
{
|
||||
if (AyaNovaVersion.Major < 7)
|
||||
{
|
||||
MessageBox.Show("This ClientRemover plugin requires AyaNova version 7.5 or newer");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (AyaNovaVersion.Minor < 5)
|
||||
{
|
||||
MessageBox.Show("This ClientRemover plugin requires AyaNova version 7.5 or newer");
|
||||
return false;
|
||||
}
|
||||
|
||||
ObjectsWeCanDealWith = new List<RootObjectTypes>();
|
||||
ObjectsWeCanDealWith.Add(RootObjectTypes.Client);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
#region ShowMenu?
|
||||
public bool SingleObjectMenuShow(RootObjectTypes objectType)
|
||||
{
|
||||
return (ObjectsWeCanDealWith.Contains(objectType));
|
||||
}
|
||||
|
||||
public bool MultipleObjectsMenuShow(RootObjectTypes objectType)
|
||||
{
|
||||
return (ObjectsWeCanDealWith.Contains(objectType));
|
||||
}
|
||||
|
||||
#endregion show menu?
|
||||
|
||||
public List<AyaNovaPluginMenuItem> SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject)
|
||||
{
|
||||
if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
|
||||
List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
|
||||
list.Add(new AyaNovaPluginMenuItem("ClientRemover", "Delete this client and all it's records", null, null));
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<AyaNovaPluginMenuItem> MultipleObjectsMenuOptions(RootObjectTypes objectType)
|
||||
{
|
||||
if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
|
||||
if (objectType == RootObjectTypes.Nothing) return null;
|
||||
List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
|
||||
list.Add(new AyaNovaPluginMenuItem("ClientRemover", "Delete selected clients and all their records", null, null));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List<Guid> objectIDList, object listObject)
|
||||
{
|
||||
if (!User.CurrentUserIsAnAdministrator)
|
||||
{
|
||||
MessageBox.Show("This action can only be done by the AyaNova Administrator account");
|
||||
return false;
|
||||
}
|
||||
if (objectIDList.Count == 0)
|
||||
{
|
||||
MessageBox.Show("There are no Clients selected in the list\r\nSelect one or more clients first");
|
||||
return false;
|
||||
}
|
||||
|
||||
DoDelete(objectIDList);
|
||||
return true;//true=refresh the list
|
||||
}
|
||||
|
||||
public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject)
|
||||
{
|
||||
if (!User.CurrentUserIsAnAdministrator)
|
||||
{
|
||||
MessageBox.Show("This action can only be done by the AyaNova Administrator account");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
List<Guid> objectIDList = new List<Guid>(1);
|
||||
objectIDList.Add(((Client)ayaNovaObject).ID);
|
||||
DoDelete(objectIDList);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region DELETE
|
||||
|
||||
private void DoDelete(List<Guid> SelectedItems)
|
||||
{
|
||||
//REally delete... this client.... these 14 clients...
|
||||
string sAffected = string.Empty;
|
||||
bool bMultiple = SelectedItems.Count > 1;
|
||||
|
||||
if (bMultiple)
|
||||
sAffected = "these " + SelectedItems.Count.ToString() + " Clients\r\n";
|
||||
else
|
||||
sAffected = "this Client\r\n";
|
||||
|
||||
DialogResult dr = MessageBox.Show("WARNING!! \r\n\r\n" +
|
||||
"You are about to permanently delete " + sAffected +
|
||||
"and all their related records including the following:\r\n\r\nService workorders, quotes, units, client notes, client users, etc.\r\n\r\n" +
|
||||
"The only way to reverse this will be to restore your AyaNova database from a backup.\r\n\r\n" +
|
||||
"Permanently delete?", "", MessageBoxButtons.YesNoCancel,
|
||||
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
|
||||
|
||||
if (dr != DialogResult.Yes)
|
||||
return;
|
||||
|
||||
StringBuilder sbRet = new StringBuilder();
|
||||
|
||||
//Delete them
|
||||
foreach (Guid id in SelectedItems)
|
||||
{
|
||||
|
||||
bool deleted = false;
|
||||
var theName = NameFetcher.GetName(RootObjectTypes.Client, id);
|
||||
sbRet.AppendLine("Attempting to delete client " + theName);
|
||||
sbRet.AppendLine();
|
||||
try
|
||||
{
|
||||
sbRet.Append(Client.DeleteAllClientWorkorders(id));
|
||||
sbRet.Append(Client.DeleteAllClientUnits(id));
|
||||
Client.DeleteItem(id);
|
||||
sbRet.AppendLine("Client deleted\r\n");
|
||||
deleted = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
while (ex.InnerException != null)
|
||||
ex = ex.InnerException;
|
||||
sbRet.AppendLine("Error attempting to delete client:");
|
||||
sbRet.AppendLine(ex.Message);
|
||||
}
|
||||
|
||||
if (!deleted)
|
||||
sbRet.AppendLine("\r\nClient " + theName + " was *NOT* deleted\r\n");
|
||||
|
||||
if (bMultiple)
|
||||
sbRet.AppendLine("************************************************************");
|
||||
|
||||
}
|
||||
|
||||
CopyableMessageBox d = new CopyableMessageBox(sbRet.ToString());
|
||||
d.ShowDialog();
|
||||
|
||||
}
|
||||
#endregion delete
|
||||
|
||||
|
||||
|
||||
|
||||
} //eoc
|
||||
|
||||
}//eons
|
||||
Reference in New Issue
Block a user