Help. I try to keep track of changes in address book. but the method
NSError err;
ABAddressBook iOSAddressBook = ABAddressBook.Create(out err);
iOSAddressBook.ExternalChange += (object sender, ExternalChangeEventArgs e) =>
{
Console.WriteLine("qorkkkk");
};
does not work.
/*First, Make change in viewDidLoad Method from where you want to change addressbook Record.*/
- (void)viewDidLoad {
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(nil, nil);
ABAddressBookRegisterExternalChangeCallback(addressBook, addressBookChanged, (__bridge void *)(self));
}
//Then,
/*------- method will call when contact updated ------*/
void addressBookChanged(ABAddressBookRef addressBook, CFDictionaryRef info, void *context)
{
#try {
[YourVewControllerObj updateRecord];
// YourViewController *viewController = (__bridge YourViewController*)context;
// [viewController updateRecord];
}
#catch (NSException *exception) {
NSLog(#"%#",exception.description);
}
}
/*------- Method call if make any change in conatct ------*/
+(void)updateRecord
{
NSMutableDictionary *dictPerson= [NSMutableDictionary dictionary];
CFErrorRef error = NULL;
ABAddressBookRef addressBook =ABAddressBookCreateWithOptions(NULL, &error) ;
ABRecordID record = ABRecordGetRecordID(ABRecordRef);
ABRecordRef contactPerson = ABAddressBookGetPersonWithRecordID(addressBook, record);
/*---Here you get your updated Record Refence----*/
//Do your other stuff here
}
Related
Error: Invalid column name 'Id'.'
I've been trying to make an update function, the logic behind it I think is fine, but it keeps throwing me this error mentioned above.
internal static void Uredi(Zahtjev odabraniZapis)
{
DB.OpenConnection();
string sql = $"UPDATE Zahtjev_za_nabavu SET Ponuda = '{odabraniZapis.Ponuda}', Opis_predmeta = '{odabraniZapis.Opis_predmeta}', Cijena = '{odabraniZapis.Cijena}', ID_zaposlenika = {odabraniZapis.ID_zaposlenika} WHERE ID_zahtjeva = {odabraniZapis.ID_zahtjeva};";
DB.ExecuteCommand(sql);
DB.CloseConnection();
}
This above is the function that I call to Update existing data.
I get the row that i want to change through ID_zahtjeva .
And this is the function that calls the UPDATE function.
private void btnAzuriraj_Click(object sender, EventArgs e)
{
Zahtjev noviZahtjev = new Zahtjev(int.Parse(txtZahtjev.Text), txtPonuda.Text, txtOpis.Text, txtCijena.Text, int.Parse(txtZaposlenik.Text));
var provjera = ZahtjeviRepository.GetZahtjevi(noviZahtjev.ID_zahtjeva);
if(provjera == null)
{
ZahtjeviRepository.Kreiraj(noviZahtjev);
this.Close();
}
else
{
ZahtjeviRepository.Uredi(noviZahtjev);
this.Close();
}
}
I am trying to pass a 2d string array as a parameter to a click event (searchButton_Click) which is generated within a click event so I can perform a search function. However, I get the error No overload for 'searchButton_Click' matches delegate 'RoutedEventHandler'.
I have tried several solutions as seen on stackoverflow and other sources but none has worked.
I'm new to C# programming, any help will be appreciated.
private string[,] LongRunningTask()
{
workSheetName = getWorkSheetName();
var sourceFile = OpenExcelFile(filePath);
var sourceWorkSheet = GetWorkSheet(sourceFile.Item1, sourceFile.Item2, workSheetName); //instantiating the object.
var doc_Max = GetDocRow_Col(sourceWorkSheet.Item1);
var maxRow_Col = GetMaxRow_Col(sourceWorkSheet.Item1, doc_Max.Item1, doc_Max.Item2);
int maxRowCount = maxRow_Col.Item1;
int maxColCount = maxRow_Col.Item2;
WriteLine("Last column with content is Row {0} ", maxRowCount);
WriteLine("Last column with content is Column {0} ", maxColCount);
var getItemsResult = getItems(sourceWorkSheet.Item1, maxRow_Col);
string[,] itemsArr = getItemsResult;
Bindng2DArrayToListview2(listview, itemsArr, maxColCount);
//enableItems();
GarbageCollector(sourceWorkSheet.Item1, sourceWorkSheet.Item2, sourceWorkSheet.Item3, sourceWorkSheet.Item4);
//searchButton.Click += (sender2, e2) => { searchButton_Click(sender2, e2, itemsArr); };
return itemsArr;
}
private async void StartTask()
{
this.progressLabel.Content = "Getting Sheets..";
try
{
await Task.Run(() => LongRunningTask());
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
this.progressLabel.Content = "Done";
}
You could put the result of LongRunningTask into a field on the class (which I assume is the Window itself), then just access that field from searchButton_Click.
For example...
public partial class TheWindow : Window
{
private string[,] LongRunningTask()
{
// Your LongRunningTask implementation.
}
private async Task StartTask()
{
progressLabel.Content = "Getting Sheets...";
try
{
_itemsArr = await Task.Run(() => LongRunningTask());
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
progressLabel.Content = "Done!";
}
private void searchButton_Click(object sender, RoutedEventArgs e)
{
if (_itemsArr == null)
{
// The field is null for some reason. You'll have to decide what to do in this case, but
// naturally you can't use it if it's null.
return;
}
// Do the search using the field _itemsArr.
}
private string[,] _itemsArr = null;
}
I am trying to make a text box in a WPF C# application populate a text box from a variable gathered from an external database using WCF and having little luck. Currently the text box states ScoreBoardClientTest.FeedServiceAgent instead of the value of agentsavailable. I was able to make this exact same code work in a console application when using this line of code inside of OnMessageReceived
console.writeline(e.cmsdata.skill.agentsavailable.tostring());
so I assumed I could do something similar here.
any help understanding where I'm going wrong would be great.
DisplayNumber is the name of the textbox.
public void TextBlock_Loaded(object sender, EventArgs e)
{
using (var data = new FeedServiceAgent())
{
data.MessageReceived += OnMessageReceived;
data.Subscribe("92", 3);
DisplayNumber.Text = data.ToString();
}
}
public static void OnMessageReceived(object sender, MessageReceivedEventArgs e)
{
try
{
if (e == null)
return;
if (e.CmsData == null)
{
e.CmsData.Skill.AgentsAvailable.ToString();
}
// if (!String.IsNullOrEmpty(e.Message))
// Console.WriteLine(e.Message);
}
catch (Exception ex)
{
// logger.Error(" Exception " + ex);
// throw ex;
}
}
Edit
Changed:
DisplayNumber.Text =e.CmsData.Skill.AgentsAvailable.ToString();
to:
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { DisplayNumber.Text = e.CmsData.Skill.AgentsAvailable.ToString() ; }
This will handle multithreaded calls. You might have to add a using System.Threading statement for the DispatcherPriority enum
EndEdit
It is still unclear how to get from the data of Type FeedServiceAgent to a Skill.AgentsAvailable property in your Loaded event handler. We need more information on how to make that navigation. Is the assignment even necessary in the Loaded handler? I've marked the location in the code below.
I've also made what appears to be the necessary changes to the message handler method.
public void TextBlock_Loaded(object sender, EventArgs e)
{
using (var data = new FeedServiceAgent())
{
data.MessageReceived += OnMessageReceived;
data.Subscribe("92", 3);
//DisplayNumber.Text = data.ToString();
//Is this assignment even necessary?
DisplayNumber.Text = /*Still unclear what goes here because we don't know what how to get from `data` to `Skill`*/
}
}
public static void OnMessageReceived(object sender, MessageReceivedEventArgs e)
{
try
{
if (e == null)
return;
if (e.CmsData == null)
{
//e.CmsData.Skill.AgentsAvailable.ToString();
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { DisplayNumber.Text = e.CmsData.Skill.AgentsAvailable.ToString() ; }));
}
// if (!String.IsNullOrEmpty(e.Message))
// Console.WriteLine(e.Message);
}
catch (Exception ex)
{
// logger.Error(" Exception " + ex);
// throw ex;
}
}
I have a ListView whose items are fetched from an Api call. Then I add another item , send it to api to add it. I want to update the existing list with the value I just added.
I am doing something like this:-
itemList = dataAgent.GetItemList(some params);
cAdapter = new ItemsListAdapter(this, itemList);
lvItems.Visibility = ViewStates.Visible;
lvItems.Adapter = cAdapter;
SetListViewHeightBasedOnChildren(lvItems);
}
btnItemComment.Click += btnItemComment_Click;
void btnItemComment_Click(object sender, EventArgs e)
{
string itemsText = editComments.Text.ToString().Trim();
if(string.IsNullOrEmpty(itemsText))
{
CreateAndShowAlert(this, "", "Please enter a text");
}
else
{
var status = dataAgent.PostItem (Some more params);
if(status)
{
cAdapter.NotifyDataSetChanged();
}
}
}
But the ListView does not get refreshed. Is there anything else I need to do? Any help would be appreciated
Set adapter again and then add NotifyDataSetChanged:-
cAdapter = new ItemsListAdapter(this, itemList);
cAdapter.NotifyDataSetChanged();
I have two List <>.
List<Musei> ListMusei;
List<Regioni> reg;
the object "Musei" has the property "Paese", while the object "Regioni" has the property "NomeProvincia".
The List "reg" is inserted in a ListView, and when pressed on an item, this method is invoked:
private void Listviewcitt_ItemClick(object sender, ItemClickEventArgs e)
{
var result = ((Regioni)e.ClickedItem).NomeProvincia.ToString();
var filtro = ListMusei.Where(x => x.Paese.Equals(result));
try
{
Frame.Navigate(typeof(PageAroundMe), filtro);
}
catch(Exception)
{
}
}
application where I always closes. I thought there was some problem in the "AroundMe", and then paste the code here:
In Page AroundMe I do this:
List<Musei> ListMusei;
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
ListMusei = (List<Musei>) e.Parameter;
List<Pushpin> push = new List<Pushpin>();
foreach (Musei SingoloMuseo in ListMusei)
{
Pushpin Pushpin pushpin1 = new ();
GeoPoint posizioneP;
try
{
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync (SingoloMuseo.Indirizzo, null);
posizioneP result.Locations.FirstOrDefault = ().Point;
pushpin1.Name = SingoloMuseo.NomeMuseo;
pushpin1.Location = posizioneP;
push.Add (pushpin1);
}
catch (Exception)
{
continue;
}
}
Where is the problem? I can not even figure out where I will close
You can pass the parameter like
Frame.Navigate(typeof(PageAroundMe), filtro.ToList());
The invalid cast exception occurs because you are trying to cast IEnumerable type to List.