/// <summary>
        /// Populates the fields based on the supplied itemID or categoryID
        /// </summary>
        private void PopulateFields()
        {
            if (_itemId == 0)
                return;

            Items itm = new Items();

            DataTable dtItem = itm.GetItemById(_itemId);
            txtItemName.Text = dtItem.Rows[0]["ItemName"].ToString() + " - " + dtItem.Rows[0]["DosageForm"].ToString() + " - " + dtItem.Rows[0]["Strength"].ToString();
            ckExculed.Checked =itm.IsInHospitalList;
            chkNeedExpiryBatch.Checked = itm.NeedExpiryBatch;
            txtText.Text = itm.StockCodeDACA ?? string.Empty;
            txtQuantityPerPack.Text = itm.Cost ?? string.Empty;

            try
            {
                if (dtItem.Rows[0]["ABC"].ToString() == "A")
                    rdA.Checked = true;
                else if (dtItem.Rows[0]["ABC"].ToString() == "B")
                    rdB.Checked = true;
                else if (dtItem.Rows[0]["ABC"].ToString() == "C")
                    rdC.Checked = true;
            }
            catch { }

            try
            {
                if (dtItem.Rows[0]["VEN"].ToString() == "V")
                    rdV.Checked = true;
                else if (dtItem.Rows[0]["VEN"].ToString() == "E")
                    rdE.Checked = true;
                else if (dtItem.Rows[0]["VEN"].ToString() == "N")
                    rdN.Checked = true;
            }
            catch { }

            //ItemShelf itmShelf = new ItemShelf();
            //DataTable dtSlf = itmShelf.GetLocationByItem(itm.ID);
            //lstBinLocation.DataSource = dtSlf;

            var unit = new ItemUnit();
            var itemunits= unit.LoadFromSQl(_itemId);
            itemunitbindingSource.DataSource = itemunits;

            if (VisibilitySetting.HandleUnits == 2)
            {
                listBox1.Visible = true;
            }
            else if(VisibilitySetting.HandleUnits == 3)
            {
                 listBox1.Visible = true;
            }
            else if(VisibilitySetting.HandleUnits == 1)
            {
                listBox1.Hide();
            }
            Supplier sup = new Supplier();
            sup.GetActiveSuppliers();

            ItemSupplier itmSup = new ItemSupplier();
            itm.GetItemsBySupplier(_itemId);
            foreach (DataRowView dv in sup.DefaultView)
            {
                bool check = false;
                check = itmSup.CheckIfExist(_itemId, Convert.ToInt32(dv["ID"]));
                object obj = dv["CompanyName"];
                lstSuppliers.Items.Add(obj, check);
            }

            Programs prog = new Programs();
            prog.GetSubPrograms();
            ProgramProduct progItem = new ProgramProduct();
            lstPrograms.Items.Clear();
            foreach (DataRowView dv in prog.DefaultView)
            {
                bool check = false;
                check = progItem.CheckIfExists(_itemId, Convert.ToInt32(dv["ID"]));
                lstPrograms.Items.Add(dv["Name"], check);
            }

            ReceivingUnits dus = new ReceivingUnits();
            dus.GetActiveDispensaries();
            lstDUs.Items.Clear();

            DUsItemList duItem = new DUsItemList();

            foreach (DataRowView drDus in dus.DefaultView)
            {
                bool check = false;
                check = duItem.CheckIfExsits(_itemId, Convert.ToInt32(drDus["ID"]));
                lstDUs.Items.Add(drDus["Name"], check);
            }
        }
 private void unitsrepositoryItemLookUpEdit_Enter(object sender, EventArgs e)
 {
     var edit = sender as LookUpEdit;
     if (edit == null) return;
     var clone = new ItemUnit();
     var row = gridRecieveView.GetFocusedDataRow();
     var id = Convert.ToInt32(row["ID"]);
     var filterunit = clone.LoadFromSQl(id);
     edit.Properties.DataSource = filterunit;
     edit.Properties.DisplayMember = "Text";
     edit.Properties.ValueMember = "ID";
 }
        /// <summary>
        /// Load the lookups and Prepare the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditReceive_Load(object sender, EventArgs e)
        {
            lkItemUnit.Enabled = VisibilitySetting.HandleUnits != 1;
            var str = new Stores();
            str.LoadAll();
            cboStores.DataSource = str.DefaultView;

            var sup = new Supplier();
            sup.GetActiveSuppliers();
            cboSupplier.DataSource = sup.DefaultView;

            if(_tranId != 0)
            {
                var rec = new ReceiveDoc();
                var itm = new Items();

                rec.LoadByPrimaryKey(_tranId);

                var dtItm = itm.GetItemById(rec.ItemID);

                var units = new ItemUnit();
                var unit = units.LoadFromSQl(rec.ItemID);
                lkItemUnit.Properties.DataSource = unit;
                lkItemUnit.Properties.DisplayMember = "Text";
                lkItemUnit.Properties.ValueMember = "ID";

                var programs = new Programs();
                var allprograms = programs.GetSubPrograms();
                lkPrograms.Properties.DataSource = allprograms;
                lkPrograms.Properties.ValueMember = "ID";
                lkPrograms.Properties.DisplayMember = "Name";

                string itemName = dtItm.Rows[0]["ItemName"].ToString() + " - " + dtItm.Rows[0]["DosageForm"].ToString() + " - " + dtItm.Rows[0]["Strength"].ToString();

                txtRefNo.Text = rec.RefNo;
                txtBatchNo.Text = rec.BatchNo;
                try
                {
                    txtPack.Text = rec.NoOfPack.ToString();
                    txtQtyPack.Text =rec.QtyPerPack.ToString();
                    txtPrice.Text = (rec.Cost * rec.QtyPerPack).ToString();
                    //txtQuantityLeft.Text = rec.QuantityLeft.ToString();
                }
                catch
                {
                    txtPack.Text = "0";
                    txtQtyPack.Text = "0";
                    txtPrice.Text = (rec.Cost * 1).ToString();
                }
                txtQuantity.Text = rec.Quantity.ToString();
                lkPrograms.EditValue = rec.SubProgramID;
                DateTime dtDate = Convert.ToDateTime(rec.Date.ToString("MM/dd/yyyy"));
                txtDate.Text = dtDate.ToShortDateString();
                dtRecDate.Value = DateTime.Now;
                dtRecDate.CustomFormat = "MM/dd/yyyy";
                if (!rec.IsColumnNull("ExpDate"))
                    dtExpiryDate.Value = rec.ExpDate;
                cboStores.SelectedValue = rec.StoreID;
                cboSupplier.SelectedValue = rec.SupplierID;

                if (!rec.IsColumnNull("UnitID"))
                    lkItemUnit.EditValue = rec.UnitID;
                txtItemName.Text = itemName;
                txtReceivedBy.Text = rec.ReceivedBy;
                txtRemark.Text = rec.Remark;

            }
        }