private void buttonAdd_Click(object sender, EventArgs e) { FormName formName = new FormName(); formName.Text = StringTable.AddNewCategory; formName.NameValue = ""; formName.AllowEmpty = false; formName.ValidateName += delegate(object sender1, ValidateNameEventArgs e1) { if (dataBase.AllCategories.Names.Contains(e1.Name) && e1.Name != e1.OriginalName) { MessageBox.Show(string.Format(StringTable.CategoryAlreadyExists, e1.Name), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); e1.Cancel = true; } }; if (formName.ShowDialog(this) == DialogResult.OK) { CategoryTableAdapter cta = new CategoryTableAdapter(dataBase); CategoryDataSet.CategoryDataTable cdt = cta.GetData(); cdt.AddCategoryRow(formName.NameValue, listBoxCategories.Items.Count + 1); cta.Update(cdt); FillList(); } UpdateWindowState(); }
public int GetIdByName(string name, bool createIfNew) { if (string.IsNullOrEmpty(name)) { return(0); } Category category = GetByName(name); if (category != null) { return(category.CategoryID); } else { // Nicht vorhanden, also neue Kategorie anlegen CategoryTableAdapter cta = new CategoryTableAdapter(dataBase); CategoryDataSet.CategoryDataTable cdt = cta.GetData(); cdt.AddCategoryRow(name, cdt.Rows.Count); cta.Update(cdt); int categoryid = (int)(decimal)dataBase.ExecuteScalar("SELECT @@IDENTITY"); dataBase.UpdateCategories(); return(categoryid); } }
private void buttonImport_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = StringTable.FilterHitbase; if (openFileDialog.ShowDialog(this) == DialogResult.OK) { DataBase dbImport = new DataBase(); dbImport.Open(openFileDialog.FileName); CategoryTableAdapter cta = new CategoryTableAdapter(dataBase); CategoryDataSet.CategoryDataTable cdt = cta.GetData(); int count = listBoxCategories.Items.Count + 1; foreach (Category category in dbImport.AllCategories) { if (dataBase.GetIdByCategory(category.Name) < 0) { cdt.AddCategoryRow(category.Name, count++); } } cta.Update(cdt); dbImport.Close(); FillList(); UpdateWindowState(); } }
private void buttonEdit_Click(object sender, EventArgs e) { if (listBoxCategories.SelectedItem == null) { return; } ListBoxItem item = (ListBoxItem)listBoxCategories.SelectedItem; FormName formName = new FormName(); formName.Text = StringTable.EditCategory; formName.NameValue = item.Category.Name; if (formName.ShowDialog(this) == DialogResult.OK) { int oldId = dataBase.GetIdByCategory(item.Category.Name); CategoryTableAdapter cta = new CategoryTableAdapter(dataBase); CategoryDataSet.CategoryDataTable cdt = cta.GetDataById(item.Category.CategoryID); cdt[0].Name = formName.NameValue; cta.Update(cdt); listBoxCategories.Items[listBoxCategories.SelectedIndex] = new ListBoxItem(cdt[0]); UpdateSoundfiles(oldId, item.Category.Name, formName.NameValue, false); } UpdateWindowState(); }
public void AddNew(string category) { // Nicht vorhanden, also neue Kategorie anlegen CategoryTableAdapter cta = new CategoryTableAdapter(dataBase); CategoryDataSet.CategoryDataTable cdt = cta.GetData(); cdt.AddCategoryRow(category, GetNextOrder()); cta.Update(cdt); dataBase.UpdateCategories(); }
/// <summary> /// Aktualisiert die Order aus der Liste in die Datenbank. /// </summary> private void SetOrderByList() { int index = 1; foreach (ListBoxItem item in listBoxCategories.Items) { CategoryTableAdapter cta = new CategoryTableAdapter(dataBase); CategoryDataSet.CategoryDataTable dt = cta.GetDataById(item.Category.CategoryID); dt[0].Order = index; cta.Update(dt); index++; } }
private void FillList() { listBoxCategories.Items.Clear(); CategoryTableAdapter cta = new CategoryTableAdapter(dataBase); CategoryDataSet.CategoryDataTable cdt = cta.GetData(); if (checkBoxAutoSort.Checked) { foreach (CategoryDataSet.CategoryRow category in cdt.OrderBy(x => x.Name)) { listBoxCategories.Items.Add(new ListBoxItem(category)); } } else { foreach (CategoryDataSet.CategoryRow category in cdt.OrderBy(x => x.Order)) { listBoxCategories.Items.Add(new ListBoxItem(category)); } } }