Beispiel #1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            Important.ProdName = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            this.labelProdName.Text = Important.ProdName;


            this.textBoxQuan.TabIndex = 0;
            this.textBoxQuan.Text = "0";

            string Query = "select Price from Product where ProdName = '" +
                Important.ProdName + "'";

            try
            {
                SqlCommand sel = new SqlCommand(Query, Important.conex);
                Cost = Convert.ToDouble(sel.ExecuteScalar().ToString());
                AmountMoney = Convert.ToInt32(textBoxQuan.Text) * Math.Round(Cost, 2);
            }
            catch (Exception ex)
            {
                Important.message = ex.GetType().ToString();
                DialogMessageP dial = new DialogMessageP();
                dial.ShowDialog();
                this.textBoxQuan.Text = "";
            }
            labelPrice.Text = AmountMoney.ToString() + '$';
        }
Beispiel #2
0
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            string Delete;
            string Select;

            if (this.richTextBoxSQLCondition.Text == "")
            {
                Delete = "delete from Product";
                DialogConfirmationP conf = new DialogConfirmationP();
                Important.message = "Doriti sa stergeti toate datele din tabel?";
                conf.label1.Text  = Important.message;
                conf.ShowDialog();
            }

            else
            {
                Delete = "delete from Product where " + this.richTextBoxSQLCondition.Text;
                DialogConfirmationP conf = new DialogConfirmationP();
                Important.message = "Doriti sa stergeti aceste date din tabel?";
                conf.label1.Text  = Important.message;
                conf.ShowDialog();
            }

            if (Important.confirm == true)
            {
                try
                {
                    SqlCommand del = new SqlCommand(Delete, Important.conex);
                    del.ExecuteNonQuery();
                }

                catch (Exception ex)
                {
                    Important.message = ex.GetType().ToString();
                    DialogMessageP dial = new DialogMessageP();
                    dial.ShowDialog();
                }
            }

            Select = "select * from Product";
            SqlCommand     sel = new SqlCommand(Select, Important.conex);
            SqlDataAdapter da  = new SqlDataAdapter(sel);
            DataSet        ds  = new DataSet();

            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];

            this.textBox1.Text  = "";
            this.textBox2.Text  = "";
            this.textBox3.Text  = "";
            this.textBox4.Text  = "";
            this.textBox5.Text  = "";
            this.textBox6.Text  = "";
            this.textBox7.Text  = "";
            this.textBox8.Text  = "";
            this.textBox9.Text  = "";
            this.textBox10.Text = "";
            this.richTextBoxSQLCondition.Text = "";
        }
Beispiel #3
0
        private void buttonDisplay_Click(object sender, EventArgs e)
        {
            String Querry;

            if (this.richTextBoxSQLCondition.Text == "")
            {
                Querry = "select * from Sale";

                try
                {
                    if (dataGridView1.Rows.Count == 0)
                    {
                        SqlCommand     prt = new SqlCommand(Querry, Important.conex);
                        SqlDataAdapter da  = new SqlDataAdapter(prt);
                        DataSet        ds  = new DataSet();
                        da.Fill(ds);
                        dataGridView1.DataSource = ds.Tables[0];
                    }
                    else
                    {
                        dataGridView1.DataSource = null;
                        dataGridView1.Refresh();
                    }
                }

                catch (Exception ex)
                {
                    Important.message = ex.GetType().ToString();
                    DialogMessageP dial = new DialogMessageP();
                    dial.ShowDialog();
                }
            }


            else
            {
                Querry = "select * from Sale where " + this.richTextBoxSQLCondition.Text;

                try
                {
                    SqlCommand     prt = new SqlCommand(Querry, Important.conex);
                    SqlDataAdapter da  = new SqlDataAdapter(prt);
                    DataSet        ds  = new DataSet();
                    da.Fill(ds);
                    dataGridView1.DataSource = ds.Tables[0];
                }

                catch (Exception ex)
                {
                    Important.message = ex.GetType().ToString();
                    DialogMessageP dial = new DialogMessageP();
                    dial.ShowDialog();
                }
            }
        }
Beispiel #4
0
        private void buttonBuy_Click(object sender, EventArgs e)
        {
            DialogMessageP dial = new DialogMessageP();
            DialogConfirmationP conf = new DialogConfirmationP();
            string Query = "Select Charge from _User where Username = '******';";

            try
            {
                if (Convert.ToInt32(this.textBoxQuan.Text) < 1)
                {
                    Important.message = "Selecteaza cantitatea dorita de produse!";
                    dial.ShowDialog();
                }

                else
                {
                    SqlCommand money = new SqlCommand(Query, Important.conex);
                    double charge = Convert.ToDouble(money.ExecuteScalar().ToString());

                    if (charge < AmountMoney)
                    {
                        Important.message = "Nu aveti bani suficienti!";
                        dial.ShowDialog();
                    }

                    else
                    {
                        Important.message = "Sunteti siguri ca doriti sa cumparati acest produs?";
                        conf.ShowDialog();

                        if (Important.confirm == true)
                        {
                            BuyProductTransaction();
                            Important.message = "Va multumim pentru ca ati cumparat acest produs!";
                            dial.ShowDialog();
                        }
                    }
                }
            }
            catch { }
        }
