void loadWarehouseItems(string warehouseName, DataGridView dgv) { Wharehouse warehouse = (from w in ent.Wharehouses where w.name == warehouseName select w).FirstOrDefault(); foreach (WarehouseItem w in ent.WarehouseItems) { if (w.warehouse_id == warehouse.ID) { dgv.Rows.Add(w.order_id, w.Item.Name, w.quantity); } } }
private void btnNew_Click(object sender, EventArgs e) { try { string name, address, empName; name = txtName.Text; address = rtbAddress.Text; empName = cbEmployess.Text; if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(address) && !string.IsNullOrEmpty(empName)) { try { Employee employee = (from emp in ent.Employees where emp.Name == empName select emp).FirstOrDefault(); Wharehouse warehouse = new Wharehouse(); warehouse.name = name; warehouse.address = address; warehouse.employee_id = employee.id; ent.Wharehouses.Add(warehouse); ent.SaveChanges(); MessageBox.Show("Warehouse added!"); Warehouses_Load(sender, e); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("all data Required!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnUpdate_Click(object sender, EventArgs e) { try { string name, address, empName; name = txtName.Text; address = rtbAddress.Text; empName = cbEmployess.Text; if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(address) && !string.IsNullOrEmpty(empName)) { int id = int.Parse(txtId.Text); Wharehouse warehouse = new Wharehouse(); warehouse = (from w in ent.Wharehouses where w.ID == id select w).FirstOrDefault(); int empId = (from employee in ent.Employees where employee.Name == empName select employee.id).FirstOrDefault(); warehouse.name = name; warehouse.address = address; warehouse.employee_id = empId; ent.SaveChanges(); MessageBox.Show("Warehouse Updated!"); Warehouses_Load(sender, e); } else { MessageBox.Show("Select Warehouse to edit or Enter all data!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnDelete_Click(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(txtId.Text)) { int id = int.Parse(txtId.Text); Wharehouse warehouse = new Wharehouse(); warehouse = (from i in ent.Wharehouses where i.ID == id select i).FirstOrDefault(); if (warehouse.WarehouseItems.Count > 0) { MessageBox.Show("Cant Delete Warehouse!\n" + "Move all Items from Warehouse first!\n"); } else { ent.Wharehouses.Remove(warehouse); ent.SaveChanges(); MessageBox.Show("Warehouse Deleted!"); Warehouses_Load(sender, e); } } else { MessageBox.Show("Select an Item to Delete!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnView_Click(object sender, EventArgs e) { dgvItems.Rows.Clear(); if (cbWarehouses.SelectedIndex != -1 && nudDuration.Value > 0) { string warehouseName = cbWarehouses.Text; Wharehouse warehouse = (from w in ent.Wharehouses where w.name == warehouseName select w).FirstOrDefault(); int duration = (int)nudDuration.Value; // foreach item in warehouseItems, get orderId // in SupplyOrderItems where itemCode, and orderId get date foreach (WarehouseItem wItem in ent.WarehouseItems) { if (wItem.warehouse_id == warehouse.ID) { SupplyingOrder_Items item = (from i in ent.SupplyingOrder_Items where i.item_code == wItem.item_id && i.order_number == wItem.order_id select i).FirstOrDefault(); // calc date DateTime expiratinDate = (DateTime.Today).AddDays(duration); if (item.expiration_date == expiratinDate) { dgvItems.Rows.Add(item.order_number, item.Item.Name, wItem.quantity, item.Production_Date, item.expiration_date); } } } MessageBox.Show("Done!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Select warehouse, and Enter duration"); } }
private void btnMove_Click(object sender, EventArgs e) { try { // if both warehouses selected if (!string.IsNullOrEmpty(warehouseFrom) && !string.IsNullOrEmpty(warehouseTo)) { // if row selected if (rowIndex != -1) { // get item details string itemName = dgvWarehouseFrom.Rows[rowIndex].Cells[1].Value.ToString(); Item item = (from i in ent.Items where i.Name == itemName select i).FirstOrDefault(); // get warehouseItems from row int orderId = int.Parse(dgvWarehouseFrom.Rows[rowIndex].Cells[0].Value.ToString()); WarehouseItem warehouseFromItems = (from w in ent.WarehouseItems where w.Wharehouse.name == warehouseFrom && w.Item.Name == itemName && w.order_id == orderId select w).FirstOrDefault(); // get warehouse_To details Wharehouse warehouse = (from w in ent.Wharehouses where w.name == warehouseTo select w).FirstOrDefault(); // TODO: check if exist, increase quantity // insert into warehouse items WarehouseItem warehouseItemTo = (from w in ent.WarehouseItems where w.item_id == warehouseFromItems.item_id && w.warehouse_id == warehouse.ID && w.order_id == warehouseFromItems.order_id select w ).FirstOrDefault(); if (warehouseItemTo == null) { warehouseItemTo = new WarehouseItem(); warehouseItemTo.item_id = warehouseFromItems.item_id; warehouseItemTo.warehouse_id = warehouse.ID; warehouseItemTo.order_id = warehouseFromItems.order_id; warehouseItemTo.quantity = warehouseFromItems.quantity; ent.WarehouseItems.Add(warehouseItemTo); } else { warehouseItemTo.quantity += warehouseFromItems.quantity; } // Move from transaction moveFrom = 4, moveTo = 3 Transaction moveFrom = new Transaction(); moveFrom.date = DateTime.Now; moveFrom.type_id = 4; moveFrom.order_id = warehouseFromItems.order_id; moveFrom.item_id = warehouseFromItems.item_id; moveFrom.wharehouse_id = warehouseFromItems.warehouse_id; moveFrom.quantity = warehouseFromItems.quantity; // total item quantity in all warehouses moveFrom.total_quantity_for_item_in_wharehouse = (int)item.quantity; // total item quantity in current warehouse moveFrom.total_quantity_for_product_in_wharehouse = (int)item.quantity; ent.Transactions.Add(moveFrom); ent.SaveChanges(); ent.WarehouseItems.Remove(warehouseFromItems); // Move to transaction Transaction moveTo = new Transaction(); moveTo.date = DateTime.Now; moveTo.type_id = 3; moveTo.move_from_transaction_id = moveFrom.id; moveTo.order_id = warehouseItemTo.order_id; moveTo.item_id = warehouseItemTo.item_id; moveTo.wharehouse_id = warehouseItemTo.warehouse_id; moveTo.quantity = warehouseItemTo.quantity; // total item quantity in all warehouses moveTo.total_quantity_for_item_in_wharehouse = (int)item.quantity; // total item quantity in current warehouse moveTo.total_quantity_for_product_in_wharehouse = (int)item.quantity; ent.Transactions.Add(moveTo); ent.SaveChanges(); MoveItems_Load(sender, e); } else { MessageBox.Show("Select Item", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Select warehouses", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }