private void Initialize()
        {
            this._medicineDeliverDetail.PropertyChanged += new PropertyChangedEventHandler(_medicineDeliverDetail_PropertyChanged);
            // Init Value
            this.bdsDefine.DataSource = this._defineRepository.GetUnit();
            this.bdsMedicine.DataSource = this._medicineRepo.GetAll();
            
            this._warehouse = this._warehouseRepo.GetByIdMedicine(this._medicineDeliverDetail.MedicineId, AppContext.CurrentClinic.Id);
            this.bdsWareHouse.DataSource = this._warehouse;

            this._vWarehouseDetail = this._vWareHouseDetailRepo.GetByMedicine(this._medicineDeliverDetail.MedicineId);
            foreach (var item in _vWarehouseDetail) {
                item.PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged);
            }

            foreach (var item in this._medicineDeliverDetail.AllocatedWareHouseDetail)
            {
                foreach (var original in this._vWarehouseDetail) {
                    if (item.LotNo != original.LotNo) continue;
                    if (item.ExpiredDate != original.ExpiredDate) continue;
                    original.AllocatedQty = item.AllocatedQty;
                }
            }
            this.bdsVWareHouseDetail.DataSource = this._vWarehouseDetail;
            this._warehouse.RemainQty = this._warehouse.Volumn - this._medicineDeliverDetail.AllocatedQty;

        }
