protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); string username = Convert.ToString(Session["username"]); double tamount = 0.0; tamount = obj.CheckBoxAmount(username); Label1.Text = Convert.ToString(tamount); }
protected void Button2_Click(object sender, EventArgs e) { try { string ashares = string.Empty; string quantity = string.Empty; string username = Convert.ToString(Session["username"]); string symbol = DropDownList1.SelectedValue; string company = Label1.Text; ashares = Label3.Text; quantity = TextBox1.Text; double cashbox = obj.CheckBoxAmount(username); string price = Label4.Text; string price1 = Label2.Text; string from = TextBox2.Text; string to = TextBox3.Text; double price11 = 0.0; int validity = Convert.ToInt32(DropDownList3.SelectedValue); int ordertype = Convert.ToInt32(DropDownList2.SelectedValue); int ashares11 = 0; int quantity11 = 0; if (quantity.Length != 0) { ashares11 = Convert.ToInt32(ashares); quantity11 = Convert.ToInt32(quantity); price11 = Convert.ToDouble(Label2.Text); } var regexItem = new Regex("^[0-9 ]*$"); if (symbol == "0") { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Please select Company symbol' )</script>", false); } else if (quantity.Length == 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Please Enter quntity' )</script>", false); } else if (quantity11 > ashares11) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Quantity should be less than Available shares' )</script>", false); } else if (!(regexItem.IsMatch(quantity))) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Quantity shuld be Numeric value' )</script>", false); } else if ((price11 * quantity11) > cashbox) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('You Don't have enough Money on CashBOX' )</script>", false); } else if (ordertype == 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Please select Order Type' )</script>", false); } else { if (ordertype == 2) { DateTime odate = DateTime.Now; string status = "closed"; int ashares1 = Convert.ToInt32(Label3.Text); int quantity1 = Convert.ToInt32(TextBox1.Text); string rshares = Convert.ToString(ashares1 - quantity1); int result = obj.InsertUserStockDetails(username, symbol, quantity, price, status, odate, rshares); if (result == 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Order has been failed')</script>", false); Response.Redirect(ResolveUrl("NewOrder.aspx")); } else { double price123 = Convert.ToDouble(price); double amount = -price123; string amount1 = Convert.ToString(amount); DateTime tdate = DateTime.Now; int result11 = obj.InsertCashBox(username, amount1, tdate); string emailid = obj.GetEmail(username); string to123 = emailid; string from123 = "*****@*****.**"; string subject = "TrdeMonitoring Notification on Bought Shares"; string body = "You have Bought : " + quantity + " Shares on : " + DateTime.Now + " from : " + symbol; using (MailMessage mm = new MailMessage(from123, to123)) { mm.Subject = subject; mm.Body = body; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(from123, "srilakshmi123"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } //ClientScript.RegisterStartupScript(GetType(), "alert", "alert('You have successfully Bought the shares');", true); ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('You have successfully Bought the shares');window.location='NewOrder.aspx';", true); } } else { string status = "open"; DateTime orderdate = DateTime.Now; DateTime rdate = DateTime.MinValue; if (from.Length == 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Please Enter start Price' )</script>", false); } else if (!(regexItem.IsMatch(from))) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('start Price should be numeric Values' )</script>", false); } else if (to.Length == 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Please Enter End Price' )</script>", false); } else if (!(regexItem.IsMatch(to))) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('End Price should be numeric Values' )</script>", false); } else if (validity == 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Please select Validity' )</script>", false); } else { if (validity == 1) { rdate = orderdate.AddDays(1); } else { rdate = orderdate.AddDays(5); } int result = obj.InsertUserOpenStock(username, symbol, quantity, price1, from, to, status, orderdate, rdate); if (result == 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Placing Order has been failed')</script>", false); Response.Redirect(ResolveUrl("NewOrder.aspx")); } else { string emailid = obj.GetEmail(username); string to123 = emailid; string from123 = "*****@*****.**"; string subject = "TrdeMonitoring Notification on Hold Shares"; string body = "You have Placed the order of: " + quantity + " Shares on : " + DateTime.Now + " from : " + symbol + " and Order ID is : " + result + ". The Order is open till :" + rdate; using (MailMessage mm = new MailMessage(from123, to123)) { mm.Subject = subject; mm.Body = body; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(from123, "srilakshmi123"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } //ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Your shares are in hold.');", true); //ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Your shares are in hold');window.location='NewOrder.aspx';", true); ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('Your shares are in hold'),alert('Your Order ID is :" + result + "');window.location='NewOrder.aspx';", true); } } } } } catch (Exception e11) { } }
public void checkuserstocstatus() { string username = Convert.ToString(Session["username"]); DataSet ds11 = new DataSet(); int orderid = 0; string symbol = string.Empty; int quantity = 0; double fromprice = 0.0; double toprice = 0.0; DateTime orderdate = DateTime.MinValue; DateTime rdate = DateTime.MinValue; double marketprice = 0.0; DateTime today = DateTime.Now; int ashares = 0; ds11 = obj.getopenstocdetails(username); double cashbox = obj.CheckBoxAmount(username); double amount = quantity * marketprice; if (ds11 != null) { for (int i = 0; i < ds11.Tables[0].Rows.Count; i++) { orderid = Convert.ToInt32(ds11.Tables[0].Rows[i]["orderid"]); symbol = ds11.Tables[0].Rows[i]["symbol"].ToString(); quantity = Convert.ToInt32(ds11.Tables[0].Rows[i]["quantity"]); fromprice = Convert.ToDouble(ds11.Tables[0].Rows[i]["fromprice"]); toprice = Convert.ToDouble(ds11.Tables[0].Rows[i]["toprice"]); orderdate = Convert.ToDateTime(ds11.Tables[0].Rows[i]["orderdate"]); rdate = Convert.ToDateTime(ds11.Tables[0].Rows[i]["rdate"]); marketprice = Convert.ToDouble(ds11.Tables[0].Rows[i]["Open1"]); ashares = Convert.ToInt32(ds11.Tables[0].Rows[i]["shares"]); if ((fromprice <= marketprice) && (marketprice <= toprice) && (rdate > today) && (ashares > quantity) && (cashbox > amount)) { string status = "closed"; int rshares = ashares - quantity; obj.InsertUserHoldStockDetails(orderid, username, symbol, quantity, marketprice, status, today, rshares); double amount11 = -marketprice; string amount1 = Convert.ToString(amount11); int result111 = obj.InsertCashBox(username, amount1, today); string emailid = obj.GetEmail(username); string to123 = emailid; string from123 = "*****@*****.**"; string subject = "TrdeMonitoring Notification on Bought Shares"; string body = "Your hold Shares have been Bought and details are : " + quantity + " Shares of : " + symbol + " on " + DateTime.Now + " Order ID is :" + orderid; using (MailMessage mm = new MailMessage(from123, to123)) { mm.Subject = subject; mm.Body = body; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(from123, "Ysatyam1991"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } } else if (rdate < today) { string status = "failed"; obj.UpdateHoldDetails(orderid, status); string emailid = obj.GetEmail(username); string to123 = emailid; string from123 = "*****@*****.**"; string subject = "TrdeMonitoring Notification on Order Failed"; string body = "Your hold Shares order has been failed and details are : " + quantity + " Shares of : " + symbol + " on " + DateTime.Now + " and Order ID is " + orderid; using (MailMessage mm = new MailMessage(from123, to123)) { mm.Subject = subject; mm.Body = body; mm.IsBodyHtml = false; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential(from123, "Ysatyam1991"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } } else { } } } else { } }