how to insert multiple dynamic row value into the database - asp.net-mvc

public void create(account_detail c, int jobcard_id)
{
SqlConnection con = new SqlConnection(#"Data source =(LocalDB)\v11.0;AttachDbFilename=C:\Users\Wattabyte Inc\Documents\CarInfo.mdf;Integrated Security=True;");
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
foreach (var details in c.Data)
{
cmd.CommandText = "insert into child_detail values ('" + jobcard_id + "','" + details.completed_by + "','" + details.reporting_time + "','" + details.cost_activity + "','" + details.spared_part_used + "');";
cmd.ExecuteNonQuery();
}
}
I am using this code but it only taking single value but I want to save the multiple values into the database ?

Try something like:
string additionalText = string.Empty;
bool needComma = false;
foreach (var details in c.Data)
{
if (needComma)
additionalText += ", ";
else
needComma = true;
additionalText += "('" + jobcard_id + "','" + details.completed_by + "','" + details.reporting_time + "','" + details.cost_activity + "','" + details.spared_part_used + "')";
}
cmd.CommandText = "insert into child_detail values " + additionalText + ";";
cmd.ExecuteNonQuery();
Basic idea - prepare the string of teh command in the foreach loop, then execute the command once.

Related

Opportunity Send Email

I tried to find a solution to my problem but I couldn't.
I have written some code to send an automatic email from Opportunity Salesforce and I write a test class but the code coverage doesn't go over 39%.
This is a code:
public class OpportunityEmail {
public static Boolean sendOppEmail(Opportunity opp){
OrgWideEmailAddress iOrgWideEmailAddress;
OrgWideEmailAddress iOrgWideEmailAddressAlert;
iOrgWideEmailAddress = OrgWideEmailAddressHelper.getByAddress(Label.SendPartnerOppEmail);
iOrgWideEmailAddressAlert = OrgWideEmailAddressHelper.getByAddress(Label.SendPartnerOppEmailAlert);
Boolean hasError = false;
Map<Id, Opportunity> mpOpp = new Map<Id, Opportunity>();
String msg = Label.OpportunitySendEmailSuccess;
Boolean myRet = false ;
System.debug(opp);
try {
Opportunity lstOpp = [select AccountId,Primary_Contact__c,CustomerAccount__c,SendEmailDone__c from Opportunity where id =: opp.Id];
Account accPrt = [select CompanyEmail__c from Account where id =: opp.AccountId];
String primContcSped = '';
if(opp.Primary_Contact__c != null){
Contact primContc = [select Email from Contact where id =: opp.Primary_Contact__c];
primContcSped = primContc.Email;
}
Account accCust = [select Account.Name,
Account.VATNumber__c,
Account.FiscalCode__c,
Account.Phone,
Account.Mobile__c,
Account.CompanyEmail__c,
Account.SDICode__c,
Account.BillingStreet,
Account.BillingPostalCode,
Account.BillingCity,
Account.BillingStateCode,
Account.BillingState,
Account.ShippingStreet,
Account.ShippingPostalCode,
Account.ShippingCity,
Account.ShippingStateCode,
Account.ShippingState from Account where id =: opp.CustomerAccount__c];
String Template = OpportunityEmail__c.getValues('Template1').TemplateEmail__c;
EmailTemplate eT = [select id, DeveloperName, Body, HtmlValue, Subject from EmailTemplate where Name =: Template];
Id TemplateId = eT.Id ;
String subject = eT.Subject;
String HtmlBody = eT.HtmlValue;
Id account = opp.Id;
String address = accPrt.CompanyEmail__c;
String ccaddress = '';
if(primContcSped != null){
ccaddress = primContcSped;
}
String ReplyToEmail = OpportunityEmail__c.getValues('Operation').ReplyToEmail__c;
String Customer = accCust.Name + '<br>' +
'P.Iva: ' + accCust.VATNumber__c + '<br>' +
'Cod.Fiscale: ' + accCust.FiscalCode__c + '<br>' +
'Telefono: ' + accCust.Phone + '<br>' +
'Mobile: ' + accCust.Mobile__c + '<br>' +
'Email: ' + accCust.CompanyEmail__c + '<br>' +
'SDI: ' + accCust.SDICode__c + '<br><br>' +
'Sede Legale: ' + '<br>' +
accCust.BillingStreet + ', ' + accCust.BillingPostalCode + ' ' + accCust.BillingCity + ' (' + accCust.BillingStateCode + ') ' + '<br><br>' +
'Sede Operativa: ' + '<br>' +
accCust.ShippingStreet + ', ' + accCust.ShippingPostalCode + ' ' + accCust.ShippingCity + ' (' + accCust.ShippingStateCode + ') ';
String Description = '';
if(opp.Description != null){
Description = opp.Description;
}
String ItemTable = '';
if(opp.HardwareBundle__c != null){
ItemTable = '<table style="width:30%;border: 1px solid black;"> <tr> <th style="text-align: left;border: 1px solid black;"> Service/Products </th> </tr>';
List<Schema.PicklistEntry> fieldResult = Opportunity.HardwareBundle__c.getDescribe().getPicklistValues();
Opportunity lstBund = [select HardwareBundle__c from Opportunity where id =: opp.Id];
String[] tmpBund = lstBund.HardwareBundle__c.split(';');
for(String s : tmpBund){
for(Schema.PicklistEntry f : fieldResult) {
if (f.getValue() == s){
ItemTable = ItemTable + '<tr> <td style = "text-align: left;">'+ f.getLabel()+'</td></tr>';
break;
}
}
}
ItemTable = ItemTable + '</table>';
}
subject = subject.replace('CustomerAccount', accCust.Name);
HtmlBody = HtmlBody.replace('{Customer1}', Customer);
HtmlBody = HtmlBody.replace('ItemTable', ItemTable);
HtmlBody = HtmlBody.replace('{!Description}', Description);
EmailManager.sendMailCcAdd(TemplateId, account, address, ccaddress, iOrgWideEmailAddress, ReplyToEmail, subject, HtmlBody);
lstOpp.SendEmailDone__c = true;
update lstOpp;
myRet = true ;
} catch (Exception e) {
String data = 'STACK TRACE:\n' +e.getStackTraceString() + '\nMESSAGE:\n' + e.getMessage()+ '\nLine:\n' + e.getLineNumber();
CustomLogHelper.addNewLog('OpportunityEmail.sendOppEmail',data);
CustomLogHelper.saveCurrentCustomLog();
hasError = true;
mpOpp.put(opp.id, opp);
msg = Label.OpportunitySendEmailFail +', Error: '+ data;
}
return myRet;
}
}
And this is a test class code
#isTest
private class OpportunityEmailTest2 {
#testSetup static void setup(){
EmailTemplate validEmailTemplate = new EmailTemplate();
validEmailTemplate.isActive = true;
validEmailTemplate.Name = 'PartnerEmail';
validEmailTemplate.DeveloperName = 'PartnerEmail';
validEmailTemplate.TemplateType = 'custom';
validEmailTemplate.FolderId = UserInfo.getUserId();
validEmailTemplate.IsActive = true;
validEmailTemplate.HtmlValue = 'Test email';
validEmailTemplate.Subject = 'Soggetto Email Test';
insert validEmailTemplate;
}
#isTest static void OpportunityEmailTest1() {
RecordType aRT = new RecordType();
aRT = [SELECT id, Name from RecordType where Name ='Company'];
Account accCust = new Account();
accCust.SDIPec__c = '1901837#gmail.com';
accCust.SDICode__c = '0000000';
accCust.Phone = '0233498737';
accCust.Mobile__c = '3452229458';
accCust.CompanyEmail__c = 'comp#gmail.com';
accCust.Name = 'Cuenta test1';
accCust.CommercialName__c = 'Cuenta test1';
accCust.VATNumber__c = '03442194837';
accCust.FiscalCode__c = 'RBNMHL70D15A059E';
accCust.BillingStreet = 'Via Pesciatina 129 Fraz. Lunata';
accCust.BillingPostalCode = '00187';
accCust.BillingCity = 'Legnano';
accCust.BillingStateCode = 'MI';
accCust.BillingState = 'Milan';
accCust.BillingCountryCode = 'IT';
accCust.ShippingStreet = 'Via Pesciatina 129 Fraz. Lunata';
accCust.ShippingPostalCode = '00187';
accCust.ShippingCity = 'Legnano';
accCust.ShippingStateCode = 'MI';
accCust.ShippingState = 'Milan';
accCust.RecordType = aRT;
insert accCust;
Account accPart = new Account();
accPart.SDIPec__c = '20190130#gmail.com';
accPart.SDICode__c = '0000000';
accPart.VATNumber__c = '03446283948';
accPart.FiscalCode__c = 'BRTLMN83C16B406T';
accPart.Name = 'Cuenta test2';
accPart.CommercialName__c = 'Cuenta test2';
accPart.CompanyEmail__c = 'CompanyEmail__2#gmail.com';
accPart.BillingStreet = 'VIA DE FLAGILLA 24';
accPart.BillingPostalCode = '00187';
accPart.BillingCity = 'ROMA';
accPart.BillingStateCode = 'RM';
accPart.BillingCountryCode = 'IT';
accPart.ShippingStreet = 'VIA DE FLAGILLA 24';
accPart.ShippingPostalCode = '00187';
accPart.ShippingCity = 'ROMA';
accPart.ShippingStateCode = 'RM';
accPart.RecordType = aRT;
insert accPart;
Contact pryCont = new Contact();
pryCont.LastName = 'Contact Test';
pryCont.MobilePhone = '3452229384';
pryCont.Email = 'contactemail#email.it';
insert pryCont;
Opportunity iOpport = new Opportunity();
iOpport.Name = 'Test Opportunity Email';
iOpport.StageName = 'Proposal';
iOpport.CloseDate = Date.today();
//iOpport.RecordTypeId = '0120N000000RUeXQAW'; //PROD
//iOpport.RecordTypeId = '0121w0000009fgJAAQ'; //PARTIAL COPY
iOpport.RecordTypeId = '0121w0000006dPnAAI'; //MYDEV
iOpport.AccountId = accPart.Id;
iOpport.CustomerAccount__c = accCust.Id;
iOpport.Primary_Contact__c = pryCont.Id;
iOpport.Description = 'Descrizione test';
iOpport.HardwareBundle__c = 'BD05';
iOpport.OpportunityHardware__c = true;
iOpport.SendEmailDone__c = false;
insert iOpport;
OpportunityEmail.sendOppEmail(iOpport);
OrgWideEmailAddress iOrgWideEmailAddress;
iOrgWideEmailAddress = OrgWideEmailAddressHelper.getByAddress(Label.SendPartnerOppEmail);
String Template = 'PartnerEmail';
EmailTemplate eT = [select id, DeveloperName, Body, HtmlValue, Subject from EmailTemplate where Name =: Template LIMIT 1];
Id TemplateId = eT.Id ;
String subject = eT.Subject;
String HtmlBody = eT.HtmlValue;
Id account = iOpport.Id;
String address = accPart.CompanyEmail__c;
String ccaddress = pryCont.Email;
String ReplyToEmail = 'replayemail#email.com';
String Customer = accCust.Name + '<br>' +
'P.Iva: ' + accCust.VATNumber__c + '<br>' +
'Cod.Fiscale: ' + accCust.FiscalCode__c + '<br>' +
'Telefono: ' + accCust.Phone + '<br>' +
'Mobile: ' + accCust.Mobile__c + '<br>' +
'Email: ' + accCust.CompanyEmail__c + '<br>' +
'SDI: ' + accCust.SDICode__c + '<br><br>' +
'Sede Legale: ' + '<br>' +
accCust.BillingStreet + ', ' + accCust.BillingPostalCode + ' ' + accCust.BillingCity + ' (' + accCust.BillingStateCode + ') ' + '<br><br>' +
'Sede Operativa: ' + '<br>' +
accCust.ShippingStreet + ', ' + accCust.ShippingPostalCode + ' ' + accCust.ShippingCity + ' (' + accCust.ShippingStateCode + ') ';
String Description = iOpport.Description;
String ItemTable = iOpport.HardwareBundle__c;
EmailManager.sendMailCcAdd(TemplateId, account, address, ccaddress, iOrgWideEmailAddress, ReplyToEmail, subject, HtmlBody);
}
}
I understood that the part of code not cover is this:
String Template = OpportunityEmail__c.getValues('Template1').TemplateEmail__c;
EmailTemplate eT = [select id, DeveloperName, Body, HtmlValue, Subject from EmailTemplate where Name =: Template];
Id TemplateId = eT.Id ;
String subject = eT.Subject;
String HtmlBody = eT.HtmlValue;
Id account = opp.Id;
String address = accPrt.CompanyEmail__c;
String ccaddress = '';
if(primContcSped != null){
ccaddress = primContcSped;
}
String ReplyToEmail = OpportunityEmail__c.getValues('Operation').ReplyToEmail__c;
String Customer = accCust.Name + '<br>' +
'P.Iva: ' + accCust.VATNumber__c + '<br>' +
'Cod.Fiscale: ' + accCust.FiscalCode__c + '<br>' +
'Telefono: ' + accCust.Phone + '<br>' +
'Mobile: ' + accCust.Mobile__c + '<br>' +
'Email: ' + accCust.CompanyEmail__c + '<br>' +
'SDI: ' + accCust.SDICode__c + '<br><br>' +
'Sede Legale: ' + '<br>' +
accCust.BillingStreet + ', ' + accCust.BillingPostalCode + ' ' + accCust.BillingCity + ' (' + accCust.BillingStateCode + ') ' + '<br><br>' +
'Sede Operativa: ' + '<br>' +
accCust.ShippingStreet + ', ' + accCust.ShippingPostalCode + ' ' + accCust.ShippingCity + ' (' + accCust.ShippingStateCode + ') ';
String Description = '';
if(opp.Description != null){
Description = opp.Description;
}
String ItemTable = '';
if(opp.HardwareBundle__c != null){
ItemTable = '<table style="width:30%;border: 1px solid black;"> <tr> <th style="text-align: left;border: 1px solid black;"> Service/Products </th> </tr>';
List<Schema.PicklistEntry> fieldResult = Opportunity.HardwareBundle__c.getDescribe().getPicklistValues();
Opportunity lstBund = [select HardwareBundle__c from Opportunity where id =: opp.Id];
String[] tmpBund = lstBund.HardwareBundle__c.split(';');
for(String s : tmpBund){
for(Schema.PicklistEntry f : fieldResult) {
if (f.getValue() == s){
ItemTable = ItemTable + '<tr> <td style = "text-align: left;">'+ f.getLabel()+'</td></tr>';
break;
}
}
}
ItemTable = ItemTable + '</table>';
}
subject = subject.replace('CustomerAccount', accCust.Name);
HtmlBody = HtmlBody.replace('{Customer1}', Customer);
HtmlBody = HtmlBody.replace('ItemTable', ItemTable);
HtmlBody = HtmlBody.replace('{!Description}', Description);
EmailManager.sendMailCcAdd(TemplateId, account, address, ccaddress, iOrgWideEmailAddress, ReplyToEmail, subject, HtmlBody);
lstOpp.SendEmailDone__c = true;
update lstOpp;'
But I don't understand which is a solution.
Thank you so much for your help!
String Template = OpportunityEmail__c.getValues('Template1').TemplateEmail__c;
In this line, I see that you are trying to access a Custom Setting OpportunityEmail__c. Custom Settings behave just like data, which means that you need to insert it in the test method before you can use it.
Your other option is to use a Custom Metadata Type instead, which can be retrieved from the environment via a SOQL query.

