public bool ChangeDomainOfApplicationName(EconomicActivity pEconomicActivity, string newName, bool isLoanPurpose)
        {
            if (newName == String.Empty)
            {
                throw new OpenCbsDoaUpdateException(OpenCbsDOAUpdateExceptionEnum.NewNameIsNull);
            }

            if (_doam.ThisActivityAlreadyExist(newName, pEconomicActivity.Parent.Id, isLoanPurpose))
            {
                throw new OpenCbsDoaSaveException(OpenCbsDOASaveExceptionEnum.AlreadyExist);
            }

            EconomicActivity activity = pEconomicActivity;

            activity.Name = newName;
            if (isLoanPurpose)
            {
                _doam.UpdateEconomicActivity(activity, isLoanPurpose);
            }
            else
            {
                _doam.UpdateEconomicActivity(activity);
            }

            return(true);
        }
        private List <EconomicActivity> GetCasheEconomicActivities()
        {
            List <EconomicActivity> doaList = new List <EconomicActivity>();

            const string sqlText =
                "SELECT id,name,deleted,parent_id FROM EconomicActivities WHERE deleted = 0";

            using (SqlConnection connection = GetConnection())
                using (OpenCbsCommand selectAll = new OpenCbsCommand(sqlText, connection))
                {
                    using (OpenCbsReader reader = selectAll.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            EconomicActivity domain = new EconomicActivity
                            {
                                Id       = reader.GetInt("id"),
                                Name     = reader.GetString("name"),
                                ParentId = reader.GetNullInt("parent_id")
                            };
                            doaList.Add(domain);
                        }
                    }
                }

            foreach (var economicActivity in doaList)
            {
                economicActivity.Parent    = doaList.FirstOrDefault(val => val.Id == economicActivity.ParentId);
                economicActivity.Childrens = doaList.Where(val => economicActivity.Id == val.ParentId).ToList();
            }

            return(doaList);
        }
 public void TestIfParentIsCorrectlySetAndRetrieved()
 {
     EconomicActivity parent = new EconomicActivity();
     parent.Id = 1;
     doa.Parent = parent;
     Assert.AreEqual(1,doa.Parent.Id);
 }
Exemplo n.º 4
0
        public void ThisActivityAlreadyExistInThisActivity()
        {
            _economicActivityManager = (EconomicActivityManager)container["EconomicActivityManager"];
            EconomicActivity activityParentA = new EconomicActivity
            {
                Name   = "Services",
                Parent = null
            };

            activityParentA.Id = _economicActivityManager.AddEconomicActivity(activityParentA);
            EconomicActivity activityParentB = new EconomicActivity
            {
                Name   = "Services",
                Parent = null
            };

            activityParentB.Id = _economicActivityManager.AddEconomicActivity(activityParentB);
            EconomicActivity activityA = new EconomicActivity
            {
                Name   = "ServicesA",
                Parent = activityParentA,
            };

            activityA.Id = _economicActivityManager.AddEconomicActivity(activityA);

            Assert.AreEqual(true, _economicActivityManager.ThisActivityAlreadyExist("ServicesA", activityParentA.Id));
        }
