Beispiel #1
0
        public EditPriceForItem(ComboBox comboBox1)
        {
            connect = DataBaseConnection.getInstance().getConnect();
            String SelectQuery = "SELECT Name FROM [Table]";

            SqlCommand cmd = new SqlCommand(SelectQuery, connect);
            cmd.CommandText = SelectQuery;

            try
            {
                connect.Open();
                SqlDataReader drd = cmd.ExecuteReader();

                while (drd.Read())
                {
                    product p = new product();
                    p.Name = drd["Name"].ToString();
                    comboBox1.Items.Add(p);
                }
                drd.Close();
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.StackTrace.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            finally
            {
                connect.Close();
            }
        }
Beispiel #2
0
        private void Save_Click(object sender, EventArgs e)
        {
            product Product = new product();

            Product.Name = "" + NameP.Text;
            Product.Amount = Convert.ToInt32(Amount.Value);
            Product.Price = float.Parse(Price.Text);

            Thread thread = new Thread(new ParameterizedThreadStart(AddProduct.AddProductToDataBase));
            thread.Start(Product);

               // DataRow table = tableDataGridView.NewRowNeeded();
            //    table["id"] = 1;
              //  table["Name"] = "Ahaa";
              ////  table["Amount"] = 1;
               // table["Price"] = 1.3;
               // table["Date"] = DateTime.Now;
               // tableDataGridView.Rows.Add(1,"ahaa",1,1.3,DateTime.Now.ToString());

              //  tableDataGridView.DataSource = table;
               // this.tableTableAdapter.Fill(this.productsDataSet.Table.AddTableRow());
               // this.tableAdapterManager.UpdateAll(this.stockDataSet);
        }
Beispiel #3
0
        public void update(DataGridView dataGridView1)
        {
            List<product> list = new List<product>();
            connect = DataBaseConnection.getInstance().getConnect();
            String SelectQuery = "SELECT * FROM [Table]";
            SqlCommand cmd = new SqlCommand(SelectQuery,connect);
            cmd.CommandText = SelectQuery;
            try
            {
                connect.Open();
                SqlDataReader drd = cmd.ExecuteReader();
                while (drd.Read())
                {
                    product p = new product();
                    p.Name = drd["Name"].ToString();
                    p.Amount = int.Parse(drd["Amount"].ToString());
                    p.Price = float.Parse(drd["Price"].ToString());
                    list.Add(p);
                }

                foreach (product pro in list)
                {
                    dataGridView1.Rows.Add(false,pro.Name,pro.Amount,pro.Price);

                }

            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.StackTrace.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            finally
            {
                connect.Close();
            }
            //SqlDataAdapter sda;
            //DataSet ds = new DataSet();
            //sda = new SqlDataAdapter(cmd);
            //sda.Fill(ds);
            //DataTable dt = ds.Tables[0];
            //foreach(DataRow dataRow in dt.Rows)
            //{
              //  chekedListBox1.Items.Add(dataRow["Name"]);
            //}
        }
Beispiel #4
0
        //This method featches the content of database and fill them in AllProduct List
        private void CkeckPoduct()
        {
            try
            {
                SqlCommand Command = new SqlCommand(FetchQuery, Connection);
                Connection.Open();
                SqlDataReader reader = Command.ExecuteReader();

                while (reader.Read())
                {
                    product temp = new product();
                    temp.Name = reader["Name"].ToString();

                    temp.Amount = int.Parse(reader["Amount"].ToString());
                    temp.Price = float.Parse(reader["Price"].ToString());
                    //     MessageBox.Show(reader["Name"].ToString(), "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    AllProduct.Add(temp);

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Connection.Close();

            }
        }
Beispiel #5
0
        public void selectFromComboBox(TextBox textBox,ComboBox comboBox,NumericUpDown selectAmount)
        {
            connect = DataBaseConnection.getInstance().getConnect();
            String SelectQuery = "SELECT Amount,Price from [Table] where [Name] = @Name";
            SqlCommand cmd = new SqlCommand(SelectQuery, connect);
            cmd.CommandText = SelectQuery;
            cmd.Parameters.AddWithValue("@Name",comboBox.Text);
            connect.Open();
            try
            {
                SqlDataReader drd = cmd.ExecuteReader();

                product p = new product();
                while (drd.Read())
                {
                    p.Amount = int.Parse(drd[0].ToString());
                    p.Price = float.Parse(drd[1].ToString());
                    selectAmount.Value = p.Amount;
                    textBox.Text = p.Price.ToString();

                }
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.StackTrace.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            finally
            {
                connect.Close();
            }
        }