private void textAddCategory_KeyUp(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Enter && textAddCategory.Text.Trim() != String.Empty) { if (Categories.Local.FirstOrDefault(c => c.Title == textAddCategory.Text.Trim()) == null) { Category newCat = new Category(); newCat.Title = textAddCategory.Text.Trim(); newCat.VersionControl = DateTime.Now; Categories.Add(newCat); ListViewItem item = new ListViewItem(newCat.ToString()); item.Tag = newCat; listCategories.Items.Add(item); } else { errorProvider.SetIconPadding(textAddCategory, -20); errorProvider.SetError(textAddCategory, "Category exist"); } }else errorProvider.SetError(textAddCategory, null); }
private void textCategoryAdd_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && textCategoryAdd.Text.Trim() != string.Empty) { if (Global.DB.Categories.Local.SingleOrDefault(q => q.Title == textCategoryAdd.Text.Trim()) == null) { Category cat = new Category() { Title = textCategoryAdd.Text.Trim(), VersionControl = DateTime.Now }; Global.DB.Categories.Add(cat); ListViewItem item = new ListViewItem(cat.Title); item.Tag = cat; listCategories.Items.Add(item); listCategories.Sort(); item.Selected = true; if (CategoriesChanged != null) CategoriesChanged.Invoke(this, null); } else { errorProvider.SetIconPadding(textCategoryAdd, -15); errorProvider.SetError(textCategoryAdd, "Category exist!"); } } }
private void textCategoryAdd_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && textCategoryAdd.Text.Trim() != String.Empty && Global.DBHelp.Categories.Local.FirstOrDefault(q => q.Title == textCategoryAdd.Text.Trim()) == null) { Category newCategory = new Category() { Title = textCategoryAdd.Text.Trim(), VersionControl = DateTime.Now }; Global.DBHelp.Categories.Add(newCategory); comboCommandCategory.Items.Add(newCategory); listCategories.Items.Add(new ListViewItem(newCategory.Title) { Tag = newCategory }); listCommands.Groups.Add(new ListViewGroup(newCategory.Title, newCategory.Title)); buttonSave.Enabled = true; } }
private void textCategoryAdd_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && textCategoryAdd.Text.Trim() != String.Empty) { string txt = textCategoryAdd.Text.Trim(); if (DB.Categories.Local.FirstOrDefault(c => c.Title == txt) == null) { Category newCategory = new Category() { Title = txt, Color = Color.Black.ToArgb(), Icon = -1, VersionControl = DateTime.Now }; DB.Categories.Add(newCategory); ListViewItem item = new ListViewItem(txt); item.Tag = newCategory; listCategories.Items.Add(item); comboExpenseAddCategory.Items.Add(newCategory); comboIncomeAddCategory.Items.Add(newCategory); comboPlanAddCategory.Items.Add(newCategory); buttonSave.Enabled = true; } else { errorProvider.SetIconPadding(textCategoryAdd, -20); errorProvider.SetError(textCategoryAdd, "Category exist"); } } else errorProvider.SetError(textCategoryAdd, "Wrong name category"); }
private bool ParseTransactionString(string txt, out Category category, out string title, out decimal amount) { // find category category = null; if (txt[0] == '[') { int indexCloseBracket = txt.IndexOf(']'); if (indexCloseBracket > 0 && indexCloseBracket < txt.Length - 1) { category = DB.Categories.Local.FirstOrDefault(c => c.Title == txt.Substring(1, indexCloseBracket - 1)); if (category != null) txt = txt.Substring(indexCloseBracket + 1, txt.Length - indexCloseBracket - 1); } } // find amount StringBuilder strAmount = new StringBuilder(); int i = txt.Length - 1; while (i >= 0 && (Char.IsNumber(txt[i]) || txt[i] == ',' || txt[i] == '.')) { strAmount.Insert(0, txt[i]); i--; } strAmount = strAmount.Replace('.', ','); amount = 0; if (decimal.TryParse(strAmount.ToString(), out amount)) txt = txt.Substring(0, txt.Length - strAmount.ToString().Length); // find title title = txt.Trim(); if (title != String.Empty) return true; else return false; }