|
It really depends what I want to do with the list. I'll leave it as an enumerable until the point I want to do more than one thing with it. Suppose I wanted to check to see if the list had something in it before I started processing in it - the fact that I'm going to be calling Any and foreach (for example), suggests to me that I should materialise the enumerable and then act on it. If I don't, I'm just going to end up materialising it twice under the covers.
|
|
|
|
|
Hi,
I'm looking for a solution to make a circular slider control like volume control with the value inside.
I'm working on a winform.
If someone have a tips on an idea to start.
Thanks for your help
|
|
|
|
|
This is not exactly what you have asked for - nut perhaps an inspiration for doing :
Search[^]
|
|
|
|
|
write the C# windows form based program that allow user conversion of number system
|
|
|
|
|
And if I refuse?
After all, this is your assignment, not ours.
Now, if you have questions about the assignment, things you're having problems with, fine, ask your questions and describe your problems.
|
|
|
|
|
1. Learn basics of C#
2. Learn basics of converting between number systems (this is NOT a coding process)
3. Learn how to code 2 in C#.
4. Learn how to do a UI in C#
4. Put 1 to 4 together to create the solution.
|
|
|
|
|
|
Sounds more like an "architecture" thing than a coding thing.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
nice quote (and I'm french) ... even if I'm not a fan of Napoleon.
We coded then for me it is a code but true it's also about architecture, or to be more accurate it is how we code an architecture.
|
|
|
|
|
How to make an easy messenger with C#?
|
|
|
|
|
You start with a set of GOOD requirements and specifications.
Seriously, your question isn't answerable. You, and by extension we, know nothing of what you want this app to do, what devices you want to support, the type of interface, message delivery options, message caching, storage requirements, nothing at all!
We know nothing about you either and your skill set. The fact that you're even asking this question and how you asked it suggests your skills are quite limited, so that's going to be a rather large problem.
|
|
|
|
|
Console.Write( "Hello, world!" );
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
namespace ATAS.Indicators.Technical
{
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Windows.Media;
using ATAS.Indicators.Technical.Properties;
using OFT.Attributes;
[DisplayName("5.Heiken Ashi Z")]
[Category("# 1234")]
public class HeikenAshiz : Indicator
{
private readonly CandleDataSeries _candles = new CandleDataSeries("Heiken Ashi Z"){ Visible = true };
private readonly PaintbarsDataSeries _bars= new PaintbarsDataSeries("Bars Z"){ Visible = false };
public HeikenAshiz()
{
Panel = IndicatorDataProvider.NewPanel;
DataSeries[0]= _bars;
DataSeries.Add(_candles);
}
protected override void OnCalculate(int bar, decimal value)
{
var candle = GetCandle(bar);
_bars[bar] = Colors.Transparent;
if (bar == 0)
{
_candles[bar] = new Candle()
{
Close = candle.Close,
High = candle.High,
Low = candle.Low,
Open = candle.Open
};
}
else
{
var prevCandle = _candles[bar - 1];
_candles[bar] = new Candle()
{
Close = (candle.Open+candle.Close+candle.High+candle.Low)*0.25m,
High = candle.High,
Low = candle.Low,
Open = (prevCandle.Open+ prevCandle.Close)*0.5m,
};
}
}
protected override void OnApplyDefaultColors()
{
if (ChartInfo is null)
return;
_candles.UpCandleColor = Color.FromRgb(14, 203, 129);
_candles.DownCandleColor = Color.FromRgb(246, 70, 93);
_candles.BorderColor = Color.FromRgb(127, 127, 127);
}
}
}
modified 7-Dec-23 2:55am.
|
|
|
|
|
I'll bite. The "border" of what? And if you say window ...
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I have the below function which is called with a button click. It is supposed to chart from a database. The problem is that when selecting from database I am filtering the database using "WHERE". When I don't use this "WHERE" and plot the whole database table, the code works fine, but when I use this filter, it often leads to blank charts even though the data is there in the table. What is wrong with this code?
void PlotChart()
{
try
{
chart1.Series.Clear();
Series First = new Series("Series11");
Series Second = new Series("Series12");
First.ChartType = SeriesChartType.Spline;
Second.ChartType = SeriesChartType.Spline;
First.Color = Color.Blue;
Second.Color = Color.Orange;
using (SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"))
{
if(connection.State == ConnectionState.Closed)
{
connection.Open();
}
string query = $"SELECT * FROM Data WHERE RawDataOrder = {Convert.ToInt32(label86.Text.Trim())}";
using (SqlCommand command = new SqlCommand(query, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
int id = reader.GetInt32(0);
int value11 = reader.GetInt32(1);
int value12 = reader.GetInt32(8);
First.Points.AddXY(id, value11);
Second.Points.AddXY(id, value12);
}
}
}
}
chart1.Series.Add(First);
chart1.Series.Add(Second);
chart1.Titles.Clear();
chart1.Titles.Add(new Title("Channel 1"));
chart1.Update();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error PlotChart", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
without having your data it's difficult to say something because you've written "sometimes ... and sometimes not"
Have you ever checked with the Debugger wat kind of Data you get with yor Request which fails ? This would be my 1st approach to find out what happens ...
|
|
|
|
|
Ralf Meier wrote: Have you ever checked with the Debugger wat kind of Data you get with yor Request which fails ? This would be my 1st approach to find out what happens ...
How do I do this? If I run the debugger, how would it show the problem point? Where do I have to look? I am sort of new to this thing.
|
|
|
|
|
you could set Breakpoints inside your Code which stops the Code at this point. Now you can see which values your different Variables have (by hovering with the Mouse over them).
|
|
|
|
|
I tried setting breakpoints, but then got an error which said something to the effect "break point won't break because some symbol isn't there". I couldn't do away with that error so I put some checks in the code itself, to make sure that the label86 was a proper integer, that there was actually data to be plotted etc, and I ran the new code. It never went to the coded error messages and still the charts were plotted blank. Is it possible the fault is somewhere in the chart settings? maybe the series become transparent or something? But why would this happen only when we use "Where" and try to plot a part of the table data?
void PlotChart()
{
try
{
if (!int.TryParse(label86.Text.Trim(), out int rawDataOrder))
{
MessageBox.Show("Invalid RawDataOrder value. Please enter a valid integer.", "Error PlotChart", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
using (SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"))
{
using (SqlCommand command = new SqlCommand("SELECT * FROM SerialDataNIBP WHERE RawDataOrder = @RawDataOrder", connection))
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
command.Parameters.AddWithValue("@RawDataOrder", rawDataOrder);
using (SqlDataReader reader = command.ExecuteReader())
{
if (!reader.HasRows)
{
MessageBox.Show("No data found for the given RawDataOrder.", "Error PlotChart", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
chart1.Series.Clear();
Series PulseCh1 = new Series("Series11");
Series PressureCh1 = new Series("Series12");
PulseCh1.ChartType = SeriesChartType.Spline;
PressureCh1.ChartType = SeriesChartType.Spline;
PulseCh1.Color = Color.Blue;
PressureCh1.Color = Color.Orange;
while (reader.Read())
{
var id = reader.GetInt32(0);
var value11 = reader.GetInt32(1);
var value12 = reader.GetInt32(8);
PulseCh1.Points.AddXY(id, value11);
PressureCh1.Points.AddXY(id, value12);
}
chart1.Series.Add(PulseCh1);
chart1.Series.Add(PressureCh1);
chart1.Titles.Clear();
chart1.Titles.Add(new Title("Channel 1"));
chart1.Update();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error PlotChart", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
You can only set a Breakpoint to a code-line.
I would in every case look with the Debugger - it's much better than a guesswork - but it's your decission.
I don't believe that the fault is inside the Chart-Settings - but perhaps inside the data you read from the table. Perhaps you don't get any data from it because your request isn't correct ...
|
|
|
|
|
Iskander12345 wrote:
string query = $"SELECT * FROM Data WHERE RawDataOrder = {Convert.ToInt32(label86.Text.Trim())}"; Whilst in this specific instance you're probably safe, this sample suggests you're writing code which would be vulnerable to SQL Injection[^].
And even in this case, your code will result in query plan cache pollution - every value for the parameter will result in a different plan being compiled and stored.
Rather than trying to work out whether your values are "safe" to inject into the query, adopt a simple strategy: always use parameters.
const string query = "SELECT * FROM Data WHERE RawDataOrder = @RawDataOrder";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@RawDataOrder", Convert.ToInt32(label86.Text.Trim()));
...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
string query = $"SELECT * FROM Data WHERE RawDataOrder = {Convert.ToInt32(label86.Text.Trim())}";
You are trying to convert a string to an integer, just so it can be immediately converted back into a string. So remove the Convert.ToInt32 part. It is also not a good ide to use Convert as it will fail (maybe silently) if the text is not a pure number. Better to use Int32.TryParse .
|
|
|
|
|
tried both the suggestions above, it didn't work.
|
|
|
|
|
I did not say they would necessarily work, but they are things you need to consider when writing code. As to why your chart does not get created, there is only one way to make progress: debugging. You need to use the debugger to step through the code so you can see exactly what values are in all your variables as the code proceeds. Repeatedly trying random changes without understanding what is actually happening is just a waste of your time.
|
|
|
|
|
The way you've written your SQL code, specifically the parameter you put in the query string, makes it impossible to debug. It's not the existence of the WHERE clause that's the problem. It's that your WHERE clause condition doesn't match any records.
To be able to debug this, you have to rewrite the code so you can see what's going on with the debugger:
string query = "SELECT * FROM Data WHERE RawDataOrder = @orderId";
int orderId;
if (int.TryParse(label86.Text.Trim(), out orderId))
{
using (SqlConnection conn = new SqlConnection("... connection string ..."))
{
using (SqlCommand comm = new SqlCommand(query, conn))
{
SqlParameter orderIdParam = new SqlParameter("@orderId", SqlDbType.Int);
orderIdParam.Value = orderId;
comm.Parameters.Add(orderIdParam);
conn.Open();
using (SqlDataReader reader = comm.ExecuteReader())
{
while (reader.Read())
{
...
}
}
}
}
}
else
{
}
|
|
|
|