Exemplo n.º 5
0
        public void SelectEconomicActivityByIdWithChildren()
        {
            _economicActivityManager = (EconomicActivityManager)container["EconomicActivityManager"];
            EconomicActivity activityParent = new EconomicActivity
            {
                Name   = "Services",
                Parent = null
            };

            activityParent.Id = _economicActivityManager.AddEconomicActivity(activityParent);
            EconomicActivity activityA = new EconomicActivity
            {
                Name   = "ServicesA",
                Parent = activityParent,
            };

            activityA.Id = _economicActivityManager.AddEconomicActivity(activityA);
            EconomicActivity activityB = new EconomicActivity
            {
                Name   = "ServicesB",
                Parent = activityParent,
            };

            activityB.Id = _economicActivityManager.AddEconomicActivity(activityB);

            EconomicActivity selectedActivity = _economicActivityManager.SelectEconomicActivity(activityParent.Id);

            Assert.AreEqual(activityParent.Id, selectedActivity.Id);
            Assert.AreEqual("Services", selectedActivity.Name);
            Assert.AreEqual(true, selectedActivity.HasChildrens);
            Assert.AreEqual(2, selectedActivity.Childrens.Count);
            Assert.AreEqual(false, selectedActivity.Deleted);
        }
        public void FindAllEconomicActivitiesWhenResult()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activityA1 = new EconomicActivity {
                Id = 3, Name = "ServicesA1"
            };
            EconomicActivity activityB2 = new EconomicActivity {
                Id = 4, Name = "ServicesB2"
            };
            EconomicActivity activityA = new EconomicActivity {
                Id = 1, Name = "ServicesA", Parent = null, Childrens = new List <EconomicActivity> {
                    activityA1, activityB2
                }
            };
            EconomicActivity activityB = new EconomicActivity {
                Id = 2, Name = "ServicesB", Parent = null
            };

            List <EconomicActivity> activities = new List <EconomicActivity> {
                activityA, activityB
            };

            _dynamicMock.SetReturnValue("SelectAllEconomicActivities", activities);

            _economicActivityManager  = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);

            Assert.AreEqual(2, _economicActivityServices.FindAllEconomicActivities().Count);
        }
        public void AddContractRuleForEconomicActivity()
        {
            Account          genericAccount  = _accountManager.Select(1);
            Account          specificAccount = _accountManager.Select(2);
            EconomicActivity economicActivty = _economicActivityManager.SelectEconomicActivity(1);

            EventType      eventType      = _eventManager.SelectEventTypeByEventType("RGLE");
            EventAttribute eventAttribute = _eventManager.SelectEventAttributeByCode("principal");

            ContractAccountingRule rule = new ContractAccountingRule
            {
                DebitAccount     = genericAccount,
                CreditAccount    = specificAccount,
                ProductType      = OProductTypes.All,
                ClientType       = OClientTypes.Village,
                EconomicActivity = economicActivty,
                BookingDirection = OBookingDirections.Credit,
                EventType        = eventType,
                EventAttribute   = eventAttribute
            };

            rule.Id = _accountingRuleManager.AddAccountingRule(rule);
            Assert.AreNotEqual(0, rule.Id);

            ContractAccountingRule retrievedRule = _accountingRuleManager.Select(rule.Id) as ContractAccountingRule;

            _compareRules(rule, retrievedRule);
        }
Exemplo n.º 8
0
        private void DeleteEconomicActivity(EconomicActivity economicActivity)
        {
            _economicActivity = economicActivity;
            if (_isLoanPurpose)
            {
                ServicesProvider.GetInstance().GetEconomicActivityServices().DeleteEconomicActivity(_economicActivity, _isLoanPurpose);
            }
            else
            {
                ServicesProvider.GetInstance().GetEconomicActivityServices().DeleteEconomicActivity(_economicActivity);
            }

            var parent = (EconomicActivity)_selectedNode.Parent.Tag;

            if (parent != null)
            {
                parent.RemoveChildren(_economicActivity);
            }

            tvEconomicActivity.BeginUpdate();
            _selectedNode.Remove();
            tvEconomicActivity.EndUpdate();

            SelectRootNode();

            tvEconomicActivity.Sort();
        }
        public int AddEconomicActivity(EconomicActivity loanPurpose, bool isLoanPurpose)
        {
            string sqlText = "";

            if (isLoanPurpose)
            {
                sqlText = @"INSERT INTO LoanPurpose ([name] , [parent_id] , [deleted]) 
                        VALUES (@name,@parentId,@deleted) SELECT SCOPE_IDENTITY()";
            }
            using (SqlConnection connection = GetConnection())
                using (OpenCbsCommand insert = new OpenCbsCommand(sqlText, connection))
                {
                    insert.AddParam("@name", loanPurpose.Name);
                    insert.AddParam("@deleted", loanPurpose.Deleted);
                    if (loanPurpose.Parent != null)
                    {
                        insert.AddParam("@parentId", loanPurpose.Parent.Id);
                    }
                    else
                    {
                        insert.AddParam("@parentId", null);
                    }

                    var result = int.Parse(insert.ExecuteScalar().ToString());
                    RefreshCache();
                    return(result);
                }
        }
