Exemplo n.º 1
0
        private void LoadDataGrid(string joinedCustomerId)
        {
            var customerIds = StationIdHelper.SeperateStationId(CustomerDropDown.SelectedValue.ToString());

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


            var orders = db.Orders.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId).OrderByDescending(aa => aa.OrderDate).ToList();

            if (orders.Count == 0)
            {
                MessageBox.Show("No Order to show");
                dataGridView1.DataSource = null;
                return;
            }

            var orderDataGrid = orders.Select(aa => new
            {
                Order_Id       = StationIdHelper.StationIdJoined(aa.StationOrderId, aa.OrderId),
                Customer_Name  = aa.Customer.Name,
                Date           = aa.OrderDate,
                IsAdvanceOrder = IsAdvance(aa.IsAdvanceOrder),
                DeliveryDate   = DeliveryDate(aa),
                IsDelivered    = IsDelivered(aa),
                Total_Bill     = CalculateTotalBill(StationIdHelper.StationIdJoined(aa.StationOrderId, aa.OrderId))
            }
                                              ).ToList();


            dataGridView1.DataSource = orderDataGrid;
        }
        private void MarkOrderButton_Click(object sender, EventArgs e)
        {
            var SelectedRow = dataGridView1.CurrentRow;

            if (SelectedRow == null)
            {
                MessageBox.Show("No data selected");
                return;
            }
            var joinedOrderId = SelectedRow.Cells["Order_Id"].Value.ToString();

            var orderIds = StationIdHelper.SeperateStationId(joinedOrderId);

            int orderId        = int.Parse(orderIds[1]);
            int stationOrderId = int.Parse(orderIds[0]);

            var order = db.Orders.Where(aa => aa.OrderId == orderId && aa.StationOrderId == stationOrderId).FirstOrDefault();

            order.IsDelivered = true;
            order.StatusCode  = (int)LocalDBStatusCode.Updated;
            try
            {
                db.SaveChanges();
                MessageBox.Show("SuccessFully marked delivered");
            }
            catch (Exception ee)
            {
                MessageBox.Show("Fail to mark order \n" + ee.Message);
            }

            OnLoad();
        }
Exemplo n.º 3
0
        private void LoadDataGrid(string joinedCustomerId)
        {
            var customerIds       = StationIdHelper.SeperateStationId(joinedCustomerId);
            int stationCustomerId = int.Parse(customerIds[0]);
            int customerId        = int.Parse(customerIds[1]);


            var payments = db.OrderPaymentMades.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId).ToList();

            if (payments.Count > 0)
            {
                var paymentGrid = payments.Select(
                    aa => new
                {
                    CustomerName = aa.Customer.Name,
                    CustomerId   = StationIdHelper.StationIdJoined(aa.StationCustomerId, aa.CustomerId),
                    Date         = aa.Date,
                    Payment      = aa.PaymentMade
                }
                    ).ToList();
                dataGridView1.DataSource = paymentGrid;
            }

            else
            {
                MessageBox.Show("No payment to show");
            }
        }
Exemplo n.º 4
0
        private int LoadDuePayments(string joinedCustomerId)
        {
            var customerIds       = StationIdHelper.SeperateStationId(joinedCustomerId);
            int stationCustomerId = int.Parse(customerIds[0]);
            int customerId        = int.Parse(customerIds[1]);


            var OrderPayments = (int?)db.OrderLines.Where(aa => aa.Order.CustomerId == customerId && aa.Order.StationCustomerId == stationCustomerId).Select(aa => aa.PricePerUnit * aa.WeightInKg).Sum();

            if (OrderPayments == null)
            {
                OrderPayments = 0;
            }

            int paymentmadeCount = db.OrderPaymentMades.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId)
                                   .Select(aa => aa.PaymentMade).Count();

            int paymentsMade = 0;

            if (paymentmadeCount > 0)
            {
                paymentsMade = db.OrderPaymentMades.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId)
                               .Select(aa => aa.PaymentMade).Sum();
            }

            int OrderPaymentDue = 0;

            OrderPaymentDue = (int)OrderPayments - paymentsMade;

            return(OrderPaymentDue);
        }
Exemplo n.º 5
0
        private void LoadCustomerDataf()
        {
            List <string> customerIds       = StationIdHelper.SeperateStationId(CustomerComboBox.SelectedValue.ToString());
            int           customerId        = int.Parse(customerIds[1]);
            int           stationCustomerId = int.Parse(customerIds[0]);
            var           custoemr          = db.Customers.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId).FirstOrDefault();

            AddressTextBox.Text = custoemr.Address;
            CustomerPhone.Text  = custoemr.Phone;
        }
