private void saveBtn_Click(object sender, RoutedEventArgs e) { if (_contractor != null) { using (var db = new ContractorContext()) { _contractor.ContractorName = ContractorNameBox.Text; _contractor.ManagerName = ManagerNameBox.Text; _contractor.ContactEmail = Email.Text; _contractor.ContactPhone = PhoneNumber.Text; db.Contractors.AddOrUpdate(_contractor); db.SaveChanges(); } } else { using (var db = new ContractorContext()) { Contractor nc = new Contractor() { ContractorName = ContractorNameBox.Text, ManagerName = ManagerNameBox.Text, ContactEmail = Email.Text, ContactPhone = PhoneNumber.Text }; db.Contractors.AddOrUpdate(nc); db.SaveChanges(); } } this.Close(); }
private void DeleteOrderBtn_Click(object sender, RoutedEventArgs e) { if (OrdersListBox.SelectedItem == null) return; using (var db = new ContractorContext()) { Order item = (Order) OrdersListBox.SelectedItem; db.Orders.Remove(db.Orders.Find(item.OrderId)); db.SaveChanges(); FillContractorOrders(); ClearContractorDetails(); } }
private void RemoveBtn_Click(object sender, RoutedEventArgs e) { if (ContractorList.SelectedItem == null) return; Contractor item = (Contractor) ContractorList.SelectedItem; using (var db = new ContractorContext()) { if (db.Contractors.Find(item.ContractorId).Orders != null) { foreach (var order in db.Contractors.Find(item.ContractorId).Orders) { db.Orders.Remove(order); } } db.Contractors.Remove(db.Contractors.Find(item.ContractorId)); db.SaveChanges(); FillContractorList(); } }
private void FillContractorOrders(object sender, EventArgs e) { OrdersListBox.Items.Clear(); Contractor theOne = (Contractor) ContractorList.SelectedItem; if (theOne == null) return; using (var db = new ContractorContext()) { foreach (var item in db.Orders.ToList()) { if (item.ContractorId == theOne.ContractorId) { OrdersListBox.Items.Add(item); } } } }
private void FillContractorList() { using (var db = new ContractorContext()) { ContractorList.Items.Clear(); if (db.Contractors.ToList().Count <= 0) return; foreach (var item in db.Contractors.ToList()) { ContractorList.Items.Add(item); } } }
private void delPositionBtn_Click(object sender, RoutedEventArgs e) { if (_order != null) { using (var db = new ContractorContext()) { if (((PositionsQty)OrderPositions.SelectedItem).OrderId == _order.OrderId) { db.PositionsQties.Remove(db.PositionsQties.Find(((PositionsQty)OrderPositions.SelectedItem).Id)); db.SaveChanges(); } } } GridItems.Remove((PositionsQty)OrderPositions.SelectedItem); OrderPositions.Items.Refresh(); }
private void SaveBtn_Click(object sender, RoutedEventArgs e) { using (var db = new ContractorContext()) { if (_order == null) { Order order = new Order(); if (InvoiceNumberBox.Text != null) order.InvoiceNumber = InvoiceNumberBox.Text; order.DeliveryDate = DeliveryDatePick.SelectedDate ?? DateTime.Now; order.OrderDate = OrderDatePick.SelectedDate ?? DateTime.Now; if (InvoiceSumBox.Text != null) order.Sum = Decimal.Parse(InvoiceSumBox.Text.Replace('.', ',')); order.ContractorId = _contractor.ContractorId; order.PositionsQty = new List<PositionsQty>(); foreach (PositionsQty item in GridItems) { db.PositionsQties.AddOrUpdate(item); } db.Orders.AddOrUpdate(order); db.SaveChanges(); this.Close(); } else { Order order = _order; if (InvoiceNumberBox.Text != null) order.InvoiceNumber = InvoiceNumberBox.Text; order.DeliveryDate = DeliveryDatePick.SelectedDate ?? DateTime.Now; order.OrderDate = OrderDatePick.SelectedDate ?? DateTime.Now; if (InvoiceSumBox.Text != null) order.Sum = decimal.Parse(InvoiceSumBox.Text.Replace('.', ',')); order.ContractorId = _contractor.ContractorId; order.PositionsQty = new List<PositionsQty>(); foreach (PositionsQty item in GridItems) { db.PositionsQties.AddOrUpdate(item); } db.Orders.AddOrUpdate(order); db.SaveChanges(); this.Close(); } } }
private void FillOrderInfo() { InvoiceNumberBox.Text = _order.InvoiceNumber; OrderDatePick.SelectedDate = _order.OrderDate; DeliveryDatePick.SelectedDate = _order.DeliveryDate; InvoiceSumBox.Text = _order.Sum.ToString(CultureInfo.CurrentCulture); using (var db = new ContractorContext()) { foreach (var item in db.PositionsQties.ToList().Where(item => item.OrderId == _order.OrderId)) { GridItems.Add(item); } } }