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

            home.Show();
        }
 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();
            }
        }
示例#4
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
                }
            }
        }