Beispiel #5
0
        private void textBoxQuan_TextChanged(object sender, EventArgs e)
        {

            string Query = "select Quantity from Product where ProdName = '" +
                    Important.ProdName + "'";

            SqlCommand SQLprodQuan = new SqlCommand(Query, Important.conex);

            try
            {
                int prodQuan = Convert.ToInt32(SQLprodQuan.ExecuteScalar().ToString());
                if (Convert.ToInt32(this.textBoxQuan.Text) <= prodQuan)
                {
                    Query = "select Price from Product where ProdName = '" +
                        Important.ProdName + "'";
                    string text;

                    try
                    {
                        SqlCommand sel = new SqlCommand(Query, Important.conex);
                        Cost = Convert.ToDouble(sel.ExecuteScalar().ToString());
                        text = this.textBoxQuan.Text;
                        if (text == "")
                            text = "0";
                        AmountMoney = Convert.ToInt32(text) * Math.Round(Cost, 2);
                    }
                    catch (Exception ex)
                    {
                        Important.message = ex.GetType().ToString();
                        DialogMessageP dial = new DialogMessageP();
                        dial.ShowDialog();
                        this.textBoxQuan.Text = "";
                    }
                    labelPrice.Text = AmountMoney.ToString() + '$';
                }

                else
                {
                    DialogMessageP dial = new DialogMessageP();
                    Important.message = "Cantitatea selectata depaseste \ncantitatea disponibila pe stock";
                    dial.ShowDialog();
                    this.textBoxQuan.Text = "0";
                }
            }

            catch
            {

            }
        }
Beispiel #6
0
        private void buttonInsert_Click(object sender, EventArgs e)
        {
            string Insert;
            string Select;

            Insert = "insert into Product values('"
                     + this.textBox1.Text + "', '" + this.textBox2.Text + "', '"
                     + this.textBox3.Text + "', '" + this.textBox4.Text + "', '"
                     + this.textBox5.Text + "', '" + this.textBox6.Text + "', '"
                     + this.textBox7.Text + "', '" + this.textBox8.Text + "', '"
                     + this.textBox9.Text + "', '" + this.textBox10.Text + "'); ";

            try
            {
                SqlCommand ins = new SqlCommand(Insert, Important.conex);
                ins.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                Important.message = ex.GetType().ToString();
                DialogMessageP dial = new DialogMessageP();
                dial.ShowDialog();
            }

            Select = "select * from Product";
            SqlCommand     sel = new SqlCommand(Select, Important.conex);
            SqlDataAdapter da  = new SqlDataAdapter(sel);
            DataSet        ds  = new DataSet();

            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];

            this.textBox1.Text  = "";
            this.textBox2.Text  = "";
            this.textBox3.Text  = "";
            this.textBox4.Text  = "";
            this.textBox5.Text  = "";
            this.textBox6.Text  = "";
            this.textBox7.Text  = "";
            this.textBox8.Text  = "";
            this.textBox9.Text  = "";
            this.textBox10.Text = "";
            this.richTextBoxSQLCondition.Text = "";
        }
