private void LogTransfer_Load(object sender, EventArgs e)
        {
            var stor = new Stores();
            stor.GetActiveStores();
               // lkFromStore.ItemIndex = 0;
            storeBindingSource.DataSource = stor.DefaultView;

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

            // bind the supplier lookup for the grid.

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

            lkToStore.Properties.DataSource = stor.DefaultView;
            lkToStore.ItemIndex = 0;
            // bind the current dates

            try
            {
                var dr = (DataRowView)lstTree.GetDataRecordByNode(lstTree.Nodes[0].FirstNode);
                if (dr == null) return;
                var rec = new Transfer();
                if (dr["ParentID"] == DBNull.Value)
                {
                    // int yr = ((dtCurrent.Month > 10) ? dtCurrent.Year : dtCurrent.Year - 1);
                    var dt1 = new DateTime(Convert.ToInt32(dr["ID"]) - 1, 11, 1);
                    var dt2 = new DateTime(Convert.ToInt32(dr["ID"]), 11, 1);
                    dtRec = rec.GetTransactionByDateRange(Convert.ToInt32(lkToStore.EditValue), dt1, dt2);
                    lblTransferedDate.Text = dr["RefNo"].ToString();
                }
                else
                {
                    dtRec = rec.GetTransactionByRefNo(dr["RefNo"].ToString(), Convert.ToInt32(lkToStore.EditValue), dr["Date"].ToString());
                    lblTransferedDate.Text = Convert.ToDateTime(dr["Date"]).ToString("MM dd,yyyy");
                }
                gridControl1.DataSource = dtRec;
            }
            catch (Exception ex)
            {

            }
        }
        private void GeneralReport_Load(object sender, EventArgs e)
        {
            Stores stor = new Stores();
            DataTable dtStor = stor.GetActiveStores();
            DataRow rowStore = dtStor.NewRow();
            rowStore["ID"] = "0";
            rowStore["StoreName"] = "All";
            dtStor.Rows.InsertAt(rowStore, 0);

            cboStores.Properties.DataSource = dtStor;
            cboStores.ItemIndex = 0;
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            dtCurrent = ConvertDate.DateConverter(dtDate.Text);
            cboYear.Properties.DataSource = Items.AllYears();
            cboYear.EditValue = dtCurrent.Year;

            GeneratCostChartForAllStores();
        }
        public DataTable GetSavedRRFForDisplay()
        {
            this.FlushData();
            string query = "select ID,DateOfSubmission, LastRRFStatus, RRFType, cast(FromMonth as varchar) + ',' + cast(FromYear as varchar) + ' - ' + cast(ToMonth as varchar) + ',' + cast(ToYear as varchar) Period from RRF";
            this.LoadFromRawSql(query);
            this.AddColumn("DateOfSubmissionEth", typeof (string));
            this.AddColumn("RRFTypeText", typeof(string));

            while(!this.EOF)
            {
                string ethDate = this.IsColumnNull("DateOfSubmission")? "": EthiopianDate.EthiopianDate.GregorianToEthiopian(this.DateOfSubmission);
                this.SetColumn("DateOfSubmissionEth",ethDate);
                var str = new Stores();
                str.LoadByStoreID(this.RRFType);
                this.SetColumn("RRFTypeText", str.RowCount > 0 ? str.StoreName : "Unknown Store");
                this.MoveNext();
            }
            return this.DataTable;
        }
Exemplo n.º 4
0
        public DataTable GetSavedRRFForDisplay()
        {
            this.FlushData();
            string query = "select ID,DateOfSubmission, LastRRFStatus, RRFType, cast(FromMonth as varchar) + ',' + cast(FromYear as varchar) + ' - ' + cast(ToMonth as varchar) + ',' + cast(ToYear as varchar) Period from RRF";

            this.LoadFromRawSql(query);
            this.AddColumn("DateOfSubmissionEth", typeof(string));
            this.AddColumn("RRFTypeText", typeof(string));

            while (!this.EOF)
            {
                string ethDate = this.IsColumnNull("DateOfSubmission")? "": EthiopianDate.EthiopianDate.GregorianToEthiopian(this.DateOfSubmission);
                this.SetColumn("DateOfSubmissionEth", ethDate);
                var str = new Stores();
                str.LoadByStoreID(this.RRFType);
                this.SetColumn("RRFTypeText", str.RowCount > 0 ? str.StoreName : "Unknown Store");
                this.MoveNext();
            }
            return(this.DataTable);
        }
