Add image in arraylist - wpf

I have to create a WPF app. which collects strings and images in rows. I am not sure if I could use multidimedional array or ArrayList but I cannot figure out how to insert the image into the array. Anyone can help me?

So if you want 1 Image against a variable number of string's
your Image becomes the Key of the Dictionary and the List<string> it's corresponding Value.
public Dictionary<Image, List<string>> MyCollection { get; private set; }
...
// Initialisation
MyCollection = new Dictionary<Image, List<string>>();
// Adding new Row
var tempImage = new Image();
MyCollection.Add(tempImage, new List<string>(){"A", "B", "C"});
// Modifying existing row -- for `Key` tempImage we'll add a string "D" and remove string "A"
List<string> existingValues = MyCollection[tempImage];
existingValues.Add("D");
existingValues.Remove("A");
// Removing rows
MyCollection.Remove(tempImage);
You can download this sample from Here. Hope that clarifies some of the usage ideas. I'd suggest looking at some Simple Examples to get a better understanding of how you can use Dictionary<...> to achieve your requirements.

Related

How can we convert List<SelectOption> to a List<string> in apex?

I have a list of "selectoption" and I want to use this in my SOQL.
The WHERE IN clause gives me incompatible error.
Can we convert list of selectoption to a list of strings?
What exactly you want to take from SelectOption items to list of strings - labels, values or something else? In any case, you can use getter-methods, like getLabel() or getValue() and collect them to list. For instance,
List<SelectOption> selectOptions = new List<SelectOption>(); //here it's empty, but you has filled one
List<String> stringValues = new List<String>();
for(SelectOption so: selectOptions){
stringValues.add(so.getValue());
}
//use list of strings as you wish
You can find documentation about SelectOption methods here.

How to use Dapper's SqlBuilder?

I can't find any documentation or examples I can follow to use the SqlBuilder class.
I need to generate sql queries dynamically and I found this class. Would this be the best option?
the best place to start is to checkout the dapper source code from its github repo and have a look at the SqlBuilder code. The SqlBuilder class is only a 200 lines or so and you should be able to make an informed choice on whether it is right for your needed.
An other option is to build your own. I personally went down this route as it made sense. Dapper maps select querys directly to a class if you name your class properties the same as your database or add an attribute such as displayName to map from you can use reflection to get the property names. Put there names and values into a dictionary and you can genarate sql fairly easy from there.
here is something to get you started:
first an example class that you can pass to your sqlbuilder.
public class Foo
{
public Foo()
{
TableName = "Foo";
}
public string TableName { get; set; }
[DisplayName("name")]
public string Name { get; set; }
[SearchField("fooId")]
public int Id { get; set; }
}
This is fairly basic. Idea behind the DisplayName attribute is you can separate the properties out that you want to include in your auto generation. in this case TableName does not have a DisplayName attribute so will not be picked up by the next class. however you can manually use it when generating your sql to get your table name.
public Dictionary<string, object> GetPropertyDictionary()
{
var propDictionary = new Dictionary<string, object>();
var passedType = this.GetType();
foreach (var propertyInfo in passedType.GetProperties())
{
var isDef = Attribute.IsDefined(propertyInfo, typeof(DisplayNameAttribute));
if (isDef)
{
var value = propertyInfo.GetValue(this, null);
if (value != null)
{
var displayNameAttribute =
(DisplayNameAttribute)
Attribute.GetCustomAttribute(propertyInfo, typeof(DisplayNameAttribute));
var displayName = displayNameAttribute.DisplayName;
propDictionary.Add(displayName, value);
}
}
}
return propDictionary;
}
This method looks at the properties for its class and if they are not null and have a displayname attribute will add them to a dictionary with the displayname value as the string component.
This method is designed to work as part of the model class and would need to be modified to work from a separate helper class. Personally I have it and all my other sql generation methods in a Base class that all my models inherit from.
once you have the values in the dictionary you can use this to dynamically generate sql based on the model you pass in. and you can also use it to populate your dapper DynamicParamaters for use with paramiterized sql.
I hope this helps put you on the right path to solving your problems.

delete multiple objects which are inside array in Apex

Very new to Apex and never touched java, basically what I am trying to do is delete all records then insert records inside multiple custom objects. Bellow is my code for just the deleting part but I have no idea how to get this working. Once I know how to get it working I can then put it inside a lop etc I just need the basics running first.
List<String> myList = new List<String> {'More_Info_Request__c'};
String foo = myList.get(0);
List<More_Info_Request__c> existing = [SELECT Id From :foo ];
delete existing;
Any help would be amazing
for future me or future human this is how I fixed it:
List<String> objectNames = new List<String> {'More_Info_Request__c', 'Object1__c', 'Object2__c'};
for (String objectName : objectNames) {
List<SObject> existing = Database.query('select id from ' + objectName);
delete existing;
}

