public void saveNewAccount() { string accountname = ""; string description = ""; string parentaccountname = ""; if (accountnameField.Text.Length > 0) { accountname = accountnameField.Text; } else { MessageBox.Show("Add Account Name First."); return; } if (descriptionField.Text.Length > 0) { description = descriptionField.Text; } if (comboBox1.GetItemText(comboBox1.SelectedItem).Length > 0) { parentaccountname = comboBox1.GetItemText(comboBox1.SelectedItem); } else { MessageBox.Show("Choose Parent Account."); return; } using (var dbCtx = new POSApplication.Model.posdbEntities()) { var existingaccount = dbCtx.accounts.Where(b => b.AccountName == accountname).SingleOrDefault(); if (existingaccount != null) { MessageBox.Show("Account with the same name already exists."); return; } Model.account a = new Model.account(); a.AccountName = accountname; a.Description = description; if (parentaccountname.CompareTo("None") == 0) { a.ParentAccountID = null; } else { a.ParentAccountID = GetAccountID(parentaccountname); } dbCtx.accounts.Add(a); dbCtx.SaveChanges(); MessageBox.Show("New Account '" + accountname + "' has been added."); //refreshing the existing accounts list loadExistingAccounts(); } }
public void SaveProduct() { using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.cateogries where d.CategoryName == ExistingCategoriesCombo.GetItemText(ExistingCategoriesCombo.SelectedItem) select new { CategoryID = d.CategoryID }).SingleOrDefault(); string productname; string productdescription; if (ProductNameField.Text.Length > 0) { productname = ProductNameField.Text; productdescription = ProductDescriptionField.Text; Model.product p = new Model.product(); p.ProductName = ProductNameField.Text; p.ProductDescription = productdescription; p.CategoryID = query.CategoryID; p.ImageFileName = Path.GetFileName(filename); p.Barcode = SetBarcodeField.Text; db.products.Add(p); db.SaveChanges(); MessageBox.Show("New Product '" + productname + "' has been added in the system."); clearFields(); } else { } } }
public void loadCategories() { using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.categories select new { CategoryName = d.CategoryName }).ToList(); CategoryList.Items.Clear(); ExistingCategoryList.Items.Clear(); int a = 0; foreach (var item in query) { if (a == 0) { //CategoryList.Text = item.CategoryName; //ExistingCategoryList.Text = item.CategoryName; CategoryList.Text = "Select Category"; ExistingCategoryList.Text = "Select Category"; } CategoryList.Items.Add(item.CategoryName); ExistingCategoryList.Items.Add(item.CategoryName); a += 1; } } }
public void deleteCategory(string categoryName) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { var itemToRemove = dbCtx.categories.SingleOrDefault(x => x.CategoryName == categoryName); if (itemToRemove != null) { dbCtx.categories.Remove(itemToRemove); dbCtx.SaveChanges(); } } }
public void deleteRegion(string regionName) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { var itemToRemove = dbCtx.regions.SingleOrDefault(x => x.RegionName == regionName); if (itemToRemove != null) { dbCtx.regions.Remove(itemToRemove); dbCtx.SaveChanges(); } } }
public void deletePOSUser(string UserName) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { var itemToRemove = dbCtx.posusers.SingleOrDefault(x => x.UserName == UserName); if (itemToRemove != null) { dbCtx.posusers.Remove(itemToRemove); dbCtx.SaveChanges(); LoadExistingPOSUsers(); } } }
public void resetCategoriesField() { CategoryList.Items.Clear(); using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.categories select new { CategoryName = d.CategoryName }).ToList(); foreach (var item in query) { CategoryList.Items.Add(item.CategoryName); } } }
public string GetAccountName(int?accountid) { using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.accounts where d.AccountID == accountid select new { AccountName = d.AccountName }).SingleOrDefault(); if (query != null) { return(query.AccountName); } } return(null); }
public void LoadExistingPOSUsers() { ExistingUsersList.Items.Clear(); using (var dbCtx = new POSApplication.Model.posdbEntities()) { var query = from d in dbCtx.posusers select new { UserName = d.UserName }; foreach (var r in query) { ExistingUsersList.Items.Add(r.UserName); } } }
public void LoadExistingRegions() { RegionsList.Items.Clear(); using (var dbCtx = new POSApplication.Model.posdbEntities()) { var query = from d in dbCtx.regions select new { Region = d.RegionName }; foreach (var r in query) { RegionsList.Items.Add(r.Region); } } }
private void SaveButton_Click(object sender, EventArgs e) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { //Creating a new reqion variable Model.region r = new Model.region(); r.RegionName = RegionNameField.Text; dbCtx.regions.Add(r); // call SaveChanges method to save student into database dbCtx.SaveChanges(); } LoadExistingRegions(); }
public void DeleteCategory(string categoryName) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { var itemToRemove = dbCtx.categories.SingleOrDefault(x => x.CategoryName == categoryName); if (itemToRemove != null) { dbCtx.categories.Remove(itemToRemove); dbCtx.SaveChanges(); MessageBox.Show("Category " + categoryName + " has been removed."); clearFields(); } } }
private void SaveTransactionsButton_Click(object sender, EventArgs e) { if (isBalanced() == false) { return; } Model.transaction trans; try { using (var db = new POSApplication.Model.posdbEntities()) { foreach (var item in currentTransactions) { trans = new Model.transaction(); trans.accountid = GetAccountID(item.AccountName); if (item.iscredit == 0) { trans.Debit = Decimal.Parse(item.transactionAmount.ToString()); } else { trans.Credit = Decimal.Parse(item.transactionAmount.ToString()); } trans.entrydate = item.transactionDate; trans.entrytime = item.transactionTime.TimeOfDay; trans.description = item.transactionDescription; db.transactions.Add(trans); db.SaveChanges(); } MessageBox.Show("Transactions saved successfully."); } LedgerGridView.DataSource = null; LedgerGridView.DataMember = null; LedgerGridView.Refresh(); CreditAccountID.Text = ""; CreditAmountField.Text = ""; CreditTransactionDescription.Text = ""; DebitAccountID.Text = ""; DebitAmountField.Text = ""; DebitTransactionDescription.Text = ""; } catch (Exception e1) { MessageBox.Show("Transactions could not be saved."); } }
public void loadExistingCategories() { using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.categories select new { CategoryName = d.CategoryName }).ToList(); ExistingCategories.Items.Clear(); foreach (var item in query) { ExistingCategories.Items.Add(item.CategoryName); } } }
private void ExistingCategories_SelectedIndexChanged(object sender, EventArgs e) { string categoryName = ExistingCategories.GetItemText(ExistingCategories.SelectedItem); using (var dbCtx = new POSApplication.Model.posdbEntities()) { var item = dbCtx.categories.SingleOrDefault(x => x.CategoryName == categoryName); if (item != null) { CategoryNameField.Text = item.CategoryName; ParentCategoryList.Text = getCategoryName(item.ParentCategoryID); CategoryDescriptionField.Text = item.Description; } } }
public void loadProductsCombo(int categoryid) { ProductList.Items.Clear(); using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.products where d.CategoryID == categoryid select new { ProductName = d.ProductName }).ToList(); foreach (var item in query) { ProductList.Items.Add(item.ProductName); } } }
public void saveEditedAccount() { string existingaccountname = ""; string newaccountname; string newdescription; string newparentaccount = ""; if (comboBox3.GetItemText(comboBox3.SelectedItem).Length > 0) { existingaccountname = comboBox3.GetItemText(comboBox3.SelectedItem); } if (textBox2.Text.Length > 0) { newaccountname = textBox2.Text; } else { MessageBox.Show("Enter valid account name"); return; } if (textBox3.Text.Length > 0) { newdescription = textBox3.Text; } else { newdescription = ""; } if (comboBox2.GetItemText(comboBox2.SelectedItem).Length > 0) { newparentaccount = comboBox2.GetItemText(comboBox2.SelectedItem); } using (var db = new POSApplication.Model.posdbEntities()) { var existingacct = db.accounts.Where(a => a.AccountName == existingaccountname).SingleOrDefault(); existingacct.AccountName = newaccountname; existingacct.Description = newdescription; existingacct.ParentAccountID = GetAccountID(newparentaccount); db.SaveChanges(); MessageBox.Show("New changes have been saved."); loadExistingAccounts(); comboBox3.Text = newaccountname; } }
public int?getCategoryID(string categoryName) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { var query = (from d in dbCtx.categories where d.CategoryName == categoryName select new { categoryName = d.CategoryName, categoryID = d.CategoryID }).SingleOrDefault(); if (query != null) { return(query.categoryID); } else { return(null); } } }
private void DeleteProductButton_Click(object sender, EventArgs e) { string productname = ExistingProductsList.GetItemText(ExistingProductsList.SelectedItem); using (var dbCtx = new POSApplication.Model.posdbEntities()) { var itemToRemove = dbCtx.products.SingleOrDefault(x => x.ProductName == productname); if (itemToRemove != null) { dbCtx.products.Remove(itemToRemove); dbCtx.SaveChanges(); ExistingProductsList.Items.Remove(ExistingProductsList.SelectedItem); clearFields(); MessageBox.Show("Product Deleted."); } } }
public void deleteCategory(string categoryName) { string selectedCategory = ExistingCategoriesCombo.GetItemText(ExistingCategoriesCombo.SelectedItem); using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.cateogries where d.CategoryName == selectedCategory select new { CategoryID = d.CategoryID, CategoryName = d.CategoryName }).SingleOrDefault(); Model.cateogry c = new Model.cateogry(); c.CategoryID = query.CategoryID; c.CategoryName = query.CategoryName; db.cateogries.Remove(c); db.SaveChanges(); MessageBox.Show("Existing Category " + selectedCategory + " has been deleted."); } }
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { string existingaccountname = comboBox3.GetItemText(comboBox3.SelectedItem); string accountname; string description; string parentaccountname; using (var db = new POSApplication.Model.posdbEntities()) { var a = (from ac in db.accounts where ac.AccountName == existingaccountname select new { Description = ac.Description, ParentAccountID = ac.ParentAccountID }).SingleOrDefault(); textBox2.Text = existingaccountname; textBox3.Text = a.Description; comboBox2.Text = GetAccountName(a.ParentAccountID); } }
private void LoadExistingProducts() { using (var db = new POSApplication.Model.posdbEntities()) { string selectedCategoryName = ExistingCategoryList.GetItemText(ExistingCategoryList.SelectedItem); var query = (from p in db.products join c in db.categories on p.CategoryID equals c.CategoryID //join s in db.suppliers on p.SupplierID equals s.SupplierID where c.CategoryName == selectedCategoryName select new { ProductName = p.ProductName, ProductDescription = p.ProductDescription, Barcode = p.Barcode, ImageFile = p.ImageFileName, SupplierID = p.SupplierID }).ToList(); //ExistingProductList.Items.Clear(); int a = 0; foreach (var item in query) { if (a == 0) { var supp = (from s in db.suppliers where s.SupplierID == item.SupplierID select new { SupplierName = s.SupplierName }).SingleOrDefault(); //ExistingProductList.Text = item.ProductName; //ExistingDescriptionField.Text = item.ProductDescription; //if(supp != null) //{ // ExistingSupplierField.Text = supp.SupplierName; //} //else //{ // ExistingSupplierField.Text = "No Supplier"; //} //ExistingBarcodeField.Text = item.Barcode; //if(item.ImageFile != null) //{ // FileStream fs = new FileStream(item.ImageFile, System.IO.FileMode.Open, System.IO.FileAccess.Read); // ExistingProductImage.Image = Image.FromStream(fs); // fs.Close(); //} } //ExistingProductList.Items.Add(item.ProductName); a += 1; } } }
private void SaveButton_Click(object sender, EventArgs e) { var categoryName = CategoryNameField.Text; var categoryDescription = CategoryDescriptionField.Text; var parentCateogryName = ParentCategoryList.Text; using (var dbCtx = new POSApplication.Model.posdbEntities()) { var item = dbCtx.categories.SingleOrDefault(x => x.CategoryName == categoryName); if (item != null && categoryName.CompareTo(item.CategoryName) == 0) { Model.category c = (from x in dbCtx.categories where x.CategoryName == categoryName select x).First(); c.CategoryName = CategoryNameField.Text; c.ParentCategoryID = getCategoryID(ParentCategoryList.Text); c.Description = CategoryDescriptionField.Text; dbCtx.SaveChanges(); MessageBox.Show("Changes Updated Successfully."); } else if (item == null) { if (categoryName == parentCateogryName) { MessageBox.Show("This will result in Category Loop. Please select a different Parent Category."); } else { var r = new Model.category { CategoryName = categoryName, ParentCategoryID = getCategoryID(parentCateogryName), Description = categoryDescription }; dbCtx.categories.Add(r); dbCtx.SaveChanges(); MessageBox.Show("New Category " + categoryName + " has been added."); SuccessfulCategoryAddition(); } } } loadExistingCategories(); loadParentCategoryCombo(); }
public void deleteAccount() { if (ExistingAccounts.SelectedItem != null) { string existingAccount = (ExistingAccounts.GetItemText(ExistingAccounts.SelectedItem)); using (var dbCtx = new POSApplication.Model.posdbEntities()) { var itemToRemove = dbCtx.accounts.SingleOrDefault(x => x.AccountName == existingAccount); if (itemToRemove != null) { dbCtx.accounts.Remove(itemToRemove); dbCtx.SaveChanges(); } } ExistingAccounts.Items.Remove(ExistingAccounts.SelectedItem); loadExistingAccounts(); } }
public void loadParentCategoryCombo() { using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.categories select new { CategoryName = d.CategoryName }).ToList(); ParentCategoryList.Items.Clear(); int a = 0; foreach (var item in query) { if (a == 0) { ParentCategoryList.Text = item.CategoryName; } ParentCategoryList.Items.Add(item.CategoryName); a += 1; } } }
public void loadExistingSuppliers() { using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.suppliers select new { SupplierName = d.SupplierName }).ToList(); SuppliersList.Items.Clear(); int a = 0; foreach (var item in query) { if (a == 0) { SuppliersList.Text = "Select Supplier"; } SuppliersList.Items.Add(item.SupplierName); a += 1; } } }
public string getCategoryName(int?categoryID) { try { if (categoryID != null) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { var query = (from d in dbCtx.categories where d.CategoryID == categoryID select new { categoryName = d.CategoryName, categoryID = d.CategoryID }).SingleOrDefault(); return(query.categoryName); } } } catch (Exception) { } return(null); }
public void FillAccountsCombos() { using (var db = new POSApplication.Model.posdbEntities()) { //Creating a new reqion variable var acc = db.accounts.Select(x => x.AccountName).ToList(); CreditAccountID.Items.Clear(); //filling credit account combo foreach (var item in acc) { CreditAccountID.Items.Add(item); } //filling debit account combo DebitAccountID.Items.Clear(); foreach (var item in acc) { DebitAccountID.Items.Add(item); } db.SaveChanges(); } }
private void ExistingCategoryList_SelectedIndexChanged_1(object sender, EventArgs e) { var SelectedCategory = ExistingCategoryList.GetItemText(ExistingCategoryList.SelectedItem); using (var db = new POSApplication.Model.posdbEntities()) { var query = (from d in db.products join c in db.categories on d.CategoryID equals c.CategoryID where c.CategoryName == SelectedCategory select new { CategoryName = c.CategoryName, ProductName = d.ProductName }).ToList(); ExistingProductsList.Items.Clear(); foreach (var item in query) { ExistingProductsList.Items.Add(item.ProductName); } } }
public void loadExistingAccounts() { ExistingAccounts.Items.Clear(); using (var db = new POSApplication.Model.posdbEntities()) { var query = db.accounts.ToList(); foreach (var item in query) { ExistingAccounts.Items.Add(item.AccountName); } } using (var db = new Model.posdbEntities()) { var query = (from b in db.accounts select new { AccountName = b.AccountName }).ToList(); comboBox1.Items.Clear(); comboBox2.Items.Clear(); comboBox3.Items.Clear(); int a = 0; foreach (var item in query) { if (a == 0) { comboBox1.Items.Add("None"); comboBox1.Text = "None"; comboBox2.Items.Add("None"); comboBox2.Text = "None"; } a += 1; comboBox1.Items.Add(item.AccountName); comboBox2.Items.Add(item.AccountName); comboBox3.Items.Add(item.AccountName); } } drawChartOfAccount(); }