Mattersphere Developers Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

Removing Data from KeyValueCollection SearchControl.SelectedItems Empty Removing Data from KeyValueCollection SearchControl.SelectedItems

Tue 4 Feb 2020 - 8:24
We are currently writing code to link Mattercentre documents tab to a new bulk printing solution.
There is currently an unresolveable issue with Laserforms. If the Laserform document template is obsolete or missing, a Laserform error message appears on the print
server. Unfortunately, due to Laserforms not having an API, the messagebox must be closed manually or the entire print sequence for the office freezes.
My solution is to check the documents before sending them to the printing solution. If the docuemnt is a Laserform and its template is obsolete/missing reove it from
the print list. Here is my Pseudocode
const long DOC_ID_OF_OBSOLETE_LASERFORM = 1233771;
FWBS.Common.KeyValueCollection[] mySelectedItems = mySearchControl.SelectedItems;
foreach(FWBS.Common.KeyValueCollection mySelectedItem in mySelectedItems)
{
long myDocID = Convert.toInt64(mySelectedItem[“docid”].Value);
if(myDocID == DOC_ID_OF_OBSOLETE_LASERFORM)
{
SelectedItems.Remove(myDocID);
}
}

Unfortunately, I do not seem to be able to remove the selected document. Either it doesn't work at all or I clear the entire KeyValueCollection and all data is lost.
Any ideas?
avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

Removing Data from KeyValueCollection SearchControl.SelectedItems Empty Re: Removing Data from KeyValueCollection SearchControl.SelectedItems

Tue 4 Feb 2020 - 8:24
If you're using V5 then you can get access to Linq and do the following. Otherwise I'd create a generic list of KeyValueCollection and add to that as you loop through
mySelectedItems if it's not obsolete. If the consumer is expecting an array you can call .ToArray() on the completed list.But using Linq is favourable IMHO as it can be
done in 1 line of code.
avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

Removing Data from KeyValueCollection SearchControl.SelectedItems Empty Re: Removing Data from KeyValueCollection SearchControl.SelectedItems

Tue 4 Feb 2020 - 8:25

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: Consolas, “Courier New”, Courier, Monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #a31515; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4; width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }


//Add reference to System.Core
//and a using System.Linq;

KeyValueCollection[] mySelectedItems = new KeyValueCollection[3];

KeyValueCollection kvc = new KeyValueCollection(); kvc.Add(“Description”, “Desc 1”);
kvc.Add(“docid”, 1); mySelectedItems[0] = kvc;

kvc = new KeyValueCollection(); kvc.Add(“Description”, “Desc 123”);
kvc.Add(“docid”, 123); mySelectedItems[1] = kvc;

kvc = new KeyValueCollection(); kvc.Add(“Description”, “Desc 2”);
kvc.Add(“docid”, 2); mySelectedItems[2] = kvc;
var valid = mySelectedItems.Where(i=>Convert.ToInt64(i[“docid”].Value) != 123); System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach(var validKvc in valid)
{
sb.AppendLine(Convert.ToString(validKvc[“Description”]));
}

System.Windows.Forms.MessageBox.Show(sb.ToString());

avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

Removing Data from KeyValueCollection SearchControl.SelectedItems Empty Re: Removing Data from KeyValueCollection SearchControl.SelectedItems

Tue 4 Feb 2020 - 8:25
We are still on version 4.7 so I will have to loop through creating a newKeyValueCollection[].
The only issue is that the bulkprinting could invole hundreds of documents and looping through them just to remove obsolete Laserform documents will take some time. Thanks anyway.
avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

Removing Data from KeyValueCollection SearchControl.SelectedItems Empty Re: Removing Data from KeyValueCollection SearchControl.SelectedItems

Tue 4 Feb 2020 - 8:25
Just a thought -instead of looping through the items in the search control and then filtering out the laserformscouldn't you just fire a datalist, which has already filtered out the laserforms in its query and print from that list?
avatar
Lynne Harding
Posts : 335
Join date : 2018-12-20

Removing Data from KeyValueCollection SearchControl.SelectedItems Empty Re: Removing Data from KeyValueCollection SearchControl.SelectedItems

Tue 4 Feb 2020 - 8:27
Thanks to everyone for their help. I finally went with this solution


//********************************************************************
// SPR 22-08-2013
// This method returns a new KeyValueCollection of selected documents,
// with all obsolete Laserform documents removed.
//********************************************************************
private FWBS.Common.KeyValueCollection[] RemoveObsoleteLaserForms( FWBS.Common.KeyValueCollection[] theSelectedItems)
{
int ARRAY_SIZE = ((theSelectedItems.Length) - (CountOfObsoleteLaserForms(theSelectedItems)));

FWBS.Common.KeyValueCollection[] results =
new FWBS.Common.KeyValueCollection[ARRAY_SIZE]; try
{
int x = 0;
while(x < ARRAY_SIZE)
{
foreach(
FWBS.Common.KeyValueCollection mySelectedItem in theSelectedItems)
{
long myDocID = Convert.ToInt64(mySelectedItem[“docid”].Value); if(IsDocumentLaserForm(myDocID))
if(IsDocumentLaserForm(myDocID))
{
System.Collections.Generic.Dictionary<string, string> laserFormTemplateInfo = GetLaserFormTemplateFilePath(myDocID);

if(!IsLaserFormVersionObsolete(laserFormTemplateInfo))
{
results[x] = mySelectedItem; x++;
}
}
else
{
results[x] = mySelectedItem; x++;
}

}
}
}
catch(System.Exception ex)
{
KnException(ex);
}

return results;
}



Sponsored content

Removing Data from KeyValueCollection SearchControl.SelectedItems Empty Re: Removing Data from KeyValueCollection SearchControl.SelectedItems

Back to top
Permissions in this forum:
You cannot reply to topics in this forum