Exemplo n.º 2
0
        private void btnInsert_Click(object sender, System.EventArgs e)
        {
            int minAllowed;
            if (int.TryParse(txtMinAllowed.Text, out minAllowed))
            {
                WareHouse item = new WareHouse();
                this.MinAllowed = minAllowed;
                if (WareHouseID > 0)
                {
                    item = whRepository.GetById(WareHouseID);
                    item.MinAllowed = minAllowed;
                    whRepository.Update(item);
                }
                else
                {
                    item.ClinicId = ClinicID;
                    item.MedicineId = int.Parse(cboMedicine.SelectedValue.ToString());
                    item.MinAllowed = minAllowed;
                    whRepository.Insert(item);
                }

                IsOK = true;

                this.Close();
            }
        }
 // private List<MedicineDeliveryDetailAllocate> allocatedList;
 // private List<WareHouseDetail> _wareHouseDetails;
 public MedicineDeliveryAllocationEntity(int no, MedicineDeliveryDetail deliveryDetail, WareHouse warehouse) {
     this.No = no;
     this._warehouse = warehouse;
     this.MedicineDeliveryDetail = deliveryDetail;
     this.MedicineName = this.MedicineDeliveryDetail.Medicine == null
                             ? String.Empty
                             : this.MedicineDeliveryDetail.Medicine.Name;
     this.Qty= this.MedicineDeliveryDetail == null ? (int?)null : this.MedicineDeliveryDetail.Volumn;
     this.InStockQty = warehouse.Volumn;
     this.AllocatedQty = this.MedicineDeliveryDetail.AllocatedWareHouseDetail == null ? this.MedicineDeliveryDetail.Volumn : this.MedicineDeliveryDetail.AllocatedWareHouseDetail.Sum(x => x.AllocatedQty);
 }
 public void Insert(WareHouse whItem)
 {
     try
     {
         this.Context.WareHouses.Add(whItem);
         this.Context.SaveChanges();
     }
     catch (Exception ex)
     {
     }
 }
        public MedicineOutputChooser(int medicineId, DateTime date)
        {
            InitializeComponent();

            this.date = date;

            // Get Medicine
            this.medicine = medicineRepo.GetById(medicineId);
            if (this.medicine == null) throw new Exception("Medicine dose not exist");
            this.txtMedicine.Text = this.medicine.Name;
            this.txtTradeName.Text = this.medicine.TradeName;
            this.txtUnit.Text = this.medicine.Define == null ? String.Empty : this.medicine.Define.Name;

            // Get Warehouse
            this.warehouse = warehouseRepo.GetByIdMedicine(medicineId, AppContext.CurrentClinic.Id);
            this.txtInstock.Text = this.warehouse == null ? "0" : this.warehouse.Volumn.ToString();

            var vwarehouseDetail = this.vwarehouseDetailRepo.GetWarehouseDetailForOutput(this.date, medicineId, AppContext.CurrentClinic.Id);
            this.bdsVWarehouseDetail.DataSource = vwarehouseDetail;
        }
        public void Update(WareHouse whItem)
        {
            try
            {
                var oldWh = this.Context.WareHouses.FirstOrDefault(x => x.Id == whItem.Id);
                if (oldWh == null) return;
                oldWh.ClinicId = whItem.ClinicId;
                oldWh.MedicineId = whItem.MedicineId;
                oldWh.Volumn = whItem.Volumn;
                oldWh.MinAllowed = whItem.MinAllowed;
                oldWh.LastUpdatedUser = whItem.LastUpdatedUser;
                oldWh.LastUpdatedDate = DateTime.Now;
                oldWh.Version++;
                this.Context.SaveChanges();
            }
            catch (Exception ex)
            {

                throw;
            }

        }
        public void WarehouseInputRegister(WareHouseIO wareHouseIO, List<WareHouseIODetail> warehouseIODetails)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
            {
                wareHouseIO.SetInfo(false);
                this.Context.WareHouseIO.Add(wareHouseIO);
                this.Context.SaveChanges();

                var medicineDictionary = new Dictionary<int, int>();
                foreach (var wareHouseIoDetail in warehouseIODetails)
                {
                    wareHouseIoDetail.WareHouseIOId = wareHouseIO.Id;
                    wareHouseIoDetail.SetInfo(false);
                    this.Context.WareHouseIODetail.Add(wareHouseIoDetail);

                    if (medicineDictionary.ContainsKey(wareHouseIoDetail.MedicineId))
                    {
                        medicineDictionary[wareHouseIoDetail.MedicineId] += wareHouseIoDetail.Qty;
                        continue;
                    }
                    medicineDictionary.Add(wareHouseIoDetail.MedicineId, wareHouseIoDetail.Qty);
                }
                this.Context.SaveChanges();

                foreach(var item in medicineDictionary.Keys)
                {
                    var warehouse = this.Context.WareHouses.FirstOrDefault(x => x.MedicineId == item && x.ClinicId == AppContext.CurrentClinic.Id);
                    if (warehouse == null)
                    {
                        warehouse = new WareHouse()
                                        {
                                            ClinicId = AppContext.CurrentClinic.Id,
                                            MedicineId = item,
                                            Volumn = medicineDictionary[item],
                                            MinAllowed = 0
                                        };
                        this.Context.WareHouses.Add(warehouse);
                        this.Context.SaveChanges();
                    }
                    else
                    {
                        warehouse.Volumn += medicineDictionary[item];
                    }

                    foreach (var warehouseIoDetail in warehouseIODetails)
                    {
                        if (warehouseIoDetail.MedicineId != item) continue;
                        var warehouseDetail = new WareHouseDetail
                                                  {
                                                      WareHouseId = warehouse.Id,
                                                      MedicineId = warehouseIoDetail.MedicineId,
                                                      Unit = warehouseIoDetail.Unit,
                                                      UnitPrice = warehouseIoDetail.UnitPrice ?? 0,
                                                      LotNo = warehouseIoDetail.LotNo,
                                                      ExpiredDate = warehouseIoDetail.ExpireDate,
                                                      WareHouseIODetailId = warehouseIoDetail.Id,
                                                      OriginalVolumn = warehouseIoDetail.Qty,
                                                      CurrentVolumn = warehouseIoDetail.Qty
                                                  };
                        warehouseDetail.SetInfo(false);
                        this.Context.WareHouseDetails.Add(warehouseDetail);
                    }

                }
                this.Context.SaveChanges();
                scope.Complete();
            }
        }
