How to fix the error when only some data is displayed using web API on Xamarin Android - sql-server

I created a personal info page to display all the data according to specific username entered. Unfortunately, the edit text didn't display all the data from the SQL Server. It only shows 2/8 data. I'm using a WEB API to retrieve the data and the data is stored in SQL Server. Can you help me to fix this problem please!!
I obtained this code from a website and i follow step by step according to the website. I've tried using Web services, it didn't work ass well.
VehicleRecord.cs
public class VehicleRecord
{
public string clFullName{ get; set; }
public string clGender{ get; set; }
public string clICNo { get; set; }
public string clAddress { get; set; }
public string clPhoneNo { get; set; }
public string clEmail { get; set; }
public string clUsername { get; set; }
public string clPwd { get; set; }
public string clVehicPlateNo { get; set; }
public string clVehicModel { get; set; }
public string clVehicCol { get; set; }
public string clPaymentMethod { get; set; }
public VehicleRecord()
{
this.clFullName = "";
this.clGender = "";
this.clICNo = "";
this.clAddress = "";
this.clPhoneNo = "";
this.clEmail = "";
this.clUsername = "";
this.clPwd = "";
this.clVehicPlateNo = "";
this.clVehicModel = "";
this.clVehicCol = "";
this.clPaymentMethod = "";
}
}
Service.cs
public class Service
{
public static async Task<dynamic> getServiceData(string queryString)
{
dynamic acc = null;
HttpClient client = new HttpClient();
var response = await client.GetAsync(queryString);
if(response != null)
{
string json = response.Content.ReadAsStringAsync().Result;
acc = JsonConvert.DeserializeObject(json);
}
return acc;
}
}
Acc.cs
public class Acc
{
public static async Task<VehicleRecord> GetAcc(string username)
{
string queryString = "http://xxx.xxx.x.xxx/PMSAPI1/api/users/" + username;
dynamic results = await Service.getServiceData(queryString).ConfigureAwait(false);
if(results != null)
{
VehicleRecord vehicleRecord = new VehicleRecord();
vehicleRecord.clFullName = (string)results["clFullName"];
vehicleRecord.clGender = (string)results["clGender"];
vehicleRecord.clICNo = (string)results["clICNo"];
vehicleRecord.clAddress = (string)results["clAddress"];
vehicleRecord.clPhoneNo = (string)results["clPhoneNo"];
vehicleRecord.clEmail = (string)results["clEmail"];
vehicleRecord.clPwd = (string)results["clPwd"];
vehicleRecord.clVehicPlateNo = (string)results["clVehicPlateNo"];
vehicleRecord.clVehicModel = (string)results["clVehicModel"];
vehicleRecord.clVehicCol = (string)results["clVehicCol"];
vehicleRecord.clPaymentMethod = (string)results["clPaymentMethod"];
return vehicleRecord;
}
else
{
return null;
}
}
}
PersonalInfoActivity.cs
private async void BtnGetAcc_Click(object sender, EventArgs e)
{
EditText username = FindViewById<EditText>(Resource.Id.txtUsername);
if (!String.IsNullOrEmpty(username.Text))
{
VehicleRecord vehicleRecord = await Acc.GetAcc(username.Text);
FindViewById<EditText>(Resource.Id.txtFullName).Text = vehicleRecord.clFullName;
FindViewById<EditText>(Resource.Id.txtGender).Text = vehicleRecord.clGender;
FindViewById<EditText>(Resource.Id.txtIC).Text = vehicleRecord.clICNo;
FindViewById<EditText>(Resource.Id.txtAddress).Text = vehicleRecord.clAddress;
FindViewById<EditText>(Resource.Id.txtPhoneNo).Text = vehicleRecord.clPhoneNo;
FindViewById<EditText>(Resource.Id.txtEmail).Text = vehicleRecord.clEmail;
FindViewById<EditText>(Resource.Id.txtPwd).Text = vehicleRecord.clPwd;
FindViewById<EditText>(Resource.Id.txtPayMethod).Text = vehicleRecord.clPaymentMethod;
}
}
The expected output should display all the data according to the username entered, but the actual output only displayed 2/8 data.
The error that i get is System.NullReferenceException:Object reference not set to an instance of an object.
The output displayed on screen

It seems to me that the issue starts at this line
vehicleRecord.clICNo = (string)results["clICNo"];
IMO results does not contains "clICNo". Check this by surrounding this line in try - catch block.

Related

Call Apex Method from the Custom Button

