private void searchControl1_OnSearch(object sender, SearchEventArgs e) { using (var p = new POSEntities()) { var products = p.Products.Where(x => x.Item.Barcode == e.Text && x.Item.Type == ItemType.Quantifiable.ToString()); if (products.Count() == 0) { products = p.Products.Where(x => x.Item.Name.Contains(e.Text) && x.Item.Type == ItemType.Quantifiable.ToString()); if (products.Count() == 0) { if (MessageBox.Show("Would you like to create an item?", "Item not found", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { createItemBtn.PerformClick(); } return; } } itemsTable.Rows.Clear(); e.SearchFound = true; foreach (var i in products) { itemsTable.Rows.Add(i.ItemId, i.Item.Name, i.Cost, i.Supplier.Name); } } }
void setAutoComplete() { using (var p = new POSEntities()) { searchControl.SetAutoComplete(p.Products.Where(x => x.Item.Type == ItemType.Quantifiable.ToString()).GroupBy(y => y.Item.Name).Select(a => a.Key).ToArray()); } }
private async Task SetTable() { itemsTable.InvokeIfRequired(() => { itemsTable.Rows.Clear(); }); await Task.Run(() => { loadingLabelItem.InvokeIfRequired(() => { loadingLabelItem.Visible = true; }); searchControl.InvokeIfRequired(() => { searchControl.Enabled = false; }); using (var p = new POSEntities()) { IEnumerable <Product> prod = p.Products; var rows = prod.Where(x => x.Item.Type == ItemType.Quantifiable.ToString()).Select(y => itemsTable.createRow(y.Item?.Barcode, y.Item.Name, y.Cost, y.Supplier?.Name)).ToArray(); itemsTable.InvokeIfRequired(() => { if (itemsTable.IsDisposed || itemsTable.Disposing) { return; } itemsTable.Rows.AddRange(rows); }); } loadingLabelItem.InvokeIfRequired(() => { loadingLabelItem.Visible = false; }); searchControl.InvokeIfRequired(() => { searchControl.Enabled = true; }); }); }
bool searchItem(string s) { CancelLoading(); IEnumerable <Item> searchElements; ///barcode using (var p = new POSEntities()) { searchElements = p.Items.Where(x => x.Barcode == s); if (searchElements.Count() == 0) { searchElements = p.Items.Where(x => x.Name.Contains(s)); } if (!checkBox1.Checked) { searchElements = searchElements.Where(x => x.QuantityInInventory != 0); } if (searchElements.Count() == 0) { MessageBox.Show("Sorry, Product not found.", "", MessageBoxButtons.OK, MessageBoxIcon.Hand); return(false); } fillTable(searchElements); return(true); } }
public void StartDDL() { using (POSEntities db = new POSEntities()) { var RCategoria = db.Categorias.ToList(); cmbCategoria.DisplayMember = "Categoria1"; cmbCategoria.ValueMember = "id"; cmbCategoria.DataSource = RCategoria; var RAlmacen = db.Almacens.ToList(); cmbAlmacen.DisplayMember = "Almacen1"; cmbAlmacen.ValueMember = "id"; cmbAlmacen.DataSource = RAlmacen; var RUnidadM = db.UnidadMedidas.ToList(); cmbUnidad.DisplayMember = "Name"; cmbUnidad.ValueMember = "id"; cmbUnidad.DataSource = RUnidadM; if (Id != null) { var FoundP = db.Productos.Find(Id); cmbUnidad.SelectedIndex = cmbUnidad.FindString(FoundP.UnidadMedida.Name); cmbCategoria.SelectedIndex = cmbCategoria.FindString(FoundP.Categoria.Categoria1); cmbAlmacen.SelectedIndex = cmbAlmacen.FindString(FoundP.Almacen.Almacen1); txtProducto.Text = FoundP.Producto1; txtPrecioCompra.Text = FoundP.Precio_Compra.ToString(); txtPrecioVenta.Text = FoundP.Precio_Venta.ToString(); txtStock.Text = FoundP.Stock.ToString(); cbarra.Text = FoundP.CodigoBarra; txtCodigo.Text = Id.ToString(); } } }
private void soldTo_SelectedIndexChanged(object sender, EventArgs e) { var newCustomer = validateNewCustomer(soldTo.Text); using (var p = new POSEntities()) { var oldCustomer = p.Customers.FirstOrDefault(x => x.Id == sale.CustomerId); if (newCustomer != null) { if (oldCustomer.Name == newCustomer.Name) { return; } if (MessageBox.Show("Are you sure you want to change Customer?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { soldTo.Text = p.Customers.FirstOrDefault(x => x.Id == sale.CustomerId).Name; return; } } var s = p.Sales.FirstOrDefault(x => x.Id == sale.Id); s.CustomerId = newCustomer.Id; p.SaveChanges(); } }
public void Save(Product product) { try { using (var context = new POSEntities()) { Product Product = new Product { productCode = product.productCode, productName = product.productName, unitPrice = product.unitPrice, buyQuantity = product.buyQuantity, discount = product.discount, discountType = product.discountType, getQuantity = product.getQuantity }; context.Products.Add(Product); context.SaveChanges(); } } catch (Exception ex) { throw ex; } }
Customer validateNewCustomer(string newCustomer) { using (var p = new POSEntities()) { return(p.Customers.FirstOrDefault(x => x.Name == newCustomer)); } }
public void SetItemId(string Id) { using (var p = new POSEntities()) { item = p.Items.FirstOrDefault(x => x.Barcode == Id); barcode.Text = item.Barcode; itemName.Text = item.Name; sellingPrice.Text = string.Format("₱ {0:n}", item.SellingPrice); itemType.Text = item.Type; setTypeColor(item.Type.Trim()); department.Text = item.Department; details.Text = item.Details; ImageBox.Image = Misc.ImageDatabaseConverter.byteArrayToImage(item.SampleImage); var stock = p.InventoryItems.Where(x => x.Product.Item.Barcode == item.Barcode); foreach (var i in stock) { stockTable.Rows.Add(i.SerialNumber, i.Quantity, i.Product.Supplier?.Name); } groupBox9.Text = groupBox9.Text + " - " + stock.Select(x => x.Quantity).DefaultIfEmpty(0).Sum().ToString(); var variations = p.Products.Where(x => x.ItemId == item.Barcode); variationsTable.Rows.Clear(); foreach (var x in variations) { variationsTable.Rows.Add(x.Supplier?.Name, x.Cost); } variationsTable.Columns[1].ReadOnly = UserManager.instance?.currentLogin.CanEditProduct ?? false ? false : true; } }
/// <summary> /// this handles the creation of new customer when the supplied customer is not registered yet. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void soldTo_Validated(object sender, EventArgs e) { if (soldTo.Text == string.Empty) { return; } using (var pos = new POSEntities()) { if (!pos.Customers.Any(x => x.Name == soldTo.Text.Trim())) { if (MessageBox.Show("Customer is not found in database?\nWould you like to register it to proceed? ", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { using (var createCustomer = new CreateCustomerProfile(soldTo.Text)) { createCustomer.OnSave += CreateCustomer_OnSave; if (createCustomer.ShowDialog() == DialogResult.OK) { var text = (string)createCustomer.Tag; soldTo.Text = text; } } } else { soldTo.ResetText(); } } } }
bool RemoveInventoryItem() { if (invTable.RowCount == 0 || !currlogin.CanEditInventory) { return(false); } var cells = invTable.SelectedCells; if (cells[2].Value.ToString() == "Infinite") { return(false); } if (MessageBox.Show("Are you sure you want to remove this from inventory? This action cannot be undone.", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { var id = (int)(cells[0].Value); //string b = barcodeField.Text; //string s = cells[3].Value.ToString(); using (var p = new POSEntities()) { var i = p.InventoryItems.FirstOrDefault(x => x.Id == id); p.InventoryItems.Remove(i); p.SaveChanges(); } // OnSave.Invoke(this, null); changesDone = true; MessageBox.Show("Successfully removed from inventory"); return(true); } return(false); }
/// <summary> /// initializes the values /// </summary> /// <param name="id"></param> private void Initialize(int id) { using (var p = new POSEntities()) { sale = p.Sales.FirstOrDefault(x => x.Id == id); var soldItems = sale.SoldItems; SaleId.Text = sale.Id.ToString(); foreach (var x in soldItems) { itemsTable.Rows.Add(x.Id, x.Product.Item.Name, x.SerialNumber, x.Quantity, string.Format("₱ {0:n}", x.ItemPrice), string.Format("₱ {0:n}", x.Discount), string.Format("₱ {0:n}", (x.Quantity * (x.ItemPrice - x.Discount))), x.Product.Supplier?.Name, "Return Item"); } total.Text = string.Format("₱ {0:n}", sale.Total); amountRecieved.Text = string.Format("₱ {0:n}", sale.AmountRecieved); soldTo.Text = sale.Customer.Name; var items = p.Customers.Select(x => x.Name).ToArray(); soldTo.Items.AddRange(items); soldTo.AutoCompleteCustomSource.AddRange(items); dateOfPurchase.Value = sale.Date.Value; } remaining.Text = string.Format("₱ {0:n}", (sale.Total - sale.AmountRecieved)); }
private void searchControl_OnSearch(object sender, Misc.SearchEventArgs e) { using (var p = new POSEntities()) { var s = p.Customers.Where(x => x.Name.Contains(e.Text)); if (s.Count() == 0) { MessageBox.Show("Entry not found.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } e.SearchFound = true; customerTable.Rows.Clear(); foreach (var i in s) { customerTable.Rows.Add( i.Id, i.Name, i.Address, i.ContactDetails, "Delete", "Transactions" ); } } }
public virtual void Init() { try { using (var p = new POSEntities()) { itemDepartment.Items.Clear(); itemDepartment.AutoCompleteCustomSource.Clear(); var itemDeptGroup = p.Items.GroupBy(x => x.Department); foreach (var i in itemDeptGroup) { //Console.WriteLine("add"); if (i.Key != null) { itemDepartment.Items.Add(i.Key); itemDepartment.AutoCompleteCustomSource.Add(i.Key); } } } var textboxes = this.GetContainedControls <TextBox>(); foreach (var i in textboxes) { i.Leave += Helper.TextBoxTrimSpaces; } } catch { } }
Item getItemById(string id) { using (var p = new POSEntities()) { return(p.Items.FirstOrDefault(x => x.Barcode == id)); } }
private void itemsTable_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex != 6) { return; } if (!UserManager.instance.currentLogin.CanEditItem) { return; } if (MessageBox.Show("Are you sure you want to delete the selected item?", "This will also delete items in inventory.", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { return; } using (var p = new POSEntities()) { var selected = itemsTable.Rows[itemsTable.SelectedCells[0].RowIndex].Cells[0].Value.ToString(); var i = p.Items.FirstOrDefault(x => x.Barcode == selected); p.Items.Remove(i); p.SaveChanges(); } itemsTable.Rows.RemoveAt(e.RowIndex); }
private async void searchControl1_OnSearch(object sender, Misc.SearchEventArgs e) { using (var p = new POSEntities()) { IEnumerable <StockinHistory> s = null; s = p.StockinHistories.Where(x => x.SerialNumber == e.Text); if (s.Count() == 0) { s = p.StockinHistories.AsEnumerable().Where(x => x.ItemName.Contains(e.Text)); } if (dateTimePicker1.Checked) { s = s.Where(x => x.Date.Value.Date == dateTimePicker1.Value.Date); } if (s.Count() == 0) { MessageBox.Show("No items found.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } e.SearchFound = true; histTable.Rows.Clear(); var row = await createRowAsync(s); histTable.Rows.AddRange(row); } }
private void addBtn_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(supplier.Text)) { MessageBox.Show("Supplier can never be empty"); return; } switch (MessageBox.Show("Are you sure you want to continue?", "", MessageBoxButtons.OKCancel)) { case DialogResult.OK: break; case DialogResult.Cancel: return; } using (var p = new POSEntities()) { var newVariation = new Product(); newVariation.Item = p.Items.FirstOrDefault(x => x.Barcode == target.Barcode); newVariation.Supplier = p.Suppliers.FirstOrDefault(x => x.Name == supplier.Text); newVariation.Cost = cost.Value; p.Products.Add(newVariation); p.SaveChanges(); //changesMade = true; varTable.Rows.Add(newVariation.Id, newVariation.Supplier.Name, cost.Value, "Delete"); } supplier.Items.RemoveAt(supplier.SelectedIndex); }
public JsonResult GetAllUser() { POSEntities db = new POSEntities(); var dataList = db.Users.Where(x => x.Status == 1).ToList(); return(Json(dataList, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveProductStock(ProductStock stock) { POS.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage(); POSEntities db = new POSEntities(); retMessage.IsSuccess = true; if (stock.ProductQtyId > 0) { db.Entry(stock).State = EntityState.Modified; retMessage.Messagae = "Update Success!"; } else { db.ProductStocks.Add(stock); retMessage.Messagae = "Save Success!"; } try { db.SaveChanges(); } catch (Exception) { retMessage.IsSuccess = false; } return(Json(retMessage, JsonRequestBehavior.AllowGet)); }
private void Eliminar() { int?Id = GetIdRow(); if (Id != null) { try { DialogResult result = MessageBox.Show("Quiere Eliminartar el registro " + Id.ToString(), "Alerta", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { using (POSEntities db = new POSEntities()) { var forDelete = db.Productos.Find(Id); db.Productos.Remove(forDelete); MessageBox.Show("Registro Eliminado"); db.SaveChanges(); GetGRVData(); } } } catch (Exception) { MessageBox.Show("Registro no pudo ser eliminado verifique no esta asignado a otros registros"); } } }
void resetAutoComplete() { using (var p = new POSEntities()) { searchControl1.SetAutoComplete(p.Suppliers.Select(x => x.Name).ToArray()); } }
private void supplierTable_CellEndEdit(object sender, DataGridViewCellEventArgs e) { var dgt = (DataGridView)sender; var current = dgt.CurrentCell.Value.ToString(); ///name if ((e.ColumnIndex == 1 && current == targetSupplier.Name) || (e.ColumnIndex == 2 && current == targetSupplier.ContactDetails)) { return; } using (var p = new POSEntities()) { var id = (int)(dgt.Rows[e.RowIndex].Cells[0].Value); var supp = p.Suppliers.FirstOrDefault(x => x.Id == id); if (e.ColumnIndex == 1) { supp.Name = dgt.Rows[e.RowIndex].Cells[1].Value.ToString(); } else if (e.ColumnIndex == 2) { supp.ContactDetails = dgt.Rows[e.RowIndex].Cells[2].Value.ToString(); } OnSave?.Invoke(this, null); p.SaveChanges(); MessageBox.Show("Edit saved"); } resetAutoComplete(); }
private void addSuppBtn_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to add a new Supplier?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } using (var p = new POSEntities()) { var name = supplierName.Text.Trim(' '); var contact = contactDetails.Text.Trim(' '); //if(p.Suppliers.Any(x=>x.Name == name )) //{ // MessageBox.Show("Supplier already present."); // return; //} var newSupplier = new Supplier(); newSupplier.Name = name; newSupplier.ContactDetails = contact; p.Suppliers.Add(newSupplier); supplierTable.Rows.Add(newSupplier.Id, newSupplier.Name, newSupplier.ContactDetails, "Delete"); //suppliers.Add(newSupplier); p.SaveChanges(); } resetAutoComplete(); OnSave?.Invoke(this, null); supplierName.ResetText(); contactDetails.ResetText(); }
private void supplierTable_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex != 3) { return; } var dgt = sender as DataGridView; var id = (int)(dgt.Rows[e.RowIndex].Cells[0].Value); if (MessageBox.Show("Are you sure you want to delete supplier: " + dgt.Rows[e.RowIndex].Cells[1].Value.ToString() + "\n\nTo edit details, simply edit the cells in the table." , "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } try { using (var p = new POSEntities()) { var s = p.Suppliers.FirstOrDefault(x => x.Id == id); p.Suppliers.Remove(s); p.SaveChanges(); } } catch { MessageBox.Show("Supplier cannot be deleted\nThis supplier is already referenced in one of the items", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } resetAutoComplete(); dgt.Rows.RemoveAt(e.RowIndex); }
public JsonResult SaveUser(User user) { POSEntities db = new POSEntities(); bool isSuccess = true; if (user.UserId > 0) { db.Entry(user).State = EntityState.Modified; } else { user.Status = 1; user.Password = AppHelper.GetMd5Hash(user.Password); db.Users.Add(user); } try { db.SaveChanges(); } catch (Exception) { isSuccess = false; } return(Json(isSuccess, JsonRequestBehavior.AllowGet)); }
void setAutoComplete() { using (var p = new POSEntities()) { searchControl1.SetAutoComplete(p.InventoryItems.Select(x => x.Product.Item.Name).ToArray()); } }
public static Supplier getSupplier(this Control control) { using (var p = new POSEntities()) { return(p.Suppliers.FirstOrDefault(x => x.Name == control.Text)); } }
private void ImprimirFact(object sender, PrintPageEventArgs e) { using (var db = new POSEntities()) { Factura fac = db.Facturas.Where(x => x.Tipo == txtnudoc.Text).FirstOrDefault(); Font font = new Font("Arial", 9, GraphicsUnit.Point); int width = 300; string line = ""; for (int i = 0; i < width; i++) { line += "-"; } int y = 20; e.Graphics.DrawString("FERRETERIA NAPOLES ", font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString("Calle penetración # 17 Recidencial Amalia", font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString("829-921-7825", font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString("FACTURA# : " + fac.Tipo, font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString("FECHA: " + fac.Fecha_Facturacion.ToString(), font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString("VENCIMIENTO: " + fac.Fecha_Facturacion.ToString(), font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString(line, font, Brushes.Black, new RectangleF(0, y += 10, width, 20)); e.Graphics.DrawString("CANt. DESCRIPCION VALOR ", font, Brushes.Black, new RectangleF(0, y += 10, width, 20)); e.Graphics.DrawString(line, font, Brushes.Black, new RectangleF(0, y += 5, width, 20)); foreach (FacturaDetalle item in fac.FacturaDetalles) { e.Graphics.DrawString(item.Cantida.ToString() + " " + item.Decripcion.Substring(0, 22) + " " + item.Precio.ToString(), font, Brushes.Black, new RectangleF(0, y += 10, width, 20)); } e.Graphics.DrawString(line, font, Brushes.Black, new RectangleF(0, y += 5, width, 20)); e.Graphics.DrawString("DESCUENTO: " + fac.Total_Descuento.ToString(), font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString("TOTAL A PAGAR " + fac.Total_Facturado.ToString(), font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); e.Graphics.DrawString("TOTAL PAGADO " + fac.Total_Facturado.ToString(), font, Brushes.Black, new RectangleF(0, y += 20, width, 20)); } }
private void saveBtn_Click(object sender, EventArgs e) { if (!canSave()) { return; } using (var p = new POSEntities()) { var add = address.Text.Trim(); var cont = contact.Text.Trim(); Customer c = new Customer(); c.Name = name.Text.Trim(); c.Address = add == string.Empty ? null : add; c.ContactDetails = cont == string.Empty ? null : cont; p.Customers.Add(c); p.SaveChanges(); OnSave?.Invoke(this, null); } this.Tag = name.Text.Trim(); DialogResult = DialogResult.OK; this.Close(); }
private static Dto.Brand GetById(int id) { //jalamos base de datos var entities = new POSEntities(); var brandTemp = entities.Brand.Find(id); //traducimos a dto bus var brand = new Brand(); brand.Id = brandTemp.id; brand.Name = brandTemp.name; //retornamos return brand; }
private static Dto.Category GetById(int id) { //jalamos base de datos var entities = new POSEntities(); var categoryTemp = entities.Category.Find(id); //traducimos a dto bus var category = new Category(); category.Id = categoryTemp.id; category.Name = categoryTemp.name; category.Description = categoryTemp.description; //retornamos return category; }
private static List<Dto.Brand> GetByAll() { //jalamos base de datos var entities = new POSEntities(); var brandTemp = entities.Brand; //creamos lista vacia de dto var brandList = new List<Dto.Brand>(); //recorremos la lista de buises temporal foreach (var item in brandTemp) { //traducimos a dto bus var brand = new Brand(); brand.Id = item.id; brand.Name = item.name; brandList.Add(brand); } return brandList; }
private static List<Dto.Category> GetByAll() { //jalamos base de datos var entities = new POSEntities(); var categoryTemp = entities.Category; //creamos lista vacia de dto var listofCategory = new List<Dto.Category>(); //recorremos la lista de employees temporal foreach (var item in categoryTemp) { //traducimos a dto employees var category = new Category(); category.Id = item.id; category.Name = item.name; category.Description = item.description; listofCategory.Add(category); } return listofCategory; }