private void comboBox_Initialized(object sender, EventArgs e) { DBConnection.FillCombo("faculties", comboBox); }
private void saveRoom_MouseUp(object sender, EventArgs e) { try { if (txtName.Text == null || txtName.Text == "") { MessageBox.Show("Room name is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (txtSize.Text == null || txtSize.Text == "") { MessageBox.Show("Room size is required!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (int.Parse(comboBox.SelectedIndex.ToString()) < 0) { MessageBox.Show("Please select building!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); return; } if (txtId.Text == "") { string code = null; for (int i = 1; i < 1000; i++) { code = "r" + i.ToString("000"); DataView data = DBConnection.Select("rooms", "'*'", " code = '" + code + "'").DefaultView; if (data.Count == 0) { break; } } string values = "'" + txtName.Text + "', '" + Convert.ToInt32(txtSize.Text) + "', '" + code.ToString() + "', '" + comboBox.SelectedValue + "', '" + txtNote.Text + "'"; int result = DBConnection.Create("rooms", "name, size, code, building_id, note", values); if (result > 0) { MessageBox.Show("New room has been successfully created!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } else if (Convert.ToInt32(txtId.Text) > 0) { string values = " name='" + txtName.Text + "', size='" + Convert.ToInt32(txtSize.Text) + "', code='" + txtCode.Text + "', building_id='" + comboBox.SelectedValue + "', note='" + txtNote.Text + "'"; int result = DBConnection.Update("rooms", values, Convert.ToInt32(txtId.Text)); if (result > 0) { MessageBox.Show("Room has been successfully updated!", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } } Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }