Ejemplo n.º 1
0
        public void setEmsOrDrugList(XapDataList <EmsOrDrug> list)
        {
            lock (this) {
                IMaterialStockService stoctService = XapServiceMgr.find <IMaterialStockService>();
                List <GetStockReqDTO> reqDtos      = new List <GetStockReqDTO>();
                if (emsOrDrugList == null)
                {
                    emsOrDrugList = new XapDataList <EmsOrDrug>();
                }
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].Fg_mm == true)
                    {
                        GetStockReqDTO reqDTO = new GetStockReqDTO();
                        reqDTO.Id_mm       = list[i].Id_mm;
                        reqDTO.Id_dep      = list[i].Id_dep_wh;
                        reqDTO.Req_unit_id = list[i].Id_unit_sale;
                        reqDtos.Add(reqDTO);
                    }
                }
                if (reqDtos.Count > 0)
                {
                    MaterialStockDTO[] stockdto = null;
                    try
                    {
                        stockdto = stoctService.getMaterialStocks(reqDtos.ToArray());
                    }
                    catch (Exception ex)
                    {
                        ex.Publish();
                        //this.ShowInfo(ex.Message);
                    }
                    if (stockdto == null)
                    {
                        return;
                    }
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        MaterialStockDTO materialDo = stockdto.FirstOrDefault(p => p.Id_mm == list[i].Id_mm);
                        if (materialDo != null)
                        {
                            FDouble mmcount  = materialDo.Quan_stock;
                            int?    mmStatus = materialDo.Mmstatus;
                            //药房无此药的移除
                            if (mmStatus != null && mmStatus == (int)MaterialStatus.NORELATION)
                            {
                                list.RemoveAt(i);
                            }
                            else
                            {
                                list[i].Fact_count = mmcount;
                                list[i].Price      = materialDo.Price_act;
                                list[i].Mmstatus   = materialDo.Mmstatus;

                                EmsOrDrug ems = emsOrDrugList.FirstOrDefault(p => p.Id_mm == list[i].Id_mm);
                                if (ems != null)
                                {
                                    emsOrDrugList.Remove(ems);
                                }
                                emsOrDrugList.Add(list[i]);
                            }
                        }
                    }
                    List <EmsOrDrug> sortList = null;
                    try
                    {
                        sortList = emsOrDrugList.OrderByDescending(p => p.Fact_count).OrderBy(p => p.Mmstatus).ToList();
                    }
                    catch //(Exception e)
                    {
                        // e.Message;
                    }

                    if (emsOrDrugList == null)
                    {
                        emsOrDrugList = new XapDataList <EmsOrDrug>();
                    }
                    else
                    {
                        emsOrDrugList.Clear();
                    }
                    sortList.ForEach(p => emsOrDrugList.Add(p));
                }
            }
        }