|
Hi
I have a loop that scan a list for missing dates in the first column, and then add those dates to complete the list. But in the second column I have values (close values for stocks), and I would like this code to add yesterdays value, typically Fridays value to Saturday and then Saturdays value to Sunday....
Does anyone know how to do this?
Here's the loop section in my code:
var DTsNotInTable = dts.Except(dt.Rows.Cast<DataRow>().Select(row1 => (DateTime)row1["date"]));
foreach (DateTime dateTime in DTsNotInTable)
dt.Rows.Add(dateTime, close[0]);
var ordered = dt.Rows.Cast<DataRow>().OrderBy(row1 => (DateTime)row1["date"]);
Kind regards
Espen
|
|
|
|
|
lordoftrades wrote: Does anyone know how to do this? I'd loop through the list in the database by selecting all id's. Keep the last "read" value, and if the current version is empty, insert that.
I'd recommend against using a DataTable and LINQ. You'd be changing the values in the in-memory datatable, and would still have to execute the SQL-queries to sync the data on disc.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks Eddy, I do not have much experience in programming in C#, so I'm on thin ice here. But I do not have any SQL related to this. The case is that I'm importing a file from Yahoo Finance, it's a stock, where I have set start-date and end-date.
My problem is that I also need to fill in all the missing days, like holidays and weekends etc. And I need to "copy" the last recorded value to the missing days that follows.
As for now I've just added "0" to those, because I should be able to create a formula later on that will detect this, but it would be much more clean if I could add quotes instead of just a zero.
This is my code (I guess it's pretty messy...):
public override void OnShutdown()
{
string[] row = new string[7];
double Close;
string currentLine;
var dates_in_IQB = new List<DateTime>();
int i = 0;
DateTime endDate =new DateTime(DateTimeEnd());
DateTime startDate = new DateTime (DateTimeStart());
for (var x = startDate; x <= endDate; x = x.AddDays(1)){
i = i + 1;
dates_in_IQB.Add(x);
double equity = AccountHistoryEquity(0, i);
OutputWriteLine(String.Format("Date {0}, Equity {1}",x ,equity));
if(Directory.Exists(_filePath)){
string lines = String.Format("{0}, {1}", x, equity);
file.WriteLine(lines, i);
file.Close();
}
}
}
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("date", typeof(DateTime)));
dt.Columns.Add(new DataColumn("close", typeof(double)));
string theURL = @"http://ichart.finance.yahoo.com/table.csv?s=msft"
+ @"&a=" + (startDate.Month - 1).ToString()
+ @"&b=" + startDate.Day.ToString()
+ @"&c=" + startDate.Year.ToString()
+ @"&d=" + (endDate.Month - 1).ToString()
+ @"&e=" + endDate.Day.ToString()
+ @"&f=" + endDate.Year.ToString()
+ @"&g=d&ignore=.csv";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(theURL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
string data = sb.ToString();
String[] data2 = data.Split('\n');
int iteration = 0;
double[] open;
double[] high;
double[] low;
double[] close;
double[] volume;
double[] adjClose;
DateTime[] dates = new DateTime[data2.Length - 2];
open = new double[data2.Length - 2];
high = new double[data2.Length - 2];
low = new double[data2.Length - 2];
close = new double[data2.Length - 2];
volume = new double[data2.Length - 2];
adjClose = new double[data2.Length - 2];
foreach (string strLine in data2)
{
String[] entries = strLine.Split(',');
if ((iteration != 0) && (entries[0] != ""))
{
dates[iteration - 1] = System.Convert.ToDateTime(entries[0]);
open[iteration - 1] = System.Convert.ToDouble(entries[1]);
high[iteration - 1] = System.Convert.ToDouble(entries[2]);
low[iteration - 1] = System.Convert.ToDouble(entries[3]);
close[iteration - 1] = System.Convert.ToDouble(entries[4]);
volume[iteration - 1] = System.Convert.ToDouble(entries[5]);
adjClose[iteration - 1] = System.Convert.ToDouble(entries[6]);
dt.Rows.Add(new object[] {dates[iteration - 1], close[iteration - 1]});
}
iteration = iteration + 1;
}
DateTime minDT = dt.Rows.Cast<DataRow>().Min(row1 => (DateTime)row1["date"]);
DateTime maxDT = dt.Rows.Cast<DataRow>().Max(row1 => (DateTime)row1["date"]);
List<DateTime> dts = new List<DateTime>();
DateTime DT = minDT;
while (DT <= maxDT)
{
dts.Add(DT);
DT = DT.AddDays(1);
}
var DTsNotInTable = dts.Except(dt.Rows.Cast<DataRow>().Select(row1 => (DateTime)row1["date"]));
foreach (DateTime dateTime in DTsNotInTable)
dt.Rows.Add(dateTime, 0);
var ordered = dt.Rows.Cast<DataRow>().OrderBy(row1 => (DateTime)row1["date"]);
DataTable dt2 = ordered.CopyToDataTable();
foreach (DataRow row1 in dt2.Rows)
{
OutputWriteLine(String.Join(",", row1.ItemArray));
string lines = (String.Join(",", row1.ItemArray));
System.IO.StreamWriter file = new System.IO.StreamWriter(_filePath +"\\ref1.txt", true);{
file.WriteLine(lines);
file.Close();
}
}
}
Kind regards
Espen
|
|
|
|
|
lordoftrades wrote: This is my code (I guess it's pretty messy...): It looks more complicated than it needs to be; partly because it's a single method. Divide it in two separate steps;
public override void OnShutdown()
{
FetchCsvFile();
ProcessFile();
}
void FetchCsvFile()
{
}
void ProcessFile()
{
}
Once you have the CSV as a textfile, it be easy to ReadAllLines[^], without the need to split it at each line-ending. You could loop the result directly.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks Eddy, I'll try to implement this code in the weekend.
Kind regards
Espen
|
|
|
|
|
I do know that there is a way to get the LPARAM value of the usb device when the WndProc detects the usb device change (arrival or removal). The question is... is there a way to get the LPARAM value of the device when you turn on the software (with the usb device already plugged in and powered up)?
|
|
|
|
|
LPARAM is a C/C++ type defined & used by Windows for passing values with messages, it has nothing to do with USB devices. Also, does you question relate in any way to C#?
Use the best guess
|
|
|
|
|
yes. I'm overriding WndProc method to catch unplugging & plugging of the usb device. However is that the LParam is acquired in this WndProc process. When the software launches, the LParam for each device isn't acquired.
Also I was thinking of the other way around to get that is by restarting the usb devices at startup to trigger "unplugging" and acquire LParam. Unsure of the way to do this either.
|
|
|
|
|
Another guessing game! I have no idea what message you are trying to process, nor what values you should be receiving when the device changes status. And as I said before, devices have no concept of LPARAM .
Use the best guess
|
|
|
|
|
I assume your software is watching for WM_DEVICECHANGE messages where WParam is either DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. LParam will then point to a device dependent structure, related to DEV_BROADCAST_HDR, containing device information.
Windows Management Instrumentation can probably provide similar information for connected devices but without knowing their type and the information you need it's impossible say more.
Alan.
|
|
|
|
|
Hi My Friends
I have a question.
How to use the sqllocaldb in visual studio 2010 &2012؟
Which is easier????
thank you...
|
|
|
|
|
Define what you mean by "use"...
Read these[^]...
|
|
|
|
|
public string HTMLToPdf(_TableProperty ReportProperty, string FilePath,Stream stream)
{
string htmlread2 = getReportHTML(ReportProperty, stream);
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\myPDF.pdf", FileMode.Create));
document.Open();
iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(System.Web.HttpContext.Current.Server.MapPath("pdfic.jpg"));
pdfImage.ScaleToFit(100, 50);
pdfImage.Alignment = iTextSharp.text.Image.UNDERLYING; pdfImage.SetAbsolutePosition(180, 760);
document.Add(pdfImage);
iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
iTextSharp.text.html.simpleparser.XHTMLWorker hw = new iTextSharp.text.html.simpleparser.XHTMLWorker(document);
hw.Parse(new StringReader(htmlread2));
document.Close();
ShowPdf("myPDF.pdf");
return htmlread2;
}
private void ShowPdf(string s)
{
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.ClearHeaders();
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + s);
System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
System.Web.HttpContext.Current.Response.WriteFile(s);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Clear();
}
|
|
|
|
|
I reckon it's the parameter to the method ShowPdf(String filename) that propably needs the full path. Otherwise the Request.WriteFile method won't be able to locate the file. Construct the full file path analogous to the stuff you did for the FileStream:
String fullFileName = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\myPDF.pdf";
then use fullFileName for both the FileStream creation and the call to ShowPdf .
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
The pdf s to be formed of htmlread which is the table generated from the database. How wii that be done???
|
|
|
|
|
how can we select all the items of a listview by a checkbox inside a listview only.i dont want to use a seperate button for it.can anybody suggest me something
|
|
|
|
|
Member 9961312 wrote: how can we select all the items of a listview by a checkbox inside a listview only Loop trough the items, set their "Checked[^]" property?
Member 9961312 wrote: i dont want to use a seperate button for it.can anybody suggest me something "When" do "all the items" need to be checked? If it's an action that's initiated by the user, then he/she will need some UI element to interact with. In other words, if not on a button-click, when?
How about when the form loads? That'd select them all, even before the list is shown.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
set MultiSelect property true and checked list item in loop.
|
|
|
|
|
If I'm interpreting your question right you want the user to be able to select all of the items in the ListView, but you don't want to give them a button to do it? If so, why not set up a context menu with a Select All option? Then, as others have suggested, step through all the items in the LV and set Checked = true; for each item.
|
|
|
|
|
How to use Grid in mVC3?
|
|
|
|
|
I'd start off by researching some of the results listed here[^].
|
|
|
|
|
Hello
I have to separate lists containing two columns: Dates - Values
One of the lists have all dates from startdate to enddate, while the other list is missing weekends and holidays. So this missing holes I need to replace by the value from day before and then add these values to a new list with all dates in one column, and then values-list1 and values-list2 in two next columns...
public override void OnShutdown()
{
string[] row = new string[7];
double Close;
string currentLine;
long dates_in_IQB;
for (int i=0;i<AccountHistoryCount(0);i++){
dates_in_IQB = (long)AccountHistoryDateTime(0, i);
DateTime newDate = new DateTime(dates_in_IQB);
OutputWriteLine(String.Format("Date {0}", newDate));
}
using (StreamReader sr = new StreamReader("d:/documents/SPY Ref1.csv")){
sr.ReadLine();
while((currentLine = sr.ReadLine()) != null)
{
row = currentLine.Split(',');
DateTime Date = DateTime.ParseExact(row[0], "dd.MM.yyyy", null);
Close = double.Parse(row[6]);
}
}
}
I'm pretty new to the programming, so I guess I need the information down to every details.
Kind regards
Espen
|
|
|
|
|
hi i need help about c#. i need to have a c# program code(md5 hash) simple program only. the program must have an actual and expected output embedded in the program. i just need it my Software Testing Subject. tnx for who will reply.
-IT Student
Na'Vi.Dendimon
|
|
|
|
|
You're out of your mind if you think we're going to do your homework for you.
|
|
|
|
|
if you have nothing to help. GET LOST! i dont need your comment
|
|
|
|