Exemplo n.º 1
0
        private static BLL.OrderDetail GetOrderDetail(int?orderID, IEnumerable <ApprovedOrderDetail> plitsApprovedOrderDetails)
        {
            var hcmisOrderDetail = new BLL.OrderDetail();

            //var plitsApprovedOrderDetails = plitsApprovedOrderDetail as List<ApprovedOrderDetail> ?? plitsApprovedOrderDetail.ToList();
            foreach (var plitsOrderDetail in plitsApprovedOrderDetails)
            {
                hcmisOrderDetail.AddNew();
                hcmisOrderDetail.ItemID            = plitsOrderDetail.PharmaceuticalId;
                hcmisOrderDetail.HACTOrderDetailID = plitsOrderDetail.Id;
                hcmisOrderDetail.Pack = Convert.ToDecimal(plitsOrderDetail.ApprovedQty);

                BLL.ItemUnit iu = new ItemUnit();
                iu.LoadAllForItem(plitsOrderDetail.PharmaceuticalId); //Just load it by item id.  This loads a collection but we just pick and use the first one. :)

                if (iu.RowCount == 0)
                {
                    hcmisOrderDetail.QtyPerPack = iu.QtyPerUnit;
                    hcmisOrderDetail.Quantity   = hcmisOrderDetail.Pack * iu.QtyPerUnit;
                    hcmisOrderDetail.UnitID     = iu.ID;
                    throw new Exception(string.Format("IU Not Configured correctly for item: {0}",
                                                      plitsOrderDetail.PharmaceuticalId));
                }

                hcmisOrderDetail.QtyPerPack = iu.QtyPerUnit;
                hcmisOrderDetail.Quantity   = hcmisOrderDetail.Pack * iu.QtyPerUnit;
                hcmisOrderDetail.UnitID     = iu.ID;
            }


            return(hcmisOrderDetail);
        }
        private void OnItemCheckedChanged(object sender, EventArgs e)
        {
            DataRow dr = gridItemChoiceView.GetFocusedDataRow();
            if (dr == null)
                return;
            // Determine if the selection is to select or deselect the specific raw of item
            bool b = (dr["IsSelected"] != DBNull.Value) ? Convert.ToBoolean(dr["IsSelected"]) : false;

            if (b)
            {
                if (lkForFacility.EditValue != null && dxValidation1stTab.Validate(lkForFacility))
                {
                    //Check if the item is restricted for the chosen Receiving Unit
                    int itemID = int.Parse(dr["ID"].ToString());
                    int ruID = int.Parse(lkForFacility.EditValue.ToString());

                    Item itm = new Item();
                    int allowStatus = itm.GetItemAllowStatus(itemID, ruID);
                    if (allowStatus == -1)
                    {
                        XtraMessageBox.Show(string.Format("{0} is restricted to {1}", dr["FullItemName"], lkForFacility.Text), "Item Restricted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        dr["IsSelected"] = false;
                        return;
                    }

                    // copy the selected item to the selected items data table.
                    _dtSelectedTable.ImportRow(dr);
                    if (_dvOrderTable == null)
                    {
                        BindMainOrderGrid();
                    }
                    _dvOrderTable.Table.ImportRow(dr);
                    _dvOrderTable.Table.Rows[_dvOrderTable.Table.Rows.Count - 1]["ID"] = DBNull.Value;
                    _dvOrderTable.Table.Rows[_dvOrderTable.Table.Rows.Count - 1]["ItemID"] = dr["ID"];
                    if (BLL.Settings.IsRdfMode)
                    {
                        _dvOrderTable.Table.Rows[_dvOrderTable.Table.Rows.Count - 1]["QtyPerPack"] = dr["QtyPerUnit"];
                    }
                    else
                    {
                        _dvOrderTable.Table.Rows[_dvOrderTable.Table.Rows.Count - 1]["QtyPerPack"] = BLL.ItemManufacturer.GetDefaultBuInSKU(Convert.ToInt32(dr["ID"]));
                    }
                }
                else
                {
                    dr["isSelected"] = false;
                    XtraMessageBox.Show("Please choose facility first!", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                // This section is to remove from the selected table the item that is being deselected
                // TODO: what are these all try catches?
                // TOFIX: this needs to seriously consider cleaning up.
                try
                {
                    _dtSelectedTable.PrimaryKey = new DataColumn[] { _dtSelectedTable.Columns["ID"], _dtSelectedTable.Columns["UnitID"] };
                    int id = Convert.ToInt32(dr["ID"]);
                    int unitId = Convert.ToInt32(dr["UnitID"]);
                    DataRow rw = _dtSelectedTable.Rows.Find(new Object[] {
                        id,
                        unitId
                    });

                    if (rw != null)
                    {
                        _dtSelectedTable.Rows.Remove(rw);

                        //if (Type != RequisitionType.History)
                        //     {
                        try
                        {
                            DataRow[] dataRows =
                                _dvOrderTable.Table.Select(String.Format("ItemID = {0} and UnitID = {1}", dr["ID"],
                                                                         dr["UnitID"]));
                            // dtRecGrid.Rows.Remove(dtRecGrid.Rows.Find(dr["ID"]));
                            foreach (DataRow r in dataRows)
                            {
                                if (r["ID"] != DBNull.Value && Type != RequisitionType.History)
                                {
                                    BLL.OrderDetail od = new BLL.OrderDetail();
                                    od.LoadByPrimaryKey(Convert.ToInt32(r["ID"]));
                                    od.MarkAsDeleted();
                                    od.Save();
                                }
                                r.Delete();
                                r.EndEdit();
                            }
                        }
                        catch
                        {

                        }

                    }
                }
                catch (Exception ex) { throw (ex); }
            }
            EnableDisableButtons();
        }
        private void BindMainOrderGrid()
        {
            // Given some items are already selected on the first step of the order process (CDR Request)
            // Bind the second grid with the selected items for the quantity to be filled by the HCMIS Operator

            if (_dtSelectedTable != null && OrderID == null)
            {
                BLL.OrderDetail or = new BLL.OrderDetail();
                or.LoadByPrimaryKey(-1);
                _dvOrderTable = or.DefaultView;
                _dvOrderTable.Table.Columns.Add("FullItemName");
                _dvOrderTable.Table.Columns.Add("StockCode");
                _dvOrderTable.Table.Columns.Add("Unit");
                // RRf Columns
                _dvOrderTable.Table.Columns.Add("BeginningBalance");
                _dvOrderTable.Table.Columns.Add("Adjustment");
                _dvOrderTable.Table.Columns.Add("Loss");
                _dvOrderTable.Table.Columns.Add("DOS");
                _dvOrderTable.Table.Columns.Add("Consumption");
                _dvOrderTable.Table.Columns.Add("MaxStockQuantity");
                _dvOrderTable.Table.Columns.Add("QuantityNeedMax");
                _dvOrderTable.Table.Columns.Add("QuantityReceived");
            }
            orderGrid.DataSource = _dvOrderTable;
        }
        public void EditRequisition(int orderID)
        {
            OrderID = orderID;
            Order ord = new Order();
            ord.LoadByPrimaryKey(orderID);
            txtRefNo.Text = ord.RefNo;
            txtLetterNumber.Text = ord.LetterNo;
            labelControl4.Text = ord.RefNo;
            Institution ru = new Institution();
            ru.LoadByPrimaryKey(ord.RequestedBy);

            if (!ru.IsColumnNull("Zone"))
            {
                // Just because the region Property on the Receiving Unit is not working as desired.
                Zone zone = new Zone();
                zone.LoadByPrimaryKey(ru.Zone);

                lkRegion.EditValue = zone.RegionId;
                lkZone.EditValue = ru.Zone;
            }
            lkForFacility.EditValue = ru.ID;

            lkModes.EditValue = ord.FromStore;
            lkModes_EditValueChanged(null, null);

            lkPaymentType.EditValue = ord.PaymentTypeID;
            txtContactPerson.EditValue = ord.ContactPerson;

            BLL.OrderDetail or = new BLL.OrderDetail();
            or.LoadAllByOrderID(orderID);

            DataView selectables = (DataView)gridItemChoiceView.DataSource;

            if (_dtSelectedTable != null)
            {
                _dtSelectedTable.Clear();
            }
            else
            {
                PopulateItemsList();
            }

            while (!or.EOF)
            {
                // select the items and put it in the dtselected table.
                if (selectables != null)
                {
                    DataRow[] dataRows = selectables.Table.Select(String.Format("ID = {0} and UnitID = {1}", or.ItemID, or.UnitID));
                    if (dataRows.Length > 0)
                    {
                        _dtSelectedTable.ImportRow(dataRows[0]);
                        dataRows[0]["IsSelected"] = true;
                    }
                }
                or.MoveNext();
            }

            _dvOrderTable = or.DefaultView;
            orderGrid.DataSource = _dvOrderTable;
            EnableDisableButtons();
        }
        private static BLL.OrderDetail GetOrderDetail(int? orderID, IEnumerable<ApprovedOrderDetail> plitsApprovedOrderDetails)
        {
            var hcmisOrderDetail = new BLL.OrderDetail();
            //var plitsApprovedOrderDetails = plitsApprovedOrderDetail as List<ApprovedOrderDetail> ?? plitsApprovedOrderDetail.ToList();
            foreach (var plitsOrderDetail in plitsApprovedOrderDetails)
            {
                hcmisOrderDetail.AddNew();
                hcmisOrderDetail.ItemID = plitsOrderDetail.PharmaceuticalId;
                hcmisOrderDetail.HACTOrderDetailID = plitsOrderDetail.Id;
                hcmisOrderDetail.Pack = Convert.ToDecimal(plitsOrderDetail.ApprovedQty);

                BLL.ItemUnit iu = new ItemUnit();
                iu.LoadAllForItem(plitsOrderDetail.PharmaceuticalId); //Just load it by item id.  This loads a collection but we just pick and use the first one. :)

                if (iu.RowCount == 0)
                {
                    hcmisOrderDetail.QtyPerPack = iu.QtyPerUnit;
                    hcmisOrderDetail.Quantity = hcmisOrderDetail.Pack * iu.QtyPerUnit;
                    hcmisOrderDetail.UnitID = iu.ID;
                    throw new Exception(string.Format("IU Not Configured correctly for item: {0}",
                                                      plitsOrderDetail.PharmaceuticalId));
                }

                hcmisOrderDetail.QtyPerPack = iu.QtyPerUnit;
                hcmisOrderDetail.Quantity = hcmisOrderDetail.Pack * iu.QtyPerUnit;
                hcmisOrderDetail.UnitID = iu.ID;
            }

            return hcmisOrderDetail;
        }