I am having a problem where the user enters his inputs into a text box (like a name). If the name is Jim Bob it will output like Jim System.Windows.Form.Label Bob System.Windows.Form.Label. I searched the properties tab and I am following along from the book but they do not have the same problem I have. I added some code below but I don't think it has anything to do with the problem.
string output;
output = textBoxPrefT.Text + ". " + textBoxFirstN + " " + textBoxMiddleN + " " + textBoxLastN;
labelOutput.Text = output;
You have to include .Text for all textboxes so it should look like this
string output;
output = textBoxPrefT.Text + ". " + textBoxFirstN.Text + " " + textBoxMiddleN.Text + " " + textBoxLastN.Text;
labelOutput.Text = output;
Related
I am using C# MVC Architecture.
I am going to retrieve the questions from the database and display in the email content as a list of questions.
Below is the method of the email template.
public bool SendJobAcceptanceToRecruiter(string recruiterName, string recruiterEmail, string jobTitle,string joblink, string mailBody, string organization, List<JobQuestion> ques)
{
string subject = "Job Advert Accepted - " + jobTitle + "-" + organization;
var generaltemplate = GetEmailTemplate("GENERAL EMAIL TEMPLATE");
var template = "<br/>Hello " + organization + "<br/>" +
"<br/>Your Job Advert has now been accepted.<br/>" +
"<br/>View Job Posted: " + joblink + "<br/>" +
"<br/>Questions Posted: " + ques + "<br/>" +
"<br/>Please contact us if you need more information.<br/>";
var body = generaltemplate.Replace("#Content", template);
body = body.Replace("#Orgname", organization);
body = body.Replace("#JobLink", joblink) + GetEmailFooter();
var result = _emailProvider.SendEmail(recruiterEmail, subject, body, true);
return result;
}
Here for the List of questions, I get the questions as below.
I want to display the 'Question' in the second image as list of questions(In the above case as the count is 7,want to display the 7 questions) with numbering starting from 1.(Number of questions may differ according to the advert.) as a list in the email content.
Every other details(jobTitle,JobLink,RecruiterEmail etc..) are displayed in the email.
Only the 'ques' under Questions Posted: in the email content are displayed as
[![enter image description here][3]][3]
I want the content to be displayed as,
1.Question 1
2.Question 3
3.Question 3
...
How can I solve this?
You need to "unfold" the list of questions, if you do that, you'll have all the freedom you need.
In stead of:
"<br/>Questions Posted: " + ques + "<br/>"
use something like this:
"<br/>Questions Posted: " + string.Join(", ",Enumerable.Range(0, ques.Count()).Select(n => n.Description).ToArray()) + "<br/>"
Or for better readability:
var template = "<br/>Hello " + organization + "<br/>" +
"<br/>Your Job Advert has now been accepted.<br/>" +
"<br/>View Job Posted: " + joblink + "<br/>" +
"<br/>Questions Posted: ";
foreach(var question in ques)
template += $"somthing {question.Description} something"
template += "<br/>Please contact us if you need more information.<br/>";
var body = generaltemplate.Replace("#Content", template);
Further optimization: use a StringBuilder:
var sb = new StringBuilder();
sb.AppendLine("<br/>Hello " + organization + "<br/>");
sb.AppendLine("<br/>Your Job Advert has now been accepted.<br/>");
sb.AppendLine("<br/>View Job Posted: " + joblink + "<br/>");
sb.AppendLine("<br/>Questions Posted: ");
foreach(var question in ques)
{
sb.AppendLine($"somthing {question.Description} something");
}
sb.AppendLine("<br/>Please contact us if you need more information.<br/>");
var body = generaltemplate.Replace("#Content", sb.ToString());
Addition: for numbering you have various options. Here's a simple one to understand:
var sb = new StringBuilder();
sb.AppendLine("<br/>Hello " + organization + "<br/>");
sb.AppendLine("<br/>Your Job Advert has now been accepted.<br/>");
sb.AppendLine("<br/>View Job Posted: " + joblink + "<br/>");
sb.AppendLine("<br/>Questions Posted: ");
int number = 0;
foreach(var question in ques)
{
sb.AppendLine($"QUESTION {++number}");
sb.AppendLine($"somthing {question.Description} something");
}
sb.AppendLine("<br/>Please contact us if you need more information.<br/>");
var body = generaltemplate.Replace("#Content", sb.ToString());
I am trying to add some large string into string type varriable.But it gives an error.
string SuccessUrl = "~/Customer/Success.aspx?URL=" + Server.UrlEncode("Transactionid="
+ Transactionid + "&Amount=" + Amount + "&Name=" + Name +
"&EmailOfPayer=" + EmailOfPayer + "&bussness=" + business + "&CompanyName=" + CompanyName
+ "&PaymentDate=" + paymentDateTime +"&SecuritiesandComplianceFee=" + SecuritiesandComplianceFee
+"&Status=" + Convert.ToInt32(Status) + "&BackmyUri=" + BackmyUri);
I have an error because of the last varriable i.e. BackmyUri. The varriable have the string value as given below.
string BackmyUri = "http://localhost:11181/Payment.aspx"
it gives an error .
Input string was not in a correct format.
Any kind of help will be appreciated.
Input string was not in a correct format. is most likely the default error message for int.Parse() and `Convert.ToInt32' . You should really check that. Another helpful thing for us would be to show us an example that makes it error, show the result of:
var x = "Transactionid=" + Transactionid + "&Amount=" + Amount + "&Name=" + Name +
"&EmailOfPayer=" + EmailOfPayer + "&bussness=" + business + "&CompanyName=" + CompanyName
+ "&PaymentDate=" + paymentDateTime +"&SecuritiesandComplianceFee=" + SecuritiesandComplianceFee
+"&Status=" + Convert.ToInt32(Status) + "&BackmyUri=" + BackmyUri
I'm doing a WCF service with GUI as client, however I have a problem with printing list of current items added. I have a code to add new entries to the list:
public bool Add_Data(Data sample)
{
container.Add(sample);
Console.WriteLine("New record added!");
return true;
}
And it's working, however when I'm trying to view added records with first try it works, however if I want to view it again list is adding same element. To show you how it works:
I'm adding new entry and I "print" list:
IMAGE CLICK [works how it should]
However I want to see it again, so I'm pressing same button in my form, and here is what happens:IMAGE CLICK as you can see, we have our list + additional same record, if I will press button again, I will have 3 same records.
Here is my "show records" code:
public string Show_Data()
{
Console.WriteLine("Printing records");
foreach (Data record in container)
{
string final_result = ("\nID: "+ + record.ID + " " + "product: " + record.product + " " + "category: " + record.category + " " + "price: " + record.price + " " + "quantity: " + record.quantity + " " + "\n ");
result += final_result;
}
return result;
}
Let me know if you know how to solve it.
You need to look into variable scope. You have result declared outside of the Show_Data() method. Each time the method is called you are doing result += final_result; which is adding to result. Try the code below and you will get different results.
public string Show_Data()
{
Console.WriteLine("Printing records");
var output = string.Empty;
foreach (Data record in container)
{
string final_result = ("\nID: "+ + record.ID + " " + "product: " + record.product + " " + "category: " + record.category + " " + "price: " + record.price + " " + "quantity: " + record.quantity + " " + "\n ");
output += final_result;
}
return output;
}
Also, I would consider using a string builder and string format as well.
public string Show_Data()
{
Console.WriteLine("Printing records");
var output = new StringBuilder();
foreach (Data record in container)
{
string final_result = string.Format("ID: {0} product: {1} category: {2} price: {3} quantity: {4}", record.ID, record.product, record.category, record.price, record.quantity);
// if using C# 6
// string final_result = string.Format($"ID: {record.ID} product: {record.product} category: {record.category} price: {record.price} quantity: {record.quantity)}";
output.AppendLine(final_result);
}
return output.ToString();
}
I have some code that is currently doing the following at the end of the code:
Console.WriteLine(vid.totalCurrentCharges + " : " + vid.assetId + " : " + vid.componentName + " : " + vid.recurringCharge);
Console.readline().
I need to take the output of vid.totalCurrentCharges + " : " + vid.assetId + " : " + vid.componentName + " : " + vid.recurringCharge, and write It to a csv file. Can someone here help with this? Currently all it is doing is writing the output to console.
Instead of Console.Writeline you need to create StreamWriter. Just like this:
using (StreamWriter writer = new StreamWriter("important.csv"))
{
//probably a loop here
writer.WriteLine(vid.totalCurrentCharges + " , " + vid.assetId + " , " + vid.componentName + " , " + vid.recurringCharge);
}
Moreover you can use String.Join to concatenate strings instead of "adding" them, so above WriteLine can be converted into:
writer.WriteLine(String.Join(",", vid.totalCurrentCharges, vid.assetId, vid.componentName, vid.recurringCharge));
i currently have a textbox field, everytime a change is made, i add who it was updated by and what time
right now it keep appending that text
how can i find the line that says "LastEdited: ", and only replace the time stamp value?
this is what i do now
maybe someone can post me example of code how to grab the timestamp and replace it?
if (txtMemberNotesOriginally != txtMemberNotesChanged) {
txtMemberNotes.AppendText("LastEdited: " + DateTime.Now.ToString() + " By: " + MyProgramName.Username + Environment.NewLine);
i am not an expert, so an example of code would bevery useful
i do use this textbox to save other notes as well (which i wouldn't wanna loose)
can i do this
foreach (var line in txtMemberNotes.Lines) {
if (line.StartsWith("Last Edited: "))
{
txtMemberNotes.Text = txtMemberNotes.Text.Replace(line, "Last Edited: " + DateTime.Now.ToString() + " By: " + MyProgramName.Username + Environment.NewLine);
}
else
{
txtMemberNotes.AppendText("Last Edited: " + DateTime.Now.ToString() + " By: " + MyProgramName.Username + Environment.NewLine);
}
}
The easiest way to solve your problem seems to stop appending text and just set the text value. No parsing is necessary, just overwrite the exiting values with your newer value.
if (txtMemberNotesOriginally != txtMemberNotesChanged) {
txtMemberNotes.Text = "LastEdited: " + DateTime.Now.ToString() + " By: " + MyProgramName.Username + Environment.NewLine;
I guess theres always Regex if you really wanted:
string s = #"Some notes here etc etc..
Last edited: 12/12/2012 12:00:00 AM";
Console.Write(Regex.Replace(s, #"Last edited: .*$", "Lasted edited: " + DateTime.Now.ToString()));
Or more specifically using your code:
txtMemberNotes.Text = Regex.Replace(txtMemberNotes.Text, #"Last edited: .*$", "Lasted edited: " + DateTime.Now.ToString());