Exemple #1
0
        private void MtAdd_Click(object sender, EventArgs e)
        {
            aef = new AddEditForm();
            aef.setFormText("Add New Item");

            try{
                if (aef.ShowDialog() == DialogResult.OK)
                {
                    Connection c = new Connection();
                    DatabaseConnectionInterface dcf = c.connect();
                    string MaxQuery = "SELECT MAX(itemNumber) FROM warehouse";
                    int    newItem  = int.Parse(dcf.executeScalarQuery(MaxQuery)) + 1;

                    string InsertQuery = "INSERT INTO warehouse(itemNumber,itemName,itemPrice,itemQuantity,itemPic) VALUES(" + newItem + ",\"" + aef.getItemName() + "\"," + aef.getItemPrice() + "," + aef.getItemQuantity() + ",\"" + aef.getItempic() + "\")";
                    dcf.executeDMQuery(InsertQuery);
                    dcf.close();
                    data.Rows.Add(newItem, aef.getItemName(), aef.getItemPrice(), aef.getItemQuantity(), aef.getItempic());
                    data    = dti.getToDataTable("SELECT * FROM warehouse");
                    deldata = dti.getToDataTable("SELECT itemName, itemPrice, itemQuantity FROM warehouse WHERE itemNumber NOT IN (SELECT DISTINCT itemID FROM orderitems)");
                    StorageGridView.DataSource = data;
                    StorageGridView.Refresh();
                }
                aef.Hide();
            }
            catch (Exception ee)
            {
                return;
            }
        }
Exemple #2
0
        private void MtModify_Click(object sender, EventArgs e)
        {
            try
            {
                aef = new AddEditForm();
                aef.setFormText("Modify Item");
                foreach (DataGridViewRow row in StorageGridView.SelectedRows)
                {
                    aef.setItemname(row.Cells[1].Value.ToString().TrimEnd());
                    aef.setItemPrice(row.Cells[2].Value.ToString().TrimEnd());
                    aef.setItemQuantity(row.Cells[3].Value.ToString().TrimEnd());
                    aef.setItemPicture(row.Cells[4].Value.ToString().TrimEnd());
                }
                aef.ShowDialog();

                if (aef.DialogResult == DialogResult.OK)
                {
                    Connection c = new Connection();
                    DatabaseConnectionInterface dci = c.connect();
                    string getitemID  = "SELECT itemNumber FROM warehouse WHERE itemName=\"" + aef.getItemName() + "\"";
                    int    itemID     = int.Parse(dci.getOneField(getitemID));
                    string UpdateItem = "UPDATE warehouse SET itemName=\"" + aef.getItemName() + "\", itemPrice=\"" + aef.getItemPrice() + "\", itemQuantity=\"" + aef.getItemQuantity() + "\", itemPic=\"" + aef.getItempic() + "\" WHERE itemNumber=" + itemID;
                    dci.executeDMQuery(UpdateItem);
                    dci.close();

                    DataRow[] row = data.Select("itemNumber=" + itemID);
                    row[0]["itemName"]     = aef.getItemName();
                    row[0]["itemPrice"]    = aef.getItemPrice();
                    row[0]["itemQuantity"] = aef.getItemQuantity();
                    row[0]["itemPic"]      = aef.getItempic();
                    StorageGridView.Refresh();
                }
            }
            catch (Exception ee)
            { MessageBox.Show("Please select a row to modify!"); }
        }