|
How are you copying?
How are you pasting?
Show the relevant code fragments!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have not added any code specific for copy paste.
I have just changed the property of DateTimePicker
is.dateTimePicker.CustomFormat = "dd/MM/yy HH:mm:ss";
is.dateTimePicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
is.dateTimePickerExecTime.ShowUpDown = true;
Once right click on Control I select on Copy it copies and I copy it in excel .
From excel I again copy and trying to paste it on control.
|
|
|
|
|
Well what did you expect to happen?
You copy a date in a non-standard form, paste it into a spreadsheet (which identifies it as a date and converts it to a DateTime object), then you copy that datetime object from Excel (in standard-for-that-PC format), and paste it back onto a control that doesn't expect standard format.
There isn't a whole lot that we can do to prevent that causing a problem!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yes.
Copy in DD/MM/YY format and paste the same in spreadsheet.
Edit the DateTime in spreadsheet.
Copy from spreadsheet and paste back to the DateTime control.
But DateTime control allows MM/DD/YY format.
That's the issue 
|
|
|
|
|
And I'm confused about what you think we can do about a user input problem like that!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Your idea of "paste" may not correspond to the reality of the situation.
Sometimes you can use "windows paste commands"; at other times, you need to interect with the "clip board", reformat, copy (not "paste") to a property of the TextBox; etc. i.e. "programming".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks for all your responses
Is there a way where I can change the .MaxValue Property?
Presently it displays in MM/DD/YYYY(12/31/9999 11:59 PM).
Can I set it to DD/MM/YYYY(31/12/1999).
|
|
|
|
|
Do we have any event for Paste where I can trigger and reformat the Date and paste it in the control ?
|
|
|
|
|
You didn't specify WPF, Windows Forms or ASP.NET or ...
If you're going to use a "date picker", you need to "learn it" before "looking around" for "other" solutions.
This may help; also note the reference to "system settings".
c# - Getting date from DatePicker in format yyyy/MM/dd - Stack Overflow
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you for your suggestions.
I have achieved it using ParseExact function with some formatting the DateTime value.
Thanks
Sharan
|
|
|
|
|
Hi
if you are into privacy, freedom of speech and like things like Tor or whatsApp then read on because I want to build a network unlike one ever built before that is sort of a mix between Bitcoin, Tor, WhatsApp that is decentralized and uses Sept256k security (Pinched from Bitcoin) to send messages or requests for services around the world.
The services provided by other nodes on this new network could be anything from file storage to proxy servers or even highly encrypted messages delivered to email type services so the network itself become plugable using internal packages that look something a bit like socket addresses but instead of the IP-Address we use the public key of host service followed by the well known name of the service.
abcdef1234567-32-bit-key-abcdef:DNS
abcdef1234567-32-bit-key-abcdef:Proxy
abcdef1234567-32-bit-key-abcdef:Mail
This project will be open source and might even include a type of "Gas" at a future date with the apps talking to to the main network entry nodes using sockets with encrypted data (Will need ASE key) or decrypted data can then be pumped down the network pipe depending on how the entry node (Windows .EXE) has been configured.
Please PM me if you are interested or have any thoughts on the subject.
|
|
|
|
|
Wrong forum - try here: Collaboration / Beta Testing Discussion Boards[^]
But ... unless you spell out what part you will play in this, and what you expect a collaborator to add then don;t expect much in the way of responses.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well i would say I am the best guy for writing the network component but would be happy to be proven wrong so its hard to disuse formal rolls or requirements at this point in time because I am very open to suggestion and kind of like equal partners myself.
Hidden away from the main forum might be the reason I don't get much of a response I suspect if anything but thank you for your comments !
|
|
|
|
|
stopthespying wrote: Please PM me if you are interested or have any thoughts on the subject. Be mega big bucks involved?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I like your style so I will hand my thoughts over to you and let you pay me instead not that I really care much for money having lived a full life already
Signed
The string butcher.
|
|
|
|
|
Not likely.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have installed C# 2008 express and use a local database to create tables and show the contents in a DataGridView which show a table I have created. My problem is I have two table that are joined and I would like to show a view in the DataGridView is this possible.
|
|
|
|
|
Yes, assuming you have two tables which share a common value.
For example, an Invoice would be two tables:
Invoices
ID INT, IDENTITY
Issued DATE
Company NVARCHAR(256)
InvoiceLines
ID INT, IDENTITY
InvoiceID INT, FOREIGN KEY to Invoices.ID
Product NVARCHAR(256)
Value MONEY Then you might retrieve data like this:
SELECT i.ID, i.Date, i.Company, il.Product, il.Value
FROM Invoices i
JOIN InvoiceLines il ON il.InvoiceID = i. ID And you would get the appropriate rows in the DGV
Or
SELECT i.ID, i.Date, i.Company, il.Total
FROM Invoices i
JOIN (SELECT InvoiceID, SUM(Value) AS Total
FROM InvoiceLines
GROUP BY InvoiceID) il
ON il.InvoiceID = i. ID And you would get invoice detail and total value
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I think you can do this using table joints in a dataset and then binding that and not the table to the grid but it's been a long time since I did this.
Top credit for using an old version of visual studio and I try to stick with using VS2010 because it runs much faster and cleaner than 2017 that I only use when forced too.
|
|
|
|
|
Really struggling with these fairly simple thing.
I have some sensor values randomly generated from a class I call Sensor.cs. I use GeAnaloValues() method to get these values and display them in a text box i Form1.cs in the GUI. Now I need to make moving average filter and take moving average of the for example last 5 sensor values displayed on the screen.
I just don't know how to implement these values generated from the method GetAnalogValues() in the moving average algorithm ?
I also wonder if I should make a separate class for the implementation of the MA-Filter?
This is my code:
Form1.cs class
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Globalization;
namespace DAQ_Simulator
{
public partial class Form1 : Form
{
int counter;
int count_lines;
System.Timers.Timer t;
int LoggingTime=56;
int LogTimeLeft;
float SamplingTime = 5.9f;
private int clickcounter;
private DateTime datetime;
private DateTime datetime2;
private DateTime NextLoggingTime;
int maxAI = 7;
int maxDI = 3;
int maxSid = 9;
String sTxt;
String sTxt1;
Sensor[] sObj = new Sensor[10];
MA_Filter[] fObj = new MA_Filter[10];
public Form1()
{
InitializeComponent();
for (counter = 0; counter < maxSid; counter++)
{
sObj[counter] = new Sensor(counter);
}
}
private void displaySensorData(object sender, EventArgs e)
{
}
private void groupSampl_Enter(object sender, EventArgs e)
{
}
private void textSampling_TextChanged(object sender, EventArgs e)
{
}
private void btnSampling_Click(object sender, EventArgs e)
{
clickcounter++;
if (clickcounter == 1)
{
textSensorValues.Text = "TimeStamp AI.1, AI.2, AI.3, AI.4, AI.5, AI.6, AI.7, DI.1, DI.2, DI.3" + "\r\n";
}
if (SamplingTime <= 0)
{
SamplingTime = SamplingTime + 5.9f;
}
if (SamplingTime <= 5.9f && SamplingTime >= 0)
{
btnSampling.Enabled = false;
}
timer1 = new System.Windows.Forms.Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Start();
datetime2 = DateTime.Now.AddSeconds(5).AddMilliseconds(900);
String time2 = datetime2.ToString("HH:mm:ss.FFF", CultureInfo.InvariantCulture);
textSampling.Text = time2;
sampling();
}
private void groupLogg_Enter(object sender, EventArgs e)
{
}
private void txtLogging_TextChanged(object sender, EventArgs e)
{
}
private void labelLoggingText_Click(object sender, EventArgs e)
{
}
private void btnLogging_Click(object sender, EventArgs e)
{
if (LoggingTime == 0)
{
LoggingTime = LoggingTime + 56;
}
if (LoggingTime <= 56 && LoggingTime >= 0)
{
btnLogging.Enabled = false;
}
timer2 = new System.Windows.Forms.Timer();
timer2.Tick += new EventHandler(timer2_Tick);
timer2.Interval = 1000;
timer2.Start();
txtLogging.Text = LoggingTime.ToString();
NextLoggingTime = DateTime.Now.AddSeconds(4);
String time3 = NextLoggingTime.ToString("HH:mm:ss.FFF", CultureInfo.InvariantCulture);
txtLogging.Text =time3;
Logging();
}
private void labelSensorValues_Click(object sender, EventArgs e)
{
}
private void textSensorValues_TextChanged(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
SamplingTime--;
txtNextSamplingTime.Text = SamplingTime.ToString("F2")+"sec";
if (SamplingTime <= 0)
{
timer1.Stop();
btnSampling.Enabled = true;
txtNextSamplingTime.Clear();
}
}
private void sampling()
{
datetime = DateTime.Now;
textSensorValues.Text += datetime.ToString("HH:mm:ss.FFF", CultureInfo.InvariantCulture) + " ";
for (int id = 0; id < maxAI; id++)
{
double AnalogSensorValues = sObj[id].GetAnalogValue();
sTxt = AnalogSensorValues.ToString("F3");
textSensorValues.Text += sTxt + " ";
}
for (int id = maxSid - maxDI; id < maxSid; id++)
{
int DigitalSensorValues = sObj[id].GetDigitalValue();
sTxt1 = DigitalSensorValues.ToString();
textSensorValues.Text += " " + sTxt1 + " ";
}
textSensorValues.Text += "\r\n";
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void Logging()
{
count_lines = textSampling.Lines.Length;
txtNumberWritings.Text = count_lines.ToString();
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (Stream s = File.Open(saveFileDialog1.FileName,FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(s))
{
sw.WriteLine(textSensorValues.Text);
textFilePath.Text = string.Format("{0}", openFileDialog1.FileName);
}
textFilePath.Text = saveFileDialog1.FileName.ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
{
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
}
private void timer2_Tick(object sender, EventArgs e)
{
LoggingTime--;
txtNextLogg.Text = LoggingTime.ToString()+"sec";
if (LoggingTime <= 0)
{
timer2.Stop();
btnLogging.Enabled = true;
txtNextLogg.Clear();
txtNextLogg.Text = "56 sec";
}
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
My Sensor class where I generate my random values:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAQ_Simulator
{
public class Sensor
{
double AnalogVal;
int DigVal;
int sId;
Random rSensVal;
Random digSensVal;
public Sensor(int id)
{
sId = id;
rSensVal = new Random(id);
digSensVal = new Random(id);
AnalogVal = 0.0F;
}
public double GetAnalogValue(double minAnalogVolt=0.00F,double maxAnalogVolt=1.00F)
{
if(minAnalogVolt <= AnalogVal && AnalogVal<= maxAnalogVolt)
AnalogVal = rSensVal.NextDouble();
return AnalogVal;
}
public int GetDigitalValue(int digMin = 0, int digMax = 1)
{
DigVal = digSensVal.Next(0,2);
return DigVal;
}
public int GetSensId()
{
return sId;
}
}
}
|
|
|
|
|
For starters, don't use two Random instances:
rSensVal = new Random(id);
digSensVal = new Random(id);
Because they are initialized with the same value, they will have the same sequence - use a single instance (or better a single static instance) and you will get a "more random" set of values. You might want to consider using the parameterless version of the constructor, which uses the system clock as the seed value so it gives a different sequence each time your app runs.
For a moving average, just add an array of values the same size as the group, an index, and a count. This will become a basic queue.
So for five values, you would have five elements:
private double[] samples = new double[5];
private int index = 0;
private int count = 0; Then its just a case of a simple method:
private double GetMovingAverage(double newValue)
{
if (count != samples.Length) count++;
samples[index++] = newValue;
if (index == samples.Length) index = 0;
double sum = 0.0;
for (int i = 0; i < count; i++)
{
sum += samples[i];
}
return sum / (double) (count);
}
And you are done.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff, a bit confused in terms how I should implement the code you gave me here to my program?
I am assuming that method GetMovingAverage() shall be in the main class Form1.cs, correct ?
Also I tried to put in your code snippet, but what is newValue here?? Is that my AnalogValues?
I have a series of "random" sensor values every time I click Sampling button.
I tried to do something like this
private double GetMovingAverage(double AnalogValue)
{
if (count != samples.Length) count++;
samples[index++] = AnalogValue;
if (index == samples.Length) index = 0;
double sum = 0.0;
for (int i = 0; i < count; i++)
{
sum += samples[i];
}
return sum / (double)(count);
}
I tried to print the Moving average values here,
for (int id = 0; id < maxAI; id++)
{
double AnalogSensorValues = sObj[id].GetAnalogValue();
sTxt = AnalogSensorValues.ToString("F3");
textSensorValues.Text += sTxt + " ";
txtFilterValues.Text = fTx1;
txtFilterValues.Text = GetMovingAverage(id).ToString("F3");
}
However when I printed to my Filter text box, I got rubbish
I must have misinterpreted what you meant.
My main problem is I don't know how I get those values inside the moving average.
Any comments ?
|
|
|
|
|
You should give your actual Analogue-Value to the Method from OG (as it's parameter) and you will get the Average-Value as Result back from this method.
The Variables 'Count' and 'Samples' and 'Index' must be declared outside this method ...
|
|
|
|
|
Nice, but how about ditching the loop? Just add the newValue to the sum (as a member, not local) each time, then deduct the number which it replaces in the array and you've just reduced the algorithmic complexity.
I know, I'm just in one of those picky moods today.
Regards,
Rob Philpott.
|
|
|
|