private void btnDelete_Click(object sender, EventArgs e) { Status = false; if (MessageBox.Show("", "", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { var listPaperDetail = _repwhIoDetail.GetByIOId(whPaperId); foreach (var paperDetail in listPaperDetail) { var listExport = whExport.GetByPaperDetailId(paperDetail.Id); foreach (var export in listExport) { WareHouseDetail wareHouseDetail = repwhDetail.GetById(export.WareHouseDetailId); wareHouseDetail.CurrentVolumn += export.Volumn; repwhDetail.Update(wareHouseDetail); WareHouse wareHouse = repwh.GetById(wareHouseDetail.WareHouseId); wareHouse.Volumn += export.Volumn; repwh.Update(wareHouse); whExport.Delete(export.Id); } _repwhIoDetail.Delete(paperDetail.Id); } _repwhIo.Delete(whPaperId); Status = true; this.Close(); } }
public void Update(WareHouseDetail whDetail) { try { var oldWhDetail = this.Context.WareHouseDetails.FirstOrDefault(x => x.Id == whDetail.Id); if (oldWhDetail == null) { return; } // oldWhDetail.WareHouseId = whDetail.WareHouseId; oldWhDetail.MedicineId = whDetail.MedicineId; oldWhDetail.WareHouseIODetailId = whDetail.WareHouseIODetailId; oldWhDetail.CreatedUser = whDetail.CreatedUser; oldWhDetail.CreatedDate = whDetail.CreatedDate; oldWhDetail.ExpiredDate = whDetail.ExpiredDate; oldWhDetail.LotNo = whDetail.LotNo; oldWhDetail.Unit = whDetail.Unit; oldWhDetail.UnitPrice = whDetail.UnitPrice; oldWhDetail.OriginalVolumn = whDetail.OriginalVolumn; oldWhDetail.CurrentVolumn = whDetail.CurrentVolumn; oldWhDetail.BadVolumn = whDetail.BadVolumn; oldWhDetail.LastUpdatedUser = AppContext.LoggedInUser.Id; oldWhDetail.LastUpdatedDate = DateTime.Now; oldWhDetail.Version++; this.Context.SaveChanges(); } catch (Exception ex) { throw; } }
public bool UpdateWareHouseDetail(WareHouseDetail wareHouseDetail) { try { SqlParameter[] sqlParameters = new SqlParameter[] { new SqlParameter("@WareHouseDetailID", wareHouseDetail.WareHouseDetailID), new SqlParameter("@ItemID", wareHouseDetail.ItemID), new SqlParameter("@Quantity", wareHouseDetail.Quantity), new SqlParameter("@Price", wareHouseDetail.Price), new SqlParameter("@Amount", wareHouseDetail.Amount), new SqlParameter("@VAT", wareHouseDetail.VAT), new SqlParameter("@VATAmount", wareHouseDetail.VATAmount), new SqlParameter("@CreateUser", UserInfo.UserID), new SqlParameter("@CompanyID", wareHouseDetail.CompanyID), new SqlParameter("@S35Price", wareHouseDetail.S35Price), new SqlParameter("@S35Amount", wareHouseDetail.S35Amount), new SqlParameter("@S35VATAmount", wareHouseDetail.S35VATAmount), new SqlParameter("@S35VAT", wareHouseDetail.S35VAT), new SqlParameter("@DonGiaBinhQuan", wareHouseDetail.DonGiaBinhQuan), new SqlParameter("@SoLuongTon", wareHouseDetail.SoLuongTon), new SqlParameter("@ChuaXuat", wareHouseDetail.ChuaXuat), new SqlParameter("@IsDelete", wareHouseDetail.IsDelete) //Dùng để xác nhận ngừng khấu hao }; this.Context.ExecuteDataFromProcedure("WareHouseDetailUpdate", sqlParameters); return(true); } catch (Exception ex) { Console.WriteLine("Update WareHouse Detail Fail! " + ex.Message); return(false); } }
/// <summary> /// Datas the grid view x1 cell double click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="DataGridViewCellEventArgs"/> instance containing the event data.</param> private void DataGridViewX1CellDoubleClick(object sender, DataGridViewCellEventArgs e) { var warehouse = this.bdsWareHouse.Current as Data.Entities.WareHouse; if (warehouse == null) return; var warehouseDetail = new WareHouseDetail(warehouse.Id); warehouseDetail.ShowDialog(this); }
public void Insert(WareHouseDetail whDetail) { try { whDetail.CreatedUser = AppContext.LoggedInUser.Id; whDetail.CreatedDate = DateTime.Now; whDetail.LastUpdatedDate = DateTime.Now; whDetail.Version = 0; this.Context.WareHouseDetails.Add(whDetail); this.Context.SaveChanges(); } catch (Exception ex) { } }
public void Delete(long id) { using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { var delivery = this.Context.MedicineDeliveries.FirstOrDefault(x => x.Id == id); if (delivery == null) { return; } var deliveryDetail = this.Context.MedicineDeliveryDetails.Where(x => x.MedicineDeliveryId == delivery.Id).ToList(); var deliveryDetailId = deliveryDetail.Select(x => x.Id).ToList(); var medicineId = deliveryDetail.Select(x => x.MedicineId).ToList(); var deliveryAllocatedDetail = this.Context.MedicineDeliveryDetailAllocates.Where(x => deliveryDetailId.Contains(x.MedicineDeliveryDetailId)).ToList(); var warehouseDetailId = deliveryAllocatedDetail.Select(x => x.WareHouseDetailId); var warehouseDetail = this.Context.WareHouseDetails.Where(x => warehouseDetailId.Contains(x.Id)).ToList(); var warehouse = this.Context.WareHouses.Where(x => medicineId.Contains(x.MedicineId)).ToList(); foreach (var allocated in deliveryAllocatedDetail) { WareHouseDetail wareHouseDetail = warehouseDetail.FirstOrDefault(x => x.Id == allocated.WareHouseDetailId); wareHouseDetail.CurrentVolumn += allocated.Volumn; WareHouse wareHouse = warehouse.FirstOrDefault(x => x.Id == wareHouseDetail.WareHouseId); wareHouse.Volumn += allocated.Volumn; this.Context.MedicineDeliveryDetailAllocates.Remove(allocated); } this.Context.SaveChanges(); foreach (var detail in deliveryDetail) { this.Context.MedicineDeliveryDetails.Remove(detail); } this.Context.SaveChanges(); this.Context.MedicineDeliveries.Remove(delivery); this.Context.SaveChanges(); scope.Complete(); } }
public static string ExcuteData(string data) { try { WareHouseDetail DataMain = JsonConvert.DeserializeObject <WareHouseDetail>(data); if (_CurrentID == null) { using (Models.ExecuteDataBase connFunc = new Models.ExecuteDataBase()) { DataTable dt = connFunc.ExecuteDataTable("[YYY_sp_Product_WareHouse_Insert]", CommandType.StoredProcedure, "@Name ", SqlDbType.Int, DataMain.Name.Replace("'", "").Trim(), "@BranchID ", SqlDbType.NVarChar, DataMain.BranchID.Replace("'", "").Trim(), "@Created_By", SqlDbType.Int, Comon.Global.sys_userid, "@Created", SqlDbType.DateTime, Comon.Comon.GetDateTimeNow(), "@Code ", SqlDbType.Int, DataMain.Code.Replace("'", "").Trim(), "@Address ", SqlDbType.Int, DataMain.Address.Replace("'", "").Trim() ); if (dt.Rows.Count > 0) { if (dt.Rows[0][0].ToString() != "0") { return("Tên Hoặc Mã Đã Tồn Tại Vui Lòng Kiểm Tra Lại"); } else { return("1"); } } else { return("1"); } } } else { using (Models.ExecuteDataBase connFunc = new Models.ExecuteDataBase()) { DataTable dt = connFunc.ExecuteDataTable("YYY_sp_Product_WareHouse_Update", CommandType.StoredProcedure, "@Name", SqlDbType.NVarChar, DataMain.Name.Replace("'", "").Trim(), "@Modified_By", SqlDbType.Int, Comon.Global.sys_userid, "@Modified", SqlDbType.DateTime, Comon.Comon.GetDateTimeNow(), "@currentID ", SqlDbType.Int, _CurrentID, "@BranchID", SqlDbType.NVarChar, DataMain.BranchID.Replace("'", "").Trim(), "@Code", SqlDbType.NVarChar, DataMain.Code.Replace("'", "").Trim(), "@Address ", SqlDbType.NVarChar, DataMain.Address.Replace("'", "").Trim() ); if (dt.Rows.Count > 0) { if (dt.Rows[0][0].ToString() != "0") { return("Tên Hoặc Mã Đã Tồn Tại Vui Lòng Kiểm Tra Lại"); } else { return("1"); } } else { return("1"); } } } } catch (Exception ex) { return("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) { } }
public bool UpdateWareHouseDetail(WareHouseDetail WareHouseDetail) { return(this.WareHouseDetailDAO.UpdateWareHouseDetail(WareHouseDetail)); }
public bool InsertWareHouseDetail(WareHouseDetail WareHouseDetail) { return(this.WareHouseDetailDAO.InsertWareHouseDetail(WareHouseDetail)); }
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(); } }