private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            Home home = Home.getInstance(Home.getUser());

            home.Show();
        }
 private void button2_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Equals(""))
     {
         MessageBox.Show("Username cant be empty!");
     }
     else if (textBox2.Text.Equals(""))
     {
         MessageBox.Show("Password cant be empty!");
     }
     else
     {
         sqlcon.Open();
         SqlCommand sqlcmd = new SqlCommand("adduser", sqlcon);
         sqlcmd.CommandType = CommandType.StoredProcedure;
         sqlcmd.Parameters.AddWithValue("@username", textBox1.Text.Trim());
         sqlcmd.Parameters.AddWithValue("@password", textBox2.Text.Trim());
         sqlcmd.ExecuteNonQuery();
         MessageBox.Show("User registration successful");
         textBox1.Text = textBox2.Text = ""; //clear
         this.Hide();
         //Home home = new Home(textBox1.Text.Trim());
         Home home = Home.getInstance(textBox1.Text.Trim());
         home.Show();
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Equals(""))
     {
         MessageBox.Show("Username cant be empty!");
     }
     else if (textBox2.Text.Equals(""))
     {
         MessageBox.Show("Password cant be empty!");
     }
     else
     {
         //SqlConnection sqlcon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\DELL\Documents\StockDB.mdf;Integrated Security=True;Connect Timeout=30;");
         sqlcon.Open();
         string         login_query = "select count(*) from [dbo].[user] where username='******' and password='******'";
         SqlDataAdapter sda         = new SqlDataAdapter(login_query, sqlcon);
         DataTable      dt          = new DataTable();
         sda.Fill(dt);
         if (dt.Rows[0][0].ToString() == "1")
         {
             this.Hide();
             //Home home = new Home(textBox1.Text.Trim());
             Home home = Home.getInstance(textBox1.Text.Trim());
             home.Show();
         }
         else
         {
             MessageBox.Show("Invalid credentials!");
             textBox1.Text = textBox2.Text = ""; //clear
         }
         sqlcon.Close();
     }
 }
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Trim() == "")
     {
         MessageBox.Show("Name cant be blank!");
     }
     else
     {
         sqlcon.Open();
         SqlCommand sqlcmd = new SqlCommand("addscript", sqlcon);
         sqlcmd.CommandType = CommandType.StoredProcedure;
         sqlcmd.Parameters.AddWithValue("@scriptName", textBox1.Text.Trim());
         sqlcmd.Parameters.AddWithValue("@scriptComment", textBox2.Text.Trim());
         sqlcmd.ExecuteNonQuery();
         MessageBox.Show("Added script!");
         textBox1.Text = textBox2.Text = ""; //clear
         this.Hide();
         Home home = Home.getInstance(Home.getUser());
         home.Show();
         home.disp_scripts();
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim() == "")
            {
                MessageBox.Show("Script Number cant be blank!");
            }
            else if (textBox2.Text.Trim() == "")
            {
                MessageBox.Show("Please enter the price!");
            }
            else if (textBox3.Text.Trim() == "")
            {
                MessageBox.Show("Please enter the number of shares!");
            }
            else
            {
                sqlcon.Open();

                string         check_query = "select count(*) from [dbo].[inventory] where scriptID='" + textBox1.Text.Trim() + "'";
                SqlDataAdapter sda         = new SqlDataAdapter(check_query, sqlcon);
                DataTable      dt          = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() == "1")
                {
                    //Present

                    string         retrieve_details = "select * from [dbo].[inventory] where scriptID='" + textBox1.Text.Trim() + "'";
                    SqlDataAdapter sda2             = new SqlDataAdapter(retrieve_details, sqlcon);
                    DataTable      dt2 = new DataTable();
                    sda2.Fill(dt2);
                    double price          = (double)dt2.Rows[0][1];
                    int    numberofshares = (int)dt2.Rows[0][2];
                    double totalCost      = price * numberofshares;

                    double newtotalcost = totalCost + ((Convert.ToDouble(textBox2.Text.Trim())) * (Convert.ToInt32(textBox3.Text.Trim())));
                    int    newShares    = numberofshares + (Convert.ToInt32(textBox3.Text.Trim()));
                    double newprice     = (double)(newtotalcost / newShares);

                    SqlCommand ucmd = sqlcon.CreateCommand();
                    ucmd.CommandType = CommandType.Text;
                    ucmd.CommandText = "update [dbo].[inventory] set price='" + newprice + "', noShares='" + newShares + "', totalCost='" + newtotalcost + "' where ScriptID='" + textBox1.Text.Trim() + "'";
                    ucmd.ExecuteNonQuery();
                    MessageBox.Show("Bought and updated script!");
                }
                else
                {
                    //Not present
                    SqlCommand sqlcmd = new SqlCommand("buyscript", sqlcon);
                    sqlcmd.CommandType = CommandType.StoredProcedure;
                    sqlcmd.Parameters.AddWithValue("@scriptID", textBox1.Text.Trim());
                    sqlcmd.Parameters.AddWithValue("@price", Convert.ToDouble(textBox2.Text.Trim()));
                    sqlcmd.Parameters.AddWithValue("@noShares", Convert.ToInt32(textBox3.Text.Trim()));
                    sqlcmd.Parameters.AddWithValue("@totalCost", ((Convert.ToDouble(textBox2.Text.Trim())) * (Convert.ToInt32(textBox3.Text.Trim()))));

                    sqlcmd.ExecuteNonQuery();
                    MessageBox.Show("Bought script!");
                }

                ViewInventory.getInstance().disp_inventory();

                textBox1.Text = textBox2.Text = textBox3.Text = ""; //clear
                this.Hide();
                Home home = Home.getInstance(Home.getUser());
                home.Show();
                sqlcon.Close();
            }
        }
