/// <summary>
 /// Create a new HeaderDeliveryTransaction object.
 /// </summary>
 /// <param name="receiptID">Initial value of the ReceiptID property.</param>
 /// <param name="staffID">Initial value of the StaffID property.</param>
 /// <param name="customerID">Initial value of the CustomerID property.</param>
 /// <param name="destinationID">Initial value of the DestinationID property.</param>
 /// <param name="vehicle">Initial value of the Vehicle property.</param>
 /// <param name="totalPayment">Initial value of the TotalPayment property.</param>
 /// <param name="transactionDate">Initial value of the TransactionDate property.</param>
 /// <param name="expectedDeliveredDate">Initial value of the ExpectedDeliveredDate property.</param>
 /// <param name="deliveredDate">Initial value of the DeliveredDate property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 public static HeaderDeliveryTransaction CreateHeaderDeliveryTransaction(global::System.String receiptID, global::System.String staffID, global::System.String customerID, global::System.String destinationID, global::System.String vehicle, global::System.Decimal totalPayment, global::System.DateTime transactionDate, global::System.DateTime expectedDeliveredDate, global::System.DateTime deliveredDate, global::System.String status)
 {
     HeaderDeliveryTransaction headerDeliveryTransaction = new HeaderDeliveryTransaction();
     headerDeliveryTransaction.ReceiptID = receiptID;
     headerDeliveryTransaction.StaffID = staffID;
     headerDeliveryTransaction.CustomerID = customerID;
     headerDeliveryTransaction.DestinationID = destinationID;
     headerDeliveryTransaction.Vehicle = vehicle;
     headerDeliveryTransaction.TotalPayment = totalPayment;
     headerDeliveryTransaction.TransactionDate = transactionDate;
     headerDeliveryTransaction.ExpectedDeliveredDate = expectedDeliveredDate;
     headerDeliveryTransaction.DeliveredDate = deliveredDate;
     headerDeliveryTransaction.Status = status;
     return headerDeliveryTransaction;
 }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //if button submit is clicked, validate the field according to the project case
            if (cmbStaff.SelectedIndex < 0)
            {
                MessageBox.Show("Please select delivery staff");
            }
            else if (dateTrans.Value < DateTime.Now.Date)
            {
                MessageBox.Show("Transaction date must be at least today");
            }
            else if (cmbVehicle.SelectedIndex < 0)
            {
                MessageBox.Show("Please select vehicle");
            }
            else
            {
                //if all field is valid, insert into table headerdeliverytransaction
                string oldID = "TR000";
                HeaderDeliveryTransaction[] temp = (from x in ent.HeaderDeliveryTransaction select x).ToArray();
                if( temp.Length != 0 )
                    oldID = temp[temp.Length - 1].ReceiptID;

                int newID = 0;

                int.TryParse(oldID.Substring(2), out newID);

                newID++;
                String transID = "TR" + newID.ToString("000");

                //insert the new customer data if user use new customer
                if (newc)
                {
                    ent.AddToMsCustomer(newCustomer);
                    ent.SaveChanges();
                }

                //insert the new destination data if user use new destination
                if (newd)
                {
                    ent.AddToMsDestination(newDestination);
                    ent.SaveChanges();
                }

                HeaderDeliveryTransaction newTrans = new HeaderDeliveryTransaction();
                newTrans.ReceiptID = transID;
                newTrans.StaffID = staff[cmbStaff.SelectedIndex].StaffID;
                newTrans.CustomerID = newCustomer.CustomerID;
                newTrans.DestinationID = newDestination.DestinationID;
                newTrans.Vehicle = cmbVehicle.SelectedItem.ToString();
                newTrans.TotalPayment = decimal.Parse(txtTotal.Text);
                newTrans.TransactionDate = dateTrans.Value;
                newTrans.ExpectedDeliveredDate = dateDelivered.Value;
                newTrans.DeliveredDate = dateDelivered.Value;
                newTrans.Status = "In Progress";

                ent.AddToHeaderDeliveryTransaction(newTrans);
                ent.SaveChanges();
                for (int i = 0; i < totalProduct; i++)
                {
                    //insert into table detaildeliverytransaction for each product
                    DetailDeliveryTransaction newDetail = new DetailDeliveryTransaction();
                    newDetail.ReceiptID = transID;
                    newDetail.ProductID = newProduct[i].ProductID;
                    newDetail.Qty = qty[i];

                    ent.AddToDetailDeliveryTransaction(newDetail);
                    ent.SaveChanges();
                }

                MessageBox.Show("Transaction is complete");
                this.Dispose();
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the HeaderDeliveryTransaction EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToHeaderDeliveryTransaction(HeaderDeliveryTransaction headerDeliveryTransaction)
 {
     base.AddObject("HeaderDeliveryTransaction", headerDeliveryTransaction);
 }
        private void txtID_TextChanged(object sender, EventArgs e)
        {
            string id = txtID.Text;

            //validate the receiptId can only be 5 characters max
            if (id.Length > 5)
            {
                txtID.Text = id.Substring(0, 5);
                lblStatus.ForeColor = Color.Black;
                lblStatus.Text = "Receipt ID can only receives 5 characters at max";

            }
            else if (id.Length == 5)
            {
                try
                {
                    //check if the id match in the database
                    temp = (from x in ent.HeaderDeliveryTransaction where x.ReceiptID.Equals(txtID.Text) select x).First();

                    if (temp != null)
                    {
                        if (temp.Status.Equals("In Progress"))
                        {
                            //if the id matched, and the status is In Progress
                            btnDelivered.Visible = true;
                            lblStatus.ForeColor = Color.Red;
                            lblStatus.Visible = true;
                            lblStatus.Text = "In Progress";
                        }
                        else if (temp.Status.Equals("Delivered"))
                        {
                            //if the id matched, and the status is Delivered
                            btnDelivered.Visible = false;
                            lblStatus.ForeColor = Color.Green;
                            lblStatus.Visible = true;
                            lblStatus.Text = "Delivered";
                        }
                        else
                        {
                            lblStatus.ForeColor = Color.Black;
                            lblStatus.Text = "No Transaction with this ReceiptID";
                        }
                    }
                    else
                    {
                        //if the id don't match
                        lblStatus.ForeColor = Color.Black;
                        lblStatus.Text = "No Transaction with this ReceiptID";

                    }
                }
                catch (Exception)
                {
                    //if exception occured
                    lblStatus.ForeColor = Color.Black;
                    lblStatus.Text = "No Transaction with this ReceiptID";
                }

            }
            else
            {
                btnDelivered.Visible = false;
                lblStatus.Visible = false;
            }
        }