private void PopulateItems()
        {
            Item itm = new Item();
            itm.GetItemByPrimaryKey(this._itemID);
            if (itm.IsColumnNull("StorageTypeID"))
            {
                itm.StorageTypeID = 1;
                itm.Save();
            }
            if (itm.StorageTypeID.ToString() == StorageType.BulkStore && !itm.IsColumnNull("IsStackStored") && itm.IsStackStored)
            {
                layoutStackedView.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
            }
            else
                layoutStackedView.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;

            lblItemName.Text = itm.FullItemName;
            BLL.ItemManufacturer imfr = new BLL.ItemManufacturer();
            imfr.LoadManufacturersFor(this._itemID);
            lstManufacturers.DataSource = imfr.DefaultView;
            itemUnit.LoadAllForItem(_itemID);
            gridUnits.DataSource = itemUnit.DefaultView;
        }
        private void gridView1_FocusedRowChanged(object sender,
            DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if(ValidateForBindingNewPalletLocation()){
            DataRow dr = gridView1.GetFocusedDataRow();

            //for validation
            Double writeoff = 0;
            Double reLocate = 0;
            try
            {
                if (dr["WriteOff"] != DBNull.Value)
                {
                    writeoff = Double.Parse(dr["WriteOff"].ToString());
                }
                if (dr["ReLocate"] != DBNull.Value)
                {
                    reLocate = Double.Parse(dr["ReLocate"].ToString());
                }
            }
            catch (Exception exc)
            {
            }
            // bind data set to the repository item
            try
            {

                if (dr["WriteOff"] != DBNull.Value && writeoff>0)
                {
                    int palletid = int.Parse(dr["PalletID"].ToString());
                    PalletLocation pl = new PalletLocation();
                    newpalletlocationrepositoryItemGridLookUpEdit.DataSource =
                        pl.GetPalletLocationsOnTheSameStore(palletid);
                }
                else if (dr["ReLocate"] != DBNull.Value & reLocate>0)
                {
                    Item itms = new Item();
                    itms.GetItemByPrimaryKey(Convert.ToInt32(dr["ItemID"]));
                    newpalletlocationrepositoryItemGridLookUpEdit.DataSource =
                        PalletLocation.GetAllFreeForIntheSameStore(Convert.ToInt32(dr["ItemID"]),
                            int.Parse(dr["PalletID"].ToString()));
                }
                else
                {
                    newpalletlocationrepositoryItemGridLookUpEdit.DataSource = null;
                }

            }
            catch (Exception except)
            {
            }
            }
        }
        /// <summary>
        /// Recommends the pallet movments.
        /// </summary>
        /// <returns></returns>
        public DataView RecommendPalletMovments()
        {
            // check for each pallet in bulk store
            this.LoadFromRawSql(HCMIS.Repository.Queries.PalletLocation.SelectRecommendPalletMovments(StorageType.BulkStore));
            DataTable dtbl = new DataTable();
            dtbl.Columns.Add("ItemID");
            dtbl.Columns.Add("FullItemName");
            dtbl.Columns.Add("PalletNo");
            dtbl.Columns.Add("FromID");
            dtbl.Columns.Add("ToID");
            dtbl.Columns.Add("From");
            dtbl.Columns.Add("To");
            int itemID = 0;
            int freePreferedLocationCount = 0;
            Item itms = new Item();
            bool checkable = false;
            PalletLocation pl = new PalletLocation();

            while (!this.EOF)
            {
                if (Convert.ToInt32(this.DataRow["ItemID"]) != itemID)
                {
                    itemID = Convert.ToInt32(this.DataRow["ItemID"]);
                    // do this if this item is a bulk storage
                    itms.GetItemByPrimaryKey(itemID);
                    if (itms.StorageTypeID.ToString() == StorageType.BulkStore)
                    {
                        checkable = true;

                        pl.LoadFreePrefferedLocationFor(itemID);
                        freePreferedLocationCount = pl.RowCount;
                    }
                    else
                    {
                        checkable = false;
                    }
                }

                if (checkable && freePreferedLocationCount > 0)
                {
                    //add it to the table
                    DataRowView drv = dtbl.DefaultView.AddNew();
                    drv["ItemID"] = itemID;
                    drv["FullItemName"] = itms.FullItemName;
                    drv["FromID"] = this.ID;
                    drv["ToID"] = pl.ID;
                    Pallet pallet = new Pallet();
                    pallet.LoadByPrimaryKey(this.PalletID);
                    drv["PalletNo"] = pallet.PalletNo;
                    pl.MoveNext();
                    freePreferedLocationCount--;
                    drv["From"] = this.FullName;
                    drv["To"] = pl.FullName;
                }

                this.MoveNext();
            }

            return dtbl.DefaultView;
        }