|
class product
namespace EssentialTools.Models {
public class Product {
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public string Category { set; get; }
}
}
class LinqValueCalculator
using System.Collections.Generic;
using System.Linq;
namespace EssentialTools.Models {
public class LinqValueCalculator {
public decimal ValueProducts(IEnumerable<Product> products) {
return products.Sum(p => p.Price);
}
}
}
The ShoppingCart Class
using System.Collections.Generic;
namespace EssentialTools.Models {
public class ShoppingCart {
private LinqValueCalculator calc;
public ShoppingCart(LinqValueCalculator calcParam) {
calc = calcParam;
}
public IEnumerable<product> Products { get; set; }
public decimal CalculateProductTotal() {
return calc.ValueProducts(Products);
}
}
i dont understand logic code ...plz help me .Thank you
|
|
|
|
|
There is no "logic code" there - it's just blank classes except for one very simple line.
Are you trying to say "I don't understand this line of code:
return products.Sum(p => p.Price); Because if so, it's pretty trivial.
It uses a Linq method to return the total sum of all the Price properties of each item in the products collection. It's the equivalent of saying:
double total = 0.0;
foreach (Product p in products) total += p.Price;
return total;
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
using System.Collections.Generic;
namespace EssentialTools.Models {
public class ShoppingCart {
private LinqValueCalculator calc;
public ShoppingCart(LinqValueCalculator calcParam) {
calc = calcParam;
}
public IEnumerable<Product> Products { get; set; }
public decimal CalculateProductTotal() {
return calc.ValueProducts(Products);
}
}
}
and line calc.ValueProducts(Products); =>>>i dont undertand ...plz help me
modified 4-Jan-15 5:12am.
|
|
|
|
|
You are joking, right?
It calls an method on the LinqValueCalculator instance and passes it a collection of products.
I don't mean to sound rude here, but if you don't understand that simple code, then seriously you need to go right back to first principles and review the basics of C# coding - you aren't ready to start looking at complex stuff yet, and certainly nothing that involves lambda expressions.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
hi i am newbie ...thank you bro
|
|
|
|
|
There is a Products collection that contains Product objects.
Each Product object has some properties e.g. Price, Description, Category etc.
The ShoppingCart class calculates the total price of various products using LinqValueCalculator class.
What is missing in your code here is the class that instantiates ShoppingCart .
This class would be responsible for instantiating ShoppingCart and LinqValueCalculator .
|
|
|
|
|
hi bro.Thank you so much. i have a question
why they need a param private LinqValueCalculator calc;
.I am a newbie.Sorry bro
|
|
|
|
|
LinqValueCalculator is a class level variable i.e. it can be used across the class.
It is assigned in the constructor of the class and then used later.
|
|
|
|
|
hi every body ...why/when use the IEnumerable/IEnumerator interfaces.Thank you!
|
|
|
|
|
I suggest you start by reading this CodeProject article: [^].
You use these interfaces when the standard built-in iterators like 'foreach (which use these interfaces !) do not provide the functionality you wish to have in sequential access of a Collection of objects. Or, as in this example, to enable a Class which is not natively enumerable to act like it is by exposing a private collection defined in the Class.
For example, if you implement a Class that contains some form of custom Collection, which is private to the Class, but you want to be able to use 'foreach on an 'instance of that Class, and have the 'foreach loop move in sequence through the private custom-collection, you can have the Class implement (inherit from) IEnumerable, and then have the Class instance expose the Enumerator of the private Collection by making the private Collection's Enumerator be accessed in the implementation of the required 'GetEnumerator method.
Sound complex ? It's really not:
public class SomeClass: IEnumerable
{
private List<string> ListOStrings;
public SomeClass()
{
ListOStrings = new List<string>
{
"one","two","three"
};
}
public IEnumerator GetEnumerator()
{
return ListOStrings.GetEnumerator();
}
}
SomeClass someClass = new SomeClass();
foreach (var str in someClass)
{
Console.WriteLine(str);
} Also suggest you read: [^].
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
|
I am developing an addin for AutoCAD using c# with a WPF xaml dockable pane, I would like to sometimes show a webpage in the pane so I am using the WebBrowser, however it is not displaying the HTML5 content well as it defaults to IE7. using FEATURE_BROWSER_EMULATION I should be able to point it to using IE11 if installed, however setting the application that the addin is loaded into in the registry isnt working. I also tried the dll file that my addin creates and this doesnt work either. Is there a way to tell my WebBrowser in my dll within acad.exe to use IE11?
|
|
|
|
|
CodeProject is your friend: "Configuring the emulation mode of an Internet Explorer WebBrowser control" July, 2014: [^].
However, the fact you have such a complex embedding scenario, AutoCad/Add-In/WPF/WebBrowser, could be a constraining factor here, I would guess (and, I'll never know because I don't have AutoCad).
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
Thanks for the reply Bill, I just found that if I put the registry entry onto the HKEY_CURRENT_USER instead of HKEY_LOCAL_MACHINE it works, so I am a happy boy!
|
|
|
|
|
Glad you got it working. You might consider adding a Tip/Trick to CodeProject describing the problem, how you fixed it, and ... if the CP article did help you ... cite it.
cheers, Bill
«A man will be imprisoned in a room with a door that's unlocked and opens inwards ... as long as it does not occur to him to pull rather than push» Wittgenstein
|
|
|
|
|
The current search i have implemented into my program is limited to specific tables in the database. How do i go about adding the capabilities of searching all the tables within a database? In addition i would like to offer filters using check boxes to narrow the search parameters.
A JOIN would allow the search across multiple tables but the following line of code limits the search because of the "TestDescription='"
DataRow[] returnRows = DS.Tables[0].Select("TestDescription='" + search + "'");
I have provided my code below:
private void BtnSearch_Click(object sender, RoutedEventArgs e)
{
string ConnectionString = "Data Source=RATTLERR;Initial Catalog=medical;Integrated Security=True;";
SqlConnection conn = new SqlConnection(ConnectionString);
SqlDataAdapter dAdapter = new SqlDataAdapter("Select * FROM test", conn);
conn.Open();
DataSet DS = new DataSet();
string search = tbSearch.Text;
int result = 0;
if (tbSearch.Text.Length >= 1)
{
dAdapter.Fill(DS);
DataRow[] returnRows = DS.Tables[0].Select("TestDescription='" + search + "'");
result = returnRows.Length;
if (result > 0)
{
dgInfo.ItemsSource = returnRows.CopyToDataTable().DefaultView;
}
else
{
System.Windows.MessageBox.Show("No Records Found");
}
conn.Close();
}
}
modified 3-Jan-15 14:06pm.
|
|
|
|
|
|
Thank you for the information i will give it a try and see how it turns out..
|
|
|
|
|
Hi everyone,
I'm facing a problem while sending bulk mails with multiple attachments.
I could send mails to everyone but only the first recipient was able to receive the attachments and rest of the recipients could receive the emails with malfunctioning attachment.
error from the second recipients gmail when I checked it out - Quote: Whoops!
There was a problem displaying this image.
Retrying...
Thanks in advance.
|
|
|
|
|
That is not a question that can be answered here. You need to get that recipient to investigate exactly what happened, or to get you a copy of the raw message data.
|
|
|
|
|
Hello,
I'm trying to email images to my tumblr blog. I can go into my live account, create an email, attach an image and send it -- this works fine and post to my tubmlr blog fine. However, when I try to to do the same thing in my C# application nothing happens, no error, and nothing post to tumblr. I was hoping somebody could give me some insight as to what live.com does differently than me when sending email. My code is below, thanks in advanced.
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential("myliveaccount@live.com", "mylivepass");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("myliveaccount@live.com");
smtpClient.Host = "smtp.live.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
smtpClient.Timeout = (60 * 5 * 1000);
smtpClient.EnableSsl = true;
message.From = fromAddress;
message.Subject = "subject";
message.IsBodyHtml = false;
message.Body = "#Tag1 #Tag2 #Tag3 #Tag4";
message.To.Add("tumblrblogemail@tumblr.com");
string attachmentFilename = @"C:\0103150633034149.jpg";
Attachment attachment = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
ContentDisposition disposition = attachment.ContentDisposition;
disposition.CreationDate = File.GetCreationTime(attachmentFilename);
disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
disposition.ReadDate = File.GetLastAccessTime(attachmentFilename);
disposition.FileName = Path.GetFileName(attachmentFilename);
disposition.Size = new FileInfo(attachmentFilename).Length;
disposition.DispositionType = DispositionTypeNames.Attachment;
message.Attachments.Add(attachment);
smtpClient.Send(message);
|
|
|
|
|
try by adding ssl port
smtpClient.Port = 587;
|
|
|
|
|
Hey, thanks for replying. yup, I tried that, same results...
Some how or another, Tumblr knows the difference between hotmail and an application using Hotmail smtp. I can't for the life of me figure out what it is though.
|
|
|
|
|
You should check the required settings for email access. Login to your hotmail account and use the help system.
|
|
|
|
|
Interesting, so it works if I don't attach the photo.....
|
|
|
|