I have two forms on my mvc site, FeedbackForm and CareerForm. I need to send both forms to the same email. I created two models for my forms and two views, then I added in the first my controller
/*Feedback*/
[HttpGet]
public ActionResult Feedback(string ErrorMessage)
{
if (ErrorMessage != null)
{
}
return View();
}
[HttpPost]
public ActionResult Feedback(FeedbackForm Model)
{
string ErrorMessage;
//email
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.BodyEncoding = Encoding.UTF8;
msg.Priority = MailPriority.High;
msg.From = new MailAddress(Model.Email, Model.Name);
msg.To.Add("tayna-anita#mail.ru");
msg.Subject = #Resources.Global.Feedback_Email_Title + " " + Model.Company;
string message = #Resources.Global.Feedback_Email_From + " " + Model.Name + "\n"
+ #Resources.Global.Feedback_Email + " " + Model.Email + "\n"
+ #Resources.Global.Feedback_Phone + " " + Model.Phone + "\n"
+ #Resources.Global.Feedback_Company + " " + Model.Company + "\n\n"
+ Model.AdditionalInformation;
msg.Body = message;
msg.IsBodyHtml = false;
//Attachment
if (Model.ProjectInformation != null && !(String.IsNullOrEmpty(Model.ProjectInformation.FileName)))
{
HttpPostedFileBase attFile = Model.ProjectInformation;
if (attFile.ContentLength > 0)
{
var attach = new Attachment(attFile.InputStream, attFile.FileName);
msg.Attachments.Add(attach);
}
}
SmtpClient client = new SmtpClient("denver.corepartners.local", 55);
client.UseDefaultCredentials = false;
client.EnableSsl = false;
try
{
client.Send(msg);
}
catch (Exception ex)
{
return RedirectToAction("Feedback", "Home", ErrorMessage = "Ошибка при отправке письма, попробуйте позже");
}
return RedirectToAction("Feedback", "Home");
}
and added to the second controller
/*CareerForm*/
[HttpGet]
public ActionResult CareerForm()
{
CareerForm model = new CareerForm();
model.StartNow = true;
model.EmploymentType = new List<CheckBoxes>
{
new CheckBoxes { Text = "полная занятость" },
new CheckBoxes { Text = "частичная занятость" },
new CheckBoxes { Text = "контракт" }
};
return View(model);
}
[HttpPost]
public ActionResult CareerForm(CareerForm Model)
{
string ErrorMessage;
//curricula vitae to email
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.BodyEncoding = Encoding.UTF8;
msg.Priority = MailPriority.Normal;
msg.From = new MailAddress(Model.Email, Model.Name + " " + Model.Surname);
msg.To.Add("tayna-anita#mail.ru");
msg.Subject = "Анкета с сайта";
string message = "Имя: " + Model.Name + " " + Model.Surname + "\n"
+ "Контактный телефон: " + Model.Phone + "\n";
if (Model.Adress != null)
{
message += "Адрес: " + Model.Adress + "\n";
}
message += "Email: " + Model.Email + "\n"
+ "Желаемая должность: " + Model.Position;
bool check = false;
foreach (var item in Model.EmploymentType)
{
if (item.Checked) check = true;
};
if (check == true)
{
message += "\nТип занятости: ";
foreach (var item in Model.EmploymentType)
{
if (item.Checked) message += item.Text + " ";
};
}
else
{
message += "\nТип занятости: не выбран";
}
if (Model.StartNow)
{
message += "\nМогу ли немедленно приступить к работе: да";
}
else
{
message += "\nГотов приступить к работе с: " + Model.StartFrom;
}
msg.Body = message;
msg.IsBodyHtml = false;
//Attachment
if (Model.Resume != null && !(String.IsNullOrEmpty(Model.Resume.FileName)))
{
HttpPostedFileBase attFile = Model.Resume;
if (attFile.ContentLength > 0)
{
var attach = new Attachment(attFile.InputStream, attFile.FileName);
msg.Attachments.Add(attach);
}
}
SmtpClient client = new SmtpClient("denver.corepartners.local", 55);
client.UseDefaultCredentials = false;
client.EnableSsl = false;
try
{
client.Send(msg);
}
catch (Exception ex)
{
return RedirectToAction("CareerForm", "Career", ErrorMessage = "Ошибка при отправке письма, попробуйте позже");
}
return RedirectToAction("CareerForm", "Career");
}
But I get an attached file only at the first case, when I send FeedbackForm to email.
For CareerForm I get email, but every time it is without an attachment.
I checked in debagger and I saw Model.Resume = null every time, but I dont undestand why.
what's wrong with my code?
Maybe it's bacause I create CareerForm model = new CareerForm(); in [HttpGet] ?
How can I fix that?
UPD
Views:
FeedbackForm http://jsfiddle.net/fcnk9/
CareerForm http://jsfiddle.net/9Gz9u/
You need to set enctype = "multipart/form-data" in your Career form, just like you have in your Feedback form...
#using (Html.BeginForm("CareerForm", "Career", FormMethod.Post, new { id = "career-form", #class = "form-horizontal", enctype = "multipart/form-data" }))
For more information as to why, see Why File Upload didn't work without enctype?
Related
I'm trying to send images from xamarin forms android to my C# asp.net core MVC web page. I can do it when I have wifi. but i can't do it when i don't have it.
how could I send the images when I have wifi back?
basically, what I need is storage the images and when the user has wifi again send the images.
Thank you very much!
C# Xamarin forms Android code:
string[] subs;
MultipartFormDataContent content2 = new MultipartFormDataContent();
List<StreamContent> listStreamContent = new List<StreamContent>();
List<string> listImgName = new List<string>();
List<string> ControlCantName = new List<string>();
List<int> listDelete = new List<int>();
private async void Scanner()
{
try
{
var scannerPage = new ZXingScannerPage();
scannerPage.Title = "scanner";
scannerPage.OnScanResult += (result) =>
{
scannerPage.IsScanning = false;
string resultado = Convert.ToString(result);
if (resultado.Contains("http") || resultado.Contains("https"))
{
Browser.OpenAsync(resultado, BrowserLaunchMode.External);
Navigation.PopAsync();
}
else
Device.BeginInvokeOnMainThread(async () =>
{
Navigation.PopAsync();
//Hace el display del valor obtenido
subs = result.Text.Split('\t');
string cadena = "var1 N°: " + subs[0] + "\var2 N°: " + subs[1] + "\nvar3 N°: " + subs[2];
await this.DisplayAlert("Datos del QR", cadena, "OK");
takesPhotos();
});
};
await Navigation.PushAsync(scannerPage);
}
catch(Exception ex)
{
await DisplayAlert("Error", "We had a problem. Try again", "OK");
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
}
private async void takesPhotos()
{
try
{
var file2 = await MediaPicker.CapturePhotoAsync();
while (file2 != null)
{
Image im = new Image();
im.ClassId = contador.ToString();
im.Source = ImageSource.FromFile(file2.FullPath);
im.HeightRequest = 600;
im.WidthRequest = 600;
im.MinimumHeightRequest = 600;
im.MinimumWidthRequest = 600;
im.VerticalOptions = LayoutOptions.End;
im.HorizontalOptions = LayoutOptions.End;
im.Aspect = Aspect.AspectFill;
imgs.Children.Add(im);
Button deleteButton = new Button();
deleteButton.ClassId = contador.ToString();
deleteButton.Text = "Delete image";
deleteButton.VerticalOptions = LayoutOptions.CenterAndExpand;
deleteButton.HorizontalOptions = LayoutOptions.Center;
deleteButton.MinimumWidthRequest = 100;
deleteButton.ClassId = contador.ToString();
deleteButton.AutomationId = contador.ToString();
deleteButton.Clicked += async (sender, args) => {
listDelete.Add(Convert.ToInt32(deleteButton.ClassId));
imgs.Children.Remove(im);
imgs.Children.Remove(deleteButton);
};
imgs.Children.Add(deleteButton);
listStreamContent.Add(new StreamContent(await file2.OpenReadAsync()));
listImgName.Add(subs[0] + "_" + subs[1] + "_" + subs[2] + "_" + contador + "_" + file2.FileName);
ControlCantName.Add(subs[0] + "_" + subs[1] + "_" + subs[2] + "_" + contador + "_" + file2.FileName);
file2 = await MediaPicker.CapturePhotoAsync();
contador++;
}
btnScannerQR.IsVisible = false;
btnSacarFotos.IsVisible = true;
btnEnviarImagenes.IsVisible = true;
}
catch(Exception ex)
{
await DisplayAlert("Error", "We had a problem. Try again", "OK");
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
private async void sendImages()
{
try
{
bool answer = await DisplayAlert("¿Have you finished?", "¿are you sure you want to send the images?", "Yes", "No");
if(answer)
{
int contImgBorradas;
if (listDelete.Count > 0 || listDelete != null)
{
foreach (var num in listDelete)
{
contImgBorradas = 1;
foreach (var img in ControlCantName)
{
if (num == contImgBorradas)
{
listImgName.Remove(num - 1);
listStreamContent.Remove(num - 1);
}
contImgBorradas++;
}
}
}
for (int x = 0; x < listStreamContent.Count; x++)
{
content2.Add(listStreamContent[x], "file", listImgName[x]);
}
var httpClient = new HttpClient();
var response = await httpClient.PostAsync("urlMyWeb", content2);
string res = await response.Content.ReadAsStringAsync();
await DisplayAlert("Result", res, "OK");
btnSacarFotos.IsVisible = false;
btnEnviarImagenes.IsVisible = false;
btnScannerQR.IsVisible = true;
content = null;
content2 = null;
imgs.Children.Clear();
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
}
catch(Exception ex)
{
await DisplayAlert("Error", "We had a problem. Try again", "OK");
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
I am new to ASP NET MVC
I need Populate a drop down list from values obtained from a database table using MySql database and view model, after checking if the current user is application enabled, using ASP NET MVC.
This is the tutorial
My code below return
Error: returns void, a return keyword must not be followed by an object expression
On this line
return items;
Any help really appreciated.
Controller
public ActionResult Recovery()
{
try
{
string cs = ConfigurationManager.ConnectionStrings["cnj"].ConnectionString;
using (var connection =
new MySqlConnection(cs))
{
string commandText = " SELECT cCountry FROM `dotable_user` " +
" WHERE cName = #Username; ";
using (var command =
new MySqlCommand(commandText, connection))
{
if (!String.IsNullOrEmpty(HttpContext.User.Identity.Name.ToString()))
{
command.Parameters.AddWithValue("#Username", HttpContext.User.Identity.Name.ToString());
}
connection.Open();
string cCountry = (string)command.ExecuteScalar();
if (String.IsNullOrEmpty(cCountry))
{
TempData["Message"] = "No user.";
ViewBag.Message = String.Format("No user.");
}
List<SelectListItem> items = new List<SelectListItem>();
using (MySqlConnection con = new MySqlConnection(cs))
{
string query = " SELECT cCountry FROM `dotable_countries` " +
" WHERE cCountry = '" + cCountry.ToString() + "' ";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Connection = con;
con.Open();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
items.Add(new SelectListItem
{
Text = sdr["cCountry"].ToString(),
Value = sdr["cCountry"].ToString()
});
}
}
connection.Close();
}
}
return items;
}
}
}
catch (Exception ex)
{
TempData["Message"] = "Login failed.Error - " + ex.Message;
}
}
Update
I have tried with this code.
I have error
Error CS0103 The name 'cCountry' does not exist in the current context
public ActionResult Recovery()
{
try
{
string cs = ConfigurationManager.ConnectionStrings["cnj"].ConnectionString;
using (var connection =
new MySqlConnection(cs))
{
string commandText = " SELECT cCountry FROM `dotable_user` " +
" WHERE cName = #Username; ";
using (var command =
new MySqlCommand(commandText, connection))
{
if (!String.IsNullOrEmpty(HttpContext.User.Identity.Name.ToString()))
{
command.Parameters.AddWithValue("#Username", HttpContext.User.Identity.Name.ToString());
}
connection.Open();
string cCountry = (string)command.ExecuteScalar();
if (String.IsNullOrEmpty(cCountry))
{
TempData["Message"] = "No user.";
ViewBag.Message = String.Format("No user.");
}
TempData["Dates"] = PopulateDates();
}
}
}
catch (Exception ex)
{
TempData["Message"] = "Login failed.Error - " + ex.Message;
}
}
private static List<SelectListItem> PopulateDates()
{
List<SelectListItem> items = new List<SelectListItem>();
string cs = ConfigurationManager.ConnectionStrings["cnj"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(cs))
{
string query = " SELECT cCountry FROM `dotable_countries` " +
" WHERE cCountry = '" + cCountry.ToString() + "'; ";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Connection = con;
con.Open();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
items.Add(new SelectListItem
{
Text = sdr["cCountry"].ToString(),
Value = sdr["cCountry"].ToString()
});
}
}
cmd.Connection.Close();
}
}
return items;
}
You are not passing cCountry value to populateDates.That's why you are getting this error. You can do something like below to get drop down populated. However it is not good idea to write Business Logic directly in controller. You should move it to model or Business layer.
private static List<SelectListItem> PopulateDates(string country)
{
List<SelectListItem> items = new List<SelectListItem>();
string cs = ConfigurationManager.ConnectionStrings["cnj"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(cs))
{
string query = " SELECT cCountry FROM dotable_countries WHERE cCountry = #country";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("#country",country);
cmd.Connection = con;
con.Open();
using (MySqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
items.Add(new SelectListItem
{
Text = sdr["cCountry"].ToString(),
Value = sdr["cCountry"].ToString()
});
}
}
cmd.Connection.Close();
}
}
return items;
}
and while calling this method in Action pass country value to it like below
TempData["Dates"] = PopulateDates(cCountry);
I'm having a contactForm in a view. When I hit submit the method below starts. In the try/catch section it now returns a new blank page with the content written in "return Content("Message was sent")". How can I instead return the original ContactForm-View with just a nice div under the form saying "Message was sent".
Here is the [HttpPost]-Method code:
[HttpPost]
public ActionResult SendMail(string SenderName, string SenderAddress, string phone, string Message)
{
const string username = "myMail#gmail.com";
const string password = "myPassword";
var loginInfo = new NetworkCredential(username, password);
var msg = new MailMessage();
var smtpClient = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = loginInfo
};
string message = SenderName + " have a message for you:<br /><br /><br />" + Message
+ "<br /><br />Avs. Phone: " + phone
+ "<br /><br />Avs. Mail: " + SenderAddress;
try
{
msg.From = new MailAddress(SenderAddress, "Some content");
msg.To.Add(new MailAddress("myMail#gmail.com"));
msg.Subject = "Some Content";
msg.Body = message;
msg.IsBodyHtml = true;
smtpClient.Send(msg);
return Content("Message was sent");
}
catch (Exception)
{
return Content("Something went wrong. Try again");
}
}
1) Instead of sending each parameter separately, create (for instance EmailModel) and post this model to SendMail(EmailModel model) action
2) On the end of SendMail(MailModel model) action, just return the same view with the same model but with flag like: model.IsSuccess = true
3) Check this flag on the view:
#if(model.IsSuccess)
{
<div>Good!</div>
}
I have had a couple of questions on this issue. However, now I have redone my code and almost all of it is working. The only issue is after the for is submitted it is not checking the model state, because even when the form is successful it displays there is an error. Here is my code.
[HttpPost]
public ActionResult ContactForm(ContactModel emailModel)
{
MailMessage oMail = new MailMessage();
oMail.From = new MailAddress("no-reply#hovdenoil.com", "Web Contact Form");
oMail.To.Add("email#hovdenoil.com");
oMail.Subject = emailModel.Subject;
string body = "Name: " + emailModel.Name + "\n"
+ "Email: " + emailModel.Email + "\n"
+ "Phone: " + emailModel.Phone + "\n\n"
+ "Company: " + emailModel.Company + "\n"
+ "Website: " + emailModel.Website + "\n"
+ emailModel.Message;
oMail.Body = body;
SmtpClient client = new SmtpClient("smtpout.secureserver.net");
client.Credentials = new NetworkCredential("username", "password");
client.Send(oMail);
string message = "There are a few errors";
if (ModelState.IsValid)
{
message = "Thanks! We'll get back to you soon.";
ModelState.Clear();
}
if (Request.IsAjaxRequest())
{
return new JsonResult { ContentEncoding = Encoding.UTF8, Data = new { success = true, message = message } };
}
TempData["Message"] = message;
return View();
}
My bad. I put the If(ModelState.IsValid) too early. Hear is my final code which worked.
[HttpPost]
public ActionResult ContactForm(ContactModel emailModel)
{
string message = "There are a few errors";
if (ModelState.IsValid)
{
MailMessage oMail = new MailMessage();
oMail.From = new MailAddress("no-reply#hovdenoil.com", "Web Contact Form");
oMail.To.Add("email#hovdenoil.com");
oMail.Subject = emailModel.Subject;
string body = "Name: " + emailModel.Name + "\n"
+ "Email: " + emailModel.Email + "\n"
+ "Phone: " + emailModel.Phone + "\n\n"
+ "Company: " + emailModel.Company + "\n"
+ "Website: " + emailModel.Website + "\n"
+ emailModel.Message;
oMail.Body = body;
SmtpClient client = new SmtpClient("smtpout.secureserver.net");
client.Credentials = new NetworkCredential("username", "password");
client.Send(oMail);
message = "Thanks! We'll get back to you soon.";
ModelState.Clear();
}
if (Request.IsAjaxRequest())
{
return new JsonResult { ContentEncoding = Encoding.UTF8, Data = new { success = true, message = message } };
}
TempData["Message"] = message;
return View();
}
I have been trying from last three days and i was not able to solve this problem;ed the tables and query.
I have been using perstlite for storing the data; I have created tables and queries for the required class;
Now I have been listening to contacts in the mobile and I am able to get the data in that class only but I am not able to get the information in the main class or any where in the project though i have called the class. Can anybody help me with this issue?
This is my program
package com.Wblower.listeners;
import java.util.Hashtable;
import javax.microedition.pim.Contact;
import javax.microedition.pim.PIMItem;
import javax.microedition.pim.PIMList;
import com.Wblower.db.ContactlistdatabaseQueries;
import com.Wblower.db.Contactlistdatabasetable;
import com.Wblower.db.DataBaseConnectivity;
import com.Wblower.util.DateTimeUtil;
import net.rim.blackberry.api.pdap.BlackBerryContact;
import net.rim.blackberry.api.pdap.BlackBerryContactList;
import net.rim.blackberry.api.pdap.PIMListListener;
public class ContactListener implements PIMListListener {
BlackBerryContactList contactList;
DataBaseConnectivity dbconnectVity = new DataBaseConnectivity();
public void itemAdded(PIMItem arg0) {
System.out.println("Item Added ==");
String firstname = "none";
String lastname = "none";
String mobile = "none";
String mobile1 = "none";
String mobile2 = "none";
String email = "none";
String email1 = "none";
String web = "none";
String company = "none";
String address = "none";
String address1 = "none";
String name[] = { "" };
String timeStamp = "none";
PIMList contacts = arg0.getPIMList();
Contact contact = (Contact) arg0;
if (contacts.isSupportedField(Contact.NAME)) {
try {
if (contact.countValues(Contact.NAME) > 0)
name = contact.getStringArray(Contact.NAME, 0);
if (name[Contact.NAME_GIVEN] != null)
firstname = name[Contact.NAME_GIVEN];
System.out.println("FirstName= " + firstname);
if (name[Contact.NAME_FAMILY] != null)
lastname = name[Contact.NAME_FAMILY];
System.out.println("LastName= " + lastname);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.EMAIL)) {
try {
if (contact.countValues(Contact.EMAIL) > 0)
email = contact.getString(Contact.EMAIL, 0);
System.out.println("Email " + email);
if (contact.countValues(Contact.EMAIL) > 1)
email1 = contact.getString(Contact.EMAIL, 1);
System.out.println("Email " + email1);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.ORG)) {
try {
if (contact.countValues(Contact.ORG) > 0)
company = contact.getString(Contact.ORG, 0);
System.out.println("Company " + company);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.URL)) {
try {
if (contact.countValues(Contact.URL) > 0)
web = contact.getString(Contact.URL, 0);
System.out.println("web " + web);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.TEL)) {
try {
if (contact.countValues(Contact.TEL) > 0)
mobile = contact.getString(Contact.TEL, 0);
System.out.println("Phone " + mobile);
if (contact.countValues(Contact.TEL) > 1)
mobile1 = contact.getString(Contact.TEL, 1);
System.out.println("Phone " + mobile1);
if (contact.countValues(Contact.TEL) > 2)
mobile2 = contact.getString(Contact.TEL, 2);
System.out.println("Phone " + mobile2);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
if (contacts.isSupportedField(Contact.ADDR)) {
try {
address = "";
String[] addressarr = contact.getStringArray(
BlackBerryContact.ADDR, 0);
for (int i = 0; i < addressarr.length; i++) {
if (addressarr[i] != null) {
address = address + " " + addressarr[i];
}
}
System.out.println("Address==" + address);
address1 = "";
String[] addressar = contact.getStringArray(
BlackBerryContact.ADDR, 1);
for (int i = 0; i < addressar.length; i++) {
if (addressar[i] != null) {
address1 = address1 + " " + addressar[i];
}
}
System.out.println("Address==" + address1);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
timeStamp = DateTimeUtil.timestamp();
try {
System.out.println("Entering into the db");
dbconnectVity.setDataBase();
Contactlistdatabasetable Contactlist;
Contactlist = new Contactlistdatabasetable(
"Contacts", "Add", firstname, lastname, mobile,
mobile1, mobile2, email, email1, web, company,
address, address1, timeStamp);
ContactlistdatabaseQueries.insertSingleContactlist(Contactlist);
ContactlistdatabaseQueries.selectWholeContactlist();
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
return;
}
}
}
public void itemRemoved(PIMItem arg0) {
System.out.println("Item Removed ==");
String firstname = "none";
String lastname = "none";
String mobile = "none";
String mobile1 = "none";
String mobile2 = "none";
String email = "none";
String email1 = "none";
String web = "none";
String company = "none";
String address = "none";
String address1 = "none";
String name[] = { "" };
String timeStamp = "none";
PIMList contacts = arg0.getPIMList();
Contact contact = (Contact) arg0;
if (contacts.isSupportedField(Contact.NAME)) {
try {
if (contact.countValues(Contact.NAME) > 0)
name = contact.getStringArray(Contact.NAME, 0);
if (name[Contact.NAME_GIVEN] != null)
firstname = name[Contact.NAME_GIVEN];
System.out.println("FirstName= " + firstname);
if (name[Contact.NAME_FAMILY] != null)
lastname = name[Contact.NAME_FAMILY];
System.out.println("LastName= " + lastname);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.EMAIL)) {
try {
if (contact.countValues(Contact.EMAIL) > 0)
email = contact.getString(Contact.EMAIL, 0);
System.out.println("Email " + email);
if (contact.countValues(Contact.EMAIL) > 1)
email1 = contact.getString(Contact.EMAIL, 1);
System.out.println("Email " + email1);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.ORG)) {
try {
if (contact.countValues(Contact.ORG) > 0)
company = contact.getString(Contact.ORG, 0);
System.out.println("Company " + company);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.URL)) {
try {
if (contact.countValues(Contact.URL) > 0)
web = contact.getString(Contact.URL, 0);
System.out.println("web " + web);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.TEL)) {
try {
if (contact.countValues(Contact.TEL) > 0)
mobile = contact.getString(Contact.TEL, 0);
System.out.println("Phone " + mobile);
if (contact.countValues(Contact.TEL) > 1)
mobile1 = contact.getString(Contact.TEL, 1);
System.out.println("Phone " + mobile1);
if (contact.countValues(Contact.TEL) > 2)
mobile2 = contact.getString(Contact.TEL, 2);
System.out.println("Phone " + mobile2);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
if (contacts.isSupportedField(Contact.ADDR)) {
try {
address = "";
String[] addressarr = contact.getStringArray(
BlackBerryContact.ADDR, 0);
for (int i = 0; i < addressarr.length; i++) {
if (addressarr[i] != null) {
address = address + " " + addressarr[i];
}
}
System.out.println("Address==" + address);
address1 = "";
String[] addressar = contact.getStringArray(
BlackBerryContact.ADDR, 1);
for (int i = 0; i < addressar.length; i++) {
if (addressar[i] != null) {
address1 = address1 + " " + addressar[i];
}
}
System.out.println("Address==" + address1);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
timeStamp = DateTimeUtil.timestamp();
try {
System.out.println("Entering into the db");
dbconnectVity.setDataBase();
Contactlistdatabasetable Contactlist;
Contactlist = new Contactlistdatabasetable(
"Contacts", "Delete", firstname, lastname, mobile,
mobile1, mobile2, email, email1, web, company,
address, address1, timeStamp);
ContactlistdatabaseQueries.insertSingleContactlist(Contactlist);
ContactlistdatabaseQueries.selectWholeContactlist();
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
return;
}
}
}
public void itemUpdated(PIMItem arg0, PIMItem arg1) {
System.out.println("Item Updated ==");
String firstname = "none";
String lastname = "none";
String mobile = "none";
String mobile1 = "none";
String mobile2 = "none";
String email = "none";
String email1 = "none";
String web = "none";
String company = "none";
String address = "none";
String address1 = "none";
String name[] = { "" };
String timeStamp = "none";
PIMList contacts = arg1.getPIMList();
Contact contact = (Contact) arg1;
if (contacts.isSupportedField(Contact.NAME)) {
try {
if (contact.countValues(Contact.NAME) > 0)
name = contact.getStringArray(Contact.NAME, 0);
if (name[Contact.NAME_GIVEN] != null)
firstname = name[Contact.NAME_GIVEN];
System.out.println("FirstName= " + firstname);
if (name[Contact.NAME_FAMILY] != null)
lastname = name[Contact.NAME_FAMILY];
System.out.println("LastName= " + lastname);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.EMAIL)) {
try {
if (contact.countValues(Contact.EMAIL) > 0)
email = contact.getString(Contact.EMAIL, 0);
System.out.println("Email " + email);
if (contact.countValues(Contact.EMAIL) > 1)
email1 = contact.getString(Contact.EMAIL, 1);
System.out.println("Email " + email1);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.ORG)) {
try {
if (contact.countValues(Contact.ORG) > 0)
company = contact.getString(Contact.ORG, 0);
System.out.println("Company " + company);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.URL)) {
try {
if (contact.countValues(Contact.URL) > 0)
web = contact.getString(Contact.URL, 0);
System.out.println("web " + web);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
}
if (contacts.isSupportedField(Contact.TEL)) {
try {
if (contact.countValues(Contact.TEL) > 0)
mobile = contact.getString(Contact.TEL, 0);
System.out.println("Phone " + mobile);
if (contact.countValues(Contact.TEL) > 1)
mobile1 = contact.getString(Contact.TEL, 1);
System.out.println("Phone " + mobile1);
if (contact.countValues(Contact.TEL) > 2)
mobile2 = contact.getString(Contact.TEL, 2);
System.out.println("Phone " + mobile2);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
if (contacts.isSupportedField(Contact.ADDR)) {
try {
address = "";
String[] addressarr = contact.getStringArray(
BlackBerryContact.ADDR, 0);
for (int i = 0; i < addressarr.length; i++) {
if (addressarr[i] != null) {
address = address + " " + addressarr[i];
}
}
System.out.println("Address==" + address);
address1 = "";
String[] addressar = contact.getStringArray(
BlackBerryContact.ADDR, 1);
for (int i = 0; i < addressar.length; i++) {
if (addressar[i] != null) {
address1 = address1 + " " + addressar[i];
}
}
System.out.println("Address==" + address1);
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
timeStamp = DateTimeUtil.timestamp();
try {
System.out.println("Entering into the db");
dbconnectVity.setDataBase();
Contactlistdatabasetable Contactlist;
Contactlist = new Contactlistdatabasetable(
"Contacts", "Update", firstname, lastname, mobile,
mobile1, mobile2, email, email1, web, company,
address, address1, timeStamp);
ContactlistdatabaseQueries.insertSingleContactlist(Contactlist);
ContactlistdatabaseQueries.selectWholeContactlist();
} catch (Exception e) {
System.out.println("Exception::" + e.getMessage());
}
return;
}
}
}
}
I hope u have understood my problem
When I have selected "ContactlistdatabaseQueries.selectWholeContactlist();" this method in any main class i am not able to fetch the data in the database, the response when i am getting is 0. but i need to get the value of the stored data i.e number of rows inserted.
i have got my problem sloved it is nothing but just changing the database,
ihave used perstlite in the issue but persistent will be the better one for the above problem