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 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(); } }
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 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(); } } }
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."); } }
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(); } } }
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 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 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 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 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 SaveCategoryButton_Click(object sender, EventArgs e) { string newCategoryName; try { newCategoryName = NewCategoryField.Text; if (newCategoryName.Length > 0) { using (var db = new POSApplication.Model.posdbEntities()) { var query2 = (from d in db.cateogries where d.CategoryName == newCategoryName select new { CategoryName = d.CategoryName }).SingleOrDefault(); if (query2 == null) { Model.cateogry c = new Model.cateogry(); c.CategoryName = newCategoryName; db.cateogries.Add(c); db.SaveChanges(); MessageBox.Show("New Category '" + newCategoryName + "' has been added in the system."); resetCategoriesField(); } else { MessageBox.Show("Category already exists in the system."); NewCategoryField.Text = ""; } } } } catch (Exception e1) { MessageBox.Show("Enter Correct CategoryName"); } }
private void SaveButton_Click(object sender, EventArgs e) { string username = ""; string password = ""; if (UserNameField.Text.Length > 0) { username = UserNameField.Text; if (RePasswordField.Text.Length > 0) { if (PasswordField.Text.CompareTo(RePasswordField.Text) == 0) { password = PasswordField.Text; } else { MessageBox.Show("Password does not match with re-password."); } } else { MessageBox.Show("Empty password or re-password field."); } if (username.Length > 0 && password.Length > 0) { using (var dbCtx = new POSApplication.Model.posdbEntities()) { var query = (from u in dbCtx.roles where u.RoleName == RoleCombo.Text select new { RoleID = u.RoleID }).SingleOrDefault(); int roleid = (int)query.RoleID; var query1 = (from t1 in dbCtx.posusers join t2 in dbCtx.roles on new { t1.RoleID } equals new { t2.RoleID } where t1.RoleID == roleid && t1.UserName == username select new { RoleName = t2.RoleName, UserName = t1.UserName, UserID = t1.UserID }).SingleOrDefault(); bool userexists = false; if (query1 != null) { userexists = true; } else { userexists = false; } //if user does not already exists then if (!userexists) { //Creating a new posuser variable Model.posuser r = new Model.posuser(); r.UserName = username; r.RoleID = roleid; r.Password = password; dbCtx.posusers.Add(r); // call SaveChanges method to save posuser dbCtx.SaveChanges(); MessageBox.Show("New User '" + username + "' with role '" + RoleCombo.Text + "' has been added into POS System."); clearFields(); LoadExistingPOSUsers(); } else { MessageBox.Show("User already exists in the system."); clearFields(); } } } } else { MessageBox.Show("Please enter password for the new user."); } }
public int SaveProduct() { using (var db = new POSApplication.Model.posdbEntities()) { string selectedCategory = CategoryList.GetItemText(CategoryList.SelectedItem); string selectedSupplier = SuppliersList.GetItemText(SuppliersList.SelectedItem); string path = System.Reflection.Assembly.GetExecutingAssembly().Location; var directory = System.IO.Path.GetDirectoryName(path); if (selectedCategory.Length > 0) { var query = (from d in db.categories where d.CategoryName == selectedCategory select new { CategoryID = d.CategoryID }).SingleOrDefault(); var supp = (from d in db.suppliers where d.SupplierName == selectedSupplier select new { SupplierID = d.SupplierID }).SingleOrDefault(); if (ProductNameField.Text.Length > 0) { if (selectedProductName == null) { Model.product p = new Model.product(); p.ProductName = ProductNameField.Text; p.ProductDescription = ProductDescriptionField.Text; p.CategoryID = query.CategoryID; if (supp != null) { p.SupplierID = supp.SupplierID; } else { p.SupplierID = 0; } p.ImageFileName = Path.GetFileName(filename); p.Barcode = ProductBarcodeField.Text; p.WarrantyPeriodYears = WarrantyField.Text; p.GuaranteePeriodYears = GuaranteeField.Text; p.ProductCode = ProductCodeField.Text; p.ProductSize = SizeField.Text; p.ProductWeight = WeightField.Text; p.ProductColor = ColorField.Text; p.ProductWidth = WidthField.Text; p.ProductHeight = HeightField.Text; db.products.Add(p); db.SaveChanges(); //adding the same product in inventory with sum quantity 0 /////////////////////////////////////////////////////////////////////////// var existprd = (from ep in db.products where ep.ProductName == p.ProductName && ep.CategoryID == p.CategoryID && ep.ProductCode == p.ProductCode select new { ProductID = ep.ProductID } ).SingleOrDefault(); if (existprd != null) { POSApplication.Model.inventory inv = new POSApplication.Model.inventory(); inv.ProductID = existprd.ProductID; inv.Quantity = 0; inv.PackingTypeID = 0; inv.PurchasePrice = 0; inv.SalePrice = 0; inv.PurchaseDate = null; inv.SaleDate = null; inv.CreateDt = DateTime.Now; inv.UpdateDt = null; inv.SumQuantity = 0; db.inventories.Add(inv); db.SaveChanges(); } /////////////////////////////////////////////////////////////////////////// if (filename != null) { string destfile = System.IO.Path.Combine(path + "\\images", filename); string ImagesDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images"); destfile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\" + Path.GetFileName(filename)); //MessageBox.Show(destfile); var dir = new System.IO.DirectoryInfo(ImagesDirectory); //foreach (var file in dir.EnumerateFiles(Path.GetFileNameWithoutExtension(filename))) //{ // file.Delete(); //} try { //File.Copy(filename.Replace("\\\\","\\"), destfile, true); File.Copy(filename, destfile, true); } catch (Exception e) { MessageBox.Show(e.ToString()); } //Model.AppConfig.imagefile = destfile; //FileStream fs = new FileStream(Model.AppConfig.imagefile, System.IO.FileMode.Open, System.IO.FileAccess.Read); //ProductImage.Image = Image.FromStream(fs); //fs.Close(); } MessageBox.Show("New Product '" + ProductNameField.Text + "' has been added in the system."); clearFields(); loadCategories(); return(1); } else { Model.product p = (from x in db.products where x.ProductName == selectedProductName select x).First(); p.ProductName = ProductNameField.Text; p.ProductDescription = ProductDescriptionField.Text; p.CategoryID = query.CategoryID; if (supp != null) { p.SupplierID = supp.SupplierID; } else { p.SupplierID = 0; } if (ProductImage.Image != null) { p.ImageFileName = Path.GetFileName(filename); } else { p.ImageFileName = null; } p.Barcode = ProductBarcodeField.Text; p.WarrantyPeriodYears = WarrantyField.Text; p.GuaranteePeriodYears = GuaranteeField.Text; p.ProductCode = ProductCodeField.Text; p.ProductSize = SizeField.Text; p.ProductWeight = WeightField.Text; p.ProductColor = ColorField.Text; p.ProductWidth = WidthField.Text; p.ProductHeight = HeightField.Text; db.SaveChanges(); if (filename != null) { string destfile = System.IO.Path.Combine(path + "\\images", filename); string ImagesDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images"); destfile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images\\" + Path.GetFileName(filename)); //MessageBox.Show(destfile); var dir = new System.IO.DirectoryInfo(ImagesDirectory); //foreach (var file in dir.EnumerateFiles(Path.GetFileNameWithoutExtension(filename))) //{ // file.Delete(); //} try { //File.Copy(filename.Replace("\\\\","\\"), destfile, true); File.Copy(filename, destfile, true); } catch (Exception e) { MessageBox.Show(e.ToString()); } //Model.AppConfig.imagefile = destfile; //FileStream fs = new FileStream(Model.AppConfig.imagefile, System.IO.FileMode.Open, System.IO.FileAccess.Read); //ProductImage.Image = Image.FromStream(fs); //fs.Close(); //return 1; } else { } MessageBox.Show("Product '" + selectedProductName + "' has been updated."); clearFields(); return(1); } } else { MessageBox.Show("Enter name for the new Product."); return(0); } } else { MessageBox.Show("Select a Category for the new Product."); return(0); } } }