private void PopulateFields()
        {
            // Bind the lookups first
            ABC abc = new ABC();
            abc.LoadAll();

            radioGroupABC.Properties.Items.Clear();
            while(!abc.EOF){
                radioGroupABC.Properties.Items.Add(new RadioGroupItem(abc.ID, abc.Description));
                abc.MoveNext();
            }

            radioGroupVEN.Properties.Items.Clear();
            VEN ven = new VEN();
            ven.LoadAll();
            while (!ven.EOF)
            {
                radioGroupVEN.Properties.Items.Add(new RadioGroupItem(ven.ID, ven.Description));
                ven.MoveNext();
            }

            if(itemId != 0)
            {
                Item itm = new Item();

                //itm.LoadByPrimaryKey(itemId);
                DataTable dtItem = itm.GetItemById(itemId);
                txtItemName.Text = itm.FullItemName;//String.Format("{0} - {1} - {2}", dtItem.Rows[0]["ItemName"], dtItem.Rows[0]["DosageForm"], dtItem.Rows[0]["Strength"]);
                ckExculed.Checked = (!itm.IsColumnNull("IsInHospitalList"))?itm.IsInHospitalList:false;

                chkProcessDecimal.Checked = (!itm.IsColumnNull("ProcessInDecimal")) ? itm.ProcessInDecimal : false;

                if (!itm.IsColumnNull("ABCID"))
                {
                    radioGroupABC.EditValue = itm.GetColumn("ABCID");
                }
                if (!itm.IsColumnNull("VENID"))
                {
                    radioGroupVEN.EditValue = itm.GetColumn("VENID");
                }

                Supplier sup = new Supplier();
                sup.LoadAll();
                ItemSupplier itmSup = new ItemSupplier();
                itmSup.GetSuppliersAndMarkThoseUsed(itemId);

                while(!itmSup.EOF)
                {
                    lstSuppliers.Items.Add(itmSup.GetColumn("CompanyName"),Convert.ToBoolean(itmSup.GetColumn("IsUsed")));
                    itmSup.MoveNext();
                }

                BLL.Program prog = new BLL.Program();
                prog.GetSubPrograms();
                ItemProgram progItem = new ItemProgram();
                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);
                }
            }
        }
        /// <summary>
        /// Saves the item policy
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            var itm = new Items();
            var itmSup = new ItemSupplier();
            if (_itemId != 0)
                itm.LoadByPrimaryKey(_itemId);
            else
            {
                itm.AddNew();
                var prodCate = new ProductsCategory();
                prodCate.AddNew();
                prodCate.ItemId = itm.ID;
                prodCate.SubCategoryID = Convert.ToInt32(_categoryId);
                prodCate.Save();
            }
            //if (rdA.Checked || rdB.Checked || rdC.Checked)
            //    itm.ABC = ((rdA.Checked) ? 1 : (rdB.Checked) ? 2 : 3);

            //if (rdV.Checked || rdE.Checked || rdN.Checked)
            //    itm.VEN = ((rdV.Checked) ? 1 : (rdE.Checked) ? 2 : 3);

                itm.IsInHospitalList = ckExculed.Checked;
                //itm.NeedExpiryBatch = chkNeedExpiryBatch.Checked;

            string valid = ValidateFields();
            if (valid == "true")
            {
                itm.NeedExpiryBatch = chkNeedExpiryBatch.Checked;
                itm.StockCodeDACA = txtText.Text;
                itm.Cost = txtQuantityPerPack.Text;
                itm.Save();
            }

            else
            {
                XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            //TODO: To add categories
            //Needs some modification on edit

            // this will only add the suppliers
            //do some thing on edit

            itmSup.DeleteAllSupForItem(itm.ID);
            Supplier sup = new Supplier();
            foreach (object t in lstSuppliers.CheckedItems)
            {
                sup.GetSupplierByName(t.ToString());
                itmSup.AddNew();
                itmSup.ItemID = itm.ID;
                itmSup.SupplierID = sup.ID;
                itmSup.Save();
            }

            var progItm = new ProgramProduct();
            progItm.DeleteAllProgramsForItem(_itemId);

            var prog = new Programs();
            //prog.AddNew();
            //prog.Name = cboPrograms.Text;
            //prog.Save();

            foreach (object t in lstPrograms.CheckedItems)
            {
                prog.GetProgramByName(t.ToString());
                progItm.AddNew();
                progItm.ItemID = itm.ID;
                progItm.ProgramID = prog.ID;
                progItm.Save();
            }

            var duItem = new DUsItemList();
            var dus = new ReceivingUnits();

            foreach (object t in lstDUs.CheckedItems)
            {
                dus.GetDUByName(t.ToString());
                duItem.AddNew();
                duItem.DUID = dus.ID;
                duItem.ItemID = _itemId;
                try
                {
                    duItem.Save();
                }
                catch
                {

                }
            }

            XtraMessageBox.Show("Item Detail is Saved Successfully!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!AccountTypeSelectionValid())
            {
                XtraMessageBox.Show("Please choose to which account types this item applies to.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                gridViewStoreItemMatrix.SetColumnError(gridColAcctType, "At least one account type needs to be selected");
                return;
            }
            Item itm = new Item();
            ItemSupplier itmSup = new ItemSupplier();
            if (itemId != 0)
                itm.LoadByPrimaryKey(itemId);
            else
            {
                itm.AddNew();
                ItemCategory prodCate = new ItemCategory();
                prodCate.AddNew();
                prodCate.ItemId = itm.ID;
                prodCate.SubCategoryID = Convert.ToInt32(categoryId);
                prodCate.Save();
            }
            if(radioGroupABC.EditValue != null){
                itm.ABC = Convert.ToInt32(radioGroupABC.EditValue);
            }

            if (radioGroupVEN.EditValue != null)
            {
                itm.VEN = Convert.ToInt32(radioGroupVEN.EditValue);
            }
            itm.IsInHospitalList = ckExculed.Checked;
            itm.ProcessInDecimal = chkProcessDecimal.Checked;
            itm.Save();

            if (itm.IsInHospitalList)
            {
                SaveHubDetails();
            }
            else
            {
                // clear out the prefered locations
                // clear out the pick face locations
                // make sure that this item could be made not in the list

            }

            itmSup.DeleteAllSupForItem(itm.ID);
            Supplier sup = new Supplier();
            for (int i = 0; i < lstSuppliers.CheckedItems.Count;i++ )
            {
                sup.GetSupplierByName(lstSuppliers.CheckedItems[i].ToString());
                itmSup.AddNew();
                itmSup.ItemID = itm.ID;
                itmSup.SupplierID = sup.ID;
                itmSup.Save();
            }

            ItemProgram progItm = new ItemProgram();
            progItm.DeleteAllProgramsForItem(itemId);
            BLL.Program prog = new BLL.Program();
            for (int i = 0; i < lstPrograms.CheckedItems.Count; i++)
            {
                prog.GetProgramByName(lstPrograms.CheckedItems[i].ToString());
                progItm.AddNew();
                progItm.ItemID = itm.ID;
                progItm.ProgramID = prog.ID;
                progItm.Save();
            }

                XtraMessageBox.Show("Item Detail is Saved Successfully!", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
        /// <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);
            }
        }