Exemplo n.º 5
0
        public bool InventoryRequiredForHandlingUnit(bool ignoreAutomatic)
        {
            var ethDate = new EthiopianDate.EthiopianDate();

            if ((ethDate.Month == 10 && ethDate.Day == 30) || ethDate.Month == 11)
            {
                var stores = new Stores();
                stores.GetActiveStores();
                while (!stores.EOF)
                {
                    var itm = new Items();
                    itm.ExcludeNeverReceivedItemsNoCategoryForHandlingUnit(stores.ID);
                    if (!this.DoesBalanceExist(ethDate.Year, stores.ID, !ignoreAutomatic) && itm.RowCount > 0)
                    {
                        return(true);
                    }
                    stores.MoveNext();
                }
            }
            return(false);
        }
        private void DetailMos()
        {
            //dtDate.Value = DateTime.Now;
            //dtDate.CustomFormat = "MM/dd/yyyy";
            // DateTime dtCurrent = ConvertDate.DateConverter(dtDate.Text);

            ReceivingUnits du = new ReceivingUnits();
            DataTable dtDus = du.GetApplicableDUsAll(_itemId);
            int col = 0;
            Balance bal = new Balance();
            IssueDoc iss = new IssueDoc();
            Stores stor = new Stores();
            stor.GetActiveStores();
            DataTable dtStores = stor.DefaultView.ToTable();
            //  lstTrendMos.Items.Clear();
            foreach (DataRow drStr in dtStores.Rows)
            {
                int storeId = Convert.ToInt32(drStr["ID"]);
                //Int64 soh = bal.GetSOH(itemId, storeId, dtCurrent.Month, dtCurrent.Year);
                //Int64 amc = bal.CalculateAMC(itemId, storeId, dtCurrent.Month, dtCurrent.Year);
                //Int64 issue = iss.GetIssuedQuantityByMonth(itemId, storeId, dtCurrent.Month, dtCurrent.Year);
                //decimal mos = ((amc > 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                //mos = Decimal.Round(mos, 1);

                int[] mon = { 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

                decimal[] cons = new decimal[12];
                for (int i = 0; i < mon.Length; i++)
                {
                    int yr = (mon[i] > 10) ? _dtCurrent.Year - 1 : _dtCurrent.Year;
                    if (!(yr == _dtCurrent.Year && mon[i] > _dtCurrent.Month && mon[i] < 11))
                    {
                        Int64 soh = bal.GetSOH(_itemId, storeId, mon[i], yr);
                        double amc = Builder.CalculateAverageConsumption(_itemId, _storeId,
                                                                        _dtCurrent.Subtract(TimeSpan.FromDays(180)), _dtCurrent,
                                                                        CalculationOptions.Monthly);
                        decimal mos = ((amc != 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                        cons[i] = Decimal.Round(mos, 1);
                    }
                    else
                        cons[i] = 0;
                }

                string[] str = { drStr["StoreName"].ToString(), ((cons[0] != 0) ? cons[0].ToString() : "0"), ((cons[1] != 0) ? cons[1].ToString() : "0"), ((cons[2] != 0) ? cons[2].ToString() : "0"), ((cons[3] != 0) ? cons[3].ToString() : "0"), ((cons[4] != 0) ? cons[4].ToString() : "0"), ((cons[5] != 0) ? cons[5].ToString() : "0"), ((cons[6] != 0) ? cons[6].ToString() : "0"), ((cons[7] != 0) ? cons[7].ToString() : "0"), ((cons[8] != 0) ? cons[8].ToString() : "0"), ((cons[9] != 0) ? cons[9].ToString() : "0"), ((cons[10] != 0) ? cons[10].ToString() : "0"), ((cons[11] != 0) ? cons[11].ToString() : "0") };
                ListViewItem lstItm = new ListViewItem(str);

                if (col != 0)
                {
                    lstItm.BackColor = Color.FromArgb(233, 247, 248);

                    col = 0;
                }
                else
                {
                    col++;
                }
                //  lstTrendMos.Items.Add(lstItm);
            }
            //  lstTrendMos.Items.Add(new ListViewItem());
            foreach (DataRow drDus in dtDus.Rows)
            {
                int duid = Convert.ToInt32(drDus["ID"]);
                //Int64 soh = bal.GetDUSOH(itemId, duid, dtCurrent.Month, dtCurrent.Year);
                //Int64 amc = bal.CalculateDUAMC(itemId, duid, dtCurrent.Month, dtCurrent.Year, 0);
                //Int64 issue = iss.GetDUIssueByMonth(itemId, duid, dtCurrent.Month, dtCurrent.Year);
                //decimal mos = ((amc > 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                //mos = Decimal.Round(mos, 1);
                int[] mon = { 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

                decimal[] cons = new decimal[12];
                for (int i = 0; i < mon.Length; i++)
                {
                    int yr = (mon[i] > 10) ? _dtCurrent.Year - 1 : _dtCurrent.Year;
                    Int64 soh = bal.GetDUSOH(_itemId, duid, mon[i], yr);
                    double amc = Builder.CalculateAverageConsumption(_itemId, duid, _dtCurrent.Subtract(TimeSpan.FromDays(180)), _dtCurrent, CalculationOptions.Monthly);//bal.CalculateDUAMC(_itemId, duid, mon[i], yr, 0);
                    decimal mos = ((amc != 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                    cons[i] = Decimal.Round(mos, 1);
                }

                string[] str = { drDus["Name"].ToString(), ((cons[0] != 0) ? cons[0].ToString() : "0"), ((cons[1] != 0) ? cons[1].ToString() : "0"), ((cons[2] != 0) ? cons[2].ToString() : "0"), ((cons[3] != 0) ? cons[3].ToString() : "0"), ((cons[4] != 0) ? cons[4].ToString() : "0"), ((cons[5] != 0) ? cons[5].ToString() : "0"), ((cons[6] != 0) ? cons[6].ToString() : "0"), ((cons[7] != 0) ? cons[7].ToString() : "0"), ((cons[8] != 0) ? cons[8].ToString() : "0"), ((cons[9] != 0) ? cons[9].ToString() : "0"), ((cons[10] != 0) ? cons[10].ToString() : "0"), ((cons[11] != 0) ? cons[11].ToString() : "0") };
                ListViewItem lstItm = new ListViewItem(str);

                if (col != 0)
                {
                    lstItm.BackColor = Color.FromArgb(233, 247, 248);
                    col = 0;
                }
                else
                {
                    col++;
                }
                // lstTrendMos.Items.Add(lstItm);
            }
        }
        /// <summary>
        /// The save button should be active only when the date is Sene 30 or in the month of Hamle.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void YearEndProcess_Load(object sender, EventArgs e)
        {
            var ethDate = new EthiopianDate.EthiopianDate();

            lkCommodityTypes.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCommodityTypes.ItemIndex = 0;
            btnSave.Enabled = false;
            var unit = new ItemUnit();
            var allunits = unit.GetAllUnits();
            unitBindingSource.DataSource = allunits.DefaultView;
            var unitcolumn = ((GridView)grdYearEnd.MainView).Columns[9];
            switch (VisibilitySetting.HandleUnits)
            {
                case 1:
                    unitcolumn.Visible = false;
                    break;
                case 2:
                    unitcolumn.Visible = true;
                    break;
                default:
                    unitcolumn.Visible = true;
                   break;
            }
            var str = new Stores();
            str.GetActiveStores();

            cboStores.Properties.DataSource = str.DefaultView;
            cboStores.ItemIndex = 0;
            dtDate.CustomFormat = "MMMM dd, yyyy";
        }
        /// <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";
            }
        }
 /// <summary>
 /// Populates lstStores based stores supplied
 /// </summary>
 /// <param name="str"></param>
 private void PopulateStores(Stores str)
 {
     lstStores.Items.Clear();
     int count = 1;
     int col = 0;
     foreach (DataRowView dv in str.DefaultView)
     {
         string[] st = { count.ToString(), dv["StoreName"].ToString(), "" };
         ListViewItem lst = new ListViewItem(st) {Tag = dv["ID"]};
         if (col != 0)
         {
             lst.BackColor = Color.FromArgb(233, 247, 248);
             col = 0;
         }
         else
             col++;
         lstStores.Items.Add(lst);
         count++;
     }
 }
        private void EditIssue_Load(object sender, EventArgs e)
        {
            Stores str = new Stores();
            str.LoadAll();
            cboStores.DataSource = str.DefaultView;

            ReceivingUnits rUnit = new ReceivingUnits();
            rUnit.GetActiveDispensaries();
            cboReceivingUnit.DataSource = rUnit.DefaultView;

            if (_tranId != 0)
            {
                IssueDoc iss = new IssueDoc();
                Items itm = new Items();

                iss.LoadByPrimaryKey(_tranId);

                DataTable dtItm = itm.GetItemById(iss.ItemID);
                string itemName = dtItm.Rows[0]["ItemName"].ToString() + " - " + dtItm.Rows[0]["DosageForm"].ToString() + " - " + dtItm.Rows[0]["Strength"].ToString();

                txtRefNo.Text = iss.RefNo;
                txtBatchNo.Text = iss.BatchNo;
                try
                {
                    txtPack.Text = iss.NoOfPack.ToString();
                    txtQtyPack.Text = iss.QtyPerPack.ToString();
                    txtPrice.Text = (iss.Cost * iss.QtyPerPack).ToString();
                }
                catch
                {
                    txtPack.Text = "0";
                    txtQtyPack.Text = "0";
                    txtPrice.Text = (iss.Cost * 1).ToString();
                }
                txtQuantity.Text = iss.Quantity.ToString();
                DateTime dtDate = Convert.ToDateTime(iss.Date.ToString("MM/dd/yyyy"));
                txtDate.Text = dtDate.ToShortDateString();
                //dtIssDate.Value = DateTime.Now;
                //dtIssDate.CustomFormat = "MM/dd/yyyy";
                //DateTime dtCurrent = Convert.ToDateTime(dtIssDate.Text);

                //long tic = (DateTime.Now.Ticks - dtCurrent.Ticks);
                //DateTime dtIssG = dtDate.AddTicks(tic);

                //dtIssDate.Value = dtIssG;
                cboStores.SelectedValue = iss.StoreId;
                cboReceivingUnit.SelectedValue = iss.ReceivingUnitID;
                txtItemName.Text = itemName;
                txtReceivedBy.Text = iss.IssuedBy;
                txtRemark.Text = iss.Remark;

            }
        }
        /// <summary>
        /// Load the drop downs and tables
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HospitalSettings_Load(object sender, EventArgs e)
        {
            Supplier sup = new Supplier();
            sup.LoadAll();
            PopulateSupplier(sup);

            Stores str = new Stores();
            str.LoadAll();
            PopulateStores(str);

            Shelf slf = new Shelf();
            DataTable dtSlf = slf.GetShelves();
            PopulateShelves(dtSlf.DefaultView);

            ReceivingUnits recUnit = new ReceivingUnits();
            recUnit.LoadAll();
            PopulateReceivingUnit(recUnit);

            DataTable dtdumin = new DataTable();
            dtdumin.Columns.Add("Value");
            dtdumin.Columns.Add("Month");
            object[] objdumin01 = { 0.25, "1 Weeks" };
            dtdumin.Rows.Add(objdumin01);
            object[] objdumin0 = { 0.5, "2 Weeks" };
            dtdumin.Rows.Add(objdumin0);
            object[] objdumin1 = { 0.75, ("3 Weeks") };
            dtdumin.Rows.Add(objdumin1);
            object[] objdumin2 = { 1, (1 + " Month") };
            dtdumin.Rows.Add(objdumin2);
            object[] objdumin3 = { 2, (2 + " Month") };
            dtdumin.Rows.Add(objdumin3);
            cboDUMin.DataSource = dtdumin;

            DataTable dtdumax = new DataTable();
            dtdumax.Columns.Add("Value");
            dtdumax.Columns.Add("Month");
            object[] objdumax01 = { 0.25, "1 Weeks" };
            dtdumax.Rows.Add(objdumax01);
            object[] objdumax010 = { 0.5, "2 Weeks" };
            dtdumax.Rows.Add(objdumax010);
            object[] objdumax011 = { 0.75, ("3 Weeks") };
            dtdumax.Rows.Add(objdumax011);
            object[] objdumax012 = { 1, (1 + " Month") };
            dtdumax.Rows.Add(objdumax012);
            object[] objdumax013 = { 2, (2 + " Month") };
            dtdumax.Rows.Add(objdumax013);
            cboDUMax.DataSource = dtdumax;
        }
        private void TransferForm_Load(object sender, EventArgs e)
        {
            var store = new Stores();
            store.GetActiveStores();
            lkFromStore.Properties.DataSource = store.DefaultView;
            lkCategories.Properties.DataSource = BLL.Type.GetAllTypes();

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

            lkToStore.Properties.DataSource = store.DefaultView;
            var unitcolumn0 = ((GridView)gridItemsChoice.MainView).Columns[7];
            var unitcolumn1 = ((GridView)gridItemsChoice.MainView).Columns[2];
            var unitcolumn2 = ((GridView)receivingGrid.MainView).Columns[4];

            switch (VisibilitySetting.HandleUnits)
            {
                case 1:
                    unitcolumn0.Visible = false;
                    unitcolumn1.Visible = true;
                    unitcolumn2.Visible = false;
                    break;
                case 2:
                    unitcolumn0.Visible = true;
                    unitcolumn1.Visible = false;
                    unitcolumn2.Visible = true;
                    break;
                default:
                    unitcolumn0.Visible = true;
                    unitcolumn1.Visible = false;
                    unitcolumn2.Visible = true;
                    break;
            }

            lkCategories.ItemIndex = 0;
            lkFromStore.ItemIndex = 0;

            var userID = MainWindow.LoggedinId;
            var us = new User();
            us.LoadByPrimaryKey(userID);
            txtApprovedBy.Text = us.FullName;

            // bind the current date as the datetime field
            dtRecDate.Value = DateTime.Now;
            gridItemsView.ActiveFilterString = String.Format("[ExpiryDate] > #{0}# ", DateTime.Now);
        }
        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);
            }
        }
        private void ManageItems_Load(object sender, EventArgs e)
        {
            ReceivingUnits rec = new ReceivingUnits();
            DataTable drRec = rec.GetAllApplicableDU();
            cboIssuedTo.Properties.DataSource = drRec;
            cboIssuedTo.ItemIndex = -1;//.SelectedIndex = -1;
            cboIssuedTo.Text = @"Select Issue Location";

            Stores stor = new Stores();
            stor.GetActiveStores();
            cboStores.Properties.DataSource = stor.DefaultView;
            cboStores.ItemIndex = 0;
        }
        /// <summary>
        /// Load all the stores and put them in the combo box
        /// Set the logged in user name in the issued by text box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void IssuingForm_Load(object sender, EventArgs e)
        {
            var unitcolumn = ((GridView)gridItemsChoice.MainView).Columns[4];
            var unitid = ((GridView)issueGrid.MainView).Columns[14];
            var unitcolumn1 = ((GridView)issueGrid.MainView).Columns[2];
            var duamc = ((GridView)issueGrid.MainView).Columns[8];
            var mrdusoh = ((GridView)issueGrid.MainView).Columns[6];
            var recommendedqty = ((GridView)issueGrid.MainView).Columns[9];
            var requestedqty = ((GridView)issueGrid.MainView).Columns[12];
            var qtyperpack = ((GridView)issueGrid.MainView).Columns[11];
            var unitcolumn3 = ((GridView)gridItemsChoice.MainView).Columns[14];
            switch (VisibilitySetting.HandleUnits)
            {
                case 3:
                    unitcolumn.Visible = false;
                    unitcolumn1.Visible = false;
                    unitid.Visible = true;
                    qtyperpack.Visible = true;
                    mrdusoh.Visible = true;
                    duamc.Visible = true;
                    recommendedqty.Visible = true;
                    duamc.Visible = true;
                    requestedqty.Visible = false;
                    unitcolumn3.Visible = true;
                    break;
                case 2:
                    unitcolumn.Visible = false;
                    unitcolumn1.Visible = false;
                    unitid.Visible = true;
                    qtyperpack.Visible = true;
                    mrdusoh.Visible = false;
                    recommendedqty.Visible = false;
                    duamc.Visible = false;
                    requestedqty.Visible = false;
                    unitcolumn3.Visible = true;
                    break;
                default:
                    unitcolumn.Visible = true;
                    unitcolumn1.Visible = true;
                    unitid.Visible = false;
                    qtyperpack.Visible = true;
                    duamc.Visible = true;
                    unitcolumn3.Visible = false;
                    break;
            }

            PopulateCatTree(_selectedType);
            var stor = new Stores();
            stor.GetActiveStores();
            storebindingSource.DataSource = stor.DefaultView;
            cboStores.Properties.DataSource = storebindingSource.DataSource;
            cboStores.ItemIndex = 0;
            cboStores.Properties.DisplayMember = "StoreName";
            cboStores.Properties.ValueMember = "ID";
            cboStoreConf.Properties.DataSource = stor.DefaultView;
            lkCategories.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCategories.ItemIndex = 0;

            var unit = new ItemUnit();
            var xx = unit.GetAllUnits();
            UnitsbindingSource.DataSource = xx.DefaultView;

            var userID = MainWindow.LoggedinId;
            var us = new User();
            us.LoadByPrimaryKey(userID);
            txtIssuedBy.Text = us.FullName;

            if (!chkExcludeStockedOut.Checked)
                gridItemChoiceView.ActiveFilterString = String.Format("TypeID={0}", Convert.ToInt32(lkCategories.EditValue));
        }
        /// <summary>
        /// Loads the lookups
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ManageItems_Load(object sender, EventArgs e)
        {
            PopulateCatTree(_selectedType);
            DataTable table = new DataTable();
            table = BLL.Type.GetAllTypes();
            DataRow row = table.NewRow();
            row["ID"] = "0";
            row["Name"] = "All";
            table.Rows.InsertAt(row, 0);

            lkCommodityTypes.Properties.DataSource = table;

            // Select the very first commodity type.
            lkCommodityTypes.ItemIndex = 0;
            //DateTime xx = dtDate.Value;
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            _dtCurrent = ConvertDate.DateConverter(dtDate.Text);
               // dtDate.Value = xx;
            var stor = new Stores();
            stor.GetActiveStores();
            cboStores.Properties.DataSource = stor.DefaultView;
            cboStores.ItemIndex = 0;

            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            _dtCurrent = ConvertDate.DateConverter(dtDate.Text);

            DataTable dtYear = Items.AllYearsReport();
            DataRow roww = dtYear.NewRow();
            roww["year"] = "All";
            dtYear.Rows.InsertAt(roww, 0);
            cboYear.Properties.DataSource = dtYear;
            cboYear.ItemIndex = 0;
        }
        /// <summary>
        /// Load the dropdowns and the category tree
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ManageItems_Load(object sender, EventArgs e)
        {
            PopulateCatTree(_selectedType);

            var type = new BLL.Type();
            var alltypes = type.GetAllCategory();
            lkCategory.Properties.DataSource = alltypes;
            lkCategory.Properties.DisplayMember = "Name";
            lkCategory.Properties.ValueMember = "ID";
            lkCategory.ItemIndex = 0;

            var stor = new Stores();
            stor.GetActiveStores();
            cboStores.DataSource = stor.DefaultView;
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            _dtCur = ConvertDate.DateConverter(dtDate.Text);
            dtTo.Value = DateTime.Now;
               // int yearFrom = ((_dtCur.Month == 11 && _dtCur.Month == 12) ? _dtCur.Year : _dtCur.Year - 1 );
            int currYear = (EthiopianDate.EthiopianDate.Now.Month < 11) ? EthiopianDate.EthiopianDate.Now.Year - 1 : EthiopianDate.EthiopianDate.Now.Year;
            dtFrom.Value = EthiopianDate.EthiopianDate.EthiopianToGregorian(String.Format("{0}/{1}/{2}", 1, 11, currYear));

            dtFrom.CustomFormat = "MM/dd/yyyy";
            DateTime dt1 = ConvertDate.DateConverter(dtFrom.Text);
            dtTo.CustomFormat = "MM/dd/yyyy";
            DateTime dt2 = ConvertDate.DateConverter(dtTo.Text);
            //string dRange = "From " + dtFrom.Text + " to " + dtTo.Text;
            //layoutControlGroup3.Text = "Cost Report " + dRange;
            if (dt1 == dt2)
            {
                dt1 = ((dt1.Month == 11 || dt1.Month == 12) ? new DateTime(dt1.Year, 11, 1) : new DateTime(dt1.Year - 1, 11, 1));
                //dRange = "For Year " + dt1.Year.ToString();
            }
            this._isReady = true;

            txtFromDate.Text = dt1.ToShortDateString();

            PopulateItemList();
        }
        private void ManageItems_Load(object sender, EventArgs e)
        {
            var stor = new Stores();
            stor.GetActiveStores();
            cboStores.Properties.DataSource = stor.DefaultView;
            cboStores.ItemIndex = 0;

            var sup = new Supplier();
            var dtSup = sup.GetSuppliersWithTransaction();
            cboSupplier.Properties.DataSource = dtSup;
            cboSupplier.ItemIndex = -1;
            cboSupplier.Text = "Select Supplier";

            var itemunit = new ItemUnit();
            var units = itemunit.GetAllUnits();
            unitsbindingSource.DataSource = units.DefaultView;

            // bind the supplier lookup for the grid.
            lkEditSupplier.DataSource = dtSup;
            var unitcolumn = ((GridView)gridReceives.MainView).Columns[14];
            switch (VisibilitySetting.HandleUnits)
            {
                case 1:
                    unitcolumn.Visible = false;
                    break;
                case 2:
                    unitcolumn.Visible = true;
                    break;
                default:
                    unitcolumn.Visible = true;
                    break;
            }

            // bind the current dates

               try
            {
                var dr = (DataRowView) lstTree.GetDataRecordByNode(lstTree.Nodes[0].FirstNode);
                if (dr == null) return;
                var rec = new ReceiveDoc();
                if (dr["ParentID"] == DBNull.Value)
                {
                   // int yr = ((dtCurrent.Month > 10) ? dtCurrent.Year : dtCurrent.Year - 1);
                    var dt1 = new DateTime(Convert.ToInt32(dr["ID"]) - 1, 11, 1);
                    var dt2 = new DateTime(Convert.ToInt32(dr["ID"]), 11, 1);
                    dtRec = rec.GetTransactionByDateRange(Convert.ToInt32(cboStores.EditValue), dt1, dt2);
                    lblRecDate.Text =  dr["RefNo"].ToString();
                }
                else
                {
                    dtRec = rec.GetTransactionByRefNo(dr["RefNo"].ToString(), Convert.ToInt32(cboStores.EditValue),dr["Date"].ToString());
                    lblRecDate.Text = Convert.ToDateTime(dr["Date"]).ToString("MM dd,yyyy");
                }
                gridReceives.DataSource = dtRec;
            }
            catch (Exception ex)
            {

            }
        }
        private void PopulateLogisticSummary()
        {
            //dtDate.Value = DateTime.Now;
            //    dtDate.CustomFormat = "MM/dd/yyyy";
            //DateTime dtCurrent = ConvertDate.DateConverter(dtDate.Text);

            ReceivingUnits du = new ReceivingUnits();
            DataTable dtDus = du.GetApplicableDUsAll(_itemId);
            Balance bal = new Balance();
            IssueDoc iss = new IssueDoc();
            Stores stor = new Stores();
            stor.GetActiveStores();
            DataTable dtStores = stor.DefaultView.ToTable();

            DataTable dtbl = new DataTable();
            dtbl.Columns.Add("StoreName");
            dtbl.Columns.Add("SOH");
            dtbl.Columns.Add("AMC");
            dtbl.Columns.Add("Issue");
            dtbl.Columns.Add("MOS");

            foreach (DataRow drStr in dtStores.Rows)
            {
                int storeId = Convert.ToInt32(drStr["ID"]);
                Int64 soh = bal.GetSOH(_itemId, storeId, _dtCurrent.Month, _dtCurrent.Year);
                double amc = Builder.CalculateAverageConsumption(_itemId, storeId, _dtCurrent.Subtract(TimeSpan.FromDays(180)), _dtCurrent, CalculationOptions.Monthly); //bal.CalculateAMC(_itemId, storeId, _dtCurrent.Month, _dtCurrent.Year); //Builder.CalculateAverageConsumption(_itemId, storeId,dtCurrent.Subtract(TimeSpan.FromDays(180)),dtCurrent,CalculationOptions.Monthly);
                //bal.CalculateAMC(_itemId, storeId, _dtCurrent.Month, _dtCurrent.Year);
                Int64 issue = iss.GetIssuedQuantityByMonth(_itemId, storeId, _dtCurrent.Month, _dtCurrent.Year);
                decimal mos = ((amc > 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                mos = Decimal.Round(mos, 1);

                string[] str = { drStr["StoreName"].ToString(), ((soh != 0) ? soh.ToString("#,###") : "0"), ((amc != 0) ? amc.ToString("#,###") : "0"), ((issue != 0) ? issue.ToString("#,###") : "0"), mos.ToString() };
                dtbl.Rows.Add(str);
            }

            foreach (DataRow drDus in dtDus.Rows)
            {
                int duid = Convert.ToInt32(drDus["ID"]);
                Int64 soh = bal.GetDUSOH(_itemId, duid, _dtCurrent.Month, _dtCurrent.Year);
                double amc = Builder.CalculateAverageConsumption(_itemId, duid, _dtCurrent.Subtract(TimeSpan.FromDays(180)), _dtCurrent, CalculationOptions.Monthly);//bal.CalculateDUAMC(_itemId, duid, _dtCurrent.Month, _dtCurrent.Year, 0);
                Int64 issue = iss.GetDUIssueByMonth(_itemId, duid, _dtCurrent.Month, _dtCurrent.Year);
                decimal mos = ((amc > 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                mos = Decimal.Round(mos, 1);

                string[] str = { drDus["Name"].ToString(), ((soh != 0) ? soh.ToString("#,###") : "0"), ((amc != 0) ? amc.ToString("#,###") : "0"), ((issue != 0) ? issue.ToString("#,###") : "0"), mos.ToString() };
                dtbl.Rows.Add(str);
            }

            gridDispensaryView.DataSource = dtbl;
        }
        private void ManageItems_Load(object sender, EventArgs e)
        {
            PopulateCatTree(SelectedType);

            lkCommodityTypes.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCommodityTypes.ItemIndex = 0;

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

            var stor = new Stores();
            stor.GetActiveStores();
            cboStores.Properties.DataSource = stor.DefaultView;

            DataTable dtMonths = new DataTable();
            dtMonths.Columns.Add("Value");
            dtMonths.Columns.Add("Month");
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            dtCur = ConvertDate.DateConverter(dtDate.Text);
            int currentMont = dtCur.Month;
            int year = ((currentMont < 11) ? dtCur.Year : dtCur.Year + 1);
            // this is just a try
            if (currentMont >= 11)
            {
                currentMont -= 11;
            }

            var dtyears = Items.AllYears();

            cboStores.ItemIndex = 0;
            cboYear.Properties.DataSource = dtyears;
            cboYear.EditValue = year;
            if (cboYear.Properties.Columns.Count > 0)
                cboYear.Properties.Columns[0].Alignment = DevExpress.Utils.HorzAlignment.Near;

            IsReady = true;
            PopulateGrid();
        }
        private void GeneralReport_Load(object sender, EventArgs e)
        {
            var type = new BLL.Type();
            DataTable alltypes = type.GetAllCategory();
            DataRow row = alltypes.NewRow();
            row["ID"] = "0";
            row["Name"] = "All";
            alltypes.Rows.InsertAt(row, 0);

            lkCategory.Properties.DataSource = alltypes;
            lkCategory.Properties.DisplayMember = "Name";
            lkCategory.Properties.ValueMember = "ID";
            lkCategory.ItemIndex = 0;

            Stores stor = new Stores();
            stor.GetActiveStores();
            DataTable dtStor = stor.DefaultView.ToTable();
            DataRow rowStore = dtStor.NewRow();
            rowStore["ID"] = "0";
            rowStore["StoreName"] = "All";
            dtStor.Rows.InsertAt(rowStore, 0);

            cboStores.Properties.DataSource = dtStor;
            cboStores.ItemIndex = 0;

            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            dtCurrent = ConvertDate.DateConverter(dtDate.Text);
            curMont = dtCurrent.Month;
            curYear = dtCurrent.Year;

            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            _dtCur = ConvertDate.DateConverter(dtDate.Text);

            cboYear.Properties.DataSource = Items.AllYears();
            cboYear.EditValue = curYear;
        }
        /// <summary>
        /// Load the loookups
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ManageItems_Load(object sender, EventArgs e)
        {
            var unitcolumn = ((GridView) gridInventory.MainView).Columns[7];
            unitcolumn.Visible = VisibilitySetting.HandleUnits != 1;
            var stor = new Stores();

            var unit = new ItemUnit();
            var allunit = unit.GetAllUnits();
            unitbindingSource.DataSource = allunit.DefaultView;

            stor.GetActiveStores();
            cboStores.DataSource = stor.DefaultView;
        }
 /// <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 ManageItems_Load(object sender, EventArgs e)
        {
            lkCommodityTypes.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCommodityTypes.ItemIndex = 0;

            PopulateCatTree();

            Stores stor = new Stores();
            stor.GetActiveStores();
            cboStores.DataSource = stor.DefaultView;

            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            dtCurrent = ConvertDate.DateConverter(dtDate.Text);

            Programs prog = new Programs();
            DataTable dtProg = new DataTable();
            dtProg = prog.GetSubPrograms();
            object[] objProg = { 0, "All Programs", "", 0, "" };
            dtProg.Rows.Add(objProg);
            cboSubProgram.DataSource = dtProg;
            cboSubProgram.SelectedIndex = -1;
            cboSubProgram.Text = "Select Program";

            ReceivingUnits rec = new ReceivingUnits();
            DataTable drRec = rec.GetAllApplicableDU();
            cboIssuedTo.DataSource = drRec;
            cboIssuedTo.SelectedIndex = -1;
            cboIssuedTo.Text = "Select Issue Location";

            int month = dtCurrent.Month;
            int year = ((dtCurrent.Month < 11) ? dtCurrent.Year : dtCurrent.Year + 1);

            DataTable dtyears = Items.AllYears();

            foreach (DataRow drYears in dtyears.Rows)
            {
                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;
        }
 /// <summary>
 /// Handles the sorting when the user clicks on the lstStores columns
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lstStores_ColumnClick(object sender, ColumnClickEventArgs e)
 {
     Stores str = new Stores();
     str.LoadAll();
     if (_sortStore == "ASC")
     {
         str.Sort = "StoreName ASC";
         _sortStore = "DESC";
     }
     else
     {
         str.Sort = "StoreName DESC";
         _sortStore = "ASC";
     }
     PopulateStores(str);
 }
        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();
        }
        /// <summary>
        /// Populates the shelf information
        /// </summary>
        /// <param name="dtSlf"></param>
        private void PopulateShelves(DataView dtSlf)
        {
            int count = 1;
            int col = 0;
            lstShelfs.Items.Clear();
            foreach (DataRow dv in dtSlf.ToTable().Rows)
            {
                string[] st = { count.ToString(), dv["ShelfCode"].ToString(), dv["ShelfType"].ToString(), "", "" };
                ListViewItem lst = new ListViewItem(st) {Tag = dv["ID"]};
                if (col != 0)
                {
                    lst.BackColor = Color.FromArgb(233, 247, 248);
                    col = 0;
                }
                else
                    col++;
                lstShelfs.Items.Add(lst);
                count++;
            }

            Stores str = new Stores();
            str.LoadAll();
            cboStore.DataSource = str.DefaultView;
        }
        /// <summary>
        /// Loads the form and loads the lookups and the grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ManageItems_Load(object sender, EventArgs e)
        {
            //CALENDAR:
            PopulateCatTree(_selectedType);

            lkCommodityTypes.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCommodityTypes.ItemIndex = 0;

            Stores stor = new Stores();
            stor.GetActiveStores();
            cboStores.Properties.DataSource = stor.DefaultView;
            cboStores.EditValue = 0;

            string[] arr = new string[] {"All", "Stock Out", "Below EOP", "Near EOP", "Normal", "Over Stocked"};
            cboIssuedTo.Properties.DataSource = arr;

            DataTable dtMonths = new DataTable();
            dtMonths.Columns.Add("Value");
            dtMonths.Columns.Add("Month");
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            _dtCur = ConvertDate.DateConverter(dtDate.Text);
            int currentMont = _dtCur.Month;
            //int year = ((currentMont < 11) ? _dtCur.Year : _dtCur.Year + 1);
            int year = _dtCur.Year;
            // this is just a try
            //if (currentMont >= 11)
            //{
            //    currentMont -= 11;
            //}

            DataTable dtyears = Items.AllYears();
            //if (year == _dtCur.Year + 1)
            //{
            //    object[] objYear = { year };
            //    dtyears.Rows.Add(objYear);
            //}
            cboYear.Properties.DataSource = dtyears;
            cboYear.EditValue = year;
            if(cboYear.Properties.Columns.Count > 0)
                cboYear.Properties.Columns[0].Alignment = DevExpress.Utils.HorzAlignment.Near;

            //Programs prog = new Programs();
            //DataTable dtProg = prog.GetSubPrograms();
            //object[] objProg = { 0, "All Programs", "", 0, "" };
            //dtProg.Rows.Add(objProg);
            //cboSubProgram.Properties.DataSource = dtProg;
            //cboSubProgram.ItemIndex = -1;
            //cboSubProgram.Text = "Select Program";

            ReceivingUnits rec = new ReceivingUnits();
            DataTable drRec = rec.GetAllApplicableDU();
            cboDUnits.Properties.DataSource = drRec;
            cboDUnits.Properties.DisplayMember = "Name";
            cboDUnits.Properties.ValueMember = "ID";
            cboDUnits.EditValue = 1;

            this._isReady = true;
            PopulateGrid();
        }
        private void ManageItems_Load(object sender, EventArgs e)
        {
            PopulateCatTree(SelectedType);

            lkCommodityTypes.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCommodityTypes.ItemIndex = 0;

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

            var stor = new Stores();
            stor.GetActiveStores();
            cboStores.Properties.DataSource = stor.DefaultView;

            string[] arr = {"All",
            "Stock Out",
            "Below EOP",
            "Near EOP",
            "Normal",
            "Over Stocked"};

            cboStatus.Properties.DataSource = arr;

            DataTable dtMonths = new DataTable();
            dtMonths.Columns.Add("Value");
            dtMonths.Columns.Add("Month");
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            dtCur = ConvertDate.DateConverter(dtDate.Text);
            int currentMont = dtCur.Month;
            int year = ((currentMont < 11) ? dtCur.Year : dtCur.Year + 1);
            // this is just a try
            if (currentMont >= 11)
            {
                currentMont -= 11;
            }

            var dtyears = Items.AllYears();

            cboYear.Properties.DataSource = dtyears;
            cboYear.EditValue = year;
            if (cboYear.Properties.Columns.Count > 0)
                cboYear.Properties.Columns[0].Alignment = DevExpress.Utils.HorzAlignment.Near;
            var prog = new Programs();
            var dtProg = new DataTable();
            dtProg = prog.GetSubPrograms();
            object[] objProg = { 0, "All Programs", "", 0, "" };
            dtProg.Rows.Add(objProg);
            cboSubProgram.Properties.DataSource = dtProg;
            cboSubProgram.ItemIndex = -1;
            cboSubProgram.Text = "Select Program";

            var rec = new ReceivingUnits();
            var drRec = rec.GetAllApplicableDU();
            cboIssuedTo.Properties.DataSource = drRec;
            cboIssuedTo.ItemIndex = -1;
            cboIssuedTo.Text = "Select Issue Location";
            IsReady = true;

            var unitcolumn = ((GridView)gridItemsChoice.MainView).Columns[15];
            switch (VisibilitySetting.HandleUnits)
            {
                case 1:
                    unitcolumn.Visible = false;
                    break;
                case 2:
                    unitcolumn.Visible = true;
                    break;
                default:
                    unitcolumn.Visible = true;
                    break;
            }
            PopulateGrid();
        }
        private void DetailSoh()
        {
            //CALENDAR:
            dtDate.Value = DateTime.Now;
            dtDate.CustomFormat = "MM/dd/yyyy";
            DateTime dtCurrent = new DateTime();// Convert.ToDateTime(dtDate.Text);
            try
            {
                dtCurrent = Convert.ToDateTime(dtDate.Text);
            }
            catch
            {
                string dtValid = "";
                string yer = "";
                if (Convert.ToInt32(dtDate.Text.Substring(0, 2)) == 13)
                {
                    dtValid = dtDate.Text;
                    yer = dtValid.Substring(dtValid.Length - 4, 4);
                    dtCurrent = Convert.ToDateTime("12/30/" + yer);
                }
                else if (Convert.ToInt32(dtDate.Text.Substring(0, 2)) == 2)
                {
                    dtValid = dtDate.Text;
                    yer = dtValid.Substring(dtValid.Length - 4, 4);
                    dtCurrent = Convert.ToDateTime("2/28/" + yer);
                }
            }

            ReceivingUnits du = new ReceivingUnits();
            DataTable dtDus = du.GetApplicableDUsAll(_itemId);
            int col = 0;
            Balance bal = new Balance();
            IssueDoc iss = new IssueDoc();
            Stores stor = new Stores();
            stor.GetActiveStores();
            DataTable dtStores = stor.DefaultView.ToTable();

            foreach (DataRow drStr in dtStores.Rows)
            {
                int storeId = Convert.ToInt32(drStr["ID"]);
                //Int64 soh = bal.GetSOH(itemId, storeId, dtCurrent.Month, dtCurrent.Year);
                //Int64 amc = bal.CalculateAMC(itemId, storeId, dtCurrent.Month, dtCurrent.Year);
                //Int64 issue = iss.GetIssuedQuantityByMonth(itemId, storeId, dtCurrent.Month, dtCurrent.Year);
                //decimal mos = ((amc > 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                //mos = Decimal.Round(mos, 1);

                int[] mon = { 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

                long[] cons = new long[12];
                for (int i = 0; i < mon.Length; i++)
                {
                    int yr = (mon[i] > 10) ? dtCurrent.Year - 1 : dtCurrent.Year;
                    if (!(yr == dtCurrent.Year && mon[i] > dtCurrent.Month && mon[i] < 11))
                    {

                        cons[i] = bal.GetSOH(_itemId, storeId, mon[i], yr);
                    }
                    else
                        cons[i] = 0;
                }

                string[] str = { drStr["StoreName"].ToString(), ((cons[0] != 0) ? cons[0].ToString("#,###") : "0"), ((cons[1] != 0) ? cons[1].ToString("#,###") : "0"), ((cons[2] != 0) ? cons[2].ToString("#,###") : "0"), ((cons[3] != 0) ? cons[3].ToString("#,###") : "0"), ((cons[4] != 0) ? cons[4].ToString("#,###") : "0"), ((cons[5] != 0) ? cons[5].ToString("#,###") : "0"), ((cons[6] != 0) ? cons[6].ToString("#,###") : "0"), ((cons[7] != 0) ? cons[7].ToString("#,###") : "0"), ((cons[8] != 0) ? cons[8].ToString("#,###") : "0"), ((cons[9] != 0) ? cons[9].ToString("#,###") : "0"), ((cons[10] != 0) ? cons[10].ToString("#,###") : "0"), ((cons[11] != 0) ? cons[11].ToString("#,###") : "0") };
                ListViewItem lstItm = new ListViewItem(str);

                if (col != 0)
                {
                    lstItm.BackColor = Color.FromArgb(233, 247, 248);

                    col = 0;
                }
                else
                {
                    col++;
                }
                //lstTrendSoh.Items.Add(lstItm);
            }
            //lstTrendSoh.Items.Add(new ListViewItem());
            foreach (DataRow drDus in dtDus.Rows)
            {
                int duid = Convert.ToInt32(drDus["ID"]);
                //Int64 soh = bal.GetDUSOH(itemId, duid, dtCurrent.Month, dtCurrent.Year);
                //Int64 amc = bal.CalculateDUAMC(itemId, duid, dtCurrent.Month, dtCurrent.Year, 0);
                //Int64 issue = iss.GetDUIssueByMonth(itemId, duid, dtCurrent.Month, dtCurrent.Year);
                //decimal mos = ((amc > 0) ? Convert.ToDecimal(soh) / Convert.ToDecimal(amc) : 0);
                //mos = Decimal.Round(mos, 1);
                int[] mon = { 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

                long[] cons = new long[12];
                for (int i = 0; i < mon.Length; i++)
                {
                    int yr = (mon[i] > 10) ? dtCurrent.Year - 1 : dtCurrent.Year;
                    cons[i] = bal.GetDUSOH(_itemId, duid, mon[i], yr);
                }

                string[] str = { drDus["Name"].ToString(), ((cons[0] != 0) ? cons[0].ToString("#,###") : "0"), ((cons[1] != 0) ? cons[1].ToString("#,###") : "0"), ((cons[2] != 0) ? cons[2].ToString("#,###") : "0"), ((cons[3] != 0) ? cons[3].ToString("#,###") : "0"), ((cons[4] != 0) ? cons[4].ToString("#,###") : "0"), ((cons[5] != 0) ? cons[5].ToString("#,###") : "0"), ((cons[6] != 0) ? cons[6].ToString("#,###") : "0"), ((cons[7] != 0) ? cons[7].ToString("#,###") : "0"), ((cons[8] != 0) ? cons[8].ToString("#,###") : "0"), ((cons[9] != 0) ? cons[9].ToString("#,###") : "0"), ((cons[10] != 0) ? cons[10].ToString("#,###") : "0"), ((cons[11] != 0) ? cons[11].ToString("#,###") : "0") };
                ListViewItem lstItm = new ListViewItem(str);

                if (col != 0)
                {
                    lstItm.BackColor = Color.FromArgb(233, 247, 248);
                    col = 0;
                }
                else
                {
                    col++;
                }
                // lstTrendSoh.Items.Add(lstItm);
            }
        }
        private void RRFForm_Load(object sender, EventArgs e)
        {
            btnAutoPushToPFSA.Enabled = false;
            btnSendEmergencyOrder.Enabled = false;
            var unitcolumn = ((GridView) gridItemsChoice.MainView).Columns[2];
            var unitcolumn1 = ((GridView) gridItemsChoice.MainView).Columns[13];
            layoutControlItem18.Visibility =LayoutVisibility.Never;
            switch (VisibilitySetting.HandleUnits)
            {
                case 3:
                    unitcolumn.Visible = false;
                    unitcolumn1.Visible = true;
                    break;
                case 2:
                    unitcolumn.Visible = false;
                    unitcolumn1.Visible = true;
                    break;
                default:
                    unitcolumn.Visible = true;
                    unitcolumn1.Visible = false;
                    break;
            }

            var unit = new ItemUnit();
            var units = unit.GetAllUnits();
            unitsBindingSource.DataSource = units.DefaultView;

            var type = new BLL.Type();
            var alltypes = type.GetAllCategory();
            categorybindingSource.DataSource = alltypes.DefaultView;

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

            var orderstatus = new PharmInventory.HelperClasses.OrderStatus();
            orderbindingSource.DataSource = orderstatus.GetRRFOrders();
            lkorderstatus.Properties.DataSource = orderbindingSource;
            lkorderstatus.Properties.ValueMember = "RecordId";
            lkorderstatus.Properties.DisplayMember = "Name";

            PopulateTheMonthCombos(cboFromMonth);
            PopulateTheMonthCombos(cboToMonth);
            PopulateTheYearCombo(cboFromYear);
            PopulateTheYearCombo(cboToYear);
            var stor = new Stores();
            stor.GetActiveStores();
            cboStores.Properties.DataSource = stor.DefaultView;
            PopulateRRFs();

            WindowVisibility(false);
            EnableDisableStatusCheck();

            var prog = new Programs();
            prog.GetSubPrograms();
            cboProgram.Properties.DataSource = prog.DefaultView;
            cboProgram.EditValue = 1000;
        }
        /// <summary>
        /// Populate the lookups and item lists.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReceiveingForm_Load(object sender, EventArgs e)
        {
            //gridRecieveView.Columns[4].Visible = VisibilitySetting.HandleUnits;
            var UnitColumn = ((GridView)receivingGrid.MainView).Columns[12];
            var UnitColumn1 = ((GridView)receivingGrid.MainView).Columns[5];
            var UnitColumn2 = ((GridView)gridItemsChoice.MainView).Columns[4];
            var qtyperpack = ((GridView)receivingGrid.MainView).Columns[3];
            var buqty = ((GridView)receivingGrid.MainView).Columns[4];
            switch (VisibilitySetting.HandleUnits)
            {
                case 3:
                    UnitColumn.Visible = true;
                    UnitColumn1.Visible = false;
                    UnitColumn2.Visible = false;
                    qtyperpack.Visible = false;
                    buqty.Visible = false;
                    break;
                case 2:
                    UnitColumn.Visible = true;
                    UnitColumn1.Visible = false;
                    UnitColumn2.Visible = false;
                    qtyperpack.Visible = false;
                    buqty.Visible = false;
                    break;
                case 1:
                    UnitColumn.Visible = false;
                    UnitColumn1.Visible = true;
                    qtyperpack.Visible = true;
                    UnitColumn2.Visible = true;
                    buqty.Visible = true;
                    break;
            }

            var stor = new Stores();
            stor.GetActiveStores();

            cboStores.Properties.DataSource = stor.DefaultView;
            cboStores.ItemIndex = 0;

            Programs prog = new Programs();
            DataTable dtProg = prog.GetSubPrograms();
            cboProgram.Properties.DataSource = dtProg;
            cboProgram.Properties.DisplayMember = "Name";
            cboProgram.Properties.ValueMember = "ID";

            var unit = new ItemUnit();
            var units = unit.GetAllUnits();
            UnitsbindingSource.DataSource = units.DefaultView;

            Supplier sup = new Supplier();
            DataTable dtSup = new DataTable();
            sup.GetActiveSuppliers();
            dtSup = sup.DefaultView.ToTable();
            cboSuppliers.DataSource = dtSup;
            cboSupplier.Properties.DataSource = sup.DefaultView;
            cboSuppliers.Text = "Select Supplier";
            cboSuppliers.ValueMember = "ID";
            cboSuppliers.DisplayMember = "CompanyName";

            // Bind the grid with only active items
            Items itm = new Items();
            //DataTable dtItem = itm.GetAllItems(1);
            DataTable dtItem = BLL.Items.GetActiveItemsByCommodityType(0);
            lkCategories.Properties.DataSource = BLL.Type.GetAllTypes();
            lkCategories.ItemIndex = 0;

            PopulateItemList(dtItem);
            selectedType = radioGroup1.EditValue.ToString();
            PopulateCatTree(selectedType);

            int userID = MainWindow.LoggedinId;
            User us = new User();
            us.LoadByPrimaryKey(userID);
            txtReceivedBy.Text = us.FullName;

            // bind the current date as the datetime field
            dtRecDate.Value = DateTime.Now;
        }