|
So what is your question?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
sorry sir..i want to , when we click on a question just like in this site and same question also display on in another page..
|
|
|
|
|
That's not a question. What have you tried? Where are you stuck?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
So I was discussing this subject with one of my coworkers after he asked me to review some of his code. Our software breaks apart data files, and feeds them to a separate service to be stored in a SQL Server database. His "Record" class has several properties for each of the fields in the client's data file. This particular client's module uses the FileHelpers utility library to read a CSV format, so we're not parsing it manually. Three of the fields are: City, State, ZIP.
Ultimately, we only really care to access the City/State/ZIP as a whole, a formatted string (e.g. Small-Town, USA 12345). With that being said, does it make more sense to loop over a collection of records and call a method like so:
private void SetCityStateZip(Record myRecord)
{
myRecord.CityStateZip = string.Format("{0}, {1} {2}", myRecord.City, myRecord.State, myRecord.Zip);
}
"CityStateZip" is a property in the Record class, referencing a field "_cityStateZip".
Or does it make more sense, instead of creating a whole new field/property, to use a property with a getter that contains the logic as follows:
public string CityStateZip
{
get
{
return string.Format("{0}, {1} {2}", _city, _state, _zip);
}
}
I ask because to me, it makes sense to use the getter with simple logic, as opposed to a separate method. Why? Because CityStateZip is only accessed once for each record when the processing service takes place. The individual City/State/ZIP properties are not used elsewhere.
I figured, for the sake of example, if a data file has 10,000 records, and you call the "SetCityStateZip" method for each, you're setting 10,000 "CityStateZip" properties well before it's even used. There are actually TWO properties like this, so that's 20,000 fields/properties being set when they're each only referenced once in processing. Why assign extra "string" values?
Hope this makes sense. Kind of typed it in a hurry. Just wanting some feedback, as a coworker stated that he believes it's a bad idea to use logic in getters. If he is correct, so be it. But I sometimes enjoy a second/third/fourth/nth. opinion.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Personally, I'd probably go for the property, but...there is a third option which I'd probably prefer: override ToString to return the string version:
public override string ToString()
{
return string.Format("{0}, {1} {2}", _city, _state, _zip);
}
That way, controls such as DataGridView , ComboBox and so forth can also use it.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Which object overrides the ToString() method? I understand the purpose, but the Record class holds far more than just the fields I listed.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
In that case, just stick with the property - it should be more performant since it won't be creating unnecessary strings, and the string will be up-to-date with any changes to the underlying data.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
IMHO, the 2nd option makes much more sense - a get only property that returns the composite information. If the individual components (city , state and zip ) are not read by consumers of Record , they should only be private fields and not exposed as properties.
/ravi
|
|
|
|
|
Are they any proven advantages, so to speak, in using that over the first option? I mean, in terms of maintainability, readability, etc.?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Yes, in terms of program verification and maintenance. The first method imposes a requirement that SetCityStateZip() be invoked prior to using the composite value. The latter imposes no such requirement, and further guarantees that the composite will always be correct if its constituent parts are correct.
Going further, I suggest Record have a constructor that consumes a CSV string (or better yet a bag of properties), instead of requiring one or more Set... methods or private property setters to be invoked. This dependency injection ensures a Record instance can never exist in an invalid state (i.e. constructed but not having all its properties set) before it's used. This also allows a Record to be easily unit tested by mocking a set of parsed property values.
/ravi
|
|
|
|
|
i need the marching cubes algorithmes in c#
thanks
|
|
|
|
|
If you want the algorithm, then google would have found it for you very quickly: it took me around 3 seconds: http://en.wikipedia.org/wiki/Marching_cubes[^]
So in future, please try to do at least basic research yourself, and not waste your time or ours.
If you want us to code it for you, that's different.
Please pick one of the two following options:
1) We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
Or
2) It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to VWorker.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
Your choice!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Hi. I'm trying to make a project. it's suppose to capture the firdt frame and save it as background. then compare it with current frame using background substraction, then detect human using HOG. if human detected, the the frame will recorded.
but when I run the program, it only display current frame in GUI. the background also didn't saved, so the rest process cannot proceed.
here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Drawing.Imaging;
using Emgu.CV;
using Emgu.CV.UI;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
namespace TugasAkhir
{
public partial class Form1 : Form
{
Image<Bgr, Byte> _background, _frame, _motion, _detect, _compare;
Image<Gray, Byte> dif, thresholded, dilasi, erosi, comparegray, comparebw;
Bitmap erosi1, comparebw2;
Capture grabber;
int _width = 320;
int _height = 240;
int white_pixel, white_pixel2;
Boolean status = false;
int countCap = 1;
public Form1()
{
InitializeComponent();
_background = new Image<Bgr, Byte>(_width, _height);
_background = _background.SmoothGaussian(9);
_frame = new Image<Bgr, Byte>(_width, _height);
_motion = new Image<Bgr, Byte>(_width, _height);
_detect = new Image<Bgr, Byte>(_width, _height);
_compare = new Image<Bgr, Byte>(_width, _height);
grabber = new Capture(1);
grabber.FlipHorizontal = true;
Application.Idle += new EventHandler(InisialisasiCamera);
}
void InisialisasiCamera(object sender, EventArgs e)
{
_frame = grabber.QueryFrame().PyrUp().Resize(_width, _height, INTER.CV_INTER_AREA);
captured.Image = _frame;
}
void PreProcessing(object sender, EventArgs e)
{
dif = new Image<Gray, Byte>(_width, _height);
Image<Gray, Byte> _framegray = _frame.Convert<Gray, Byte>();
Image<Gray, Byte> _test = new Image<Gray, Byte>("test.jpg");
CvInvoke.cvAbsDiff(_test, _framegray, dif);
thresholded = new Image<Gray, byte>(_width, _height);
thresholded = dif.ThresholdBinary(new Gray(20), new Gray(255));
dilasi = new Image<Gray, byte>(_width, _height);
CvInvoke.cvDilate(thresholded, dilasi, IntPtr.Zero, 2);
erosi = new Image<Gray, byte>(_width, _height);
CvInvoke.cvErode(dilasi, erosi, IntPtr.Zero, 2);
diff.Image = erosi;
erosi1 = erosi.ToBitmap();
white_pixel = countPixels(erosi1, Color.FromArgb(255, 255, 255));
textBox1.Text = white_pixel + " white pixel ";
int treshmotion = white_pixel;
treshmotion = 20000;
if (white_pixel > treshmotion && status == false)
{
_motion = grabber.QueryFrame().PyrUp().Resize(_width, _height, INTER.CV_INTER_AREA);
motion.Image = _motion;
_detect = _motion.Copy();
Rectangle[] region;
using (HOGDescriptor des = new HOGDescriptor())
{
des.SetSVMDetector(HOGDescriptor.GetDefaultPeopleDetector());
region = des.DetectMultiScale(_motion);
}
foreach (Rectangle people in region)
{
_detect.Draw(people, new Bgr(Color.Red), 3);
}
CvInvoke.cvAbsDiff(_detect, _motion, _compare);
comparegray = new Image<Gray, byte>(_width, _height);
comparegray = _compare.Convert<Gray, Byte>();
comparebw = new Image<Gray, byte>(_width, _height);
comparebw = comparegray.ThresholdBinary(new Gray(20), new Gray(255));
comparebw2 = comparebw.ToBitmap();
white_pixel2 = countPixels(comparebw2, Color.FromArgb(255, 255, 255));
if (white_pixel2 > 0)
{
_motion.Save(@"C:\xampp\mysql\captured\capture" + countCap.ToString() + ".jpg");
detect.Image = _detect;
}
status = true;
countCap++;
}
if (white_pixel <= treshmotion && status == true)
{
status = false;
}
}
private int countPixels(Bitmap erosi1, Color white_color)
{
int matches = 0;
for (int y = 0; y < erosi.Height; y++)
{
for (int x = 0; x < erosi.Width; x++)
{
if (erosi1.GetPixel(x, y) == white_color)
{
matches++;
}
}
}
return matches;
}
private void buttoncapture_Click(object sender, EventArgs e)
{
_background = grabber.QueryFrame().PyrUp().Resize(_width, _height, INTER.CV_INTER_AREA);
_background.Save(@"C:\Users\Lily\Documents\Visual Studio 2010\Projects\TugasAkhir\TugasAkhir\bin\Debug\test.jpg");
background.Image = _background;
}
private void buttondiff_Click(object sender, EventArgs e)
{
Application.Idle += PreProcessing;
}
private void buttonbg_Click(object sender, EventArgs e)
{
background.Image = _background;
}
}
}
I'm using visual studio express 2010, emgu 2.2.2, on windows 8 32 bit.
I hope you can help me immediately. I really appreciate every response..
Thank you..
|
|
|
|
|
Hye..can anyone know how I can I display graph from selected dropdownlist and radiobutton. My code like below:
<table>
<tr>
<td><h4><span>Choose House:</span></h4></td>
<td class="style4">
<asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="114px">
</asp:DropDownList>
</td>
<td class="style5"></td>
<td class="style6"></td>
</tr>
<tr>
<td><h4><span>View:</span></h4></td>
<td class="style4">
<asp:RadioButton ID="LineRadioButton" runat="server" Text="Line Graph" />
</td>
<td class="style4">
<asp:RadioButton ID="PieButton" runat="server" Text="Pie Chart" />
</td>
<td class="style4">
<asp:RadioButton ID="BarRadioButton" runat="server" Text="Bar Graph" />
</td>
</tr>
</table>
<asp:Chart ID="Chart1" runat="server" Height="394px" Width="937px"
BackColor="PaleTurquoise">
<Titles>
<asp:Title ShadowOffset="3" Name="Muhsroom House Environment" />
</Titles>
<Legends>
<asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="TempIn" LegendStyle="Row" />
<asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="TempOut" LegendStyle="Row" />
<asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Humidity" LegendStyle="Row" />
</Legends>
<Series>
<asp:Series legendtext="Temperature In" ChartType="Line" Name="TempIn"> </asp:Series>
<asp:Series legendtext="Temperature Out" ChartType="Line" Name="TempOut"> </asp:Series>
<asp:Series legendtext="Humidity" ChartType="Line" Name="Humidity"> </asp:Series>
</Series>
<borderskin backcolor="Olive" bordercolor="Olive" skinstyle="Emboss" />
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisY Title="Degrees" ></AxisY>
<AxisX Title="Time"></AxisX>
<Area3DStyle IsClustered="True"></Area3DStyle>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<br />
<table>
<tr>
<td>
TempIn: <asp:TextBox ID="TempInTextBox" runat="server" Width="20px"></asp:TextBox>
</td>
<td>
TempOut:<asp:TextBox ID="TempOutTextBox" runat="server" Width="20px"></asp:TextBox>
</td>
<td>
Humidity:<asp:TextBox ID="HumidTextBox" runat="server" Width="20px"></asp:TextBox>
</td>
</tr>
</table>
Coding aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
namespace PSM_Mushroom
{
public partial class Graph : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=MushroomHouse;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string CS = ConfigurationManager.ConnectionStrings["MushroomHouse"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("SELECT id, Name FROM TMushroomHouse", con);
con.Open();
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
}
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
String strConnString = ConfigurationManager.ConnectionStrings["MushroomHouse"].ConnectionString;
string sql = "SELECT Environmnets.TempIn, Environmnets.tempOut, Environmnets.humidity, FROM Environmnets INNER JOIN TDevice ON Environmnets.Deviceid = TDevice.id INNER JOIN TMushroomHouse ON TDevice.MushroomHouseId = TMushroomHouse.id WHERE TMushroomHouse.id=@id";
using (SqlConnection con = new SqlConnection(strConnString))
using (SqlCommand cmd = new SqlCommand(sql, con))
//SqlDataReader dr = cmd.ExecuteReader();
{
cmd.Parameters.AddWithValue("@id", DropDownList1.Text);
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
TempInTextBox.Text = dr.GetValue(0).ToString();
TempOutTextBox.Text = dr.GetValue(1).ToString();
HumidTextBox.Text = dr.GetValue(2).ToString();
Chart1.Series["TempIn"].Points.AddXY(DateTime.Now.ToShortTimeString(),Double.Parse(TempInTextBox.Text));
Chart1.Series["TempOut"].Points.AddXY(DateTime.Now.ToShortTimeString(),Double.Parse(TempOutTextBox.Text));
Chart1.Series["Humidity"].Points.AddXY(DateTime.Now.ToShortTimeString(),Double.Parse(HumidTextBox.Text));
}
}
}
}
}
|
|
|
|
|
I am using this code
<% if(storeid==1) { %>
<% } %>
<% else if(storeid==2) { %>
<% } %>
<% else if(storeid==3) { %>
<% } %>
<% else if(storeid==4) { %>
<% } %>
Getting this error
CS1525: Invalid expression term '<'
Any ideas where it is going wrong?
|
|
|
|
|
What does this have to do with C#?
|
|
|
|
|
I'm not sure, but I think the second word is "All"...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
, took me a moment.
|
|
|
|
|
helloo guys.
i make a button in expression blend 3 , how can make button to dll file?
|
|
|
|
|
Your question is not clear; please edit and add some more detail about your problem.
|
|
|
|
|
I think he is asking how to put his new button class into a DLL for reuse and distribution.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I want to show user detailed information something like user account .username that can be get by session...but I want show in a page like that
Firstname:"the account holder firstname" dob:"date of birth"
like that .not only the username
krishnendu nandi
|
|
|
|
|
Please stop reposting questions. People here are volunteers and will help you when they can get to it.
|
|
|
|
|
Get the username/userid from session in pageload
Pass the username or userid to the Database and retrieve the values.
Assign it to appropriate controls
You have to learn to think like a computer or teach him to think like a human.
-Kornfeld Eliyahu Peter
|
|
|
|
|
|