Exemplo n.º 10
0
        public void TestUpdatePerson()
        {
            AddDataForTestingTransaction addDataForTesting = new AddDataForTestingTransaction();

            clientManagement = new ClientManager(DataUtil.TESTDB);
            clientServices   = new ClientServices(clientManagement);

            DeleteAllData();
            ApplicationSettingsServices _appSettings = ServicesProvider.GetInstance().GetApplicationSettingsServices();

            _appSettings.FillGeneralDatabaseParameter();
            _appSettings.UpdateSelectedParameter(OGeneralSettings.ID_PATTERN, "[0-9]{2}[A-Z]{2}");

            EconomicActivity agriculture = addDataForTesting.AddDomainOfApplicationAgriculture();
            District         district    = addDataForTesting.AddDistrictIntoDatabase();

            Person person = AddPerson(true, agriculture, 1, "Dushambe", district, "Nicolas", "MANGIN", 'M', "12ED");

            person.Branch = _branch;
            Assert.AreEqual(String.Empty, clientServices.SavePerson(ref person));

            person.FirstName          = "floriane";
            person.IdentificationData = "34PP";
            Assert.AreEqual(String.Empty, clientServices.SavePerson(ref person));
        }
Exemplo n.º 11
0
        /// <summary>
        /// This methods allows us to find all domains of application
        /// </summary>
        /// <returns>hierarchic collection of DomainOfApplication
        /// </returns>
        public List <EconomicActivity> SelectAllEconomicActivities()
        {
            List <EconomicActivity> doaList = new List <EconomicActivity>();

            const string sqlText = "SELECT id FROM EconomicActivities WHERE parent_id IS NULL AND deleted = 0";

            using (SqlConnection connection = GetConnection())
                using (OpenCbsCommand selectAll = new OpenCbsCommand(sqlText, connection))
                {
                    using (OpenCbsReader reader = selectAll.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            EconomicActivity domain = new EconomicActivity
                            {
                                Id = reader.GetInt("id")
                            };
                            doaList.Add(domain);
                        }
                    }
                }

            for (int i = 0; i < doaList.Count; i++)
            {
                doaList[i] = SelectEconomicActivity(doaList[i].Id);
            }

            return(doaList);
        }
Exemplo n.º 12
0
        private List <EconomicActivity> SelectLPChildren(int pParentId)
        {
            List <EconomicActivity> doaList = new List <EconomicActivity>();

            const string sqlText = "SELECT id, name, deleted FROM LoanPurpose WHERE parent_id = @id AND deleted = 0";

            using (SqlConnection connection = GetConnection())
                using (OpenCbsCommand sqlCommand = new OpenCbsCommand(sqlText, connection))
                {
                    sqlCommand.AddParam("@id", pParentId);
                    using (OpenCbsReader reader = sqlCommand.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            EconomicActivity domain = new EconomicActivity
                            {
                                Id      = reader.GetInt("id"),
                                Name    = reader.GetString("name"),
                                Deleted = reader.GetBool("deleted")
                            };
                            doaList.Add(domain);
                        }
                    }
                }
            for (int i = 0; i < doaList.Count; i++)
            {
                doaList[i].Childrens = SelectLPChildren(doaList[i].Id);
            }

            return(doaList);
        }
