I am downloading data from yahoo stocks using the Web.DownloadString(); the site will have multiply users so I need to have the client send the download request rather than the server to avoid getting blocked from sending too many request from the servers Ip address. I can't find a way to run it on the client side and am looking for assistance making it run from client rather than server.
below is a poorly formatted function that I plan to clean up that I am using right now
I plan only do use the part required to get the data run client side and the rest run server I have just yet to clean up my code.
Public void DownloadData()
{
string csvData = null;
string month1 = Convert.ToString(DropDownList1.SelectedIndex);
string month2 = Convert.ToString(DropDownList2.SelectedIndex);
string Temp = "http://ichart.finance.yahoo.com/table.csv?s=" + SymbolName.Text + "&d=" + month2 + "&e=" + TextBox3.Text + "&f=" + TextBox4.Text + "&g=d&a=" + month1 + "&b=" + TextBox1.Text + "&c=" + TextBox2.Text + "&ignore=.csv";
string FileRead;
List<string> Remove1 = new List<string>();
string path = System.AppDomain.CurrentDomain.BaseDirectory;
using (WebClient web = new WebClient())
{
try
{
csvData = web.DownloadString(Temp);
}
catch
{
}
}
if (csvData != null && csvData != "")
{
File.WriteAllText(path + "\\MyTest.txt", csvData);
}
System.IO.StreamReader file = new System.IO.StreamReader(path + "\\MyTest.txt");
while ((FileRead = file.ReadLine()) != null) //reads from file
{
Remove1.Add(FileRead);
}
file.Close();
csvData = csvData.Replace("Date,Open,High,Low,Close,Volume,Adj Close", "");
List<stock> prices = YahooFinance.Parse(csvData);
double Lowest = 0;
foreach (stock price in prices) // finds lowest value to addjust priceing
{
if (Lowest == 0)
{
Lowest = Convert.ToDouble(price.low);
}
if (Lowest > Convert.ToDouble(price.low))
{
Lowest = Convert.ToDouble(price.low);
}
}
// new double[] { Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close) }
Chart1.ChartAreas[0].AxisX.Interval = 2;
Chart2.ChartAreas[0].AxisX.Interval = 2;
Chart1.ChartAreas[0].AxisX.Maximum = prices.Count + 20;
Chart1.ChartAreas[0].AxisY.Minimum = Lowest - 3;
foreach (stock price in prices)
{
Chart1.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.low), Convert.ToDouble(price.high), Convert.ToDouble(price.Open), Convert.ToDouble(price.close));
Chart2.Series[0].Points.AddXY(price.date, Convert.ToDouble(price.Volume));
}
}
`
Related
I have this ASP.NET project working with Oracle, I have the following code for operating the DB:
public int cmd_Execute_Orcl(string strSql, params OracleParameter[] paramArray)
{
OracleCommand myCmd = new OracleCommand();
try
{
myCmd.Connection = myOrclConn;
myCmd.CommandText = strSql;
foreach (OracleParameter temp in paramArray)
{
myCmd.Parameters.Add(temp);
}
ConnectionManage(true);
int i = myCmd.ExecuteNonQuery();
myCmd.Parameters.Clear();
return i;
}
catch (Exception ex)
{
throw (ex);
}
finally
{
myCmd.Dispose();
ConnectionManage(false);
}
}
"ConnectionManage()" turns on or off the connection, the following code is from data access layer of the program:
public string Edit_DAL(string id, string jh, string jz, string jd, string wd, string gzwz, string qxlx, string sx, string jx, string jb, string cfdd, string zjqssj, string zjzzsj, string bz)
{
string sql = "update JH set jh = :jh, jz = :jz, wd = :wd, jd = :jd, gzwz = :gzwz, qxlx = :qxlx, sx = :sx, jx = :jx, jb = :jb, cfdd = :cfdd, zjqssj = TO_DATE(:zjqssj, 'yyyy-mm-dd hh24:mi:ss'), zjzzsj = TO_DATE(:zjzzsj, 'yyyy-mm-dd hh24:mi:ss'), bz = :bz where ID = :idy";
string result = null;
{
String[] temp1 = zjqssj.Split('/');
String[] temp2 = zjzzsj.Split('/');
string tempString = "";
if (temp1[2].Length < 2)
{
temp1[2] = temp1[2].Insert(0, "0");
}
for (int i = 0; i < temp1.Length; i++)
{
if (i != 0)
{
temp1[i] = temp1[i].Insert(0, "/");
}
tempString += temp1[i].ToString();
}
zjqssj = tempString;
tempString = "";
if (temp2[2].Length < 2)
{
temp2[2] = temp2[2].Insert(0, "0");
}
for (int i = 0; i < temp2.Length; i++)
{
if (i != 0)
{
temp2[i] = temp2[i].Insert(0, "/");
}
tempString += temp2[i].ToString();
}
zjzzsj = tempString;
tempString = "";
}
OracleParameter[] pars ={
new OracleParameter(":idy",id),
new OracleParameter(":jh",jh),
new OracleParameter(":jz",jz),
new OracleParameter(":jd",jd),
new OracleParameter(":wd",wd),
new OracleParameter(":gzwz",gzwz),
new OracleParameter(":qxlx",qxlx),
new OracleParameter(":sx",sx),
new OracleParameter(":jx",jx),
new OracleParameter(":jb",jb),
new OracleParameter(":cfdd",cfdd),
new OracleParameter(":zjqssj",(zjqssj.Replace('/', '-') + " 00:00:00")),
new OracleParameter(":zjzzsj",(zjzzsj.Replace('/', '-') + " 00:00:00")),
new OracleParameter(":bz",bz)
};
try
{
SqlHelper.cmd_Execute_Orcl(sql, pars);
result = "ok";
}
catch (Exception ex)
{
result = "no" + "=" + ex.Message + "\n" + ex.StackTrace;
}
return result;
}
Here's where the strange thing happens, when I hit this part of the code, there's no exception, it returns 0, no rows affected, all the values of the parameters are normal, with expected value, then I tried to run the command in PL/SQL and it works, the row is correctly updated, delete function is also referencing the same "cmd_Execute_Orcl" method and it works just fine, and for the other object the edit function is working perfectly, I am posting the code below:
public string Edit(string OriginalId, string EditUserAccount, string EditUserName, string EditUserMobile, string EditDeptId, string EditRoleId, string EditRoleName)
{
string sql = "update AuthUser set UserAccount=:EditUserAccount, UserName=:EditUserName, UserMobile=:EditUserMobile, DepartmentId=:EditDeptId, RID=:EditRoleId, RoleName=:EditRoleName where ID=:OriginalId";
OracleParameter[] pars ={
new OracleParameter(":EditUserAccount",EditUserAccount),
new OracleParameter(":EditUserName",EditUserName),
new OracleParameter(":EditUserMobile",EditUserMobile),
new OracleParameter(":EditDeptId",EditDeptId),
new OracleParameter(":EditRoleId",EditRoleId),
new OracleParameter(":EditRoleName",EditRoleName),
new OracleParameter(":OriginalId",OriginalId),
};
try
{
SqlHelper.cmd_Execute_Orcl(sql, pars);
return "ok";
}
catch (Exception ex)
{
string test = ex.Message;
return "no";
}
}
In the expected table, column ID is nvarchar2 with default value of sys_guid(), column ZJQSSJ and column ZJZZSJ is of type date, all other columns are of type varchar2, I have also tried executing "COMMIT" and reformating data for date, but the same problem is still there, plz help...
I have no experience with script writing, but I was able to find a script and edit it (with lots of trial and error) to fit my need.
I have a Google Form where the first question allows users to select a date, but it is not necessarily the date users are completing the form. The results export to a Google Sheet, and I have a script that sends an email with the form responses.
It worked beautifully until Daylight Savings Time. Now, the dates in the spreadsheet are correct, but in the emails they are one day off.
Example email message:
Your child, NAME, received a dress code violation on Wed Mar 27 2019
23:00:00 GMT-0600 (CST), for No ID.
Before Daylight Savings Time, the time was showing as 00:00:00.
In the code, row[2] is the date pulled from the spreadsheet.
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script");
var startRow = 2;
var numRows = 5000;
var dataRange = sheet.getRange(startRow, 1, numRows, 5000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[12];
var message = "Your child, " + row[10] + ", received a dress code violation on " + row[2] + ", for " + row[11] + ".\nIf you have any questions, please email NAME at name.name#name.org\n\nThank you,\n\nNAME\nAssistant Principal";
var emailSent = row[13];
if (emailSent != EMAIL_SENT) {
var subject = "Uniform Violation - Do Not Reply";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 14).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
Ideally, the email would provide the date exactly from the spreadsheet in MM/DD/YYYY format.
Instead, the emails show the previous day with the time of 11 pm.
Try this:
var EMAIL_SENT = "EMAIL_SENT";
function sendEmails2() {
var ss=SpreadsheetApp.getActive();//added this
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Script");
var startRow = 2;
var numRows = 5000;
var dataRange = sheet.getRange(startRow, 1, numRows, 5000)
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = row[12];
var message = "Your child, " + row[10] + ", received a dress code violation on " + Utilities.formatDate(new Date(row[2]),ss.getSpreadsheetTimeZone(), "MM dd, yyyy HH:mm:ss" ) + ", for " + row[11] + ".\nIf you have any questions, please email NAME at name.name#name.org\n\nThank you,\n\nNAME\nAssistant Principal";//modified this
var emailSent = row[13];
if (emailSent != EMAIL_SENT) {
var subject = "Uniform Violation - Do Not Reply";
MailApp.sendEmail(emailAddress, subject, message);
sheet.getRange(startRow + i, 14).setValue(EMAIL_SENT);
SpreadsheetApp.flush();
}
}
}
You will probably have to change the dates format.
Date Format
I am developing an xamarin.forms app ,I have various fields like Item Name ,Item Number and location ,here Location of all the items are same ,by entering names or number of the items the values are generated automatically because name and number are unique but since the location number is common is for all the items I am not able to populate correct data related to a particular field ,I am using sqlite database in my project can anyone please suggest me on what basis can I generate related values ?
Here is the code
public async void OnSearch_Location(object o, EventArgs args)
{
if (location.Text == string.Empty || location.Text == null)
{
await Navigation.PushAsync(new ListValuePage("Location", filePath,
pos, list));
}
else
{
for (int p = 0; p < list.Count; p++)
{
if (list.ElementAt(p).Aisle + "." + list.ElementAt(p).Bin +
"." + list.ElementAt(p).Level == location.Text)
{
line.Text =
Convert.ToString(list.ElementAt(p).Line_Number);
location.Text = list.ElementAt(p).Aisle + "." +
list.ElementAt(p).Bin + "." + list.ElementAt(p).Level;
item.Text = list.ElementAt(p).Item_Number;
name.Text = list.ElementAt(p).Name;
if (list.ElementAt(p).Order_Qty == 0)
{
order_uom.Text = "";
}
else
{
order_qty.Text =
Convert.ToString(list.ElementAt(p).Order_Qty);
}
order_uom.Text = list.ElementAt(p).Order_UOM;
if (list.ElementAt(p).Consumption_UOM == string.Empty ||
list.ElementAt(p).Consumption_UOM == null)
{
consume_lbl.IsVisible = false;
consume_qty.IsVisible = false;
consume_uom.IsVisible = false;
}
else
{
consume_lbl.IsVisible = true;
consume_qty.IsVisible = true;
consume_uom.IsVisible = true;
if (list.ElementAt(p).Consumption_Qty == 0)
{
consume_qty.Text = "";
}
else
{
consume_qty.Text =
Convert.ToString(list.ElementAt(p).Consumption_Qty);
}
consume_uom.Text = list.ElementAt(p).Consumption_UOM;
}
}
}
}
}
SenditemsTableAdapter sen = new SenditemsTableAdapter();
RegistrationTableAdapter reg = new RegistrationTableAdapter();
SendSMS sendsms = new SendSMS();
Here using tableAdapter
DS.RegistrationDataTable rtable = reg.GetDataByUsername(Session["username"].ToString());
if (rtable.Rows.Count > 0)
{
DS.RegistrationRow rrow = (DS.RegistrationRow)rtable.Rows[0];
int smscount = Convert.ToInt32(sen.Sumcredit(Session["username"].ToString()));
string username = rrow.Username;
// int smscount=0;
string MainString2 = txtmobileno.Text;
string[] Split2 = MainString2.Split(new Char[] { ',' });
string sendid = rrow.Senderid;
int CreditLmt = rrow.Creditlimit;
if (smscount <= CreditLmt)
{
if (rrow.Validitydate >= Convert.ToDateTime(DateTime.Now.ToString()))
{
for (int i = 0; i < Split2.Length; i++)
{
int credit = txtmessage.Text.Length / 160;
credit++;
DateTime date = DateTime.Now;
SqlConnection connection2 = new SqlConnection(con);
connection2.Open();
SqlCommand cmd1 = null;
string str = " insert into [Senditems] values('" + username + "','" + sendid + "', '" + Split2[i] + "',N'" + txtmessage.Text + "','Request.Url.AbsolutePath',' Request.UserHostAddress','Request.Browser.Platform + Request.Browser.Browser', '" + credit + "','" + date + "')";
cmd1 = new SqlCommand(str, connection2);
cmd1.ExecuteNonQuery();
string message = Convert.ToString(SqlHelper.ExecuteScalar(con, CommandType.Text, "SELECT message FROM senditems WHERE id = (SELECT MAX(id) FROM senditems)"));
sendsms.send(message, Split2[i], sendid);
connection2.Close();
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script>alert('Your message send successfully');</script>", false);
reset();
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script>alert('Cant send sms because your validity is expired');</script>", false);
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "", "<script>alert('Cant send sms because you dont have credit');</script>", false);
}
}
In the button click events i have using " sendsms.send(txtmobileno.Text, Split2[i], sendid);" this method for send sms to mobile.
strUrl = "http://onlinesms.in/api/sendValidSMSdataUrl.php?login=" + user + "&pword=" + pass +
"&msg=" + HttpUtility.UrlEncode(Message) +
"&senderid=" + sendId +
"&mobnum=" + mobNum;
WebRequest request = HttpWebRequest.Create(strUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream s = (Stream)response.GetResponseStream();
StreamReader readStream = new StreamReader(s);
string dataString = readStream.ReadToEnd();
response.Close();
s.Close();
readStream.Close();
And using this url to send sms.I have insert message into table is properly and i can get message to mobile ok but getting message ???????????? like this .
I want get sms properly pls any bady help.
I think it all depends of how the website API is converting back your URL string. In my opinion, I think it is safer to use the Uri.EscapeDataString() function instead of the HttpUtility.UrlEncode() because in a space you get the %20 instead of the + sign which may screw up your message.
I have to bind an <asp:calendar> with data fetched from a database using a linq query.
Here is the linq code
public List<AllCalander> SearchCalender(int month, int zip, string type, int cause)
{
var xyz = (from m in DB.Calenders
where(m.DateFrom.Value.Month==month || m.Zip==zip || m.ActivityType==type || m.CauseID==cause)
group m by new { m.DateFrom } into grp
select new
{
caustitle = grp.Select(x => x.Caus.CauseTitle),
datfrm = grp.Key.DateFrom,
total = grp.Count()
})
.ToList()
.Select(m => new AllCalander
{
DateFrom =Convert.ToDateTime(m.datfrm),
CauseTitle = string.Join(",", m.caustitle),
Total = m.total
});
My aspx.cs code is here
List<AllCalander> calnder = calbll.SearchCalender(mnth,ZipString,type,causeString);
foreach (var myItem in calnder)
{
string datetime = myItem.DateFrom.ToString();
Literal myEventNameLiteral = new Literal();
myEventNameLiteral.ID = i + myItem.CauseID.ToString();
// string currentcalanderDate = e.Day.Date.Day.ToString() ;
if (string.Equals(DateTime.Parse(datetime).ToString("MMM dd yyyy"), e.Day.Date.ToString("MMM dd yyyy")))
{
string a = myItem.CauseTitle;
if (a != cause)
cause = a;
coun++;
myEventNameLiteral.Mode = LiteralMode.PassThrough;
myEventNameLiteral.Text = "<br /><span style='font-family:verdana; font-size:10px;'>" + myItem.CauseTitle + "(" + myItem.Total + ")"+ " ";
e.Cell.Controls.Add(myEventNameLiteral);
}
i++;
}
but on output it only shows the last value from database instead of showing all the data.
Can somebody please tell me what's wrong?
Thanks in advance
group m by new { m.DateFrom, m.Caus.CauseTitle } into grp