private void closeOrder(MWViewContract mWViewContract) { if (mWViewContract.Sum < 0) { MessageBox.Show("Оплатите долг"); return; } if (!isReturnedAllProducts(mWViewContract)) { return; } CloseOrder closeOrder = new CloseOrder(); if (closeOrder.ShowDialog() == true) { ReturnedLeaseContract returnedLeaseContract = dataBaseAC.ReturnedLeaseContracts.Where(rl => rl.Order_id == mWViewContract.OrderId).FirstOrDefault(); ArchiveLeaseContract archiveLeaseContract = new ArchiveLeaseContract(); archiveLeaseContract.Order_id = returnedLeaseContract.Order_id; archiveLeaseContract.Client_id = returnedLeaseContract.Client_id; archiveLeaseContract.Contract_id = returnedLeaseContract.Contract_id; archiveLeaseContract.Paid_amount = returnedLeaseContract.Paid_amount; archiveLeaseContract.Price_per_day = returnedLeaseContract.Price_per_day; archiveLeaseContract.Delivery_amount = returnedLeaseContract.Delivery_amount; archiveLeaseContract.Delivery_address = returnedLeaseContract.Delivery_address; archiveLeaseContract.Used_days = returnedLeaseContract.Used_days; archiveLeaseContract.Create_datetime = returnedLeaseContract.Create_datetime; archiveLeaseContract.Return_datetime = returnedLeaseContract.Return_datetime; archiveLeaseContract.Close_datetime = closeOrder.CloseTimeSpan; dataBaseAC.ArchiveLeaseContracts.Add(archiveLeaseContract); dataBaseAC.ReturnedLeaseContracts.Remove(returnedLeaseContract); dataBaseAC.SaveChanges(); GetDbToDataGrid(); } }
private void returnOrder(MWViewContract mWViewContract) { ReturnOrder returnOrder = new ReturnOrder(dataBaseAC, mWViewContract); if (returnOrder.ShowDialog() == true) { LeaseContract leaseContract = dataBaseAC.LeaseContracts.Find(mWViewContract.OrderId); if (mWViewContract.Sum < 0 || !returnOrder.IsAllProductReturned) { ReturnedLeaseContract returnedLeaseContract = new ReturnedLeaseContract(); returnedLeaseContract.Order_id = leaseContract.Id; returnedLeaseContract.Client_id = leaseContract.Client_id; returnedLeaseContract.Contract_id = leaseContract.Contract_id; returnedLeaseContract.Paid_amount = leaseContract.Paid_amount; returnedLeaseContract.Price_per_day = leaseContract.Price_per_day; returnedLeaseContract.Delivery_amount = leaseContract.Delivery_amount; returnedLeaseContract.Delivery_address = leaseContract.Delivery_address; returnedLeaseContract.Used_days = leaseContract.Used_days; returnedLeaseContract.Create_datetime = leaseContract.Create_datetime; returnedLeaseContract.Return_datetime = returnOrder.ReturnTimeSpan; returnedLeaseContract.Close_datetime = leaseContract.Close_datetime; dataBaseAC.ReturnedLeaseContracts.Add(returnedLeaseContract); } else { ArchiveLeaseContract archiveLeaseContract = new ArchiveLeaseContract(); archiveLeaseContract.Order_id = leaseContract.Id; archiveLeaseContract.Client_id = leaseContract.Client_id; archiveLeaseContract.Contract_id = leaseContract.Contract_id; archiveLeaseContract.Paid_amount = leaseContract.Paid_amount; archiveLeaseContract.Price_per_day = leaseContract.Price_per_day; archiveLeaseContract.Delivery_amount = leaseContract.Delivery_amount; archiveLeaseContract.Delivery_address = leaseContract.Delivery_address; archiveLeaseContract.Used_days = leaseContract.Used_days; archiveLeaseContract.Create_datetime = leaseContract.Create_datetime; archiveLeaseContract.Return_datetime = returnOrder.ReturnTimeSpan; archiveLeaseContract.Close_datetime = returnOrder.ReturnTimeSpan; dataBaseAC.ArchiveLeaseContracts.Add(archiveLeaseContract); } foreach (ReturnProduct returnProduct in returnOrder.ReturnProducts) { dataBaseAC.Products.Find(returnProduct.Product_id).Count += returnProduct.Count; } dataBaseAC.ReturnProducts.AddRange(returnOrder.ReturnProducts); dataBaseAC.LeaseContracts.Remove(leaseContract); dataBaseAC.SaveChanges(); GetDbToDataGrid(); } }
private void FillData() { Client client = new Client(); List <OrderProduct> orderProducts = new List <OrderProduct>(); OrderProduct orderProduct = new OrderProduct(); List <OtherProductListItem> otherProductListItems = new List <OtherProductListItem>(); OtherProductListItem otherProductListItem = new OtherProductListItem(); List <Payment> payments = new List <Payment>(); List <PaymentListItem> paymentListItems = new List <PaymentListItem>(); PaymentListItem paymentListItem; switch (selectedContract.OrderStatus) { case 0: /// New contracts LeaseContract selectedLeaseContract = dataBaseAC.LeaseContracts.Find(selectedContract.OrderId); client = dataBaseAC.Clients.Find(selectedLeaseContract.Client_id); payments = dataBaseAC.Payments.Where(p => p.Order_id == selectedLeaseContract.Id).ToList(); creationDateTimeLbl.Content = UnixTimeStampToDateTime(selectedLeaseContract.Create_datetime).ToShortDateString(); if (selectedLeaseContract.Return_datetime > 0) { returnDateTimeLbl.Content = UnixTimeStampToDateTime(selectedLeaseContract.Return_datetime).ToShortDateString(); } this.DataContext = selectedLeaseContract; break; case 1: /// Returned lease contracts ReturnedLeaseContract returnedLeaseContract = dataBaseAC.ReturnedLeaseContracts.Where(r => r.Order_id == selectedContract.OrderId).FirstOrDefault(); client = dataBaseAC.Clients.Find(returnedLeaseContract.Client_id); payments = dataBaseAC.Payments.Where(p => p.Order_id == returnedLeaseContract.Order_id).ToList(); creationDateTimeLbl.Content = UnixTimeStampToDateTime(returnedLeaseContract.Create_datetime).ToShortDateString(); if (returnedLeaseContract.Return_datetime > 0) { returnDateTimeLbl.Content = UnixTimeStampToDateTime(returnedLeaseContract.Return_datetime).ToShortDateString(); } this.DataContext = returnedLeaseContract; break; case 2: /// Closed contracts ArchiveLeaseContract archiveLeaseContract = dataBaseAC.ArchiveLeaseContracts.Where(c => c.Order_id == selectedContract.OrderId).FirstOrDefault(); client = dataBaseAC.Clients.Find(archiveLeaseContract.Client_id); payments = dataBaseAC.Payments.Where(p => p.Order_id == archiveLeaseContract.Order_id).ToList(); creationDateTimeLbl.Content = UnixTimeStampToDateTime(archiveLeaseContract.Create_datetime).ToShortDateString(); if (archiveLeaseContract.Return_datetime > 0) { returnDateTimeLbl.Content = UnixTimeStampToDateTime(archiveLeaseContract.Return_datetime).ToShortDateString(); } this.DataContext = archiveLeaseContract; break; } clientFIOLbl.Content = client.Surname + " " + client.Name + " " + client.Middle_name; clientPhoneNumberLbl.Content = client.Phone_number; clientPassNumberLbl.Content = client.Pass_number; clientPhoneNumber2Lbl.Content = client.Phone_number2; clientAddressLbl.Content = client.Address; orderDaysLbl.Content = selectedContract.UsedDays; orderProducts = dataBaseAC.OrderProducts.Where(op => op.Order_id == selectedContract.OrderId).ToList(); foreach (OrderProduct op in orderProducts) { otherProductListItem = new OtherProductListItem(); otherProductListItem.Name = dataBaseAC.Products.Find(op.Product_id).Name; otherProductListItem.Count = op.Count; otherProductListItem.Price = op.Count * op.Price; if (dataBaseAC.ReturnProducts.Where(rp => rp.Order_id == op.Order_id && rp.Product_id == op.Product_id).FirstOrDefault() != null) { otherProductListItem.Return_count = dataBaseAC.ReturnProducts.Where(rp => rp.Order_id == op.Order_id && rp.Product_id == op.Product_id).FirstOrDefault().Count; } otherProductListItems.Add(otherProductListItem); } otherProductListBox.ItemsSource = otherProductListItems; foreach (Payment payment in payments) { paymentListItem = new PaymentListItem(); paymentListItem.Amount = payment.Amount; paymentListItem.DateTime = UnixTimeStampToDateTime(payment.Datetime).ToShortDateString(); paymentListItem.PaymentType = payment.Payment_type; paymentListItems.Add(paymentListItem); } paymentListBox.ItemsSource = paymentListItems; }