Esempio n. 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string   orderdate   = Convert.ToString(Session["orderdate1"]);
        DateTime orderdate11 = Convert.ToDateTime(orderdate);
        string   symbol11    = Label1.Text;

        int      quantity11      = Convert.ToInt32(Label2.Text);
        string   marketprice11   = Label3.Text;
        double   marketprice123  = Convert.ToDouble(marketprice11);
        int      sellquantity    = Convert.ToInt32(TextBox1.Text);
        string   sellquantity123 = TextBox1.Text;
        var      regexItem       = new Regex("^[0-9 ]*$");
        string   username        = Convert.ToString(Session["username"]);
        int      rshares         = quantity11 - sellquantity;
        DateTime tdate           = DateTime.Now;
        double   amount11        = sellquantity * marketprice123;
        string   amount          = Convert.ToString(amount11);

        int availableshares = obj.getshares(symbol11);

        int totalshares = availableshares + sellquantity;

        if (sellquantity123.Length == 0)
        {
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Please Enter Number of shares you want to Sell' )</script>", false);
        }
        else if (!(regexItem.IsMatch(sellquantity123)))
        {
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Sell Quantity should be numeric Values' )</script>", false);
        }

        else if (sellquantity > quantity11)
        {
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Sell Quantity should be less or equal to Quantity' )</script>", false);
        }
        else
        {
            int result   = obj.selldetails(username, orderdate11, symbol11, marketprice11, sellquantity, totalshares, rshares, tdate);
            int result11 = obj.InsertCashBox(username, amount, tdate);

            if (result > 0)
            {
                string emailid = obj.GetEmail(username);
                string to123   = emailid;
                string from123 = "*****@*****.**";
                string subject = "TrdeMonitoring Notification on Sold Shares";
                string body    = "You have Sold : " + sellquantity + " Shares of : " + symbol11 + " on " + DateTime.Now + ". Now you have :" + rshares + " to Sell";
                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);
                }
                ClientScript.RegisterStartupScript(Page.GetType(), "Message", "alert('You have successfully sold the shares');window.location='Portfolio.aspx';", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ss", "<script>alert('Transaction Failed')</script>", false);
                Response.Redirect(ResolveUrl("Portfolio.aspx"));
            }
        }
    }
Esempio n. 2
0
    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)
        {
        }
    }
Esempio n. 3
0
    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
        {
        }
    }