// create Purchase Order and together with Purchase Order Items
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //justify how many suppliers involed
            List<Supplier> suppliers = SupplierInvolved();

            using (PurchaseOrderManager pom = new PurchaseOrderManager())
            {
                foreach (Supplier s in suppliers)
                {
                    PurchaseOrder purchaseOrder = new PurchaseOrder();

                    purchaseOrder.PONumber = pom.CreatePONumber();
                    purchaseOrder.DateOfOrder = DateTime.Now;
                    purchaseOrder.AttentionTo = Convert.ToInt32(ddlAttentionTo.SelectedValue);
                    purchaseOrder.CreatedBy = Membership.GetCurrentLoggedInUser().UserID;
                    purchaseOrder.IsDelivered = false;
                    DateTimeFormatInfo dtfi = new DateTimeFormatInfo();
                    dtfi.ShortDatePattern = "MM/dd/yyyy";
                    dtfi.DateSeparator = "/";

                    purchaseOrder.DateToSupply = Convert.ToDateTime(txtDateToSupply.Text, dtfi);
                    purchaseOrder.SupplierID = s.SupplierID;

                    foreach (GridViewRow r in gvPOItems.Rows)
                    {
                        if (Convert.ToInt32(((DropDownList)r.FindControl("ddlSupplier")).SelectedValue.ToString()) == s.SupplierID)
                        {
                            PurchaseOrderItem item = new PurchaseOrderItem();
                            item.PurchaseOrder = purchaseOrder;
                            item.StationeryID = (int)gvPOItems.DataKeys[r.RowIndex].Value;
                            //item.QuantityToOrder = 5;
                            item.QuantityToOrder = Convert.ToInt32(((TextBox)r.FindControl("txtRecommend")).Text.ToString());
                            using (CatalogManager cm = new CatalogManager())
                            {
                                StationeryPriceSearchDTO criteria = new StationeryPriceSearchDTO();
                                criteria.SupplierID = Convert.ToInt32(((DropDownList)r.FindControl("ddlSupplier")).SelectedValue.ToString());
                                criteria.StationeryID = (int)item.StationeryID;
                                item.Price = cm.FindStationeryPricesByCriteria(criteria)[0].Price;

                                // record supplier ID for the PO
                                purchaseOrder.SupplierID = criteria.SupplierID;
                            }
                            purchaseOrder.PurchaseOrderItems.Add(item); // only this way works
                        }
                    }
                    pom.CreatePurchaseOrder(purchaseOrder);
                }
            }
        }
 public List<StationeryPrice> FindStationeryPricesByCriteria(StationeryPriceSearchDTO criteria)
 {
     return catalogDAO.FindStationeryPricesByCriteria(criteria);
 }