private void Register()
        {
            try
            {
                var accountingDocumentBusiness = Business.GetAccountingDocumentBusiness();
                var accountingArticleBusiness  = Business.GetAccountingArticleBusiness();
                var accountingArticle          = new Data.AccountingArticle();
                if (AccountingArticleId.HasValue)
                {
                    accountingArticle = accountingArticleBusiness.GetById(AccountingArticleId.Value);
                }

                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted,
                    Timeout = new TimeSpan(2, 0, 0)
                }))
                {
                    if (Document == null)
                    {
                        Document = new Data.AccountingDocument()
                        {
                            ADDate        = dtpDate.Text,
                            ADDescription = txtArticleDescription.Text,
                            ADCode        = txtArticleNo.Text.ToNullableInt(),
                            ADOldCode     = txtArticleOldNo.Text,
                            ADType        = cmbDocumentType.SelectedValue.ToGUID(),
                            AIdStatus     = Common.Constants.DocumentStatus.Draft,
                            AISDeleted    = false
                        };

                        accountingDocumentBusiness.Save(Document);
                    }
                    else
                    {
                        Document.ADDate        = dtpDate.Text;
                        Document.ADDescription = txtDocument_Desc.Text;
                        Document.ADCode        = txtArticleNo.Text.ToNullableInt();
                        Document.ADOldCode     = txtArticleOldNo.Text;
                        Document.ADType        = cmbDocumentType.SelectedValue.ToGUID();
                        accountingDocumentBusiness.Save(Document);
                    }

                    if (txtCount.Text != string.Empty)
                    {
                        accountingArticle.IDAccountingDocument = Document.Id;
                        accountingArticle.ADescription         = txtArticleDescription.Text;
                        accountingArticle.ADebtor   = txtDebtor.Text.ToNullableDecimal();
                        accountingArticle.ACreditor = txtCreditor.Text.ToNullableDecimal();
                        accountingArticle.ACount    = txtCount.Text.ToNullableInt();
                        accountingArticleBusiness.Save(accountingArticle);
                    }


                    var accountingTafsilArticleBusiness = Business.GetAccountingTafsilArticleBusiness();

                    accountingTafsilArticleBusiness.Delete(accountingTafsilArticleBusiness.GetByAccountingArticleId(accountingArticle.ID).ToList());



                    ////
                    var tCode = FrmBLablels[0].code + FrmBLablels[1].code + FrmBLablels[2].code;

                    var accountingMoein = Business.GetAccountingMoeinBusiness().GetByMIdMoein(tCode);

                    var ata = new List <Data.AccountingTafsilArticle>();

                    if (FrmBLablels.Count <= 3)
                    {
                        ata.Add(new Data.AccountingTafsilArticle()
                        {
                            IDAccountingMoein             = accountingMoein.Id,
                            IDAccountingMoeinTafsilLevels = null,
                            IdAccountingTafsilLDetails    = null,
                            IdAccountingArticle           = accountingArticle.ID,
                        });
                    }

                    for (int i = 4; i <= FrmBLablels.Count; i++)
                    {
                        var satheTafsil = Common.Constants.CodeTitle.Tafsil1;
                        switch (i)
                        {
                        case 5:
                            satheTafsil = Common.Constants.CodeTitle.Tafsil2;
                            break;

                        case 6:
                            satheTafsil = Common.Constants.CodeTitle.Tafsil3;
                            break;

                        default:
                            break;
                        }


                        var accountingTafsillevelsDetailCode = FrmBLablels[i].code;
                        var accountingMoeinTafsilLevels      = Business.GetAccountingMoeinTafsilLevelBusiness().GetByIdAccountingMoein(accountingMoein.Id, satheTafsil);

                        var accountingTafsillevelsDetails = Business.GetAccountingTafsilLevelDetailBusiness().GetHesabTafsilByAccountingTafsilLevelsId(
                            accountingMoeinTafsilLevels.Select(r => r.IdAccountingTafsilLevels.Value).ToList())
                                                            .Where(r => r.IdIn == accountingTafsillevelsDetailCode).First();


                        ata.Add(new Data.AccountingTafsilArticle()
                        {
                            IDAccountingMoein             = accountingMoein.Id,
                            IDAccountingMoeinTafsilLevels = accountingMoeinTafsilLevels.First().ID,
                            IdAccountingTafsilLDetails    = accountingTafsillevelsDetails.Id,
                            IdAccountingArticle           = accountingArticle.ID,
                        });
                    }
                    accountingTafsilArticleBusiness.Save(ata);


                    scope.Complete();
                }

                SetDataGrid();

                SetDocumentInfo(Document, accountingArticleBusiness.GetByAccountingDcoumentId(Document.Id).ToList());

                txtCount.Clear();
                txtDebtor.Clear();
                txtCreditor.Clear();
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 2
0
        private void Register()
        {
            try
            {
                var accountingDocumentBusiness = Business.GetAccountingDocumentBusiness();
                var accountingArticleBusiness  = Business.GetAccountingArticleBusiness();
                var accountingArticle          = new Data.AccountingArticle();
                if (AccountingArticleId.HasValue)
                {
                    accountingArticle = accountingArticleBusiness.GetById(AccountingArticleId.Value);
                }

                using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted,
                    Timeout = new TimeSpan(2, 0, 0)
                }))
                {
                    if (xDocument == null)
                    {
                        xDocument = new Data.AccountingDocument()
                        {
                            ADDate        = dtpDate.Text,
                            ADDescription = txtArticleDescription.Text,
                            ADCode        = txtArticleNo.Text.ToNullableInt(),
                            ADOldCode     = txtArticleOldNo.Text,
                            ADType        = cmbDocumentType.SelectedValue.ToGUID(),
                            AIdStatus     = Common.Constants.DocumentStatus.Draft,
                            AISDeleted    = false
                        };

                        accountingDocumentBusiness.Save(xDocument);
                    }
                    else
                    {
                        xDocument.ADDate        = dtpDate.Text;
                        xDocument.ADDescription = txtDocument_Desc.Text;
                        xDocument.ADCode        = txtArticleNo.Text.ToNullableInt();
                        xDocument.ADOldCode     = txtArticleOldNo.Text;
                        xDocument.ADType        = cmbDocumentType.SelectedValue.ToGUID();
                        accountingDocumentBusiness.Save(xDocument);
                    }

                    if (string.IsNullOrEmpty(txtCount.Text) == false)
                    {
                        accountingArticle.IDAccountingDocument = xDocument.Id;
                        accountingArticle.ADescription         = txtArticleDescription.Text;
                        accountingArticle.ADebtor   = txtDebtor.Text.ToNullableDecimal();
                        accountingArticle.ACreditor = txtCreditor.Text.ToNullableDecimal();
                        accountingArticle.ACount    = txtCount.Text.ToNullableInt();
                        accountingArticleBusiness.Save(accountingArticle);
                    }


                    var accountingTafsilArticleBusiness = Business.GetAccountingTafsilArticleBusiness();

                    accountingTafsilArticleBusiness.Delete(accountingTafsilArticleBusiness.GetByAccountingArticleId(accountingArticle.ID).ToList());



                    ////
                    var tCode = FrmBLablels[2].code;

                    //changed by ali youensi
                    //var accountingMoein = Business.GetAccountingMoeinBusiness().GetByMIdMoein(tCode);
                    var accountingMoein = Business.GetMoeinStructureDefineBusiness().GetByCode(tCode);


                    var ata = new List <Data.AccountingTafsilArticle>();

                    if (FrmBLablels.Count <= 3)
                    {
                        ata.Add(new Data.AccountingTafsilArticle()
                        {
                            IDAccountingMoein   = accountingMoein.ID,
                            IdAccountingArticle = accountingArticle.ID,
                            IDAccountingTafsilStructureDefine = null
                        });
                    }

                    for (int i = 4; i <= FrmBLablels.Count; i++)
                    {
                        var satheTafsil = Common.Constants.CodeTitle.Tafsil1;
                        switch (i)
                        {
                        case 5:
                            satheTafsil = Common.Constants.CodeTitle.Tafsil2;
                            break;

                        case 6:
                            satheTafsil = Common.Constants.CodeTitle.Tafsil3;
                            break;

                        default:
                            break;
                        }
                        ata.Add(new Data.AccountingTafsilArticle()
                        {
                            IDAccountingMoein   = accountingMoein.ID,
                            IdAccountingArticle = accountingArticle.ID,
                            IDAccountingTafsilStructureDefine = satheTafsil
                        });
                    }
                    accountingTafsilArticleBusiness.Save(ata);


                    scope.Complete();
                }

                SetDataGrid();

                SetDocumentInfo(xDocument, accountingArticleBusiness.GetByAccountingDcoumentId(xDocument.Id).ToList());

                txtCount.Clear();
                txtDebtor.Clear();
                txtCreditor.Clear();
            }
            catch
            {
                throw;
            }
        }