Beispiel #7
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            string Update;
            string Select;
            string Check;

            try
            {
                Check = "select ProdName from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck1 = new SqlCommand(Check, Important.conex);
                if (this.textBox1.Text == "")
                {
                    this.textBox1.Text = comCheck1.ExecuteScalar().ToString();
                }

                Check = "select Type from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck2 = new SqlCommand(Check, Important.conex);
                if (this.textBox2.Text == "")
                {
                    this.textBox2.Text = comCheck2.ExecuteScalar().ToString();
                }

                Check = "select Origin from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck3 = new SqlCommand(Check, Important.conex);
                if (this.textBox3.Text == "")
                {
                    this.textBox3.Text = comCheck3.ExecuteScalar().ToString();
                }

                Check = "select Mass from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck4 = new SqlCommand(Check, Important.conex);
                if (this.textBox4.Text == "")
                {
                    this.textBox4.Text = comCheck4.ExecuteScalar().ToString();
                }

                Check = "select Length from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck5 = new SqlCommand(Check, Important.conex);
                if (this.textBox5.Text == "")
                {
                    this.textBox5.Text = comCheck5.ExecuteScalar().ToString();
                }

                Check = "select Caliber from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck6 = new SqlCommand(Check, Important.conex);
                if (this.textBox6.Text == "")
                {
                    this.textBox6.Text = comCheck6.ExecuteScalar().ToString();
                }

                Check = "select Diameter from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck7 = new SqlCommand(Check, Important.conex);
                if (this.textBox7.Text == "")
                {
                    this.textBox7.Text = comCheck7.ExecuteScalar().ToString();
                }

                Check = "select Filling from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck8 = new SqlCommand(Check, Important.conex);
                if (this.textBox8.Text == "")
                {
                    this.textBox8.Text = comCheck8.ExecuteScalar().ToString();
                }

                Check = "select Quantity from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck9 = new SqlCommand(Check, Important.conex);
                if (this.textBox9.Text == "")
                {
                    this.textBox9.Text = comCheck9.ExecuteScalar().ToString();
                }

                Check = "select Price from Product where " + this.richTextBoxSQLCondition.Text + ";";
                SqlCommand comCheck10 = new SqlCommand(Check, Important.conex);
                if (this.textBox10.Text == "")
                {
                    this.textBox10.Text = comCheck10.ExecuteScalar().ToString();
                }

                Update = "update Product set ProdName = '" + this.textBox1.Text + "', Type = '"
                         + this.textBox2.Text + "', Origin = '" + this.textBox3.Text + "', Mass = '"
                         + this.textBox4.Text + "', Length = '" + this.textBox5.Text + "', Caliber = '"
                         + this.textBox6.Text + "', Diameter = '" + this.textBox7.Text + "', Filling = '"
                         + this.textBox8.Text + "', Quantity = '" + this.textBox9.Text + "', Price = '"
                         + this.textBox10.Text + "' where " + this.richTextBoxSQLCondition.Text + ";";

                SqlCommand upd = new SqlCommand(Update, Important.conex);
                upd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                Important.message = ex.GetType().ToString();
                DialogMessageP dial = new DialogMessageP();
                dial.ShowDialog();
            }

            Select = "select * from Product";
            SqlCommand     sel = new SqlCommand(Select, Important.conex);
            SqlDataAdapter da  = new SqlDataAdapter(sel);
            DataSet        ds  = new DataSet();

            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];

            this.textBox1.Text  = "";
            this.textBox2.Text  = "";
            this.textBox3.Text  = "";
            this.textBox4.Text  = "";
            this.textBox5.Text  = "";
            this.textBox6.Text  = "";
            this.textBox7.Text  = "";
            this.textBox8.Text  = "";
            this.textBox9.Text  = "";
            this.textBox10.Text = "";
            this.richTextBoxSQLCondition.Text = "";
        }
Beispiel #8
0
        private void button4_Click(object sender, EventArgs e)
        {
            string Update;
            string Select;
            string Check;

            try
            {
                Check = "select FullName from _User where " + this.richTextBox1.Text + ";";
                SqlCommand comCheck1 = new SqlCommand(Check, Important.conex);
                if (this.textBox1.Text == "")
                {
                    this.textBox1.Text = comCheck1.ExecuteScalar().ToString();
                }

                Check = "select Username from _User where " + this.richTextBox1.Text + ";";
                SqlCommand comCheck2 = new SqlCommand(Check, Important.conex);
                if (this.textBox2.Text == "")
                {
                    this.textBox2.Text = comCheck2.ExecuteScalar().ToString();
                }

                Check = "select Email from _User where " + this.richTextBox1.Text + ";";
                SqlCommand comCheck3 = new SqlCommand(Check, Important.conex);
                if (this.textBox3.Text == "")
                {
                    this.textBox3.Text = comCheck3.ExecuteScalar().ToString();
                }

                Check = "select Password from _User where " + this.richTextBox1.Text + ";";
                SqlCommand comCheck4 = new SqlCommand(Check, Important.conex);
                if (this.textBox4.Text == "")
                {
                    this.textBox4.Text = comCheck4.ExecuteScalar().ToString();
                }

                Check = "select UserType from _User where " + this.richTextBox1.Text + ";";
                SqlCommand comCheck5 = new SqlCommand(Check, Important.conex);
                if (this.textBox5.Text == "")
                {
                    this.textBox5.Text = comCheck5.ExecuteScalar().ToString();
                }

                Check = "select Charge from _User where " + this.richTextBox1.Text + ";";
                SqlCommand comCheck6 = new SqlCommand(Check, Important.conex);
                if (this.textBox6.Text == "")
                {
                    this.textBox6.Text = comCheck6.ExecuteScalar().ToString();
                }

                Update = "update _User set FullName = '" + this.textBox1.Text + "', Username = '******', Email = '" + this.textBox3.Text + "', Password = '******', UserType = '" + this.textBox5.Text + "', Charge = " + Convert.ToDouble(this.textBox6.Text)
                         + " where " + this.richTextBox1.Text + ";";

                SqlCommand upd = new SqlCommand(Update, Important.conex);
                upd.ExecuteNonQuery();
            }

            catch (Exception ex)
            {
                Important.message = ex.GetType().ToString();
                DialogMessageP dial = new DialogMessageP();
                dial.ShowDialog();
            }

            Select = "select * from _User";
            SqlCommand     sel = new SqlCommand(Select, Important.conex);
            SqlDataAdapter da  = new SqlDataAdapter(sel);
            DataSet        ds  = new DataSet();

            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];

            this.textBox1.Text     = "";
            this.textBox6.Text     = "";
            this.textBox2.Text     = "";
            this.textBox3.Text     = "";
            this.textBox4.Text     = "";
            this.textBox5.Text     = "";
            this.richTextBox1.Text = "";
        }