private void BtnMovePalletClick(object sender, EventArgs e)
 {
     DataRow dr = gridPalletMovementView.GetFocusedDataRow();
     if (dr != null)
     {
         PalletLocation pl = new PalletLocation();
         pl.LoadByPrimaryKey(Convert.ToInt32(dr["FromID"]));
         PalletLocation pl2 = new PalletLocation();
         pl2.LoadByPrimaryKey(Convert.ToInt32(dr["ToID"]));
         if (pl2.IsColumnNull("PalletID"))
         {
             pl2.PalletID = pl.PalletID;
             pl.SetColumnNull("PalletID");
             pl2.Save();
             pl.Save();
             XtraMessageBox.Show("The pallet Movement is confirmed!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         BindPalletMovement();
     }
 }
        private void ConfirmQuantityAndLocation()
        {
            //TODO: finish updating the changed locations
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            transaction.BeginTransaction();
            try
            {
                PalletLocation pl = new PalletLocation();
                String reference = gridReceiveView.GetFocusedDataRow()["RefNo"].ToString();
                //           pl.ConfirmAllReceived(reference);
                if (gridDetailView.DataSource == null)
                    return;

                foreach (DataRowView drv in gridDetailView.DataSource as DataView)
                {
                    int PalletLocationID = Convert.ToInt32(drv["PalletLocationID"]);
                    int ProposedPalletLocationID = Convert.ToInt32(drv["ProposedPalletLocationID"]);
                    int PalletID = Convert.ToInt32(drv["PalletID"]);
                    int receiveID = Convert.ToInt32(drv["ReceiveID"]);

                    if (PalletLocationID != ProposedPalletLocationID)
                    {
                        pl.LoadByPrimaryKey(PalletLocationID);
                        if (pl.IsColumnNull("PalletID"))
                        {
                            pl.PalletID = PalletID;
                            pl.Confirmed = true;
                            pl.Save();

                            pl.LoadByPrimaryKey(ProposedPalletLocationID);
                            pl.SetColumnNull("PalletID");
                            pl.Save();
                        }
                        else
                        {
                            XtraMessageBox.Show("Some Items/Pallets were not confirmed correctly because the newly selected pallet location was already occupied.", "Some Items were not confirmed.");
                        }
                    }
                    else
                    {
                        pl.LoadByPrimaryKey(PalletLocationID);
                        pl.PalletID = PalletID;
                        pl.Confirmed = true;
                        pl.Save();
                    }
                }

                BLL.ReceiveDoc recDoc = new ReceiveDoc();
                recDoc.LoadByReferenceNo(reference);
                recDoc.ConfirmQuantityAndLocation(null);

                transaction.CommitTransaction();
                XtraMessageBox.Show("Receipt Confirmed!", "Success", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                BindFormContents();

            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                XtraMessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnConsolidate_Click(object sender, EventArgs e)
        {
            DataRow dr = gridView4.GetFocusedDataRow();
            if (dr != null)
            {
                if (DialogResult.Yes == XtraMessageBox.Show("Are you sure you want to consolidate the two pallets? you will not be able to undo this change.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    DataRow dr2 = gridView3.GetFocusedDataRow();
                    PalletLocation pl = new PalletLocation();
                    pl.LoadByPrimaryKey( Convert.ToInt32(dr2["ID"]) );

                    int sourcePalletID = pl.PalletID;
                    pl.LoadByPrimaryKey(Convert.ToInt32(dr["ID"]));
                    int destinationPalletID = pl.PalletID;

                    ReceivePallet rp = new ReceivePallet();
                    rp.Consolidate(sourcePalletID, destinationPalletID);
                    pl.LoadByPrimaryKey(Convert.ToInt32(dr2["ID"]));
                    pl.SetColumnNull("PalletID");
                    pl.Save();
                    XtraMessageBox.Show("Items Consolidated.", "Items Consolidated");

                    gridView5_RowClick(null, null);
                }
            }
        }
        /// <summary>
        /// Moves the specified from.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        public static bool Move(int from, int to)
        {
            PalletLocation pl = new PalletLocation();
            pl.LoadByPrimaryKey(from);
            if (!pl.IsColumnNull("PalletID"))
            {
                PalletLocation pl2 = new PalletLocation();

                pl2.LoadByPrimaryKey(to);
                if (pl2.IsColumnNull("PalletID"))
                {
                    pl2.PalletID = pl.PalletID;
                    pl.SetColumnNull("PalletID");
                    pl.Save();
                    pl2.Confirmed = true;
                    pl2.Save();
                    return true;
                }
            }
            return false;
        }