Ejemplo n.º 1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the DetailDeliveryTransaction EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDetailDeliveryTransaction(DetailDeliveryTransaction detailDeliveryTransaction)
 {
     base.AddObject("DetailDeliveryTransaction", detailDeliveryTransaction);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a new DetailDeliveryTransaction object.
 /// </summary>
 /// <param name="receiptID">Initial value of the ReceiptID property.</param>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="qty">Initial value of the Qty property.</param>
 public static DetailDeliveryTransaction CreateDetailDeliveryTransaction(global::System.String receiptID, global::System.String productID, global::System.Decimal qty)
 {
     DetailDeliveryTransaction detailDeliveryTransaction = new DetailDeliveryTransaction();
     detailDeliveryTransaction.ReceiptID = receiptID;
     detailDeliveryTransaction.ProductID = productID;
     detailDeliveryTransaction.Qty = qty;
     return detailDeliveryTransaction;
 }
        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();
            }
        }