Example #1
0
        public ArticleRelationEntity AddOrUpdateArticleRelation(ArticleRelationEntity entityObject)
        {
            string sqlStatement = "";

            sqlStatement += "DECLARE @NewArticleRelationId INT " + Environment.NewLine;
            //if insert
            if (entityObject.ArticleRelationId > 0)
            {
                sqlStatement += "UPDATE ArticleRelation SET  " + Environment.NewLine +
                "Comment=@Comment" + Environment.NewLine +
                "WHERE ArticleRelationId=@ArticleRelationId " + Environment.NewLine +
                "SET @NewArticleRelationId = @ArticleRelationId " + Environment.NewLine;
            }
            else
            {
                sqlStatement += "INSERT INTO ArticleRelation(  " + Environment.NewLine +
                "ArticleId," + Environment.NewLine +
                "RelatedArticleId," + Environment.NewLine +
                "Comment)" + Environment.NewLine +
                "VALUES (" + Environment.NewLine +
                "@ArticleId," + Environment.NewLine +
                "@RelatedArticleId," + Environment.NewLine +
                "@Comment)" + Environment.NewLine +
                "SET @NewArticleRelationId = (SELECT SCOPE_IDENTITY()) " + Environment.NewLine;
            }

            sqlStatement += "SELECT " + Environment.NewLine +
               "ArticleRelation.ArticleRelationId," + Environment.NewLine +
               "ArticleRelation.Comment," + Environment.NewLine +
               "Article.ArticleId," + Environment.NewLine +
               "Article.CategoryId," + Environment.NewLine +
               "Article.ArticleNo," + Environment.NewLine +
               "Article.Description," + Environment.NewLine +
               "Article.Unit," + Environment.NewLine +
               "Article.Deleted" + Environment.NewLine +
               "FROM Article JOIN ArticleRelation ON Article.ArticleId=ArticleRelation.RelatedArticleId " + Environment.NewLine +
               "WHERE Deleted=0 AND ArticleRelation.ArticleRelationId=@NewArticleRelationId" + Environment.NewLine;

            //execute
            var result = Connection.Query<ArticleRelationEntity>(sqlStatement, new
            {
                ArticleId = entityObject.ArticleId,
                RelatedArticleId = entityObject.RelatedArticleId,
                Comment = entityObject.Comment,
                ArticleRelationId = entityObject.ArticleRelationId
            }, Transaction).ToList();

            if (result.Count > 0)
                entityObject = result[0];
            else
                entityObject = null;
            return entityObject;
        }
