public LoanEntity AddOrUpdateLoan(LoanEntity entityObject) { string sqlStatement = ""; sqlStatement += "DECLARE @NewLoanId INT " + Environment.NewLine; //if insert if (entityObject.LoanId > 0) { sqlStatement += "UPDATE Loan SET " + Environment.NewLine + //"[email protected]" + Environment.NewLine + "[email protected]cleId," + Environment.NewLine + "[email protected]" + Environment.NewLine + "WHERE [email protected] " + Environment.NewLine + "SET @NewLoanId = @LoanId " + Environment.NewLine; } else { sqlStatement += "INSERT INTO Loan( " + Environment.NewLine + "OrderlineId," + Environment.NewLine + "ArticleId," + Environment.NewLine + "Quantity)" + Environment.NewLine + "VALUES (" + Environment.NewLine + "@OrderlineId," + Environment.NewLine + "@ArticleId," + Environment.NewLine + "@Quantity)" + Environment.NewLine + "SET @NewLoanId = (SELECT SCOPE_IDENTITY()) " + Environment.NewLine; } sqlStatement += "SELECT " + Environment.NewLine + "Loan.LoanId," + Environment.NewLine + "Loan.Quantity," + Environment.NewLine + "Loan.ArticleId," + Environment.NewLine + "Article.CategoryId," + Environment.NewLine + "Article.ArticleNo," + Environment.NewLine + "Article.Description," + Environment.NewLine + "Article.Unit " + Environment.NewLine + "FROM Loan JOIN Article ON Loan.ArticleId=Article.ArticleId " + Environment.NewLine + "WHERE [email protected]" + Environment.NewLine; //execute var result = Connection.Query<LoanEntity>(sqlStatement, new { OrderlineId = entityObject.OrderlineId, ArticleId = entityObject.ArticleId, Quantity = entityObject.Quantity, LoanId = entityObject.LoanId }, Transaction).ToList(); if (result.Count > 0) entityObject = result[0]; else entityObject = null; return entityObject; }
void ChildList_AddingNew(object sender, AddingNewEventArgs e) { var newObject = new LoanEntity() { OrderlineId = -1 }; e.NewObject = newObject; }
public bool DeleteLoan(LoanEntity entityObject) { string sqlStatement = "DELETE FROM Loan WHERE [email protected] " + Environment.NewLine; //execute Connection.Execute(sqlStatement, new { LoanId = entityObject.LoanId }, Transaction); return true; }
public void SaveLoan(LoanEntity entityObject) { if (entityObject != null && entityObject.LoanId > 0) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { ShowLoading(StringResources.captionInformation, StringResources.msgLoading); var updatedEntity = Factory.Resolve<IOrderDS>().AddOrUpdateLoan(entityObject); HideLoading(); } catch (Exception ex) { HideLoading(); ShowMessageBox(StringResources.captionError, ex.ToString(), MessageBoxButton.OK); } }); } }
public void DeleteLoanFromList(LoanEntity newEntity) { LoanEntity oldEntity = LoanList.FirstOrDefault<LoanEntity>(p => p.LoanId == newEntity.LoanId); if (oldEntity != null) { LoanList.Remove(oldEntity); } LoanList = new List<LoanEntity>(_loanList); }
public void DeleteLoan(LoanEntity entityObject) { if (ShowMessageBox(StringResources.captionConfirm, StringResources.msgConfirmDelete, MessageBoxButton.YesNo) == MessageBoxResult.Yes) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { ShowLoading(StringResources.captionInformation, StringResources.msgLoading); var isSuccess = Factory.Resolve<IOrderDS>().DeleteLoan(entityObject); HideLoading(); //display to UI Application.Current.Dispatcher.Invoke(new Action(() => { if (isSuccess) { DeleteLoanFromList(entityObject); } })); } catch (Exception ex) { HideLoading(); ShowMessageBox(StringResources.captionError, ex.ToString(), MessageBoxButton.OK); } }); } }
public void AddOrUpdateLoanToList(LoanEntity newEntity) { if (LoanList == null) LoanList = new List<LoanEntity>(); LoanEntity oldEntity = LoanList.FirstOrDefault<LoanEntity>(p => p.LoanId == newEntity.LoanId); if (oldEntity == null) { LoanList.Insert(0, newEntity); } else { int index = LoanList.IndexOf(oldEntity); LoanList.Remove(oldEntity); LoanList.Insert(index, newEntity); } LoanList = new List<LoanEntity>(_loanList); }
public void AddLoan() { if (SelectedOrderline != null && SelectedOrderline.OrderId > 0 && RelatedArticle != null && RelatedArticle.ArticleId > 0) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { ShowLoading(StringResources.captionInformation, StringResources.msgLoading); LoanEntity newEntity = new LoanEntity() { OrderlineId = SelectedOrderline.OrderlineId, ArticleId = RelatedArticle.ArticleId, Quantity = 0, RemainingQuantity = 0 }; var updatedEntity = Factory.Resolve<IBaseDataDS>().AddOrUpdateLoan(newEntity); HideLoading(); //display to UI Application.Current.Dispatcher.Invoke(new Action(() => { AddOrUpdateLoanToList(updatedEntity); })); } catch (Exception ex) { HideLoading(); ShowMessageBox(StringResources.captionError, ex.ToString(), MessageBoxButton.OK); } }); } }