public ExportAllocateDetail(int wareHouseId, int medicineId, int export, List <WareHouseDetail> listWareHouseDetail, bool flag) { InitializeComponent(); if (flag) { bdsWareHouseDetail.DataSource = listWareHouseDetail; } else { bdsWareHouseDetail.DataSource = repwhDetail.GetMeicineExport(wareHouseId, medicineId, export); } txtAllocatedQty.Text = txtQty.Text = export.ToString(); }
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) { } }