Exemplo n.º 8
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                //Insert data to WareHousePaper
                WareHouseIO wareHouseIo = new WareHouseIO();
                wareHouseIo.ClinicId = int.Parse(cbClinic.SelectedValue.ToString());
                wareHouseIo.Date = dateImport.Value.Date;
                // wareHouseIo.Deliverer = txtDeliverer.Text;
                //wareHouseIo.Recipient = txtRecipient.Text;
                //wareHouseIo.Type = 0;
                wareHouseIo.Version = 0;
                wareHouseIo.No = txtNo.Text;
                wareHouseIo.Note = txtNote.Text;
                WareHouseIORepository wareHouseIoRepository = new WareHouseIORepository();
                wareHouseIoRepository.Insert(wareHouseIo);

                //Insert data to WareHousePaperDetail
                foreach (DataGridViewRow row in grd.Rows)
                {
                    if (ValidateRowData(row))
                    {
                        WareHouseIODetail item = new WareHouseIODetail();
                        //item.WareHousePaperId = wareHouseIo.Id;
                        item.LotNo = row.Cells["LotNo"].Value.ToString();
                        //item.Type = 0;
                        item.MedicineId = int.Parse(row.Cells["MedicineId"].Value.ToString());
                        //item.Volumn = int.Parse(row.Cells["Volumn"].Value.ToString());
                        //item.Unit = int.Parse(row.Cells["Unit"].Value.ToString());
                        item.UnitPrice = int.Parse(row.Cells["UnitPrice"].Value.ToString());
                        item.Amount = int.Parse(row.Cells["Amount"].Value.ToString());
                        item.ExpireDate = DateTime.Parse(row.Cells["ExpireDate"].Value.ToString());
                        if (row.Cells["Note"].Value != null)
                            //item.Note = row.Cells["Note"].Value.ToString();
                        item.CreatedDate = wareHouseIo.CreatedDate;
                        _repwhIoDetail.Insert(item);

                        //Insert data to WareHouse
                        var wareHouse = repwh.GetByIdMedicine(item.MedicineId, wareHouseIo.ClinicId);
                        if (wareHouse != null)
                        {
                            //wareHouse.Volumn += item.Volumn;
                            repwh.Update(wareHouse);
                        }
                        else
                        {
                            wareHouse = new WareHouse();
                            wareHouse.MedicineId = item.MedicineId;
                            wareHouse.ClinicId = wareHouseIo.ClinicId;
                            //wareHouse.Volumn = item.Volumn;
                            wareHouse.MinAllowed = 0;
                            repwh.Insert(wareHouse);
                        }

                        //Insert data to WareHouseDetail
                        WareHouseDetail wareHouseDetail = new WareHouseDetail();
                        wareHouseDetail.MedicineId = item.MedicineId;
                        wareHouseDetail.WareHouseId = wareHouse.Id;
                        wareHouseDetail.WareHouseIODetailId = item.Id;
                        wareHouseDetail.LotNo = item.LotNo;
                        wareHouseDetail.ExpiredDate = item.ExpireDate;
                        //wareHouseDetail.OriginalVolumn = item.Volumn;
                        //wareHouseDetail.CurrentVolumn = item.Volumn;
                        wareHouseDetail.BadVolumn = 0;
                        //wareHouseDetail.Unit = item.Unit;
                        wareHouseDetail.UnitPrice = item.UnitPrice.Value;
                        wareHouseDetail.CreatedDate = DateTime.Now;
                        wareHouseDetail.LastUpdatedDate = DateTime.Now;
                        repwhDetail.Insert(wareHouseDetail);
                    }
                }

                MessageBox.Show("Nhập kho thành công!");
                dateImport.Value = DateTime.Now;
                txtDeliverer.Text = string.Empty;
                txtNo.Text = string.Empty;
                txtNote.Text = string.Empty;
                txtRecipient.Text = string.Empty;
                grd.Rows.Clear();
            }
            catch (Exception ex)
            {

            }
        }