private void ClearText() { ProductCodeComboBox.SelectedIndex = -1; QuantityUpDown.Value = 0; DepComboBox.SelectedIndex = -1; RequesteeTextBox.Clear(); ProductCodeComboBox.Focus(); }
private void SOButton_Click(object sender, EventArgs e) { const string stmt = "SELECT COUNT(*) FROM dbo.Cart"; int count1 = 0; int count2 = 0; _connection = DB_Connect.connect(); _connection.Open(); _command = new SqlCommand(stmt, _connection); var count = (int)_command.ExecuteScalar(); string[,] array = new string[count, count]; var command1 = new SqlCommand(@"SELECT * FROM[Cart]", _connection); _connection.Close(); try { _connection.Open(); var myReader = command1.ExecuteReader(); array = new string[count, count]; while (myReader.Read()) { array[count1, count2] = myReader.GetString(0); count2++; array[count1, count2] = Convert.ToString(myReader.GetInt32(1)); count2--; count1++; } _connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } double jj = Math.Round(OrderTotal(array), 2); var localDate = DateTime.Today; OrderTime = localDate; var error = "dialog box('s) empty. Please fill before submitting"; if (DepComboBox.Text == "" && RequesteeTextBox.Text == "") { MessageBox.Show("Both" + error); DepComboBox.Focus(); } else if (DepComboBox.Text == "") { MessageBox.Show("Department" + error); DepComboBox.Focus(); } else if (RequesteeTextBox.Text == "") { MessageBox.Show("Requestee " + error); RequesteeTextBox.Focus(); } else { _connection.Open(); _command = new SqlCommand("INSERT INTO[Orders]([OrderID],[NumberOfItems],[Department],[Requestee],[OrderDate],[OrderStatus],[OrderTotal]) VALUES" + "('" + _randCode + "', '" + NumOfItems + "', '" + DepComboBox.Text + "', '" + RequesteeTextBox.Text + "', '" + localDate.ToString().Substring(0, 10) + "', '" + status + "', '" + jj + "')", _connection); _command.ExecuteNonQuery(); _command = new SqlCommand("SELECT * FROM Cart", _connection); _command.ExecuteNonQuery(); _connection.Close(); ClearText(); dataGridView1.Rows.Clear(); NumOfItems = 0; MessageBox.Show(message + _randCode + ""); notifyIcon1.ShowBalloonTip(1000, "Important notification", "Something important", ToolTipIcon.Info); } }