private void SaveButton_Click(object sender, EventArgs e)
        {
            if (AmountPaidField.Value == 0)
            {
                MessageBox.Show("Please enter Amount Paid");
                return;
            }

            else if (AmountPaidField.Value > DueAmountField.Value)
            {
                MessageBox.Show("Amount paid cannot be greater than due amount");
                return;
            }

            OrderPaymentMade orderPayment = new OrderPaymentMade();

            orderPayment.CustomerId                = customer.CustomerId;
            orderPayment.Date                      = DateTime.Now;
            orderPayment.StationCustomerId         = customer.StationCustomerId;
            orderPayment.StationOrderPaymentMadeId = (int)Station.StationId;
            orderPayment.PaymentMade               = (int)AmountPaidField.Value;
            orderPayment.StatusCode                = (int)LocalDBStatusCode.Added;

            db.OrderPaymentMades.Add(orderPayment);

            try
            {
                db.SaveChanges();
                MessageBox.Show("Payment added successfully");
                this.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show("Unexpected error occured \n" + ee.Message);
            }
        }
Esempio n. 2
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("Please enter orders");
                return;
            }
            #region order
            Order            order          = new Order();
            List <OrderLine> orderLinesList = new List <OrderLine>();
            order.OrderLines = orderLinesList;

            var customerIds = StationIdHelper.SeperateStationId(CustomerComboBox.SelectedValue.ToString());

            int customerId        = int.Parse(customerIds[1]);
            int stationCustomerId = int.Parse(customerIds[0]);

            order.CustomerId        = customerId;
            order.StationCustomerId = stationCustomerId;
            order.IsAdvanceOrder    = AdvanceOrderCheck.Checked;
            order.Address           = AddressTextBox.Text;
            order.Description       = DescriptionTextBox.Text;
            order.IsDelivered       = true;
            order.OrderDate         = DateTime.Now;
            order.StationOrderId    = (int)Station.StationId;
            order.StatusCode        = (int)LocalDBStatusCode.Added;
            if (order.IsAdvanceOrder)
            {
                order.IsAdvanceOrder = true;
                order.DeliveryDate   = DeliveryDateField.Value;
                order.IsDelivered    = false;
            }

            #endregion

            #region payment

            if (PaymentMadeField.Value != 0)
            {
                if (PaymentMadeField.Value - TotalField.Value > 1)
                {
                    MessageBox.Show("Amount Paid cannot be greater than Total Value");
                    return;
                }

                OrderPaymentMade orderPayment = new OrderPaymentMade();
                orderPayment.CustomerId        = (int)order.CustomerId;
                orderPayment.StationCustomerId = order.StationCustomerId;
                orderPayment.Date        = DateTime.Now;
                orderPayment.PaymentMade = (int)PaymentMadeField.Value;
                orderPayment.StationOrderPaymentMadeId = (int)Station.StationId;
                orderPayment.StatusCode = (int)LocalDBStatusCode.Added;
                order.OrderPaymentMades.Add(orderPayment);
            }

            #endregion

            var rows = dataGridView1.Rows;

            if (rows.Count == 0)
            {
                MessageBox.Show("please enter some values");
                return;
            }

            for (int i = 0; i < rows.Count; i++)
            {
                var row = rows[i];

                #region Extras
                if (row.Cells["PricePerUnitColumn"].Value == null)
                {
                    OrderLine orderLine = new OrderLine();
                    orderLine.ItemId             = int.Parse(row.Cells["ItemIdColumn"].Value.ToString());
                    orderLine.PricePerUnit       = double.Parse(row.Cells["TotalPriceColumn"].Value.ToString());
                    orderLine.WeightInKg         = 1;
                    orderLine.StationOrderLineId = (int)Station.StationId;
                    orderLine.StatusCode         = (int)LocalDBStatusCode.Added;
                    //orderLine.isReturned=false
                    orderLinesList.Add(orderLine);
                }

                #endregion

                #region Items
                else
                {
                    OrderLine orderLine = new OrderLine();
                    orderLine.Bundle = int.Parse(row.Cells["BundleColumn"].Value.ToString());
                    if (orderLine.Bundle == 0)
                    {
                        orderLine.Bundle = null;
                    }

                    orderLine.ItemId  = int.Parse(row.Cells["ItemIdColumn"].Value.ToString());
                    orderLine.Lengths = double.Parse(row.Cells["LengthColumn"].Value.ToString());
                    if (orderLine.Lengths == 0)
                    {
                        orderLine.Lengths = null;
                    }
                    orderLine.PieceCut     = int.Parse(row.Cells["PieceCutColumn"].Value.ToString());
                    orderLine.PricePerUnit = double.Parse(row.Cells["PricePerUnitColumn"].Value.ToString());
                    //orderLine.isReturned=false

                    var    kg    = double.Parse(row.Cells["KiloColumn"].Value.ToString());
                    var    grams = double.Parse(row.Cells["GramColumn"].Value.ToString());
                    double totalWeightInKg;
                    if (grams == 0)
                    {
                        totalWeightInKg = kg;
                    }
                    else
                    {
                        totalWeightInKg = kg + (grams / 1000);
                    }
                    orderLine.WeightInKg         = totalWeightInKg;
                    orderLine.StationOrderLineId = (int)Station.StationId;
                    orderLine.StatusCode         = (int)LocalDBStatusCode.Added;
                    orderLinesList.Add(orderLine);
                }
                #endregion
            }

            try
            {
                db.Orders.Add(order);
                db.SaveChanges();
                _order = order;

                MessageBox.Show("Order Saved");

                if (sender != null)
                {
                    this.Close();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("Order Failed");
            }
        }