QuickBooks Desktop Integration

I have a task to make a syncing service that can sync the sales records present in the Quick books point of sale into the local database.
How to integrate Quick books desktop point of sale and web application(c#) via web connector?
Code used :
public string sendRequestXML(string ticket, string strHCPResponse, string
strCompanyFileName,
string qbXMLCountry, int qbXMLMajorVers, int qbXMLMinorVers) {
if (Session["counter"] == null) {
Session["counter"] = 0;
}
string evLogTxt="WebMethod: sendRequestXML() has been called by
QBWebconnector" + "\r\n\r\n";
evLogTxt=evLogTxt+"Parameters received:\r\n";
evLogTxt=evLogTxt+"string ticket = " + ticket + "\r\n";
evLogTxt=evLogTxt+"string strHCPResponse = " + strHCPResponse +
"\r\n";
evLogTxt=evLogTxt+"string strCompanyFileName = " +
strCompanyFileName + "\r\n";
evLogTxt=evLogTxt+"string qbXMLCountry = " + qbXMLCountry + "\r\n";
evLogTxt=evLogTxt+"int qbXMLMajorVers = " +
qbXMLMajorVers.ToString() + "\r\n";
evLogTxt=evLogTxt+"int qbXMLMinorVers = " +
qbXMLMinorVers.ToString() + "\r\n";
evLogTxt=evLogTxt+"\r\n";
ArrayList req=buildRequest();
string request="";
int total = req.Count;
count=Convert.ToInt32(Session["counter"]);
if(count<total) {
request=req[count].ToString();
evLogTxt=evLogTxt+ "sending request no = " + (count+1) + "\r\n";
Session["counter"] = ((int) Session["counter"]) + 1;
}
else{
count=0;
Session["counter"]=0;
request="";
}
evLogTxt=evLogTxt+"\r\n";
evLogTxt=evLogTxt+"Return values: " + "\r\n";
evLogTxt=evLogTxt+"string request = " + request + "\r\n";
logEvent(evLogTxt);
return request;
}
It is creating log in the end, how will i fetch the data from the QBPOS?

Twitter API link parser

I am having an issue and tried to do everything regarding this!! even HttpUtility.ParseQueryString won't help!
I am trying to parse twitter links coming from the API in the form of http://t.co/oEVQbihMWu. I need the fully resolved URL.
My code:
richTextBox1.Clear();
richTextBox1.Visible = true;
SearchOptions SO = new SearchOptions();
SO.GeoCode = richTextBox3.Text + "," + richTextBox2.Text + "mi";
TwitterResponse<TwitterSearchResultCollection> TweetSearchResult = TwitterSearch.Search(tokens, "#blogger", SO);
if (TweetSearchResult.Result != RequestResult.Success) richTextBox1.Text = "connection Error";
else
{
string a = null;
foreach (var tweet in TweetSearchResult.ResponseObject)
{
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, tweet.User.Website, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + tweet.User.Website + "\n" + tweet.Text + "\n\n\n");
}
links being represented by tweet.user.website.
any help? :)
In the API response, there is entities.urls which contains an array of url and expanded_url mappings. Check your library's documentation for equivalent.
Alternatively, if you inspect the response for t.co links, you will find this:
<noscript><META http-equiv="refresh" content="0;URL=http://www.fitnessbydanielle.com"></noscript><title>http://www.fitnessbydanielle.com</title><script>window.opener = null; location.replace("http:\/\/www.fitnessbydanielle.com")</script>
Parse it to get the url.
I managed to crack it.
What I did:
foreach (var tweet in TweetSearchResult.ResponseObject)
{
if(tweet.User.Website != null)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(tweet.User.Website);
req.AllowAutoRedirect = false;
var resp = req.GetResponse();
string realUrl = resp.Headers["Location"];
string b = tweet.User.Location.Contains(",") ? tweet.User.Location.Replace(",", "-") : tweet.User.Location;
a += string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", tweet.CreatedDate, b, tweet.User.Id,
tweet.User.ScreenName, tweet.User.Name, tweet.User.NumberOfFollowers, realUrl, Environment.NewLine);
richTextBox1.AppendText(" " + tweet.CreatedDate + "\n" + tweet.User.Location + "\n" + tweet.User.Id + "\n" + tweet.User.ScreenName + "\n" + tweet.User.Name + "\n" + tweet.User.NumberOfFollowers +
"\n" + realUrl + "\n" + tweet.Text + "\n\n\n");
}
}
File.AppendAllText(#".\BloggerTable.csv", a, Encoding.UTF8);
}
Wrapped it inside a condition so no users without website will show and used a webrequest to get the link. stored the location inside the httprequest header for each and every tweet.

