public void Save(Data.AssetGood entity, string parentUniquePath)
        {
            try
            {
                if (entity.ID == Guid.Empty)
                {
                    entity.ID       = Guid.NewGuid();
                    entity.LastEdit = DateTime.Now;
                    this.Table.Add(entity);
                }
                else
                {
                    var view = this.GetViewById(entity.ID);
                    if (view.code != entity.code)
                    {
                        entity.LastEdit = DateTime.Now;
                    }
                }

                entity.uniquepath = string.Format("{0}{1}{2}", parentUniquePath, Common.Constants.Seperators.UniquePath, entity.ID);

                this.SubmitChanges();
            }
            catch
            {
                throw;
            }
        }
        private bool ValidateDelete(Data.AssetGood entity, out string errorMessage)
        {
            try
            {
                errorMessage = string.Empty;

                if (entity == null)
                {
                    errorMessage = Localize.ex_no_record;
                    return(false);
                }

                if (Business.GetAssetBusiness().GetByAssetGoodId(entity.ID).Any())
                {
                    errorMessage = Localize.ex_record_already_used;
                }

                if (this.GetAll().Where(r => r.parentId == entity.ID).Any())
                {
                    errorMessage = Localize.ex_record_already_used;
                }

                return(errorMessage == string.Empty);
            }
            catch
            {
                throw;
            }
        }
Пример #3
0
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var assetGoodsBusiness = Business.GetAssetGoodsBusiness();
                var parent             = assetGoodsBusiness.GetByCode(txtSubsidiaryGroup.Text);
                if (parent == null)
                {
                    throw new Exception(Localize.ex_subsidiarygroup_not_found);
                }

                var entity = assetGoodsBusiness.GetById(AssetGoodId.ToGUID());
                if (entity == null)
                {
                    entity = new Data.AssetGood();
                }

                entity.name        = txtAssetGroupTitle.Text;
                entity.code        = txtSubsidiaryGroup.Text + txtAssetGroupCode.Text;
                entity.parentId    = parent.ID;
                entity.codetitleId = Common.Constants.CodeTitle.AssetGoodTitle;

                assetGoodsBusiness.Save(entity, parent.uniquepath);
                this.Close();
            }
            catch (Exception ex)
            {
                AccountingKernel.Forms.Base.BaseWindow.ShowError(ex);
            }
        }
 public bool IsNameExist(Data.AssetGood entity)
 {
     try
     {
         return(this.GetAll().Any(r => r.name == entity.name && r.ID != entity.ID));
     }
     catch
     {
         throw;
     }
 }
Пример #5
0
 public MainGroup(Data.AssetGood assetGroup, List <Data.AssetGood> subGroups)
 {
     ID        = assetGroup.ID;
     name      = assetGroup.name;
     code      = assetGroup.code;
     SubGroups = new List <SubGroup>();
     foreach (var item in subGroups)
     {
         SubGroups.Add(new SubGroup()
         {
             name = item.name, code = item.code, Id = item.ID
         });
     }
 }
 public void Insert(Data.AssetGood entity)
 {
     try
     {
         if (entity.ID == Guid.Empty)
         {
             entity.ID = Guid.NewGuid();
         }
         this.Table.Add(entity);
         this.SubmitChanges();
     }
     catch
     {
         throw;
     }
 }
        public void Delete(Data.AssetGood entity)
        {
            try
            {
                var    parentId     = entity.parentId;
                string errorMessage = string.Empty;
                if (!this.ValidateDelete(entity, out errorMessage))
                {
                    throw new Exception(errorMessage);
                }

                this.Table.Remove(entity);
                this.SubmitChanges();

                if (parentId != null && !this.GetByParentId(parentId.Value).Where(r => r.ID != entity.ID).Any())
                {
                    this.Delete(this.GetById(parentId.Value));
                }
            }
            catch
            {
                throw;
            }
        }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMainGroupCode.Text.Trim().Length == 0)
                {
                    throw new Exception(Localize.ex_no_main_group_code);
                }

                if (txtMainGroupTitle.Text.Trim().Length == 0)
                {
                    throw new Exception(Localize.ex_no_main_group_title);
                }

                if (txtSubsidiaryGroupCode.Text.Trim().Length != 0 && txtSubsidiaryGroupTitle.Text.Trim().Length == 0)
                {
                    throw new Exception(Localize.ex_no_subsidiary_group_title);
                }

                if (txtSubsidiaryGroupCode.Text.Trim().Length == 0 && txtSubsidiaryGroupTitle.Text.Trim().Length != 0)
                {
                    throw new Exception(Localize.ex_no_subsidiary_group_code);
                }

                var assetGoodsBusiness = Business.GetAssetGoodsBusiness();

                Data.AssetGood mainGroup, subsidiaryGroup = null;

                if (MainAssetGoodGroupId.HasValue && SubsidiaryAssetGoodGroupId.HasValue)
                {
                    subsidiaryGroup = assetGoodsBusiness.GetById(SubsidiaryAssetGoodGroupId.Value);
                    mainGroup       = assetGoodsBusiness.GetById(subsidiaryGroup.parentId.Value);
                }
                else if (MainAssetGoodGroupId.HasValue)
                {
                    mainGroup = assetGoodsBusiness.GetById(MainAssetGoodGroupId.Value);
                }
                else
                {
                    mainGroup = assetGoodsBusiness.GetByCode(txtMainGroupCode.Text);
                    if (mainGroup == null)
                    {
                        mainGroup = new Data.AssetGood();
                    }

                    subsidiaryGroup = assetGoodsBusiness.GetByCode(txtMainGroupCode.Text + txtSubsidiaryGroupCode.Text);
                    if (subsidiaryGroup == null)
                    {
                        subsidiaryGroup = new Data.AssetGood();
                    }
                    else
                    {
                        throw new Exception(Localize.ex_duplicated_subsidiary_group_code);
                    }
                }


                mainGroup.code        = txtMainGroupCode.Text;
                mainGroup.name        = txtMainGroupTitle.Text;
                mainGroup.codetitleId = Common.Constants.CodeTitle.AssetGoodMianGroup;


                if (subsidiaryGroup != null)
                {
                    subsidiaryGroup.code        = txtMainGroupCode.Text + txtSubsidiaryGroupCode.Text;
                    subsidiaryGroup.name        = txtSubsidiaryGroupTitle.Text;
                    subsidiaryGroup.codetitleId = Common.Constants.CodeTitle.AssetGoodSubsidiaryGroup;
                    if (assetGoodsBusiness.IsNameExist(subsidiaryGroup))
                    {
                        throw new Exception(Localize.ex_duplicated_subsidiary_group_name);
                    }
                }

                if (assetGoodsBusiness.IsNameExist(mainGroup))
                {
                    throw new Exception(Localize.ex_duplicated_main_group_name);
                }

                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted,
                    Timeout = new TimeSpan(2, 0, 0)
                }))
                {
                    assetGoodsBusiness.Save(mainGroup, string.Empty);

                    if (subsidiaryGroup != null && txtSubsidiaryGroupTitle.Text != string.Empty && txtSubsidiaryGroupCode.Text != string.Empty)
                    {
                        subsidiaryGroup.parentId = mainGroup.ID;
                        assetGoodsBusiness.Save(subsidiaryGroup, mainGroup.uniquepath);
                    }

                    scope.Complete();
                }

                this.Close();
            }
            catch (Exception ex)
            {
                AccountingKernel.Forms.Base.BaseWindow.ShowError(ex);
            }
        }