public void Insert(WareHouseIO whIo)
 {
     whIo.CreatedUser = AppContext.LoggedInUser.Id;
     whIo.CreatedDate = DateTime.Now;
     whIo.Version = 0;
     this.Context.WareHouseIO.Add(whIo);
     this.Context.SaveChanges();
 }
Exemplo n.º 2
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 = 1;
                wareHouseIo.Version = 0;
                wareHouseIo.No = txtNo.Text;
                wareHouseIo.Note = txtNote.Text;
                WareHouseIORepository wareHouseIoRepository = new WareHouseIORepository();
                wareHouseIoRepository.Insert(wareHouseIo);

                foreach (DataGridViewRow row in grd.Rows)
                {
                    if (row.Cells["Volumn"].Value != null)
                    {
                        int medicineId = int.Parse(row.Cells["MedicineIdHidden"].Value.ToString());
                        int export = int.Parse(row.Cells["Export"].Value.ToString());
                        //update data to WareHouse
                        var wareHouse = repwh.GetByIdMedicine(medicineId, AppContext.CurrentClinic.Id);
                        if (wareHouse != null)
                        {
                            wareHouse.Volumn -= export;
                            repwh.Update(wareHouse);
                        }

                        var list = repwhDetail.GetMeicineExport(wareHouse.Id, medicineId);

                        foreach (var obj in list)
                        {
                            if (obj.CurrentVolumn >= export)
                            {
                                //Update whDetail
                                obj.CurrentVolumn -= export;
                                repwhDetail.Update(obj);

                                //Insert data to WareHousePaperDetail
                                WareHouseIODetail item = new WareHouseIODetail();
                                //item.WareHousePaperId = wareHouseIo.Id;
                                item.LotNo = obj.LotNo;
                                //item.Type = 1;
                                item.MedicineId = obj.MedicineId;
                                //item.Volumn = export;
                                //item.Unit = obj.Unit;
                                item.UnitPrice = obj.UnitPrice;
                                item.ExpireDate = obj.ExpiredDate;
                                _repwhIoDetail.Insert(item);

                                //Insert whExportAllocate
                                WareHouseExportAllocate wareHouseExportAllocate = new WareHouseExportAllocate();
                                wareHouseExportAllocate.WareHouseDetailId = obj.Id;
                                wareHouseExportAllocate.WareHouseIODetailId = item.Id;
                                wareHouseExportAllocate.Volumn = export;
                                wareHouseExportAllocate.Unit = obj.Unit;
                                // whExport.Insert(wareHouseExportAllocate);
                                break;
                            }
                            else
                            {
                                //Insert data to WareHousePaperDetail
                                WareHouseIODetail item = new WareHouseIODetail();
                                //item.WareHousePaperId = wareHouseIo.Id;
                                item.LotNo = obj.LotNo;
                                //item.Type = 1;
                                item.MedicineId = obj.MedicineId;
                                //item.Volumn = obj.CurrentVolumn;
                                //item.Unit = obj.Unit;
                                item.UnitPrice = obj.UnitPrice;
                                item.ExpireDate = obj.ExpiredDate;
                                _repwhIoDetail.Insert(item);

                                export -= obj.CurrentVolumn;

                                //Update whDetail
                                obj.CurrentVolumn = 0;
                                repwhDetail.Update(obj);

                                //Insert whExportAllocate
                                WareHouseExportAllocate wareHouseExportAllocate = new WareHouseExportAllocate();
                                wareHouseExportAllocate.WareHouseDetailId = obj.Id;
                                wareHouseExportAllocate.WareHouseIODetailId = item.Id;
                                wareHouseExportAllocate.Volumn = obj.CurrentVolumn;
                                wareHouseExportAllocate.Unit = obj.Unit;
                                // whExport.Insert(wareHouseExportAllocate);
                            }
                        }
                    }
                }

                MessageBox.Show("Xuất 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)
            {

            }
        }