Exemplo n.º 13
0
        private void EditDomain()
        {
            try
            {
                if (buttonEdit.Text.Equals(GetString("buttonEdit")))
                {
                    selectedNode      = tvEconomicActivity.SelectedNode;
                    _economicActivity = (EconomicActivity)selectedNode.Tag;

                    if (_economicActivity != null)
                    {
                        _economicActivity.Parent = (EconomicActivity)selectedNode.Parent.Tag;
                        textBoxName.Text         = _economicActivity.Name;
                        IsSame                     = textBoxName.Text;
                        buttonExit.Enabled         = false;
                        buttonAdd.Enabled          = false;
                        buttonDelete.Enabled       = false;
                        tvEconomicActivity.Enabled = false;

                        buttonEdit.Text = GetString("buttonSave");
                    }
                }
                else
                {
                    if (ServicesProvider.GetInstance().GetEconomicActivityServices().NodeEditable(selectedNode.Tag))
                    {
                        if (selectedNode.Level == 1)
                        {
                            _economicActivity.Parent = new EconomicActivity(); // no parent
                        }
                        if (IsSame != textBoxName.Text)
                        {
                            if (ServicesProvider.GetInstance().GetEconomicActivityServices().ChangeDomainOfApplicationName(_economicActivity, textBoxName.Text))
                            {
                                tvEconomicActivity.BeginUpdate();
                                selectedNode.Tag  = _economicActivity;
                                selectedNode.Text = textBoxName.Text;
                                tvEconomicActivity.EndUpdate();
                            }
                        }
                    }

                    buttonExit.Enabled         = true;
                    buttonAdd.Enabled          = true;
                    buttonDelete.Enabled       = true;
                    tvEconomicActivity.Enabled = true;
                    textBoxName.Text           = string.Empty;

                    buttonEdit.Text = GetString("buttonEdit");
                }
            }
            catch (Exception ex)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(ex)).ShowDialog();
            }

            SelectRootNode();

            tvEconomicActivity.Sort();
        }
        public void TestNodeEditableWhenObjectIsNotNullAndDAO()
        {
            EconomicActivity dom = new EconomicActivity {
                Id = 1, Name = "Services", Parent = null
            };

            Assert.IsTrue(_economicActivityServices.NodeEditable(dom));
        }
Exemplo n.º 15
0
        public void TestIfDomainOfApplicationIsCorrectlySetAndRetrieved()
        {
            EconomicActivity agriculture = new EconomicActivity(1, "Agriculture", new EconomicActivity(), false);

            person.Activity = agriculture;
            Assert.AreEqual(1, person.Activity.Id);
            Assert.AreEqual("Agriculture", person.Activity.Name);
            Assert.IsNotNull(person.Activity.Parent);
            Assert.IsFalse(person.Activity.Deleted);
        }
Exemplo n.º 16
0
        public void DeleteEconomicActivity(EconomicActivity pEconomicActivity)
        {
            if (pEconomicActivity.HasChildrens)
            {
                throw new OpenCbsDoaDeleteException(OpenCbsDOADeleteExceptionEnum.HasChildrens);
            }

            pEconomicActivity.Deleted = true;
            _doam.UpdateEconomicActivity(pEconomicActivity);
        }
Exemplo n.º 17
0
        private void BtnSelectClick(object sender, EventArgs e)
        {
            frmActivity frmActivity = new frmActivity();

            frmActivity.ShowDialog();

            txbActivity.Clear();
            Activity = frmActivity.EconomicActivity;
            OnActivityChange();
        }