Exemplo n.º 6
0
        public OrderReturn(string joinedOrderId)
        {
            InitializeComponent();
            var orderIds = StationIdHelper.SeperateStationId(joinedOrderId);

            int orderId        = int.Parse(orderIds[1]);
            int stationOrderId = int.Parse(orderIds[0]);

            order = db.Orders.Where(aa => aa.OrderId == orderId && aa.StationOrderId == stationOrderId).Include(aa => aa.OrderLines).FirstOrDefault();
        }
        private int CalculateTotalBill(string joinedOrderId)
        {
            var OrderIds = StationIdHelper.SeperateStationId(joinedOrderId);

            int orderId        = int.Parse(OrderIds[1]);
            int stationOrderId = int.Parse(OrderIds[0]);

            int TotalBill = (int)db.OrderLines.Where(aa => aa.OrderId == orderId && aa.StationOrderId == stationOrderId).Select(aa => aa.PricePerUnit * aa.WeightInKg).Sum();

            return(TotalBill);
        }
Exemplo n.º 8
0
        public CompleteOrderDetails(string joinedOrderId)
        {
            InitializeComponent();
            var OrderIds       = StationIdHelper.SeperateStationId(joinedOrderId);
            int orderId        = int.Parse(OrderIds[1]);
            int stationOrderId = int.Parse(OrderIds[0]);

            order = db.Orders.Where(aa => aa.OrderId == orderId && aa.StationOrderId == stationOrderId).FirstOrDefault();

            InitializeOrderDetails();
            InitializeDataGrid();
        }
Exemplo n.º 9
0
        private void OldPaymentButton_Click(object sender, EventArgs e)
        {
            if (CustomerDropDown.SelectedValue == null)
            {
                MessageBox.Show("Please seelct some customer");
                return;
            }

            var joinedCustomerId = CustomerDropDown.SelectedValue.ToString();

            var CustomerIds = StationIdHelper.SeperateStationId(joinedCustomerId);

            int stationCustId = int.Parse(CustomerIds[0]);

            int custId = int.Parse(CustomerIds[1]);

            AddOldPayment oldPaymentForm = new AddOldPayment(custId, stationCustId, this);

            oldPaymentForm.ShowDialog();
        }
        private void InitializeValue(string joinedCustomerId)
        {
            var customerIds = StationIdHelper.SeperateStationId(joinedCustomerId);

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

            customer           = db.Customers.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId).FirstOrDefault();
            CustomerLabel.Text = customer.Name;

            var duePay     = LoadPreviousBill();
            int duePayment = 0;

            if (duePay != null)
            {
                duePayment = (int)duePay;
            }

            DueAmountField.Value = duePayment;
        }
        private void OrderDetailButton_Click(object sender, EventArgs e)
        {
            string joinedOrderId = OrderIdField.Text;

            List <string> orderIds;
            int           stationOrderId;
            int           orderId;

            try
            {
                orderIds       = StationIdHelper.SeperateStationId(joinedOrderId);
                stationOrderId = int.Parse(orderIds[0]);
                orderId        = int.Parse(orderIds[1]);
            }
            catch
            {
                MessageBox.Show("Order id is not in correct format");
                return;
            }


            var   orderCount = db.Orders.Where(aa => aa.OrderId == orderId && aa.StationOrderId == stationOrderId).Count();
            Order order;

            if (orderCount > 0)
            {
                order = db.Orders.Where(aa => aa.OrderId == orderId && aa.StationOrderId == stationOrderId).FirstOrDefault();
            }

            if (orderCount == 0)
            {
                MessageBox.Show("No such order found");
                return;
            }

            CompleteOrderDetails orderDetail = new CompleteOrderDetails(joinedOrderId);

            orderDetail.Show();
        }
Exemplo n.º 12
0
        private void LoadPreviousBill()
        {
            var customerIds       = StationIdHelper.SeperateStationId(CustomerComboBox.SelectedValue.ToString());
            int stationCustomerId = int.Parse(customerIds[0]);
            int customerId        = int.Parse(customerIds[1]);


            //var OrderPaymentsDue = db.OrderLines.Where(aa => aa.Order.CustomerId == customerId &&
            //  (aa.IsReturned == false || aa.IsReturned == null).Select(aa => aa.PricePerUnit * aa.WeightInKg).Sum();

            //var ItemsReturnedPayments = db.OrderLines.Where(aa => aa.Order.CustomerId == customerId &&
            //  (aa.IsReturned == true)).Select(aa => aa.PricePerUnit * aa.WeightInKg).Sum();


            var OrderPaymentsDue = db.OrderLines.Where(aa => aa.Order.CustomerId == customerId && aa.Order.StationCustomerId == stationCustomerId).Select(aa => aa.PricePerUnit * aa.WeightInKg).Sum();

            if (OrderPaymentsDue == null)
            {
                OrderPaymentsDue = 0;
            }

            int paymentmadeCount = db.OrderPaymentMades.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId)
                                   .Select(aa => aa.PaymentMade).Count();

            double paymentsMade = 0;

            if (paymentmadeCount > 0)
            {
                paymentsMade = db.OrderPaymentMades.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId)
                               .Select(aa => aa.PaymentMade).Sum();
            }



            OrderPaymentsDue -= paymentsMade;

            OldPaymentField.Value = (int)OrderPaymentsDue;
        }
Exemplo n.º 13
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");
            }
        }