Exemple #1
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            string q1    = "SELECT COUNT(*) FROM EQUIPMENT WHERE EQUIPMENT.EQUIPMENT_NAME = '" + EquipCombobox.Text + "' AND EQUIPMENT.STATUS = '1' ";
            string q2    = "SELECT COUNT(*) FROM INVENTORY WHERE INVENTORY.TERM_ID = '" + TermIDTextbox.Text + "' AND INVENTORY.STATUS = '1' ";
            string query = "SELECT TERM_ID FROM INVENTORY WHERE INVENTORY_ID = '" + IDTextbox.Text + "' ";

            string queryCheck1 = "SELECT PROJECT_NAME FROM PROJECT JOIN INVENTORY ON INVENTORY.PROJECT_ID = PROJECT.PROJECT_ID " +
                                 "WHERE INVENTORY.INVENTORY_ID = '" + IDTextbox.Text + "' ";
            string queryCheck2 = "SELECT EQUIPMENT_NAME FROM EQUIPMENT JOIN INVENTORY ON INVENTORY.EQUIPMENT_ID = EQUIPMENT.EQUIPMENT_ID " +
                                 "WHERE INVENTORY.INVENTORY_ID = '" + IDTextbox.Text + "' ";
            string queryCheck3 = "SELECT TERM_ID FROM INVENTORY WHERE INVENTORY.INVENTORY_ID = '" + IDTextbox.Text + "' ";

            List <string> editList = new List <string>();


            //EditChecking(q1);
            //EditTermIDCheck(q2);

            if (DataTableSQLQuery(q1).Rows[0][0].ToString() == "0")
            {
                MessageBox.Show("Not a valid value");
            }
            else
            {
                eqCheck = true;
            }

            if ((DataTableSQLQuery(q2).Rows[0][0].ToString() == "1") && (ScalarSQLQuery(query, con) != TermIDTextbox.Text))
            {
                MessageBox.Show("TERM ID already exists.");
            }
            else
            {
                tmCheck = true;
            }

            if ((eqCheck == true) && (tmCheck == true))
            {
                eqCheck = false;
                tmCheck = false;
                UpdateList(queryCheck1, IDTextbox.Text, ProjectCombobox.Text, editList);
                UpdateList(queryCheck2, IDTextbox.Text, EquipCombobox.Text, editList);
                UpdateList(queryCheck3, IDTextbox.Text, TermIDTextbox.Text, editList);

                for (int i = 0; i < editList.Count; i++)
                {
                    Console.WriteLine(editList[i]);
                    History.HistoryInventoryUpdate(editList[i]);
                }
                Inventory.UpdateButton(EquipCombobox, ProjectCombobox, TermIDTextbox, IDTextbox, con);
            }

            InventoryDataGrid.DataSource = null;
            Inventory.DisplayInventory(InventoryDataGrid, con);
            checkBox1.Checked = false;
        }