Example #1
0
        // ------------Added by Wei Guang Yan----------------
        // Method of updating product name to database
        public void UpdateProduct(string txtUpdate)
        {
            // Initialization for messagebox
            string            message;
            string            title  = "Product Update";
            MessageBoxButtons button = MessageBoxButtons.OK;
            MessageBoxIcon    icon   = MessageBoxIcon.Warning;

            // Excute updating
            int  id   = ProductsDB.GetProductId(comboBox2.Text);
            bool flag = ProductsDB.UpdateProduct(id, txtUpdate);

            // Check whether updating is successful, and show message
            if (flag == true)
            {
                int index = comboBox2.SelectedIndex;
                comboBox2.DataSource    = ProductsDB.GetProducts();
                comboBox2.DisplayMember = "ProdName";
                comboBox2.ValueMember   = "ProductId";
                comboBox2.SelectedIndex = index;
                message = "The product is updated successfully!";
                icon    = MessageBoxIcon.None;
            }
            else
            {
                message = "Error: Fail to update product!\n Please try again or contact IT support.";
                icon    = MessageBoxIcon.Error;
            }
            MessageBox.Show(message, title, button, icon);
        }