ASP.NET MVC PartialView gives an error some times?

I use partialview like
<td style="vertical-align: top;">#Html.Action("_HavaDurumuPartial")
And It is working on server now. But sometimes It gives error. Erros is below:
This error not occur allways.
I cant find any reason for this problem.And I cant understand why does it sometimes give this error.
If it is neccesary, I write the content of partialview and controller action.
action
public ActionResult _HavaDurumuPartial(string il)
{
il = "Izmir";
HttpWebRequest GoogleRequest;
HttpWebResponse GoogleResponse = null;
XmlDocument GoogleXMLdoc = null;
try
{
GoogleRequest = (HttpWebRequest)WebRequest.Create("http://www.google.com/ig/api?weather=" + il + "&hl=tr&ie=utf-8&oe=utf-8");
GoogleResponse = (HttpWebResponse)GoogleRequest.GetResponse();
GoogleXMLdoc = new XmlDocument();
GoogleXMLdoc.Load(GoogleResponse.GetResponseStream());
XmlNode root = GoogleXMLdoc.DocumentElement;
XmlNodeList nodeList1 = root.SelectNodes("weather/forecast_information");
//ViewBag.HavaDurumu = ViewBag.HavaDurumu + "<b>Şehir : " + nodeList1.Item(0).SelectSingleNode("city").Attributes["data"].InnerText + "</b>";
XmlNodeList nodeList = root.SelectNodes("weather/current_conditions");
ViewBag.HavaDurumu = ViewBag.HavaDurumu + "<table cellpadding=\"5\"><tbody><tr><td style=\"width:50%;\"><b><big><nobr>" + nodeList.Item(0).SelectSingleNode("temp_c").Attributes["data"].InnerText + " °C | " + nodeList.Item(0).SelectSingleNode("temp_f").Attributes["data"].InnerText + " °F</nobr></big></b></br>";
ViewBag.HavaDurumu = ViewBag.HavaDurumu + "<b>Şuan:</b> " + nodeList.Item(0).SelectSingleNode("condition").Attributes["data"].InnerText + "";
ViewBag.HavaDurumu = ViewBag.HavaDurumu + " " + nodeList.Item(0).SelectSingleNode("wind_condition").Attributes["data"].InnerText + "</br>" + "";
ViewBag.HavaDurumu = ViewBag.HavaDurumu + " " + nodeList.Item(0).SelectSingleNode("humidity").Attributes["data"].InnerText;
nodeList = root.SelectNodes("descendant::weather/forecast_conditions");
int i = 0;
foreach (XmlNode nod in nodeList)
{
if (i == 0)
{
i++;
continue;
}
ViewBag.HavaDurumu = ViewBag.HavaDurumu + "</td><td align=\"center\">" + nod.SelectSingleNode("day_of_week").Attributes["data"].InnerText + "</br>" + "";
ViewBag.HavaDurumu = ViewBag.HavaDurumu + "<img src=\"http://www.google.com" + nod.SelectSingleNode("icon").Attributes["data"].InnerText + "\" alt=\"" + nod.SelectSingleNode("condition").Attributes["data"].InnerText + "\">" + "</br>";
ViewBag.HavaDurumu = ViewBag.HavaDurumu + nod.SelectSingleNode("low").Attributes["data"].InnerText + "°C" + "</br>";
ViewBag.HavaDurumu = ViewBag.HavaDurumu + nod.SelectSingleNode("high").Attributes["data"].InnerText + "°C" + "</br>";
}
ViewBag.HavaDurumu = ViewBag.HavaDurumu + "</td></tr></tbody></table>";
}
catch (System.Exception ex)
{
ViewBag.HavaDurumu = ex.Message;
}
finally
{
GoogleResponse.Close();
}
return PartialView();
}
I get the weather for specific location from google with this action.
Thanks.
There is currently an intermittent 403 Forbidden response to the Google Weather API that you are using. See Google Weather API 403 Error
The reason for the intermittent 403 response is not known but has been a problem since the 7th of August 2012.
Add a null reference check in your finally. Initializing GoogleResponse could fail, so it would still be null. Then you'll hit your finally block and get a null reference exception since GoogleResponse is null when you try to call .Close().
finally
{
if (GoogleResponse != null)
{
GoogleResponse.Close();
}
}

