예제 #1
0
        public Result Delete(Order order)
        {
            bool res = Entities.Find(I => I.Id == order.Id && I.CustomerId == order.CustomerId) != null;

            if (res)
            {
                Cash        cash        = _cashManager.Entities.Find(I => I.OrderId == order.Id);
                Check       check       = _checkManager.Entities.Find(I => I.OrderId == order.Id);
                Credit      credit      = _creditManager.Entities.Find(I => I.OrderId == order.Id);
                OrderDetail orderDetail = _orderDetailManager.Entities.Find(I => I.OrderId == order.Id);
                Customer    customer    = _customerManager.Entities.Find(I => I.Id == order.CustomerId);
                if (cash != null)
                {
                    _cashManager.Delete(cash);
                }

                if (check != null)
                {
                    _checkManager.Delete(check);
                }

                if (credit != null)
                {
                    _creditManager.Delete(credit);
                }
                if (orderDetail != null)
                {
                    _orderDetailManager.Delete(orderDetail);
                }
                if (customer != null)
                {
                    int orderId = customer.OrderIds.Find(I => I == order.Id);
                    if (orderId != 0)
                    {
                        customer.OrderIds.Remove(orderId);
                        _customerManager.Update(customer);
                    }
                }

                return(base.Delete(Entities.FindIndex(I => I.Id == order.Id)));
            }
            return(new Result {
                ResultState = ResultState.Erorr
            });
        }
        private void btnCheckDelete_Click(object sender, EventArgs e)
        {
            Result result = _checkManager.Delete(new Check
            {
                Id      = int.Parse(txtCheckId.Text),
                OrderId = _orderId,
                Amount  = decimal.Parse(txtCheckAmount.Text),
                Name    = txtCheckName.Text,
                Surname = txtCheckSurname.Text,
                BankId  = int.Parse(txtBankId.Text)
            });

            if (result.ResultState == ResultState.Erorr)
            {
                MessageBox.Show(result.Message, "Hata işlem yapılamadı");
            }
            else
            {
                DataGridCheckFill();
                TextBoxCheckClear();
            }
        }