Exemplo n.º 18
0
        private void AddDomain()
        {
            _selectedNode = tvEconomicActivity.SelectedNode;

            //var doan = new FrmEconomicActivityName { DoaName = String.Empty, Text = "Economic activity" };
            //doan.ShowDialog();
            //if (doan.IsClosed) return;

            var doa = new EconomicActivity {
                Name = textBoxName.Text
            };

            try
            {
                EconomicActivity parent;

                // add economic activity (in the root)
                if (_selectedNode.Tag == null)
                {
                    parent     = new EconomicActivity();
                    doa.Parent = parent;
                }
                // add in the tree
                else
                {
                    parent     = (EconomicActivity)_selectedNode.Tag;
                    doa.Parent = parent;
                }

                doa.Id = _isLoanPurpose ?
                         ServicesProvider.GetInstance().GetEconomicActivityServices().AddEconomicActivity(doa, _isLoanPurpose)
                    : ServicesProvider.GetInstance().GetEconomicActivityServices().AddEconomicActivity(doa);

                var node = new TreeNode(doa.Name)
                {
                    Tag = doa
                };
                _selectedNode.Nodes.Add(node);

                if (parent != null)
                {
                    parent.Childrens.Add(doa);
                    _selectedNode.Tag = parent;
                }
                _selectedNode.Expand();
            }
            catch (Exception up)
            {
                new frmShowError(CustomExceptionHandler.ShowExceptionText(up)).ShowDialog();
            }

            SelectRootNode();

            tvEconomicActivity.Sort();
        }
        public void TestChangeDomainNameWhenNewNameIsEmpty()
        {
            EconomicActivity dom = new EconomicActivity
            {
                Id     = 1,
                Name   = "Services",
                Parent = new EconomicActivity()
            };

            _economicActivityServices.ChangeDomainOfApplicationName(dom, String.Empty);
        }
        public EconomicActivity AddDomainOfApplicationAgri()
        {
            EconomicActivity services = new EconomicActivity();

            services.Name    = "Agri";
            services.Parent  = null;
            services.Deleted = false;
            services.Id      = _domainOfApplicationManagement.AddEconomicActivity(services);

            return(services);
        }
        public EconomicActivity AddDomainOfApplicationAgriculture()
        {
            EconomicActivity agriculture = new EconomicActivity();

            agriculture.Name    = "Agriculture";
            agriculture.Parent  = null;
            agriculture.Deleted = false;
            agriculture.Id      = _domainOfApplicationManagement.AddEconomicActivity(agriculture);

            return(agriculture);
        }
Exemplo n.º 22
0
        public void AddEconomicActivityWithoutChildren()
        {
            _economicActivityManager = (EconomicActivityManager)container["EconomicActivityManager"];
            EconomicActivity activity = new EconomicActivity
            {
                Name   = "Services",
                Parent = null
            };

            activity.Id = _economicActivityManager.AddEconomicActivity(activity);
            Assert.AreNotEqual(0, activity.Id);
        }
Exemplo n.º 23
0
        public void UpdateEconomicActivity(EconomicActivity pEconomicActivity, bool isLoanPurpose)
        {
            const string sqlText = "UPDATE LoanPurpose SET name = @name,deleted = @wasDeleted WHERE id = @id";

            using (SqlConnection connection = GetConnection())
                using (OpenCbsCommand update = new OpenCbsCommand(sqlText, connection))
                {
                    update.AddParam("@id", pEconomicActivity.Id);
                    update.AddParam("@name", pEconomicActivity.Name);
                    update.AddParam("@wasDeleted", pEconomicActivity.Deleted);
                    update.ExecuteNonQuery();
                }
        }
