public async Task <Unit> Handle(DeleteWriteOffCommand request, CancellationToken cancellationToken) { WriteOff writeOff = await _database.WriteOff .Include(w => w.WriteOffDetail) .FirstOrDefaultAsync(w => w.Id == request.Id); if (writeOff == null) { throw new NotFoundException(nameof(WriteOff), request.Id); } // add the writen off value back to storage lot location quantity foreach (var item in writeOff.WriteOffDetail) { var storage = await _database.StockBatchStorage.FindAsync(item.BatchStorageId); storage.Quantity += item.Quantity; _database.StockBatchStorage.Update(storage); } _database.WriteOff.Remove(writeOff); await _database.SaveAsync(); return(Unit.Value); }
public string Get(string FDate, string ToDate, string GCode, string UserName, string RCode) { DataSet ds = new DataSet(); ManageSQLConnection manageSQLConnection = new ManageSQLConnection(); List <KeyValuePair <string, string> > sqlParameters = new List <KeyValuePair <string, string> >(); sqlParameters.Add(new KeyValuePair <string, string>("@FDate", FDate)); sqlParameters.Add(new KeyValuePair <string, string>("@ToDate", ToDate)); sqlParameters.Add(new KeyValuePair <string, string>("@Godcode", GCode)); sqlParameters.Add(new KeyValuePair <string, string>("@RCode", RCode)); ds = manageSQLConnection.GetDataSetValues("GetWriteOff", sqlParameters); WriteOff writeOff = new WriteOff(); ManageReport manageReport = new ManageReport(); if (manageReport.CheckDataAvailable(ds)) { CommonEntity entity = new CommonEntity { dataSet = ds, GCode = GCode, FromDate = FDate, Todate = ToDate, UserName = UserName }; Task.Run(() => writeOff.GenerateWriteOffReport(entity)); //Generate the Report } return(JsonConvert.SerializeObject(ds.Tables[0])); }
public async Task <uint> Handle(NewWriteOffDto request, CancellationToken cancellationToken) { var item = await _database.Item.Where(i => i.Id == request.ItemId).CountAsync(); if (item == 0) { throw new NotFoundException(nameof(Item), request.ItemId); } if (request.WriteOffBatchs.Count() == 0) { throw new BelowRequiredMinimumItemException("Batch", 1, "Write Off"); } WriteOff newWriteOff = new WriteOff() { Status = "Valid", ItemId = request.ItemId, Type = request.Type, Note = request.Note }; foreach (var data in request.WriteOffBatchs) { var batch = await _database.StockBatchStorage .Include(s => s.Batch) .Where(b => b.Id == data.BatchStorageId) .FirstOrDefaultAsync(); if (batch == null) { throw new NotFoundException(nameof(StockBatchStorage), data.BatchStorageId); } else if (batch.Quantity < data.Quantity) { throw new QuantityGreaterThanAvailableException( nameof(WriteOff), data.Quantity, batch.Quantity); } batch.Quantity = batch.Quantity - data.Quantity; batch.Batch.Quantity = batch.Batch.Quantity - data.Quantity; newWriteOff.WriteOffDetail.Add(new WriteOffDetail() { BatchStorageId = data.BatchStorageId, Quantity = data.Quantity, }); // update storage _database.StockBatchStorage.Update(batch); } _database.WriteOff.Add(newWriteOff); await _database.SaveAsync(); return(newWriteOff.Id); }
public ActionResult DeleteConfirmed(int id) { WriteOff writeOff = db.WriteOff.Find(id); db.WriteOff.Remove(writeOff); db.SaveChanges(); return(RedirectToAction("Index")); }
private void AddProductToListView(WriteOff writeOff) { ListViewItem item = new ListViewItem(writeOff.Date.ToShortDateString()); item.SubItems.Add(writeOff.Master); item.SubItems.Add(writeOff.ToString()); item.Tag = writeOff; listView_WriteOffs.Items.Add(item); }
public IActionResult Index(WriteOff writeoff) { db.WriteOffs.Add(writeoff); // сохраняем в бд все изменения db.SaveChanges(); DateTime resultdate = DateTime.Now; ViewBag.resultdate = resultdate; return(View()); }
public ActionResult Edit([Bind(Include = "Id,Date,Id_Item,Count")] WriteOff writeOff) { if (ModelState.IsValid) { db.Entry(writeOff).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_Item = new SelectList(db.Item, "Id", "barcode", writeOff.Id_Item); return(View(writeOff)); }
public int CreateWriteOff(WriteOff writeOff) { DynamicParameters paras = new DynamicParameters(); paras.Add("@writeOffCode", writeOff.WriteOffCode, System.Data.DbType.String); paras.Add("@orderCode", writeOff.OrderCode, System.Data.DbType.String); paras.Add("@CreateTime", DateTime.Now, System.Data.DbType.DateTime); return(DapperSqlHelper.ExcuteNonQuery <WriteOff>(@"INSERT INTO [dbo].[WriteOff]([WriteOffCode],[OrderCode],[CreateTime] ) VALUES ( @writeOffCode, @orderCode, @CreateTime )", paras, false)); }
public void Save(string action = "") { using (var scope = new TransactionScope()) { if (Id == Guid.Empty) { Id = Guid.NewGuid(); CreateTime = DateTime.Now; LastUpdateTime = DateTime.Now; CreateUserAccount = ClientCookie.UserCode; CreateUserNameZHCN = ClientCookie.UserNameZHCN; CreateUserNameENUS = ClientCookie.UserNameENUS; IsHistory = false; Add(this); } else { LastUpdateTime = DateTime.Now; Update(this); } if (ReinBasicInfo != null) { ReinBasicInfo.ConsInfoID = Id; ReinBasicInfo.Save(); var rbdInfo = RebuildInfo.FirstOrDefault(e => e.ProjectId == ProjectId); if (rbdInfo != null) { rbdInfo.GBDate = ReinBasicInfo.GBDate; rbdInfo.ReopenDate = ReinBasicInfo.ReopenDate; rbdInfo.ConstCompletionDate = ReinBasicInfo.ConsCompletionDate; rbdInfo.Update(); } } if (ReinCost != null) { ReinCost.ConsInfoID = Id; ReinCost.SaveByRebuild(); } if (WriteOff != null) { WriteOff.ConsInfoID = Id; WriteOff.SaveByRebuild(); } SaveApproveUsers(action); SaveComments(action); scope.Complete(); } }
public void Save(string action = "") { using (var scope = new TransactionScope()) { if (Id == Guid.Empty) { Id = Guid.NewGuid(); CreateTime = DateTime.Now; LastUpdateTime = DateTime.Now; CreateUserAccount = ClientCookie.UserCode; IsHistory = false; Add(this); } else { LastUpdateTime = DateTime.Now; Update(this); } if (ReinBasicInfo != null) { ReinBasicInfo.ConsInfoID = Id; ReinBasicInfo.Save(); //同步更新GBDate与ReopenDate var reimageInfo = ReimageInfo.GetReimageInfo(ProjectId); reimageInfo.ReopenDate = ReinBasicInfo.ReopenDate; reimageInfo.GBDate = ReinBasicInfo.GBDate; reimageInfo.Update(); } if (ReinCost != null) { ReinCost.ConsInfoID = Id; ReinCost.Save(); } if (WriteOff != null) { WriteOff.ConsInfoID = Id; WriteOff.Save(); } SaveApproveUsers(action); if (string.Compare(action, "edit", true) != 0) { SaveComments(action); } scope.Complete(); } }
// GET: WriteOffs/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WriteOff writeOff = db.WriteOff.Find(id); if (writeOff == null) { return(HttpNotFound()); } return(View(writeOff)); }
// GET: WriteOffs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WriteOff writeOff = db.WriteOff.Find(id); if (writeOff == null) { return(HttpNotFound()); } ViewBag.Id_Item = new SelectList(db.Item, "Id", "barcode", writeOff.Id_Item); return(View(writeOff)); }
public async Task <Unit> Handle(UpdateWriteOffCommand request, CancellationToken cancellationToken) { WriteOff writeOff = await _database.WriteOff .Include(w => w.WriteOffDetail) .FirstOrDefaultAsync(w => w.Id == request.Id); if (writeOff == null) { throw new NotFoundException(nameof(WriteOff), request.Id); } _Mapper.Map(request, writeOff); foreach (var data in request.WriteOffDetail) { var batch = await _database.StockBatchStorage .Include(b => b.WriteOffDetail) .AsNoTracking() .Where(b => b.Id == data.BatchStorageId) .FirstOrDefaultAsync(); if (batch == null) { throw new NotFoundException(nameof(StockBatchStorage), data.BatchStorageId); // check if there is available stock } else if (batch.Quantity < data.Quantity) { throw new QuantityGreaterThanAvailableException( nameof(WriteOff), data.Quantity, batch.Quantity); } writeOff.WriteOffDetail.Add(new WriteOffDetail() { WriteOffId = request.Id, BatchStorageId = data.BatchStorageId, Quantity = data.Quantity, }); } _database.WriteOff.Update(writeOff); await _database.SaveAsync(); return(Unit.Value); }
public bool CheckWriteOff(string orderCode, string writeOffCode) { DynamicParameters paras = new DynamicParameters(); paras.Add("@orderCode", orderCode, System.Data.DbType.String); paras.Add("@writeOffCode", writeOffCode, System.Data.DbType.String); paras.Add("@CreateTime", DateTime.Now.AddMinutes(-5), System.Data.DbType.DateTime); WriteOff writeOff = DapperSqlHelper.FindOne <WriteOff>("select * from [dbo].[WriteOff] where orderCode=@orderCode and writeOffCode=@writeOffCode and CreateTime > @CreateTime ", paras, false); if (writeOff != null) { return(true); } else { return(false); } }
public ActionResult Create([Bind(Include = "Id,Id_Item,Count")] WriteOff writeOff) { if (ModelState.IsValid) { if (db.Item.Find(writeOff.Id_Item).count - writeOff.Count < Utils.ItemUsed(writeOff.Id_Item)) { TempData["ErrMessage"] = "Вы пытаетесь списать необходимый товар. Разберитесь с заказами в которых он участвует прежде чем списывать его."; return(RedirectToAction("Create")); } writeOff.Date = DateTime.Now; db.WriteOff.Add(writeOff); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Id_Item = new SelectList(db.Item, "Id", "barcode", writeOff.Id_Item); return(View(writeOff)); }
public async Task <uint> Handle(CreateWriteOffCommand request, CancellationToken cancellationToken) { WriteOff writeOff = _Mapper.Map <CreateWriteOffCommand, WriteOff> (request); writeOff.WriteOffDetail = new List <WriteOffDetail> (); foreach (var data in request.WriteOffDetail) { var batch = await _database.StockBatchStorage .Include(s => s.Batch) .Where(b => b.Id == data.BatchStorageId) .FirstOrDefaultAsync(); if (batch == null) { throw new NotFoundException(nameof(StockBatchStorage), data.BatchStorageId); } else if (batch.Quantity < data.Quantity) { throw new QuantityGreaterThanAvailableException( nameof(WriteOff), data.Quantity, batch.Quantity); } batch.Quantity = batch.Quantity - data.Quantity; batch.Batch.Quantity = batch.Batch.Quantity - data.Quantity; writeOff.WriteOffDetail.Add(new WriteOffDetail() { BatchStorageId = data.BatchStorageId, Quantity = data.Quantity, }); // update storage _database.StockBatchStorage.Update(batch); } await _database.WriteOff.AddAsync(writeOff); await _database.SaveAsync(); return(writeOff.Id); }
public ActionResult SearchReportWrittenOffCompare(WriteOff wo) { DataTable dt = new DataTable(); DataTable dt_main_menu = new DataTable(); DataTable dtwrittenoff = new DataTable(); DataTable dtColumnTitle = new DataTable(); mutility.DbName = Settings.Default["DbName"].ToString(); mutility.UserName = Settings.Default["UserName"].ToString(); mutility.Password = Settings.Default["Password"].ToString(); mutility.ServerName = Settings.Default["ServerName"].ToString(); if (mutility.ServerName == "" || mutility.DbName == "" || mutility.UserName == "") { return(RedirectToAction("Index", "Setting_Connection/Index")); } else { if (Session["ID"] != null) { UserAccessRightController UsAccRight = new UserAccessRightController(); string sql = "select row_number() over(order by BrCode) as id,* from Rep_WrittenOffMBWIN where reportdate='" + String.Format("{0:yyyy-MM-dd}", wo.date_start) + @"' order by BrCode ASC"; dtwrittenoff = wo.Write_Off(sql); string userkey = Session["user_key"].ToString(); dt = UsAccRight.UserAccessRight(userkey); dt_main_menu = UsAccRight.Main_Menu(userkey); ViewBag.manin_menu = dt_main_menu; ViewBag.sub_manin = dt; ViewBag.writtenoff = dtwrittenoff; ViewBag.date_start = wo.date_start; ViewBag.ColumnTitle = dtColumnTitle; ViewBag.CurrRunDate = CurrRunDate.CurrRunDate(userkey); return(View("GlComTool")); } else { return(RedirectToAction("Index", "Login/Index")); } } }
private void ChangeWriteOffForm_Load(object sender, EventArgs e) { WriteOffsContainer.Instance.Load(); ProductsContainer.Instance.Load(); products.Clear(); WriteOff selectedItem = listView.SelectedItems[0].Tag as WriteOff; if (selectedItem is null) { throw new ArgumentNullException("Выбранное списание не существует."); } selectedItem.Products.ToList().ForEach(product => products.Add(product)); textBox_master.Text = selectedItem.Master; FillComboBox(); RefreshListView(); label_measurement.Text = "единица измерения"; }
public WriteOffEditWindow(WriteOff writeOff) { InitializeComponent(); DataContext = viewModel = new WriteOffEditViewModel(this, writeOff); }
private void ChangeWriteOff() { WriteOff writeOff = new WriteOff(dateTimePicker_writeOffDate.Value, textBox_master.Text, products); WriteOffsContainer.Instance.Change((WriteOff)listView.SelectedItems[0].Tag, writeOff); }
public static WriteOffViewModel create(WriteOff writeoff) { return(Projection.Compile().Invoke(writeoff)); }
private void AddWriteOff() { WriteOff writeOff = new WriteOff(dateTimePicker_writeOffDate.Value, textBox_master.Text, products); WriteOffsContainer.Instance.Add(writeOff); }