private void btnEditItems_Click(object sender, EventArgs e) { try { string warehouse, supplier, date; warehouse = cbWarehouses.Text; supplier = cbSuppliers.Text; date = dtpDate.Text; if (!string.IsNullOrEmpty(txtOrderNumber.Text)) { int id = int.Parse(txtOrderNumber.Text); SupplyingOrder order = (from c in ent.SupplyingOrders where c.number == id select c).FirstOrDefault(); obj = new SupplyOrderInfo(order.number); obj.Show(); } else { MessageBox.Show("Error!\n" + "the Order you are trying to update doesn't exist.\n" + "hint: try \"New\" instaed"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnNew_Click(object sender, EventArgs e) { try { string warehouse, supplier, date; warehouse = cbWarehouses.Text; supplier = cbSuppliers.Text; date = dtpDate.Text; if (!string.IsNullOrEmpty(warehouse) && !string.IsNullOrEmpty(supplier) && !string.IsNullOrEmpty(date)) { int warehouseId = (from w in ent.Wharehouses where w.name == warehouse select w.ID).FirstOrDefault(); int supplierId = (from s in ent.Providers where s.name == supplier select s.id).FirstOrDefault(); var d = Convert.ToDateTime(date); SupplyingOrder order = new SupplyingOrder { supplier_id = supplierId, warehouse_id = warehouseId, date = d }; ent.SupplyingOrders.Add(order); ent.SaveChanges(); MessageBox.Show("Order added!\n", "", MessageBoxButtons.OK, MessageBoxIcon.Information); //SupplingOrders_Load(sender, e); obj = new SupplyOrderInfo(order.number); obj.Show(); } else { MessageBox.Show("All Fields Required!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }