// event for save button private void button1_Click_1(object sender, EventArgs e) { if (string.IsNullOrEmpty(NameField.Text) || string.IsNullOrEmpty(PhoneField.Text) || string.IsNullOrEmpty(CityField.Text) || string.IsNullOrEmpty(AddressField.Text)) { MessageBox.Show("Please fill mendatory fields."); } else { Customer cust = new Customer(); cust.Name = NameField.Text; cust.Phone = PhoneField.Text; cust.Address = AddressField.Text; cust.City = CityField.Text; cust.StationCustomerId = (int)Station.StationId; cust.StatusCode = (int)LocalDBStatusCode.Added; db.Customers.Add(cust); db.SaveChanges(); MessageBox.Show("User Added"); LoadCustomers(); var joinedCustomerId = StationIdHelper.StationIdJoined(cust.StationCustomerId, cust.CustomerId); if (orderForm != null) { orderForm.SetCustomer(joinedCustomerId); } this.Close(); } }
private void LoadButton_Click(object sender, EventArgs e) { var startDate = StartDateField.Value.Date; var endDate = EndDateField.Value; FaridiaIronStoreEntities db = new FaridiaIronStoreEntities(); var orders = db.Orders.Where(aa => aa.OrderDate >= startDate && aa.OrderDate <= endDate).OrderBy(aa => aa.OrderDate).ToList(); 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 async void LoadButton_Click(object sender, EventArgs e) { label1.Visible = true; await Task.Yield(); var customersIds = db.Customers.Select(ss => new { customerId = ss.CustomerId, stationCustomerId = ss.StationCustomerId } ); List <customerPayments> customerPaymentsList = new List <customerPayments>(); foreach (var custId in customersIds) { int duePayment = LoadDuePayments(custId.customerId, custId.stationCustomerId); if (duePayment < 0) { customerPayments custPayment = new customerPayments(); custPayment.CustomerName = db.Customers.Where(aa => aa.CustomerId == custId.customerId && aa.StationCustomerId == custId.stationCustomerId).FirstOrDefault().Name; custPayment.JoinedCustomerId = StationIdHelper.StationIdJoined(custId.stationCustomerId, custId.customerId); custPayment.DuePayment = duePayment; customerPaymentsList.Add(custPayment); } } dataGridView1.DataSource = customerPaymentsList; label1.Visible = false; }
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"); } }
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(); }
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); }
private void AddOldPayment_Load(object sender, EventArgs e) { FaridiaIronStoreEntities db = new FaridiaIronStoreEntities(); var customer = db.Customers.Where(aa => aa.CustomerId == customerId && aa.StationCustomerId == stationCustomerId).FirstOrDefault(); CustomerNameLabel.Text = customer.Name; CustomerIdLabel.Text = StationIdHelper.StationIdJoined(stationCustomerId, customerId); OldDuePaymentLabel.Text = LoadPreviousBill().ToString(); }
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 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; }
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); }
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(); }
private void OnLoad() { var Pending = db.Orders.Where(aa => aa.IsAdvanceOrder == true && aa.IsDelivered == false) .OrderBy(aa => aa.DeliveryDate).ToList(); var pendingOrder = Pending.Select(aa => new { Order_Id = StationIdHelper.StationIdJoined(aa.StationOrderId, aa.OrderId), Customer_Name = aa.Customer.Name, Date = aa.OrderDate, DeliveryDate = aa.DeliveryDate, Total_Bill = CalculateTotalBill(aa.OrderId, aa.StationOrderId) } ).ToList(); dataGridView1.DataSource = pendingOrder; }
private void InitializeOrderDetails() { CustomerLabel.Text = order.Customer.Name; OrderIdLabel.Text = StationIdHelper.StationIdJoined(order.StationOrderId, order.OrderId); if (order.Address != null) { AddressField.Text = order.Address; } if (order.Description != null) { DescriptionField.Text = order.Description; } if (order.IsAdvanceOrder) { AdvanceOrderLabel.Text = "Yes"; DeliveryDateLabel.Text = order.DeliveryDate.ToString(); if (order.IsDelivered) { DeliveredLabel.Text = "Yes"; } else { DeliveredLabel.Text = "No"; } } else { AdvanceOrderLabel.Text = "No"; DeliveredLabel.Text = "--"; DeliveryDateLabel.Text = "--"; } OrderDateLabel.Text = order.OrderDate.ToString(); int TotalBill = (int)db.OrderLines.Where(aa => aa.OrderId == order.OrderId && aa.StationOrderId == order.StationOrderId).Select(aa => aa.PricePerUnit * aa.WeightInKg).Sum(); TotalBillLabel.Text = TotalBill.ToString(); }
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(); }
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; }
private void SaveAndPrintButton_Click(object sender, EventArgs e) { SaveButton_Click(null, null); if (_order == null) { MessageBox.Show("Order not saved"); return; } List <InvoiceOrderList> OrdersList = new List <InvoiceOrderList>(); foreach (DataGridViewRow row in dataGridView1.Rows) { InvoiceOrderList order = new InvoiceOrderList(); if (row.Cells["ItemColumn"].Value != null) { order.Item = row.Cells["ItemColumn"].Value.ToString(); } else { order.Item = " "; } if (row.Cells["KiloColumn"].Value != null) { order.Kilo = row.Cells["KiloColumn"].Value.ToString(); } else { order.Kilo = " "; } if (row.Cells["GramColumn"].Value != null) { order.Gram = row.Cells["GramColumn"].Value.ToString(); } else { order.Gram = " "; } if (row.Cells["PricePerUnitColumn"].Value != null) { order.PricePerUnit = row.Cells["PricePerUnitColumn"].Value.ToString(); } else { order.PricePerUnit = " "; } if (row.Cells["TotalPriceColumn"].Value != null) { order.TotalPrice = row.Cells["TotalPriceColumn"].Value.ToString(); } else { order.TotalPrice = " "; } if (row.Cells["BundleColumn"].Value != null) { order.Bundle = row.Cells["BundleColumn"].Value.ToString(); } else { order.Bundle = " "; } if (row.Cells["LengthColumn"].Value != null) { order.Length = row.Cells["LengthColumn"].Value.ToString(); } else { order.Length = " "; } if (row.Cells["PieceCutColumn"].Value != null) { order.PieceCut = row.Cells["PieceCutColumn"].Value.ToString(); } else { order.PieceCut = " "; } OrdersList.Add(order); } string total = TotalField.Value.ToString(); string bill = BillField.Value.ToString(); string paymentMade = PaymentMadeField.Value.ToString().Trim(); string oldpayments = OldPaymentField.Value.ToString().Trim(); string customer = CustomerComboBox.Text.ToString().Trim(); string adress = AddressTextBox.Text.Trim(); string invoiceId = StationIdHelper.StationIdJoined(_order.StationOrderId, _order.OrderId); string detail = DescriptionTextBox.Text.Trim(); string orderDate = DateTime.Today.ToShortDateString(); string deliveryDate = string.Empty; if (AdvanceOrderCheck.Checked) { DateTime dateTime = DeliveryDateField.Value; deliveryDate = dateTime.ToShortDateString(); } else { deliveryDate = DateTime.Today.ToShortDateString(); } Invoice invoice = new Invoice(OrdersList, total, bill, paymentMade, oldpayments, customer, adress, invoiceId, detail, deliveryDate, orderDate); invoice.Show(); this.Close(); }
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"); } }