Exemplo n.º 24
0
        public void Get_Set_EconomicActivity()
        {
            ContractAccountingRule rule = new ContractAccountingRule();

            Assert.AreEqual(null, rule.EconomicActivity);

            EconomicActivity economicActivity = new EconomicActivity {
                Id = 1, Name = "Econimic Acvitity"
            };

            rule.EconomicActivity = economicActivity;
            Assert.AreEqual(economicActivity, rule.EconomicActivity);
        }
        public void TestDeleteDomainWhenDomainHasNoChildrens()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activity = new EconomicActivity {
                Id = 1, Name = "Services", Childrens = new List <EconomicActivity>()
            };

            _dynamicMock.Expect("UpdateEconomicActivity", activity);

            _economicActivityManager  = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);

            _economicActivityServices.DeleteEconomicActivity(activity);
        }
        public void AddEconomicActivityWhenNameIsEmpty()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activity = new EconomicActivity {
                Name = String.Empty
            };

            _dynamicMock.ExpectAndReturn("AddEconomicActivity", 0, activity);

            _economicActivityManager  = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);

            _economicActivityServices.AddEconomicActivity(activity);
        }
        public void TestChangeDomainOfApplicationNameWhenNotInUse()
        {
            _dynamicMock = new DynamicMock(typeof(EconomicActivityManager));
            EconomicActivity activity = new EconomicActivity {
                Id = 2, Name = "Services", Parent = new EconomicActivity {
                    Id = 1
                }
            };

            _dynamicMock.Expect("UpdateEconomicActivity", activity);
            _dynamicMock.ExpectAndReturn("ThisActivityAlreadyExist", false, "GMO agriculture", 1);
            _economicActivityManager  = (EconomicActivityManager)_dynamicMock.MockInstance;
            _economicActivityServices = new EconomicActivityServices(_economicActivityManager);
            Assert.AreEqual(true, _economicActivityServices.ChangeDomainOfApplicationName(activity, "GMO agriculture"));
        }
Exemplo n.º 28
0
 private static void _DisplayAllChildrensNodes(TreeNode pNode, EconomicActivity pApplication)
 {
     foreach (EconomicActivity domainOfApplication in pApplication.Childrens)
     {
         var node = new TreeNode(domainOfApplication.Name)
         {
             Tag = domainOfApplication
         };
         pNode.Nodes.Add(node);
         if (domainOfApplication.HasChildrens)
         {
             _DisplayAllChildrensNodes(node, domainOfApplication);
         }
     }
 }
Exemplo n.º 29
0
        public void SelectAllEconomicActivities()
        {
            _economicActivityManager = (EconomicActivityManager)container["EconomicActivityManager"];
            EconomicActivity activityParentA = new EconomicActivity
            {
                Name   = "Services",
                Parent = null
            };

            activityParentA.Id = _economicActivityManager.AddEconomicActivity(activityParentA);
            EconomicActivity activityParentB = new EconomicActivity
            {
                Name   = "Services",
                Parent = null
            };

            activityParentB.Id = _economicActivityManager.AddEconomicActivity(activityParentB);
            EconomicActivity activityA = new EconomicActivity
            {
                Name   = "ServicesA",
                Parent = activityParentA,
            };

            activityA.Id = _economicActivityManager.AddEconomicActivity(activityA);
            EconomicActivity activityB = new EconomicActivity
            {
                Name   = "ServicesB",
                Parent = activityParentA,
            };

            activityB.Id = _economicActivityManager.AddEconomicActivity(activityB);

            List <EconomicActivity> activities = _economicActivityManager.SelectAllEconomicActivities();

            Assert.AreEqual(4, activities.Count);

            Assert.AreEqual(false, activities[0].HasChildrens);
            Assert.AreEqual(0, activities[0].Childrens.Count);

            Assert.AreEqual(false, activities[1].HasChildrens);
            Assert.AreEqual(0, activities[1].Childrens.Count);

            Assert.AreEqual(true, activities[2].HasChildrens);
            Assert.AreEqual(2, activities[2].Childrens.Count);

            Assert.AreEqual(false, activities[3].HasChildrens);
            Assert.AreEqual(0, activities[3].Childrens.Count);
        }
Exemplo n.º 30
0
        private static EconomicActivity GetEconomicActivity(OpenCbsReader pReader)
        {
            EconomicActivity doa = new EconomicActivity();

            if (pReader != null)
            {
                if (!pReader.Empty)
                {
                    pReader.Read();
                    doa.Id      = pReader.GetInt("id");
                    doa.Name    = pReader.GetString("name");
                    doa.Deleted = pReader.GetBool("deleted");
                }
            }
            return(doa);
        }