Example #2
0
 public bool DeleteArticleRelation(ArticleRelationEntity entityObject)
 {
     //execute
     using (var db = VinaGerman.Database.VinagermanDatabase.GetDatabaseInstance())
     {
         try
         {
             db.OpenConnection();
             return db.Resolve<IArticleDB>().DeleteArticleRelation(entityObject);
         }
         finally
         {
             db.CloseConnection();
         }
     }
 }
        //public void Save()
        //{
        //    System.Threading.ThreadPool.QueueUserWorkItem(delegate
        //    {
        //        try
        //        {
        //            ShowLoading(StringResources.captionInformation, StringResources.msgLoading);
        //            var updatedEntity = Factory.Resolve<IBaseDataDS>().AddOrUpdateArticle(SelectedArticle);
        //            HideLoading();
        //            //display to UI
        //            Application.Current.Dispatcher.Invoke(new Action(() =>
        //            {
        //                SelectedArticle = updatedEntity;
        //                AddOrUpdateArticle(SelectedArticle);
        //            }));
        //        }
        //        catch (Exception ex)
        //        {
        //            HideLoading();
        //            ShowMessageBox(StringResources.captionError, ex.ToString(), MessageBoxButton.OK);
        //        }
        //    });
        //    //ShowDialog<uvCompanyDetailViewModel>(new uvCompanyDetailViewModel() {
        //    //    OriginalCompany = SelectCompany
        //    //});
        //}
        public void SaveArticleRelation()
        {
            if (SelectedArticle != null && SelectedArticle.ArticleId > 0 && RelatedArticle != null && RelatedArticle.ArticleId > 0)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(delegate
                {
                    try
                    {
                        ShowLoading(StringResources.captionInformation, StringResources.msgLoading);

                        ArticleRelationEntity newEntity = new ArticleRelationEntity()
                        {
                            ArticleId = SelectedArticle.ArticleId,
                            RelatedArticleId = RelatedArticle.ArticleId,
                            Comment = ""
                        };
                        var updatedEntity = Factory.Resolve<IBaseDataDS>().AddOrUpdateArticleRelation(newEntity);

                        HideLoading();

                        //display to UI
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            AddOrUpdateArticleRelation(updatedEntity);
                        }));
                    }
                    catch (Exception ex)
                    {
                        HideLoading();
                        ShowMessageBox(StringResources.captionError, ex.ToString(), MessageBoxButton.OK);
                    }
                });
            }
        }
        public void DeleteArticleRelationFromList(ArticleRelationEntity newEntity)
        {
            ArticleRelationEntity oldEntity = ArticleRelationList.FirstOrDefault<ArticleRelationEntity>(p => p.ArticleRelationId == newEntity.ArticleRelationId);

            if (oldEntity != null)
            {
                ArticleRelationList.Remove(oldEntity);
            }

            ArticleRelationList = new List<ArticleRelationEntity>(_articleRelationList);
        }
        public void DeleteArticleRelation(ArticleRelationEntity relationEntity)
        {
            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<IBaseDataDS>().DeleteArticleRelation(relationEntity);

                        HideLoading();

                        //display to UI
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            if (isSuccess)
                            {
                                DeleteArticleRelationFromList(relationEntity);
                            }
                        }));
                    }
                    catch (Exception ex)
                    {
                        HideLoading();
                        ShowMessageBox(StringResources.captionError, ex.ToString(), MessageBoxButton.OK);
                    }
                });
            }
        }
        public void AddOrUpdateArticleRelation(ArticleRelationEntity newEntity)
        {
            if (ArticleRelationList == null) ArticleRelationList = new List<ArticleRelationEntity>();

            ArticleRelationEntity oldEntity = ArticleRelationList.FirstOrDefault<ArticleRelationEntity>(p => p.ArticleRelationId == newEntity.ArticleRelationId);

            if (oldEntity == null)
            {
                ArticleRelationList.Insert(0, newEntity);
            }
            else
            {
                int index = ArticleRelationList.IndexOf(oldEntity);
                ArticleRelationList.Remove(oldEntity);
                ArticleRelationList.Insert(index, newEntity);
            }

            ArticleRelationList = new List<ArticleRelationEntity>(_articleRelationList);
        }
 private void CopyRow()
 {
     try
     {
         List<ArticleRelationEntity> lst = (List<ArticleRelationEntity>)source.DataSource;
         int index = -1;
         index = this.gvArticleRelation.FocusedRowHandle;
         ArticleRelationEntity b = (ArticleRelationEntity)gvArticleRelation.GetFocusedRow();
         if (b != null)
         {
             source = (BindingSource)GridArticleRelation.DataSource;
             List<ArticleRelationEntity> list = (List<ArticleRelationEntity>)source.DataSource;
             if (list != null && list.Count > 0)
             {
                 ArticleRelationEntity a = new ArticleRelationEntity();
                 ApplicationHelper.TranferProperiesEx(b, a);
                 a.ArticleRelationId = 0;
                 list.Add(a);
             }
             source.DataSource = list;
             GridArticleRelation.DataSource = source;
             gvArticleRelation.RefreshData();
         }
     }
     catch (Exception e)
     {
         Log.WriteLog(this, System.Reflection.MethodBase.GetCurrentMethod().Name, e.Message);
     }
 }
 private void Clear_Text()
 {
     txtMahang.Text = "";
     txtTenhang.Text = "";
     txtDVT.Text = "";
     slkLoaihang.Text = "";
     GridArticleRelation.DataSource = null;
     List<ArticleRelationEntity> lst = new List<ArticleRelationEntity>();
     ArticleRelationEntity it = new ArticleRelationEntity();
     it.Comment = "";
     lst.Add(it);
     source.DataSource = lst;
     GridArticleRelation.DataSource = source;
 }
Example #9
0
 public bool DeleteArticleRelation(ArticleRelationEntity entityObject)
 {
     return Factory.Resolve<IArticleBL>().DeleteArticleRelation(entityObject);
 }
Example #10
0
 public ArticleRelationEntity AddOrUpdateArticleRelation(ArticleRelationEntity entityObject)
 {
     return Factory.Resolve<IArticleBL>().AddOrUpdateArticleRelation(entityObject);
 }
Example #11
0
        public bool DeleteArticleRelation(ArticleRelationEntity entityObject)
        {
            string sqlStatement = "DELETE FROM ArticleRelation WHERE ArticleRelationId=@ArticleRelationId  " + Environment.NewLine;

            //execute
            Connection.Execute(sqlStatement, new { ArticleRelationId = entityObject.ArticleRelationId }, Transaction);
            return true;
        }