Exemplo n.º 3
0
 private WareHouseIO GetWareHousePaperEntity()
 {
     WareHouseIO whIo = new WareHouseIO();
     whIo.Id = 0;
     //whIo.Type = 0;
     return whIo;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Fills to grid.
        /// </summary>
        private void InitializeWareHouseIO()
        {
            // Create warehouse input
            this._wareHouseIO = new WareHouseIO
            {
                ClinicId = AppContext.CurrentClinic.Id,
                Type = WarehouseIOType.Input,
                Date = DateTime.Today,
                CreatedUser = AppContext.LoggedInUser.Id
            };

            this.txtClinic.Text = AppContext.CurrentClinic.Name;
            this.txtRecipient.Text = AppContext.LoggedInUser.Name;

            // Create warehouse Output
            this._warehouseIODetails = new List<WareHouseIODetail>();

            this.bdsWareHouse.DataSource = this._wareHouseIO;
            this.bdsWareHouse.ResetBindings(true);

            this.bdsWareHouseIODetail.DataSource = this._warehouseIODetails;
            this.bdsWareHouseIODetail.ResetBindings(true);
            this.grd.ResetBindings();
        }
        public void WarehouseOutputRegister(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();

                // var allocatedList = new List<WareHouseExportAllocate>();
                foreach (var item in medicineDictionary.Keys)
                {
                    var warehouse = this.Context.WareHouses.FirstOrDefault(x => x.MedicineId == item && x.ClinicId == AppContext.CurrentClinic.Id);
                    var validWarehouseIODetail = this.Context.VWarehouseDetailFull.Where(x => x.MedicineId == item && x.ClinicId == AppContext.CurrentClinic.Id && (x.Date == null || x.Date <= wareHouseIO.Date) && x.CurrentVolumn > 0).Select(x => x.Id).ToList<int>();
                    var warehouseDetailList = this.Context.WareHouseDetails.Where(x => validWarehouseIODetail.Contains(x.Id)).ToList();
                    var warehouseOutputDetail = warehouseIODetails.Where(x => x.MedicineId == item).ToList();
                    foreach (var outputItem in warehouseOutputDetail)
                    {
                        var qty = outputItem.Qty;
                        foreach(var detail in warehouseDetailList)
                        {
                            if (!detail.LotNo.Equals(outputItem.LotNo)) continue;
                            var allotcateItem = new WareHouseExportAllocate
                                                    {
                                                        WareHouseDetailId = detail.Id,
                                                        WareHouseIODetailId = outputItem.Id,
                                                        Unit = outputItem.Unit,
                                                        Volumn = detail.CurrentVolumn > qty ? qty : detail.CurrentVolumn,
                                                        Version = 0
                                                    };

                            // allocatedList.Add(allotcateItem);
                            this.Context.WareHouseExportAllocates.Add(allotcateItem);
                            qty -= allotcateItem.Volumn;
                            detail.CurrentVolumn -= allotcateItem.Volumn;
                            detail.SetInfo(true);
                            warehouse.Volumn -= allotcateItem.Volumn;
                            warehouse.SetInfo(true);
                            if (qty == 0) break;
                        }

                        if (qty != 0) throw new Exception("Số lượng thuốc đã bị lệch trong lúc thay đổi, hãy chọn lại số lượng cho khớp.");
                    }
                }

                this.Context.SaveChanges();
                scope.Complete();
            }
        }
        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();
            }
        }
        public void Update(WareHouseIO whIo)
        {
            try
            {
                var oldwhPaper = this.Context.WareHouseIO.FirstOrDefault(x => x.Id == whIo.Id);
                if (oldwhPaper == null) return;
                oldwhPaper.Type = whIo.Type;
                oldwhPaper.ClinicId = whIo.ClinicId;
                oldwhPaper.CreatedUser = whIo.CreatedUser;
                oldwhPaper.CreatedDate = whIo.CreatedDate;
                oldwhPaper.Date = whIo.Date;
                oldwhPaper.No = whIo.No;
                // oldwhPaper.Recipient = whIo.Recipient;
                // oldwhPaper.Deliverer = whIo.Deliverer;
                oldwhPaper.Note = whIo.Note;
                // oldwhPaper.LastUpdatedUser = 1;
                // oldwhPaper.LastUpdatedUser = AppContext.LoggedInUser.Id;
                // oldwhPaper.LastUpdatedDate = DateTime.Now;
                oldwhPaper.Version++;
                this.Context.SaveChanges();
            }
            catch (Exception ex)
            {

                throw;
            }
        }
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)
            {

            }
        }
Exemplo n.º 9
0
 private WareHouseIO GetWareHousePaperEntity()
 {
     WareHouseIO whIo = new WareHouseIO();
     whIo.Id = 0;
     whIo.No = txtNo.Text.Trim();
     whIo.Note = txtNote.Text.Trim();
     //whIo.Recipient = txtRecipient.Text.Trim();
     whIo.ClinicId = int.Parse(cbClinic.SelectedValue.ToString());
     //whIo.Deliverer = txtDeliverer.Text.Trim();
     //whIo.Type = 0;
     return whIo;
 }
Exemplo n.º 10
0
        private void Initialize()
        {
            txtClinic.Text = AppContext.CurrentClinic.Name;
            txtDeliverer.Text = AppContext.LoggedInUser.Name;

            // Init warehouse
            _warehouseIo = new WareHouseIO
                               {
                                   ClinicId = AppContext.CurrentClinic.Id,
                                   Date = DateTime.Today,
                                   Type = WarehouseIOType.Output
                               };
            bdsWareHouseIO.DataSource = _warehouseIo;

            // Init WarehouseIODetail
            _warehouseIoDetail = new List<WareHouseIODetail>();
            bdsWarehouseIODetail.DataSource = _warehouseIoDetail;

            this.grd.EndEdit();
            this.grd.ResetBindings();
            this.grd.Refresh();
        }