Example #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //first we need to retrieve details of the share from the inventory
            if (textBox1.Text.Equals(""))
            {
                MessageBox.Show("Script ID cant be blank!");
            }
            else if (textBox2.Text.Equals(""))
            {
                MessageBox.Show("Price cant be blank!");
            }
            else if (textBox3.Text.Equals(""))
            {
                MessageBox.Show("Number of shares cant be blank!");
            }
            else
            {
                sqlcon.Open();
                //First we need to retrieve details and see if we can actually sell
                string         check_query = "select * from [dbo].[inventory] where scriptID='" + textBox1.Text.Trim() + "'";
                SqlDataAdapter sda         = new SqlDataAdapter(check_query, sqlcon);
                DataTable      dt          = new DataTable();
                sda.Fill(dt);
                if (dt.Rows[0][0].ToString() == textBox1.Text.Trim())
                {
                    //record present, now check for number of shares
                    if ((int)dt.Rows[0][2] >= Convert.ToInt32(textBox3.Text.Trim()))
                    {
                        //transaction ok
                        int    newShares    = (int)dt.Rows[0][2] - Convert.ToInt32(textBox3.Text.Trim());
                        double newTotalCost = newShares * (double)dt.Rows[0][1];

                        //Update inventory
                        SqlCommand ucmd = sqlcon.CreateCommand();
                        ucmd.CommandType = CommandType.Text;
                        ucmd.CommandText = "update [dbo].[inventory] set noShares='" + newShares + "', totalCost='" + newTotalCost + "' where ScriptID='" + textBox1.Text.Trim() + "'";
                        ucmd.ExecuteNonQuery();
                        MessageBox.Show("Sold and updated script!");


                        double profitPerShare = Convert.ToDouble(textBox2.Text) - (double)dt.Rows[0][1];
                        double totalProfit    = (profitPerShare * (int)dt.Rows[0][2]);
                        //update proft table



                        //

                        SqlCommand sqlcmd = new SqlCommand("addprofit", sqlcon);
                        sqlcmd.CommandType = CommandType.StoredProcedure;
                        sqlcmd.Parameters.AddWithValue("@ScriptID", Convert.ToInt32(textBox1.Text.Trim()));
                        sqlcmd.Parameters.AddWithValue("@price", profitPerShare);
                        sqlcmd.Parameters.AddWithValue("@noShares", Convert.ToDouble(textBox3.Text.Trim()));
                        sqlcmd.Parameters.AddWithValue("@totalCost", totalProfit);

                        sqlcmd.ExecuteNonQuery();
                        MessageBox.Show("Profit updated successfully!!");
                        textBox1.Text = textBox2.Text = ""; //clear
                        textBox3.Text = "";
                        this.Hide();
                        //Home home = new Home(textBox1.Text.Trim());
                        Home home = Home.getInstance(Home.getUser());
                        home.Show();

                        //
                        ViewInventory.getInstance().disp_inventory();
                        ViewProfit.getInstance().disp_profit();
                    }
                    else
                    {
                        MessageBox.Show("You dont have shares of the script!");
                        textBox1.Text = textBox2.Text = textBox3.Text = ""; //clear
                    }
                    sqlcon.Close();
                }
                else
                {
                    MessageBox.Show("You dont have shares of the script!");
                    textBox1.Text = textBox2.Text = textBox3.Text = ""; //clear
                }
            }
        }