private void InsertButton_Click(object sender, EventArgs e) { int state = 2; try { if (MoveTypeComboBox.Text.ToString().CompareTo("out") == 0 & Convert.ToInt32(MoveQuantityTextBox.Text) > this.quantity) { MessageBox.Show("Product in stock is not enough!", "INVALID QUANTITY"); state = 1; } else { string sql = "INSERT into StockManagementSystemDatabase.dbo.Move_Table(MoveProductID, MoveType, MoveDate, MoveQuantity, MoveQuantityUnit)" + "values('" + MoveProductIDTextBox.Text + "','" + MoveTypeComboBox.Text + "','" + MoveDateTimePicker.Value.ToString("yyyy-MM-dd") + "','" + MoveQuantityTextBox.Text + "','" + UnitComboBox.Text + "');"; SqlCommand command = new SqlCommand(sql, connection); DBUtils.OpenConnection(connection); command.ExecuteNonQuery(); DBUtils.CloseConnection(connection); int newquantity = 0; if (MoveTypeComboBox.Text.ToString().CompareTo("entry") == 0) { newquantity = this.quantity + Convert.ToInt32(MoveQuantityTextBox.Text); } else if (MoveTypeComboBox.Text.ToString().CompareTo("out") == 0) { newquantity = this.quantity - Convert.ToInt32(MoveQuantityTextBox.Text); } string Query = "update StockManagementSystemDatabase.dbo.Product_Cards_Table set ProductID='" + byID + "',ProductName='" + this.name + "',ProductUnit='" + this.unit + "',ProductQuantity='" + newquantity + "',ProductMoney='" + this.money + "',ProductMoneyUnit='" + this.moneyunit + "' WHERE ProductID=@ProductID;"; SqlCommand MyCommand = new SqlCommand(Query, connection); MyCommand.Parameters.AddWithValue("@ProductID", byID); DBUtils.OpenConnection(connection); MyCommand.ExecuteNonQuery(); DBUtils.CloseConnection(connection); mainpage.FillDataGridView(); MessageBox.Show("Product Move added!", "SUCCESS INSERTED"); state = 2; } } catch (SqlException se) { MessageBox.Show(se.ToString(), "ERROR"); } finally { DBUtils.CloseConnection(connection); FillDataGridView(); if (state == 2) { InsertPanel.Visible = false; GridPanel.Visible = true; TurnBackPictureBox.Visible = true; turnbackButton.Visible = true; MoveTypeComboBox.Text = ""; MoveQuantityTextBox.Clear(); UnitComboBox.Text = ""; MoveDateTimePicker.Text = ""; } else if (state == 1) { InsertPanel.Visible = true; GridPanel.Visible = false; TurnBackPictureBox.Visible = false; turnbackButton.Visible = false; MoveQuantityTextBox.Clear(); } } }