How to use gettext placeholders?

I'm not a programmer, but I want to help translating a project written in vala (http://live.gnome.org/Vala/Tutorial) using gettext. I encountered a problem when I had to rearrange parts of a sentence using placeholders.
Example:
public void show_retrieving_similars() {
if(hint != ViewWrapper.Hint.SIMILAR || lm.media_info.media == null)
return;
errorBox.show_icon = false;
errorBox.setWarning("<span weight=\"bold\" size=\"larger\">" + _("Loading similar songs") + "</span>\n\n" + _("BeatBox is loading songs similar to") + " <b>" + lm.media_info.media.title.replace("&", "&") + "</b> by <b>" + lm.media_info.media.artist.replace("&", "&") + "</b> " + _("..."), null);
errorBox.show();
list.hide();
albumView.hide();
similarsFetched = false;
}
What do I need to do?
I haven't used vala and I haven't tested this, it looks like you need to replace
errorBox.setWarning("<span weight=\"bold\" size=\"larger\">" + _("Loading similar songs") + "</span>\n\n" + _("BeatBox is loading songs similar to") + " <b>" + lm.media_info.media.title.replace("&", "&") + "</b> by <b>" + lm.media_info.media.artist.replace("&", "&") + "</b> " + _("..."), null);
with
string title = lm.media_info.media.title.replace("&", "&");
string artist = lm.media_info.media.artist.replace("&", "&");
errorBox.setWarning(#"<span weight=\"bold\" size=\"larger\">Loading similar songs</span>\n\n BeatBox is loading songs similar to<b> $title </b>by<b> $artist </b>...", null);

Resources