/// <summary>
        /// Handles the selectIndexChangedEvent of the lstStores
        /// Updates the store information based on the selected store
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstStores_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstStores.SelectedItems.Count > 0)
            {
                int selected = Convert.ToInt32(lstStores.SelectedItems[0].Tag);
                Stores str = new Stores();
                str.LoadByPrimaryKey(selected);
                txtStore.Text = str.StoreName;
                chkStoreIsActive.Checked = str.IsColumnNull("IsActive") ? true : str.IsActive;

                _storeId = str.ID;
                btnStoresSave.Text = "Update";
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            var transfer = new Transfer();
            var newreceiveDoc = new ReceiveDoc();
            var receiveDoc = new ReceiveDoc();
            var issuedoc = new IssueDoc();
            var valid = ValidateFields();
            if (valid == "true")
            {
                if (XtraMessageBox.Show("Are you sure you want to save this transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                try{
                      var dtRecGrid = (DataTable)receivingGrid.DataSource;
                        for (int i = 0; i < dtRecGrid.Rows.Count; i++)
                        {
                            transfer.AddNew();
                            var receiveid = Convert.ToInt32(dtRecGrid.Rows[i]["RecID"]);
                            transfer.ItemID = _itemID = Convert.ToInt32(dtRecGrid.Rows[i]["ID"]);
                            transfer.RecID = receiveid;
                            transfer.BatchNo = dtRecGrid.Rows[i]["Batch No"].ToString();
                            transfer.FromStoreID = Convert.ToInt32(lkFromStore.EditValue);
                            transfer.ToStoreID = Convert.ToInt32(lkToStore.EditValue);
                            transfer.Quantity = Convert.ToInt64(dtRecGrid.Rows[i]["Qty To Transfer"]);
                            transfer.RefNo = txtRefNo.Text;
                            transfer.UnitID = VisibilitySetting.HandleUnits == 1 ? 0 : Convert.ToInt32(dtRecGrid.Rows[i]["UnitID"]);

                            DateTime xx = dtRecDate.Value;
                            dtRecDate.CustomFormat = "MM/dd/yyyy";
                            new DateTime();
                            transfer.Date = ConvertDate.DateConverter(dtRecDate.Text);
                            ConvertDate.DateConverter(dtRecDate.Text);
                            dtRecDate.IsGregorianCurrentCalendar = true;

                            transfer.EurDate = dtRecDate.Value;
                            dtRecDate.IsGregorianCurrentCalendar = false;

                            transfer.TransferReason = txtTransferReason.Text;
                            transfer.ApprovedBy = txtApprovedBy.Text;
                            transfer.TransferRequestedBy = txtRequestedBy.Text;
                            transfer.Save();

                           transfer.GetTransfered(receiveid, _itemID, Convert.ToInt32(lkFromStore.EditValue));
                           issuedoc.AddNew();
                           issuedoc.StoreId = transfer.FromStoreID;
                           issuedoc.ItemID = transfer.ItemID;
                           issuedoc.Quantity = transfer.Quantity;
                           issuedoc.Date = transfer.Date;
                           issuedoc.BatchNo = transfer.BatchNo;
                           issuedoc.UnitID = transfer.UnitID;
                           issuedoc.RecievDocID = transfer.RecID;
                           issuedoc.IsTransfer = true;
                           issuedoc.RefNo = transfer.RefNo;
                           var allstores = new Stores();
                           allstores.LoadByPrimaryKey(transfer.ToStoreID);
                           issuedoc.ReceivingUnitID = (int) allstores.GetColumn("ReceivingUnitID");
                           issuedoc.Save();

                            receiveDoc.GetReceivedItems(receiveid,_itemID, Convert.ToInt32(lkFromStore.EditValue));
                            receiveDoc.QuantityLeft = receiveDoc.QuantityLeft - transfer.Quantity;

                            newreceiveDoc.AddNew();

                            newreceiveDoc.StoreID = transfer.ToStoreID;
                            newreceiveDoc.RefNo = transfer.RefNo;
                            newreceiveDoc.BatchNo = transfer.BatchNo;
                            newreceiveDoc.ItemID = transfer.ItemID;
                            newreceiveDoc.Quantity = transfer.Quantity;
                            newreceiveDoc.QuantityLeft = transfer.Quantity;
                            newreceiveDoc.NoOfPack =  Convert.ToInt32(transfer.Quantity) / receiveDoc.QtyPerPack;
                            newreceiveDoc.QtyPerPack = receiveDoc.QtyPerPack;
                            newreceiveDoc.Cost = receiveDoc.Cost;

                            newreceiveDoc.Date = transfer.Date;
                            newreceiveDoc.UnitID = transfer.UnitID;
                            newreceiveDoc.Out = false;
                            newreceiveDoc.ReceivedBy = transfer.ApprovedBy;
                            newreceiveDoc.ExpDate = receiveDoc.ExpDate;

                            allstores.LoadByPrimaryKey(transfer.FromStoreID);
                            newreceiveDoc.SupplierID = (int) allstores.GetColumn("SupplierID");
                            newreceiveDoc.BoxLevel = 1;
                            newreceiveDoc.Save();
                            receiveDoc.Save();
                        }

                        XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ResetFields();

                    }
                    catch (Exception exp)
                    {
                       XtraMessageBox.Show(exp.InnerException.Message ,"Error");
                    }
                }

            }
            else
            {
                XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
 /// <summary>
 /// Saves store information
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnStoresSave_Click(object sender, EventArgs e)
 {
     if (txtStore.Text != "")
     {
         Stores str = new Stores();
         if (_storeId != 0)
             str.LoadByPrimaryKey(_storeId);
         else
             str.AddNew();
         str.StoreName = txtStore.Text;
         str.IsActive = chkStoreIsActive.Checked;
         str.Save();
         str.LoadAll();
         PopulateStores(str);
         ResetStores();
     }
     else
     {
         txtStore.BackColor = Color.FromArgb(251, 214, 214);
     }
     XtraMessageBox.Show("Store Record Updated.", "Confirmation", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
 }
        private void BinCardTransaction_Load(object sender, EventArgs e)
        {
            DataTable dtyears = Items.AllYears();

            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            _dtCurrent = ConvertDate.DateConverter(dtDate.Text);
            //CALENDAR:
            foreach (DataRow drYears in dtyears.Rows)
            {
                if (drYears["year"] != DBNull.Value)
                {
                    int yr = Convert.ToInt32(drYears["year"]);
                    cboYear.Items.Add(yr);
                }
            }
            bool added = true;
            for (int x = 0; x < cboYear.Items.Count; x++)//to check if the current year is included or not
            {
                if (Convert.ToInt64(cboYear.Items[x]) == _year)
                {
                    added = false;
                    break;
                }
            }
            if (added)
            {
                cboYear.Items.Add(_year);
            }
            cboYear.SelectedItem = _year;

            var itemunit = new ItemUnit();
            var allunits = itemunit.GetAllUnits();
            unitBindingSource.DataSource = allunits.DefaultView;

            var unitcolumn = ((GridView)gridItemsList.MainView).Columns[11];
            switch (VisibilitySetting.HandleUnits)
            {
                case 1:
                    unitcolumn.Visible = false;
                    break;
                case 2:
                    unitcolumn.Visible = true;
                    break;
                default:
                    unitcolumn.Visible = true;
                    break;
            }

            PopulateBinCardYearCombo();
            cboFiscalYear.SelectedItem = _year;
            BLL.Items itm = new Items();
            DataTable dtItm = itm.GetItemById(_itemId);
            string itemName = dtItm.Rows[0]["ItemName"].ToString() + " - " + dtItm.Rows[0]["DosageForm"].ToString() + " - " + dtItm.Rows[0]["Strength"].ToString();
            txtItemName.Text = itemName;
            txtitmName.Text = itemName;
            toolTip1.SetToolTip(txtitmName, itemName);
            lblBUnit.Text = dtItm.Rows[0]["Unit"].ToString();
            this.Text = itemName + " Detail Report";

            ReceivingUnits dus = new ReceivingUnits();
            DataTable dtDU = dus.GetApplicableDUs(_itemId, _storeId);
            Stores stor = new Stores();
            stor.LoadByPrimaryKey(_storeId);
            object[] objS = { 0, stor.StoreName, "", "" };
            dtDU.Rows.Add(objS);
            cboDU.DataSource = dtDU;
            cboDU.SelectedIndex = (cboDU.Items.Count - 1);
            cboDU.Text = "Select DU";

            try
            {
                txtFreeItem.Text = (itm.IsFree) ? "Yes" : "No";
                txtRefrigerated.Text = (itm.Refrigeratored) ? "Yes" : "No";
                txtPediatric.Text = (itm.Pediatric) ? "Yes" : "No";

            }
            catch
            {
            }

            int du = ((cboDU.SelectedValue != null) ? Convert.ToInt32(cboDU.SelectedValue) : 0);
            GenerateCharts(0);
            ItemStockStatus();

            //GenerateBinCard();
            GenerateBinCardNew();
            PopulateTransaction();

            tabControl1.SelectedTabPageIndex = _tabInd;
            _first = 1;
            lblItemID.Text = _itemId.ToString();

            PopulateLogisticSummary();
        }