public OrderEntity SaveOrder(OrderEntity order, List<OrderlineEntity> orderlines) { using (var db = VinaGerman.Database.VinagermanDatabase.GetDatabaseInstance()) { try { db.OpenConnection(); db.BeginTransaction(); //save order first order = db.Resolve<IOrderDB>().AddOrUpdateOrder(order); //save orderlines if (order != null && order.OrderId > 0) { //save orderlines for (int i = 0; orderlines != null && i < orderlines.Count; i++) { orderlines[i].OrderId = order.OrderId; var newOrderline = db.Resolve<IOrderDB>().AddOrUpdateOrderline(orderlines[i]); if (newOrderline != null && newOrderline.OrderlineId > 0) { orderlines[i].OrderlineId = newOrderline.OrderlineId; //save loan for (int j = 0; j < orderlines[i].LoanList.Count; j++) { orderlines[i].LoanList[j].OrderlineId = orderlines[i].OrderlineId; var newLoan = db.Resolve<IOrderDB>().AddOrUpdateLoan(orderlines[i].LoanList[j]); if (newLoan != null && newLoan.LoanId > 0) { orderlines[i].LoanList[j].LoanId = newLoan.LoanId; } } } } } db.CommitTransaction(); return order; } catch (Exception ex) { db.RollbackTransaction(); throw ex; } finally { db.CloseConnection(); } } }
public bool DeleteOrder(OrderEntity entityObject) { using (var db = VinaGerman.Database.VinagermanDatabase.GetDatabaseInstance()) { try { db.OpenConnection(); return db.Resolve<IOrderDB>().DeleteOrder(entityObject); } finally { db.CloseConnection(); } } }
public OrderEntity AddOrUpdateOrder(OrderEntity entityObject) { //execute using (var db = VinaGerman.Database.VinagermanDatabase.GetDatabaseInstance()) { try { db.OpenConnection(); return db.Resolve<IOrderDB>().AddOrUpdateOrder(entityObject); } finally { db.CloseConnection(); } } }
public void LoadOrder(OrderEntity order = null) { //reset orderlines OrderlineList = new BindingList<PurchaseOrderlineEntity>(); OrderlineList.AddingNew += OrderlineList_AddingNew; DataGrid.DataSource = OrderlineList; if (order == null) { order = new OrderEntity() { OrderType = (int)enumOrderType.Purchase, CreatedBy = ApplicationHelper.CurrentUserProfile.ContactId }; CurrentOrder = order; } else { CurrentOrder = order; } StatusList = new List<KeyValuePair<int, string>>(); StatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Ready, "Chờ xử lí")); StatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Approved, "Đã duyệt")); StatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Processed, "Đã xử lí")); ArticleList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.IBaseDataDS>().SearchArticle(new ArticleSearchEntity() { SearchText = "" }); BusinessList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.IBaseDataDS>().SearchBusiness(new BusinessSearchEntity() { SearchText = "" }); IndustryList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.IBaseDataDS>().SearchIndustry(new IndustrySearchEntity() { SearchText = "" }); CustomerList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.ICompanyDS>().SearchCompanies(new CompanySearchEntity() { SearchText = "", IsSupplier = true, NotIncludedCompany = ApplicationHelper.CurrentUserProfile.CompanyId }); EmployeeList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.ICompanyDS>().SearchContact(new ContactSearchEntity() { SearchText = "" }); this.RepositoryArticleLookupEdit.DataSource = ArticleList; this.cboCustomer.Properties.DataSource = CustomerList; this.cboEmployee.Properties.DataSource = EmployeeList; this.cboEmployee.EditValue = ApplicationHelper.CurrentUserProfile.ContactId; this.cboBusiness.Properties.DataSource = BusinessList; this.cboIndustry.Properties.DataSource = IndustryList; this.cboStatus.Properties.DataSource = StatusList; }
public List<OrderlineEntity> GetOrderlinesForOrder(OrderEntity searchObject, bool populateLoan) { using (var db = VinaGerman.Database.VinagermanDatabase.GetDatabaseInstance()) { try { db.OpenConnection(); var orderlines = db.Resolve<IOrderDB>().GetOrderlinesForOrder(searchObject); if (populateLoan) { for (int i = 0; orderlines != null && i < orderlines.Count; i++) { orderlines[i].LoanList = db.Resolve<IOrderDB>().GetLoansForOrderline(orderlines[i]); } } return orderlines; } finally { db.CloseConnection(); } } }
public void LoadOrder() { //reset orderlines OrderlineList = new BindingList<OrderlineModel>(); DataGrid.DataSource = OrderlineList; if (CurrentOrder == null) { CurrentOrder = new OrderEntity() { OrderType = (int)enumOrderType.Purchase, OrderDate = DateTime.Now, CompanyId = ApplicationHelper.CurrentUserProfile.CompanyId, CreatedBy = ApplicationHelper.CurrentUserProfile.ContactId, ResponsibleBy = ApplicationHelper.CurrentUserProfile.ContactId, OrderNumber = "" }; } else { var orderlines = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.IOrderDS>().GetOrderlinesForOrder(CurrentOrder, true); if (orderlines != null && orderlines.Count > 0) { for (int i = 0; i < orderlines.Count; i++) { var newOrderline = new OrderlineModel() { OrderlineId = orderlines[i].OrderlineId, OrderId = orderlines[i].OrderId, ArticleId = orderlines[i].ArticleId, CreatedBy = orderlines[i].CreatedBy, ModifiedBy = orderlines[i].ModifiedBy, ModifiedDate = orderlines[i].ModifiedDate, PaidDate = orderlines[i].PaidDate, PayDate = orderlines[i].PayDate, Price = orderlines[i].Price, Quantity = orderlines[i].Quantity, RealQuantity = orderlines[i].RealQuantity, RemainingQuantity = orderlines[i].RemainingQuantity, Unit = orderlines[i].Unit }; //populate loan list if (orderlines[i].LoanList != null && orderlines[i].LoanList.Count > 0) { for (int j = 0; j < orderlines[i].LoanList.Count; j++) { newOrderline.ChildList.Add(new LoanModel() { LoanId = orderlines[i].LoanList[j].LoanId, OrderlineId = orderlines[i].LoanList[j].OrderlineId, ArticleId = orderlines[i].LoanList[j].ArticleId, Quantity = orderlines[i].LoanList[j].Quantity, RemainingQuantity = orderlines[i].LoanList[j].RemainingQuantity, Unit = orderlines[i].Unit }); } } OrderlineList.Add(newOrderline); } } } StatusList = new List<KeyValuePair<int, string>>(); StatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Ready, "Chờ xử lí")); StatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Approved, "Đã duyệt")); StatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Processed, "Đã xử lí")); ArticleList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.IBaseDataDS>().SearchArticle(new ArticleSearchEntity() { SearchText = "" }); BusinessList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.IBaseDataDS>().SearchBusiness(new BusinessSearchEntity() { SearchText = "" }); IndustryList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.IBaseDataDS>().SearchIndustry(new IndustrySearchEntity() { SearchText = "" }); CustomerList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.ICompanyDS>().SearchCompanies(new CompanySearchEntity() { SearchText = "", IsSupplier = true, NotIncludedCompany = ApplicationHelper.CurrentUserProfile.CompanyId }); EmployeeList = VinaGerman.Entity.Factory.Resolve<VinaGerman.DataSource.ICompanyDS>().SearchContact(new ContactSearchEntity() { SearchText = "" }); this.RepositoryArticleLookupEdit.DataSource = ArticleList; this.cboCustomer.Properties.DataSource = CustomerList; this.cboCustomer.EditValue = CurrentOrder.CustomerCompanyId; this.cboEmployee.Properties.DataSource = EmployeeList; this.cboEmployee.EditValue = ApplicationHelper.CurrentUserProfile.ContactId; this.cboBusiness.Properties.DataSource = BusinessList; this.cboBusiness.EditValue = CurrentOrder.BusinessId; this.cboIndustry.Properties.DataSource = IndustryList; this.cboIndustry.EditValue = CurrentOrder.IndustryId; this.cboStatus.Properties.DataSource = StatusList; this.cboStatus.EditValue = CurrentOrder.OrderStatus; this.txtOrderDate.EditValue = CurrentOrder.OrderDate; this.txtOrderNumber.Text = CurrentOrder.OrderNumber; ExpandAllRows(MasterGridView); }
public List<OrderlineEntity> GetOrderlinesForOrder(OrderEntity searchObject) { List<OrderlineEntity> result = null; string sqlStatement = "SELECT " + Environment.NewLine + "Orderline.OrderlineId," + Environment.NewLine + "Orderline.OrderId," + Environment.NewLine + "Orderline.Commission," + Environment.NewLine + "Orderline.ArticleId," + Environment.NewLine + "Orderline.Quantity," + Environment.NewLine + "Orderline.Price," + Environment.NewLine + "Orderline.CreatedBy," + Environment.NewLine + "Orderline.CreatedDate," + Environment.NewLine + "Orderline.ModifiedBy," + Environment.NewLine + "Orderline.ModifiedDate," + Environment.NewLine + "Orderline.PayDate," + Environment.NewLine + "Article.CategoryId," + Environment.NewLine + "Article.ArticleNo," + Environment.NewLine + "Article.Description," + Environment.NewLine + "Article.Unit" + Environment.NewLine + "FROM Orderline JOIN Article ON Orderline.ArticleId=Article.ArticleId " + Environment.NewLine + "WHERE Deleted=0 AND Orderline.OrderId=@OrderId" + Environment.NewLine; //execute result = Connection.Query<OrderlineEntity>(sqlStatement, new { OrderId = searchObject.OrderId }, Transaction).ToList(); return result; }
public OrderEntity AddOrUpdateOrder(OrderEntity entityObject) { string sqlStatement = ""; entityObject.CreatedDate = DateTime.Now; sqlStatement += "DECLARE @NewOrderId INT " + Environment.NewLine; //if insert if (entityObject.OrderId > 0) { sqlStatement += "UPDATE [Order] SET " + Environment.NewLine + "OrderType=@OrderType," + Environment.NewLine + "BusinessId=@BusinessId," + Environment.NewLine + "IndustryId=@IndustryId," + Environment.NewLine + "ModifiedBy=@ModifiedBy," + Environment.NewLine + "ModifiedDate=GETDATE()," + Environment.NewLine + "ResponsibleBy=@ResponsibleBy," + Environment.NewLine + "OrderDate=@OrderDate," + Environment.NewLine + "CompanyId=@CompanyId," + Environment.NewLine + "LocationId=@LocationId," + Environment.NewLine + "OrderStatus=@OrderStatus," + Environment.NewLine + "CustomerCompanyId=@CustomerCompanyId," + Environment.NewLine + "CustomerContactId=@CustomerContactId," + Environment.NewLine + "OrderNumber=@OrderNumber," + Environment.NewLine + "Description=@Description" + Environment.NewLine + "WHERE OrderId=@OrderId " + Environment.NewLine + "SET @NewOrderId=@OrderId " + Environment.NewLine; } else { sqlStatement += "INSERT INTO [Order]( " + Environment.NewLine + "OrderType," + Environment.NewLine + "BusinessId," + Environment.NewLine + "IndustryId," + Environment.NewLine + "CreatedBy," + Environment.NewLine + "ModifiedBy," + Environment.NewLine + "ResponsibleBy, " + Environment.NewLine + "OrderDate," + Environment.NewLine + "CreatedDate," + Environment.NewLine + "ModifiedDate," + Environment.NewLine + "CompanyId," + Environment.NewLine + "LocationId," + Environment.NewLine + "CustomerCompanyId," + Environment.NewLine + "CustomerContactId," + Environment.NewLine + "OrderStatus," + Environment.NewLine + "OrderNumber," + Environment.NewLine + "Description)" + Environment.NewLine + "VALUES (" + Environment.NewLine + "@OrderType," + Environment.NewLine + "@BusinessId," + Environment.NewLine + "@IndustryId," + Environment.NewLine + "@CreatedBy," + Environment.NewLine + "@ModifiedBy," + Environment.NewLine + "@ResponsibleBy," + Environment.NewLine + "@OrderDate," + Environment.NewLine + "GETDATE()," + Environment.NewLine + "GETDATE()," + Environment.NewLine + "@CompanyId," + Environment.NewLine + "@LocationId," + Environment.NewLine + "@CustomerCompanyId," + Environment.NewLine + "@CustomerContactId," + Environment.NewLine + "@OrderStatus," + Environment.NewLine + "@OrderNumber," + Environment.NewLine + "@Description)" + Environment.NewLine + "SET @NewOrderId = (SELECT SCOPE_IDENTITY() AS OrderId) " + Environment.NewLine; sqlStatement += "UPDATE [Order] Set OrderNumber=(SELECT dbo.BuildOrderNumberForOrder(@NewOrderId)) WHERE OrderId=@NewOrderId " + Environment.NewLine; } sqlStatement += "SELECT " + Environment.NewLine + "[Order].OrderId," + Environment.NewLine + "[Order].OrderType," + Environment.NewLine + "[Order].BusinessId," + Environment.NewLine + "[Order].IndustryId," + Environment.NewLine + "[Order].CreatedBy," + Environment.NewLine + "[Order].ModifiedBy," + Environment.NewLine + "[Order].ResponsibleBy," + Environment.NewLine + "[Order].OrderDate," + Environment.NewLine + "[Order].CreatedDate," + Environment.NewLine + "[Order].ModifiedDate," + Environment.NewLine + "[Order].CompanyId," + Environment.NewLine + "[Order].LocationId," + Environment.NewLine + "[Order].CustomerCompanyId," + Environment.NewLine + "[Order].CustomerContactId," + Environment.NewLine + "[Order].OrderStatus," + Environment.NewLine + "[Order].OrderNumber," + Environment.NewLine + "[Order].Description" + Environment.NewLine + "FROM [Order] " + Environment.NewLine + "WHERE OrderId=@NewOrderId " + Environment.NewLine; //execute var result = Connection.Query<OrderEntity>(sqlStatement, new { OrderId = entityObject.OrderId, OrderType = entityObject.OrderType, BusinessId = entityObject.BusinessId, IndustryId = entityObject.IndustryId, CreatedBy = entityObject.CreatedBy, ModifiedBy = entityObject.ModifiedBy, ResponsibleBy = entityObject.ResponsibleBy, OrderStatus = entityObject.OrderStatus, OrderDate = entityObject.OrderDate, CompanyId = entityObject.CompanyId, LocationId = entityObject.LocationId, CustomerCompanyId = entityObject.CustomerCompanyId, CustomerContactId = entityObject.CustomerContactId, OrderNumber = entityObject.OrderNumber, Description = entityObject.Description }, Transaction).ToList(); if (result.Count > 0) entityObject = result[0]; else entityObject = null; return entityObject; }
public void Reload(OrderEntity order) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { try { ShowLoading(StringResources.captionInformation, StringResources.msgLoading); //load order information if (order == null) order = new OrderEntity() { OrderDate = DateTime.Now, OrderNumber = "", OrderType = (int)enumOrderType.Sale, CompanyId = ApplicationHelper.CurrentUserProfile.CompanyId, CreatedBy = ApplicationHelper.CurrentUserProfile.ContactId, ResponsibleBy = ApplicationHelper.CurrentUserProfile.ContactId, OrderStatus = (int)enumOrderStatus.Ready }; _employeeList = new List<UserProfileEntity>(); var _ocompanyList = Factory.Resolve<ICompanyDS>().SearchCompanies(new CompanySearchEntity() { SearchText = "", IsSupplier = true }); var _ocontactList = Factory.Resolve<IBaseDataDS>().SearchContact(new ContactSearchEntity() { SearchText = "" }); var _obusinessList = Factory.Resolve<IBaseDataDS>().SearchBusiness(new BusinessSearchEntity() { SearchText = "" }); var _oindustryList = Factory.Resolve<IBaseDataDS>().SearchIndustry(new IndustrySearchEntity() { SearchText = "" }); var _oArticleList = Factory.Resolve<IBaseDataDS>().SearchArticle(new ArticleSearchEntity() { SearchText = "" }); var _oLocationList = Factory.Resolve<ICompanyDS>().SearchLocation(new LocationSearchEntity() { SearchText = "" }); List<UserProfileEntity> _oEmployeeList = new List<UserProfileEntity>(); _oEmployeeList.Add(ApplicationHelper.CurrentUserProfile); List<KeyValuePair<int, string>> _oStatusList = new List<KeyValuePair<int, string>>(); if (order.OrderStatus == (int)enumOrderStatus.Ready) { _oStatusList.Add(new KeyValuePair<int,string>((int)enumOrderStatus.Ready, StringResources.ORDERSTATUS_READY)); _oStatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Approved, StringResources.ORDERSTATUS_APPROVED)); } else if (order.OrderStatus == (int)enumOrderStatus.Approved) { _oStatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Approved, StringResources.ORDERSTATUS_APPROVED)); _oStatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Processed, StringResources.ORDERSTATUS_PROCESSED)); } else if (order.OrderStatus == (int)enumOrderStatus.Approved) { _oStatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Processed, StringResources.ORDERSTATUS_PROCESSED)); } else { _oStatusList.Add(new KeyValuePair<int, string>((int)enumOrderStatus.Ready, StringResources.ORDERSTATUS_READY)); } HideLoading(); //display to UI UserProfileEntity Application.Current.Dispatcher.Invoke(new Action(() => { CustomerList = _ocompanyList; ContactList = _ocontactList; EmployeeList = _oEmployeeList; BusinessList = _obusinessList; IndustryList = _oindustryList; ArticleList = _oArticleList; LocationList = _oLocationList; StatusList = _oStatusList; OrderlineList = new List<OrderlineEntity>(); LoanList = new List<LoanEntity>(); SelectedOrder = order; LoadOrderlines(); })); } catch (Exception ex) { HideLoading(); ShowMessageBox(StringResources.captionError, ex.ToString(), MessageBoxButton.OK); } }); }
public bool DeleteOrder(OrderEntity entityObject) { string sqlStatement = "UPDATE [Order] SET Deleted=1 WHERE OrderId=@OrderId " + Environment.NewLine; //execute Connection.Execute(sqlStatement, new { OrderId = entityObject.OrderId }, Transaction); return true; }
public void OpenOrder(OrderEntity entityObject) { if (entityObject != null && entityObject.OrderId > 0) { Dictionary<string, object> dicParams = new Dictionary<string, object>(); dicParams.Add("Order", entityObject); SendMessage(MessageToken.ReloadMessage, dicParams, enumView.SaleOrderDetail.ToString()); GoToView(enumView.SaleOrderDetail); } }
public OrderEntity SaveOrder(OrderEntity order, List<OrderlineEntity> orderlines) { return Factory.Resolve<IOrderBL>().SaveOrder(order, orderlines); }
public List<OrderlineEntity> GetOrderlinesForOrder(OrderEntity order, bool populateLoan) { return Factory.Resolve<IOrderBL>().GetOrderlinesForOrder(order, populateLoan); }
public bool DeleteOrder(OrderEntity entityObject) { return Factory.Resolve<IOrderBL>().DeleteOrder(entityObject); }
public OrderEntity AddOrUpdateOrder(OrderEntity entityObject) { return Factory.Resolve<IOrderBL>().AddOrUpdateOrder(entityObject); }