I created a Apex Class like
Public class test_Controller
{
Public test_Controller() { }
Public void send(set<id> oppIds)
{
List<Oppurtunity> OppLst =[Select Name from Opportunity where id IN: oppIds];
Private static string integration_key = 'abcd';
Private static string account_id = 'efgh';
Public string signer_email { get; set; }
Public string signer_name { get; set; }
Public string email_message { get; set; }
Public string output { get; set; }
Public string envelope_id { get; set; }
Public string error_code { get; set; }
Public string error_message { get; set; }
Private static string ds_server = 'callout:DocuSign_Legacy_Demo/api/3.0/dsapi.asmx';
Private static string trace_value = 'SFDC_004_SOAP_email_send'; // Used for tracing API calls
Private static string trace_key = 'X-ray';
Private DocuSignTK.APIServiceSoap api_sender = new DocuSignTK.APIServiceSoap();
configure_sender();
do_send(OppLst);
}
Private void configure_sender()
{
api_sender.endpoint_x = ds_server;
api_sender.inputHttpHeaders_x = new Map<String, String>();
String auth = '<DocuSignCredentials><Username>{!$Credential.Username}</Username>'
+ '<Password>{!$Credential.Password}</Password>'
+ '<IntegratorKey>' + integration_key + '</IntegratorKey></DocuSignCredentials>';
api_sender.inputHttpHeaders_x.put('X-DocuSign-Authentication', auth);
}
Private void do_send(List<Oppurtunity> OppurLst)
{
if (integration_key == 'xxx-xxxx-xxxx' ||
account_id == 'xxxx-xxxx-xxxx')
{
error_message = 'Please configure the Apex class DS_Recipe_Send_Env_Email_Controller with your integration key and account id.';
error_code = 'CONFIGURATION_PROBLEM';
return;
}
String file_contents = '<html><h1>Quote Document</h1>' + get_lorem(OppurLst)
+ '<p> </p>'
+ '<p>Signature: <span style="color:white;">signer1sig</span></p>'
+ '<p>Date: <span style="color:white;">signer1date</span></p></html>';
DocuSignTK.Document document = new DocuSignTK.Document();
document.ID = 1;
document.Name = 'Quote Document';
document.FileExtension = 'html';
document.pdfBytes = EncodingUtil.base64Encode(Blob.valueOf(file_contents));
DocuSignTK.Recipient recipient = new DocuSignTK.Recipient();
recipient.Email = '';
recipient.UserName = '';
recipient.ID = 1;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 1;
DocuSignTK.Tab signHereTab = new DocuSignTK.Tab();
signHereTab.Type_x = 'SignHere';
signHereTab.AnchorTabItem = new DocuSignTK.AnchorTab();
signHereTab.AnchorTabItem.AnchorTabString = 'signer1sig'; // Anchored for doc 1
signHereTab.AnchorTabItem.XOffset = 8;
signHereTab.RecipientID = 1;
signHereTab.Name = 'Please sign here';
signHereTab.ScaleValue = 1;
signHereTab.TabLabel = 'signer1sig';
DocuSignTK.Tab dateSignedTab = new DocuSignTK.Tab();
dateSignedTab.Type_x = 'DateSigned';
dateSignedTab.AnchorTabItem = new DocuSignTK.AnchorTab();
dateSignedTab.AnchorTabItem.AnchorTabString = 'signer1date'; // Anchored for doc 1
dateSignedTab.AnchorTabItem.YOffset = -6;
dateSignedTab.RecipientID = 1;
dateSignedTab.Name = 'Date Signed';
dateSignedTab.TabLabel = 'date_signed';
DocuSignTK.Envelope envelope = new DocuSignTK.Envelope();
envelope.Subject = 'Please sign the Quote Document';
envelope.AccountId = account_id;
envelope.Tabs = new DocuSignTK.ArrayOfTab();
envelope.Tabs.Tab = new DocuSignTK.Tab[2];
envelope.Tabs.Tab.add(signHereTab);
envelope.Tabs.Tab.add(dateSignedTab);
envelope.Recipients = new DocuSignTK.ArrayOfRecipient();
envelope.Recipients.Recipient = new DocuSignTK.Recipient[1];
envelope.Recipients.Recipient.add(recipient);
envelope.Documents = new DocuSignTK.ArrayOfDocument();
envelope.Documents.Document = new DocuSignTK.Document[1];
envelope.Documents.Document.add(document);
if (String.isNotBlank(email_message))
{
envelope.EmailBlurb = email_message;
}
try
{
DocuSignTK.EnvelopeStatus result = api_sender.CreateAndSendEnvelope(envelope);
envelope_id = result.EnvelopeID;
System.debug('Returned successfully, envelope_id = ' + envelope_id);
}
catch (CalloutException e)
{
System.debug('Exception - ' + e);
error_code = 'Problem: ' + e;
error_message = error_code;
}
}
Private Boolean no_error()
{
return (String.isEmpty(error_code));
}
Private static String get_lorem(List<Oppurtunity> OLst)
{
String lorem = 'Hello World';
return lorem;
}
}
And I am trying to call the send Method from the Apex from the Custom Button like
{!REQUIRESCRIPT("/soap/ajax/41.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/41.0/apex.js")}
sforce.apex.execute("test_Controller","send",{oppIds:"{!Opportunity.Id}"});
When I try to execute the button I get the following error message:
A Problem with the OnClick JavaScript for this button or link was
encountered: {faultcode:''soapenv:Client', faultstring:'No operation
available for request
{http://soap.sforce.com/schemas/package/test_Controller}send, please
check the WSDL for the service.'}'
I am new to Salesforce and Apex scripting. Any help is greatly appreciated.
Your method is expecting a list of Ids.
Public void send(set<id> oppIds)
So I am guessing that maybe you need to send it as an array?
sforce.apex.execute("test_Controller","send",{oppIds:["{!Opportunity.Id}"]});
You need to expose this method as a webservice and it needs to be static
webservice static void send(List<Id> oppIds) {
}
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_and_ajax.htm

Download a file with AngularJS + FileSaver.js + .Net MVC

I'm trying to download an file what can be pdf, cvs, word, jpg or png. To do this, I'm using angularjs + filesaver.js. don't know why but, my downloads are always corrupted.
Someone can help me ?
Note:
midia.Nome - Name of my file.
midia.Tipo - The type of the file.
midia.Path - Physical path on project.
midia.MidiaBytesString - Bytes
on Base64 to convert to blob.
Download <br />
My File download method:
$scope.Download = function(bytes,nome,tipo){
var file = new File([bytes], nome , {type: "application/octet-stream"});
saveAs(file);
};
My View Model
public class MidiaViewModel
{
public int MidiaId { get; set; }
public string MidiaDescricao { get; set; }
//public string MidiaPath { get; set; }
public byte[] MidiaBytes { get; set; }
public string MidiaBytesString { get; set; }
public int OsId { get; set; }
public virtual OsViewModel Os { get; set; }
public string MidiaNome { get; set; }
public string MidiaType { get; set; }
public string MidiaPath { get; set; }
public long MidiaSize { get; set; }
}
My register Midia:
[HttpPost]
public JsonResult AtualizarMidias(IEnumerable<HttpPostedFileBase> arquivos, IEnumerable<string> descricoes, int osId)
{
var ordermDeServico = _osService.ObterPorIdLazyLoad(osId);
foreach (var file in arquivos)
{
string targetFolder = HttpContext.Server.MapPath("~/Content/uploads/");
string targetPath = Path.Combine(targetFolder, file.FileName);
if (file != null && file.ContentLength > 0)
{
var itens = arquivos.ToList();
var des = descricoes.ToList();
var index = itens.FindIndex(c => c.FileName == file.FileName);
var midiaViewModel = new MidiaViewModel
{
MidiaType = file.ContentType,
MidiaNome = file.FileName,
MidiaPath = targetPath,
MidiaSize = file.ContentLength,
MidiaDescricao = des[index].ToString(),
MidiaBytes = converterArquivo(file)
};
var midia = Mapper.Map<MidiaViewModel, Midia>(midiaViewModel);
midia.OsId = ordermDeServico.OSId;
file.SaveAs(targetPath);
_midiaService.Salvar(midia);
}
}
return Json(new { resultado = true }, JsonRequestBehavior.AllowGet);
}
And where i make the call to my angular $scope:
[HttpPost]
public string getMidiasOS(int idOS)
{
var getMidias = _midiaService.ObterMidiaPorIdOs(idOS);
List<MidiaAngularViewModel> midiaNova = new List<MidiaAngularViewModel>();
foreach (var midia in getMidias)
{
midiaNova.Add(new MidiaAngularViewModel
{
Id = midia.MidiaId,
Path = midia.MidiaPath,
Tipo = midia.MidiaType,
Descricao = midia.MidiaDescricao,
MidiaBytesString = Convert.ToBase64String(midia.MidiaBytes),
Nome = midia.MidiaNome
});
}
return JsonConvert.SerializeObject(midiaNova);
}
EDIT
Guys, I solved my problem using the Ameni topic in the follow link: download file using angularJS and asp.net mvc
All I need to do was create like the Post method on the Ameni topic and the download by path function.
Simply add/use the download attribute and you will be fine. More about download attribute can be found at w3c download documentation.
Download

How to save FormData into sql

I need to store the path of the file along with its properties into a sql database. Currently all I can do is store the file on the server. I can see the file properties in the controller but I do not know how to access them.
public class File
{
public int FileId { get; set; }
public string FileType { get; set; }
public string FileDate { get; set; }
public string FilePdf { get; set; }
public string FileLocation { get; set; }
public string FilePlant { get; set; }
public string FileTerm { get; set; }
public DateTime? FileUploadDate { get; set; }
public string FileUploadedBy { get; set; }
public string CompanyName { get; set; }
public virtual ApplicationUser User { get; set; }
}
Controller
[HttpPost]
public async Task<HttpResponseMessage> PostFile()
{
if (!Request.Content.IsMimeMultipartContent())
{
this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
}
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
var result = await Request.Content.ReadAsMultipartAsync(provider);
foreach (var key in provider.FormData.AllKeys)
{
foreach (var val in result.FormData.GetValues("companyname")
.FirstOrDefault())
{
if (key == "companyName")
{
var companyName = val;
var fileDate = val;
var fileLocation = val;
var filePlant = val;
var fileTerm = val;
var fileType = val;
var fileUploadDate = val;
var fileUploadedBy = val;
}
}
}
// On upload, files are given a generic name like "BodyPart_26d6abe1-3ae1-416a-9429-b35f15e6e5d5"
// so this is how you can get the original file name
var originalFileName = GetDeserializedFileName(result.FileData.First());
var uploadedFileInfo = new FileInfo(result.FileData.First().LocalFileName);
string path = result.FileData.First().LocalFileName;
//Do whatever you want to do with your file here
//db.Files.Add();
db.SaveChanges();
return this.Request.CreateResponse(HttpStatusCode.OK, originalFileName);
}
private string GetDeserializedFileName(MultipartFileData fileData)
{
var fileName = GetFileName(fileData);
return JsonConvert.DeserializeObject(fileName).ToString();
}
public string GetFileName(MultipartFileData fileData)
{
return fileData.Headers.ContentDisposition.FileName;
}
Try using a function like this. You can replace with
private object GetFormData<T>(MultipartFormDataStreamProvider result)
{
if (result.FormData.HasKeys())
{
var unescapedFormData = Uri.UnescapeDataString(result.FormData
.GetValues(0).FirstOrDefault() ?? String.Empty);
if (!String.IsNullOrEmpty(unescapedFormData))
return JsonConvert.DeserializeObject<T>(unescapedFormData);
}
return null;
}
Use it like this
File file = GetFormData(result);
The main line of code you want is:
JsonConvert.DeserializeObject<File>(result.FormData.GetValues(0).FirstOrDefault());

BindingList<> (master) with a composed BindingList<> (child) reference

I have a situation where a BindingList<> represents a collection of POCOs that have sub-collections of similar nature, Here is a sample code of two such POCOs and their respective lists:
The DirectoryTypePoco
public class DirectoryTypePoco : IBasePoco
{
public DirectoryTypePoco()
{
}
public DirectoryTypePoco(Int16 directoryTypeId, String directoryImplementation, String directoryDescription, DirectoryDefinitionPocoList directoryDefinition)
{
DirectoryTypeId = directoryTypeId;
DirectoryImplementation = directoryImplementation;
DirectoryDescription = directoryDescription;
DirectoryDefinition = directoryDefinition;
}
public Int16 DirectoryTypeId { get; set; }
public String DirectoryImplementation { get; set; }
public String DirectoryDescription { get; set; }
public DirectoryDefinitionPocoList DirectoryDefinition { get; set; }
public object GenerateEntity(GenericRepository repository, params object[] parameters)
{
var lastMaxEntityId = repository.GetQuery<DirectoryType>().Select(select => #select.DirectoryTypeId).DefaultIfEmpty().Max();
var newEntity = new DirectoryType
{
DirectoryTypeId = (short)(lastMaxEntityId + 1),
DirectoryImplementation = this.DirectoryImplementation,
DirectoryDescription = this.DirectoryDescription
};
return newEntity;
}
}
And the BindingList<DirectoryTypePoco>:
public class DirectoryTypePocoList : BindingList<DirectoryTypePoco>
{
public DirectoryTypePocoList()
{
using (var repository = new GenericRepository(new PWRDbContext()))
{
var query = repository.GetQuery<DirectoryType>();
foreach (var r in query)
{
Add(new DirectoryTypePoco(r.DirectoryTypeId, r.DirectoryImplementation, r.DirectoryDescription, new DirectoryDefinitionPocoList(r.DirectoryTypeId)));
}
}
}
public DirectoryTypePocoList(short directoryTypeId)
{
using (var repository = new GenericRepository(new PWRDbContext()))
{
var query = repository.GetQuery<DirectoryType>(where => where.DirectoryTypeId == directoryTypeId);
foreach (var r in query)
{
Add(new DirectoryTypePoco(r.DirectoryTypeId, r.DirectoryImplementation, r.DirectoryDescription, new DirectoryDefinitionPocoList(r.DirectoryTypeId)));
}
}
}
}
The second object: DirectoryDefinitionPoco
public class DirectoryDefinitionPoco : IBasePoco
{
public DirectoryDefinitionPoco()
{
}
public DirectoryDefinitionPoco(Int16 directoryTypeId, Byte parameterId, String parameterName, String parameterValidation, Boolean encryptionRequired, PocoChangeType changeType = PocoChangeType.None)
{
DirectoryTypeId = directoryTypeId;
ParameterId = parameterId;
ParameterName = parameterName;
ParameterDescription = parameterName;
ParameterRequired = false;
ParameterValidation = parameterValidation;
EncryptionRequired = encryptionRequired;
}
public Int16 DirectoryTypeId { get; set; }
public Byte ParameterId { get; set; }
public String ParameterName { get; set; }
public String ParameterDescription { get; set; }
public String ParameterValidation { get; set; }
public Boolean ParameterRequired { get; set; }
public Boolean EncryptionRequired { get; set; }
public object GenerateEntity(GenericRepository repository, params object[] parameters)
{
var masterId = (short) parameters[0];
var lastMaxEntityId = repository.GetQuery<DirectoryDefinition>(where => where.DirectoryTypeId == masterId).Select(select => #select.ParameterId).DefaultIfEmpty().Max();
var newEntity = new DirectoryDefinition
{
DirectoryTypeId = (short)parameters[0],
ParameterId = (byte)(lastMaxEntityId + 1),
ParameterName = this.ParameterName,
ParameterDescription = this.ParameterDescription,
ParameterValidation = this.ParameterValidation,
ParameterRequired = this.ParameterRequired,
EncryptionRequired = this.EncryptionRequired
};
return newEntity;
}
}
And BindingList<DirectoryDefinitionPoco>:
public class DirectoryDefinitionPocoList : BindingList<DirectoryDefinitionPoco>
{
public DirectoryDefinitionPocoList(short directoryTypeId)
{
using (var repository = new GenericRepository(new PWRDbContext()))
{
var query = repository.GetQuery<DirectoryDefinition>(where => where.DirectoryTypeId == directoryTypeId);
foreach (var r in query)
{
Add(new DirectoryDefinitionPoco(r.DirectoryTypeId, r.ParameterId, r.ParameterName, r.ParameterValidation, r.EncryptionRequired));
}
}
}
public List<DirectoryDefinition> GetSourceQuery()
{
List<DirectoryDefinition> result;
using (var repository = new GenericRepository(new PWRDbContext()))
{
result = repository.GetQuery<DirectoryDefinition>().ToList();
}
return result;
}
public List<DirectoryDefinition> GetSourceQuery(short directoryTypeId)
{
List<DirectoryDefinition> result;
using (var repository = new GenericRepository(new PWRDbContext()))
{
result = repository.GetQuery<DirectoryDefinition>(where => where.DirectoryTypeId == directoryTypeId).ToList();
}
return result;
}
}
On the form, I load the data into the grid through a BindingSource component. The child rows are added properly and the data is valid.
Here is the issue: I'm able to add new DirectoryTypePoco but when try to add a DirectoryDefinitionPoco, in the code, the the DirectoryDefinitionPocoobject that I get has a zero for it's parent object. In the above picture, the Test5.dll234 is a DirectoryTypePoco with DirectoryTypeId = 8 and all child under it are ok except the new one I create. What am I suppose to do to make sure I have Master-Child relation in this case?
Ok. It seems that there are two thing I should have noticed in my design.
The individual child Poco needs to know the parent Poco through a reference.
The DevExpress Grid has methods that allow for retrieving the attached data to a parent row while in the child view' particular row.
The first part is straightforwards: add a new property in the child poco of parent poco type.
This however, in my case, doesn't solve my issue as when I visually add a new row on the grid, the default constructor is invoked and it takes no parameters and hence the parent poco reference will remain NULL and the Ids (numeric) will be defaulted to 0
The second point helped fix my issue completely. I was able to conjure up an extension method for the XtraGrid's GridView as follows:
public static class DevExpressGridHelper
{
public static IBasePoco GetPocoFromSelectedRow(this BaseView view)
{
return (IBasePoco)view.GetRow(((GridView)view).FocusedRowHandle);
}
public static IBasePoco GetParentPocoFromSelectedRow(this GridView view)
{
if (view.ParentView !=null)
{
// return (IBasePoco)(view.ParentView).GetRow(((GridView)(view.ParentView)).FocusedRowHandle);
return (IBasePoco)((GridView)view.ParentView).GetFocusedRow();
}
return null;
}
}
And used it as follows:
private void GridMain_Level_1_RowUpdated(object sender, RowObjectEventArgs e)
{
var view = sender as GridView;
if (view == null)
{
return;
}
var pocoObject = e.Row as DirectoryDefinitionPoco;
if (pocoObject == null)
{
return;
}
var parentPocoObject = view.GetParentPocoFromSelectedRow();
if (parentPocoObject == null)
{
return;
}
if (view.IsNewItemRow(e.RowHandle))
{
Create(pocoObject, parentPocoObject);
}
else
{
Update(pocoObject);
}
}

Powerpacks DataRepeater Control - Image not getting loaded in picture box

I have a winform powerpacks datareapter control having a picture box. This is the code snippet from the classes.
DisplaySystemUsersControl.Designer.cs
this.picBoxUserImage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.picBoxUserImage.DataBindings.Add(new System.Windows.Forms.Binding("Image", this.UserBindingSource, "User_Image", true));
this.picBoxUserImage.Location = new System.Drawing.Point(3, 3);
this.picBoxUserImage.Name = "picBoxUserImage";
this.picBoxUserImage.Size = new System.Drawing.Size(100, 93);
this.picBoxUserImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.picBoxUserImage.TabIndex = 0;
this.picBoxUserImage.TabStop = false;
this.picBoxUserImage.Click += new System.EventHandler(this.picBoxUserImage_Click);
DisplaySystemUsersControl.cs
public DisplaySystemUsersControl()
{
InitializeComponent();
this.dataRepeaterAccounts.DataSource = this.UserBindingSource;
LoadAccountData();
}
private void LoadAccountData()
{
SystemUserBusinessClass oSystemUserBusinessClass = new SystemUserBusinessClass();
List<SystemUserEntity_Only_For_UI_Binding> obj = oSystemUserBusinessClass.GetSystemUsersForUI();
BindingSource tempUserBindingSource = (BindingSource)dataRepeaterAccounts.DataSource;
obj.ForEach(oSystemUserEntity_Only_For_UI_Binding => tempUserBindingSource.Add(oSystemUserEntity_Only_For_UI_Binding));
}
SystemUserEntity_Only_For_UI_Binding.cs
public class SystemUserEntity_Only_For_UI_Binding
{
public string User_Id { get; set; }
public string User_Name { get; set; }
public byte[] User_Image { get; set; }
}
User ID and User name is getting loaded. But Image is not getting loaded. SystemUserEntity_Only_For_UI_Binding.User_Image() is holding the image byte array.
Can anybody please tell me what is going wrong?
Your class should look something like this:
public class SystemUserEntity_Only_For_UI_Binding
{
public string User_Id { get; set; }
public string User_Name { get; set; }
public Image User_Image { get; set; }
}
The byte array needs to be translated into an image somewhere in your code:
using (MemoryStream ms = new MemoryStream(imgBytes)) {
this.User_Image = Image.FromStream(ms);
}
public void BindRepeater (DataSet dsObj)
{
pictureBox1.DataBindings.Clear();
pictureBox1.DataBindings.Add("ImageLocation", dt, "Photo");
dataRepeater1.DataSource = dsObj;
}

Resources