Exemple #1
0
        public bool UpdateBillActor(Session session, Guid billId, Guid creatorPersonId,
                                    Guid salesPersonId, Guid chiefAccountantPersonId, Guid directorPersonId)
        {
            try
            {
                //Get bill
                Bill bill = session.GetObjectByKey <Bill>(billId);
                if (bill == null)
                {
                    throw new Exception("Could not foung bill");
                }

                //Get creator
                Person creator         = session.GetObjectByKey <Person>(creatorPersonId);
                Person sales           = session.GetObjectByKey <Person>(salesPersonId);
                Person chiefAccountant = session.GetObjectByKey <Person>(chiefAccountantPersonId);
                Person director        = session.GetObjectByKey <Person>(directorPersonId);

                int           countExistType;
                BillActorType creatorType;
                //Update CREATOR bill actor type
                creatorType    = BillActorType.GetDefault(session, BillActorTypeEnum.CREATOR);
                countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType);
                if (countExistType == 0)
                {
                    BillActor billActor = new BillActor(session)
                    {
                        BillActorTypeId = creatorType,
                        PersonId        = creator,
                        BillId          = bill
                    };
                }
                else
                {
                    BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType);
                    billActor.PersonId = creator;
                }
                session.FlushChanges();

                //Update SALES bill actor type
                creatorType    = BillActorType.GetDefault(session, BillActorTypeEnum.SALES);
                countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType);
                if (countExistType == 0)
                {
                    BillActor billActor = new BillActor(session)
                    {
                        BillActorTypeId = creatorType,
                        PersonId        = sales,
                        BillId          = bill
                    };
                }
                else
                {
                    BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType);
                    billActor.PersonId = sales;
                }
                session.FlushChanges();

                //Update CHIEFACCOUNTANT bill actor type
                creatorType    = BillActorType.GetDefault(session, BillActorTypeEnum.CHIEFACCOUNTANT);
                countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType);
                if (countExistType == 0)
                {
                    BillActor billActor = new BillActor(session)
                    {
                        BillActorTypeId = creatorType,
                        PersonId        = chiefAccountant,
                        BillId          = bill
                    };
                }
                else
                {
                    BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType);
                    billActor.PersonId = chiefAccountant;
                }
                session.FlushChanges();

                //Update DIRECTOR bill actor type
                creatorType    = BillActorType.GetDefault(session, BillActorTypeEnum.DIRECTOR);
                countExistType = bill.BillActors.Count(r => r.BillActorTypeId == creatorType);
                if (countExistType == 0)
                {
                    BillActor billActor = new BillActor(session)
                    {
                        BillActorTypeId = creatorType,
                        PersonId        = director,
                        BillId          = bill
                    };
                }
                else
                {
                    BillActor billActor = bill.BillActors.FirstOrDefault(r => r.BillActorTypeId == creatorType);
                    billActor.PersonId = director;
                }
                session.FlushChanges();

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void formlayoutInvoiceEditingForm_LoadData()
        {
            NAS.BO.Invoice.PurchaseInvoiceBO purchaseInvoiceBO = new NAS.BO.Invoice.PurchaseInvoiceBO();
            Bill bill = purchaseInvoiceBO.GetBillById(session, BillId);

            txtCode.Text       = bill.Code;
            txtIssuedDate.Date = bill.IssuedDate;
            if (bill.SourceOrganizationId != null)
            {
                comboOrganization.Value = bill.SourceOrganizationId.OrganizationId;
                comboOrganization.DataBindItems();
            }
            else
            {
                comboOrganization.SelectedIndex = -1;
            }

            int           countExistType;
            BillActorType billActorType;

            //Update index of creator combobox
            billActorType  = BillActorType.GetDefault(session, BillActorTypeEnum.CREATOR);
            countExistType = bill.BillActors.Count(r => r.BillActorTypeId == billActorType);
            if (countExistType == 0)
            {
                comboCreator.SelectedIndex = -1;
            }
            else
            {
                Person person = bill.BillActors
                                .FirstOrDefault(r => r.BillActorTypeId == billActorType).PersonId;
                if (person == null)
                {
                    comboCreator.SelectedIndex = -1;
                }
                else
                {
                    comboCreator.Value = person.PersonId;
                }
                comboCreator.DataBindItems();
            }

            //Update index of buyer combobox
            billActorType  = BillActorType.GetDefault(session, BillActorTypeEnum.BUYER);
            countExistType = bill.BillActors.Count(r => r.BillActorTypeId == billActorType);
            if (countExistType == 0)
            {
                comboBuyer.SelectedIndex = -1;
            }
            else
            {
                Person person = bill.BillActors
                                .FirstOrDefault(r => r.BillActorTypeId == billActorType).PersonId;
                if (person == null)
                {
                    comboBuyer.SelectedIndex = -1;
                }
                else
                {
                    comboBuyer.Value = person.PersonId;
                }
                comboBuyer.DataBindItems();
            }

            //Update index of chief accountant combobox
            billActorType  = BillActorType.GetDefault(session, BillActorTypeEnum.CHIEFACCOUNTANT);
            countExistType = bill.BillActors.Count(r => r.BillActorTypeId == billActorType);
            if (countExistType == 0)
            {
                comboChiefAccountant.SelectedIndex = -1;
            }
            else
            {
                Person person = bill.BillActors
                                .FirstOrDefault(r => r.BillActorTypeId == billActorType).PersonId;
                if (person == null)
                {
                    comboChiefAccountant.SelectedIndex = -1;
                }
                else
                {
                    comboChiefAccountant.Value = person.PersonId;
                }
                comboChiefAccountant.DataBindItems();
            }

            //Update index of creator combobox
            billActorType  = BillActorType.GetDefault(session, BillActorTypeEnum.DIRECTOR);
            countExistType = bill.BillActors.Count(r => r.BillActorTypeId == billActorType);
            if (countExistType == 0)
            {
                comboDirector.SelectedIndex = -1;
            }
            else
            {
                Person person = bill.BillActors
                                .FirstOrDefault(r => r.BillActorTypeId == billActorType).PersonId;
                if (person == null)
                {
                    comboDirector.SelectedIndex = -1;
                }
                else
                {
                    comboDirector.Value = person.PersonId;
                }
                comboDirector.DataBindItems();
            }
        }