How to add elements to an injected array without over-writing the other elements in Flex 4 with Parsley

I have an array that i am using to store a collection of objects. My application allows the user to add new objects to the array and edit the content of the objects. all the objects in the array are of the same type and the problem i am having is that if i add a new object or edit an existing object then all the objects contained in the array become exact copies of the newly added object.
Is there any way to stop this?
In my Application i have an object that stores an ArrayCollection:
public class MyArray
{
public var array:ArrayCollection = new ArrayCollection;
}
i have an object that i wish to store instances of in this array:
public class MyObject
{
public var things:String;
}
My Main mxml file displays all the items in MyArray in a datagrid which is held in an actionscript file:
<App xmlns:par="http://spicefactory.org/parsley">
<fx:Declarations>
<par:ContextBuilder config="MainContext"/>
<par:Configure/>
<par:FastInject property="mainpm" type="{MainPM}"/>
</fx:Declarations>
<fx:Script>
[Inject][Bindable]
public var mainpm:MainPM;
<fx:Script>
and then the actionscript file:
public class MainPM
{
[inject][Bindable]
public var thearray:MyArray;
public function addNew(thingtoadd:MyObject):void
{
thearray.addItem(thingtoadd);
}
}
I have tried to include the relevant code as the application is quite large but if more information is needed i can provide it.
Ok so the way to sole this was to create a new instance of MyObject and add that to MyArray instead.
public function addNew(thingtoadd:MyObject):void
{
var addobj:MyObject = new MyObject;
addobj.things = thingtoadd.tings;
thearray.addItem(addobj);
}

Image to Byte[] harder than thought 2 challenges

This is my 5th post over a month trying to solve what I thought was a simple problem: Write and read a small bitmap to a class.
My class:
public class Task
public byte? TaskImage { get; set; }
I recreate the bitmap in the controller after an edit, the bitmap is contained in System.Drawing. This line writes to a folder as a test. It works.
mybmp.Save("C:\\temp\\lot1.bmp",System.Drawing.Imaging.ImageFormat.Gif);
I think this puts it in a memory stream as a .bmp: Should this be .gif??
MemoryStream ms = new MemoryStream();
mybmp.Save(ms, System.Drawing.Imaging.ImageFormat.bmp);
CHALLENGE 1 provide inline code to convert to byte[] and write to class.
Task.TaskImage =
db.SaveChanges();
Later I pass the data via a viewmodel to my view and use the ForEach item concept to display the image.
CHALLENGE 2 code to display in view table:
<img src="data:image/gif;base64,#Convert.ToBase64String(item.TaskImage.Value)" />
This code has been provided by a contributor but causes this error.
Error 2 Argument 1: cannot convert from 'method group' to 'byte[]'
It was suggested I ask a new question.
I'm a beginner so please be explicit. When I have a working answer I'll go back and post answers to my earlier posts to help others.
I am assuming, you are properly saving the byte array and you already have contents of your image as a byte[]
why don't you try this, if you are using MVC4
<img src="#Url.Action("GetImage", "Controller", new{id=#Model.Id})"
alt = "img" />
where GetImage is :
public ActionResult GetImage(int id)
{
var imageByteArray= GetImageByte(id)
return File(imageByteArray, "Image/jpg");
}
Got it!
Challenge 1 the write bitmap into a byte[] field:
mybmp.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
byte[] byteArray = new byte[0];
ms.Close();
var lottoupdate = db.Lots //each task row contains the lotid to which
.Where(i => i.LotID == lotID) //it is associated. Find the LotID then
.Single(); // update the taskimage field in the lot class
byteArray = ms.ToArray();
lottoupdate.TaskImage = byteArray;
db.Entry(lottoupdate).State = EntityState.Modified;
db.SaveChanges();
There was a error in the lottoupdate.TaskImage=byteArray; line because TaskImage was nullable.
public class Task
public byte? TaskImage { get; set; }
So I removed the? therefore requiring data. I now seed the field.
Challenge 2 With the TaskImage byte[] passed in the viewmodel, display the image in the view table:
<text> #{
string imageBase64 = Convert.ToBase64String(#item.TaskImage);
String imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64);
}
</text>
<td><img src="#imageSrc" alt="Lot chart" border="0" /></td>
This displays the image in a table row. I needed the 'text' tags because html5 did not like the razor code without it. Note that I am not testing for null data, probably should. My program seeds an "base" image into the db.
I hope this helps someone else, it took about 30 hours of looking for this beginner.

Resources