示例#1
0
        public static bool addItem(DrewsGoodsBO values = null)
        {
            //Connect with SQL
            SqlConnection connection = openConnection();

            string sql = "false";

            //SQL query
            if (values.type == "add")
            {
                sql = "INSERT INTO " + tableName + "(name, stock, price) VALUES('" + values.name + "', '" + values.stock + "', " + values.price + ");";
            }
            else if (values.type == "edit")
            {
                sql = "UPDATE " + tableName + " SET name = '" + values.name + "', stock = " + values.stock + ", price = " + values.price + " WHERE name = '" + values.name + "';";
            }

            if (sql != "false")
            {
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                //Return true to signify succesful insertion ( ͡° ͜ʖ ͡°)
                return(true);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Something went wrong while adding the item.\n\nPlease try again.");
                return(false);
            }
        }
示例#2
0
        public static DataSet getItems(DrewsGoodsBO values = null)
        {
            //Connect with SQL
            SqlConnection connection = openConnection();

            //SQL query
            string     sql     = "SELECT name, stock, CAST(price AS DECIMAL(10,2)) FROM " + tableName + ";";
            SqlCommand command = new SqlCommand(sql, connection);

            //Open sql connection
            connection.Open();
            //Execute the reader
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                DataSet items = createLocalDataset();

                while (reader.Read())
                {
                    //Add row to local dataset
                    items.Tables[tableName].Rows.Add(reader[0], reader[2], reader[1]);
                }
                reader.Close();
                //Return the dataset
                return(items);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("Delete item", "Are you sure you want to delete this item?", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    string       item = lvItems.SelectedItems[0].Text;
                    DrewsGoodsBO BO   = new DrewsGoodsBO(item, null, 0);

                    if (DrewsGoodsBLL.deleteItem(BO) == true)
                    {
                        refresh();
                    }
                    else
                    {
                        MessageBox.Show("Something went wrong. \n\nPlease try again.");
                    }
                }
                catch
                {
                    MessageBox.Show("No item selected. \n \n Select an item in the list!");
                    return;
                }
                btnEdit.Enabled   = false;
                btnEdit.Visible   = false;
                btnDelete.Enabled = false;
                btnDelete.Visible = false;
            }
            else
            {
                return;
            }
        }
示例#4
0
        private void changeItem(string name, string price, int stock, string type)
        {
            if (!new Regex(@"^[A-Za-z0-9\s.,()]*$").IsMatch(name))
            {
                MessageBox.Show("Invalid characters used in name field. \n\n Only letters, numbers and the characters . , [ ] ( ) are allowed.");
                return;
            }
            else if (!new Regex(@"^([0-9]{1,5}).([0-9]{2})$").IsMatch(price))
            {
                MessageBox.Show("Invalid price syntax.\n\nUse the format '50.00' (2 decimals, minimum '0.00' maximum '99999.99'");
                return;
            }

            if (name == "" || price == "")
            {
                MessageBox.Show("Not all fields have been filled in.");
                return;
            }
            else
            {
                DrewsGoodsBO BO = new DrewsGoodsBO(name, price, stock, type);

                if (DrewsGoodsBLL.addItem(BO) == true)
                {
                    MessageBox.Show("Item " + type + "ed succesfully!");
                    refresh();
                }
            }
        }
示例#5
0
        public static bool deleteItem(DrewsGoodsBO values = null)
        {
            //Connect with SQL
            SqlConnection connection = openConnection();

            //SQL query
            string sql = values != null ? "DELETE FROM " + tableName + " WHERE name = '" + values.name + "';" : "false";

            if (sql != "false")
            {
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                //Return true to signify succesful deletion
                return(true);
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("No item selected.");
                return(false);
            }
        }
 public static bool addItem(DrewsGoodsBO BO = null)
 {
     return(DrewsGoodsDAL.addItem(BO));
 }
 public static bool deleteItem(DrewsGoodsBO BO = null)
 {
     return(DrewsGoodsDAL.deleteItem(BO));
 }
 public static DataSet getItems(DrewsGoodsBO BO = null)
 {
     return(DrewsGoodsDAL.getItems(BO));
 }