Ejemplo n.º 1
0
        /// <summary>
        /// Load the informations about the person and fill the page. 
        /// </summary>
        /// <param name="sender">The sender of the events</param>
        /// <param name="e">The args of the event</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["person"] != null)
            {
                var id = Request.QueryString["person"].ToInt();

                Extensions.SqlOperation operation = () =>
                {
                    var person = new PersonsDAO().GetPersonByID(id);

                    IDLabel.Text = person.Id.ToString();
                    NameLabel.Text = person.Name;
                    FirstNameLabel.Text = person.FirstName;
                    MailLabel.Text = person.Email;
                    PhoneLabel.Text = person.Phone;
                    DepartmentLabel.Text = person.Department == null ? "" : person.Department.Name;
                    InstitutionLabel.Text = person.Department == null ? "" : person.Department.InstitutionName;

                    StateLabel.Text = person.Archived ? "Oui" : "Non";
                };

                this.Verified(operation, ErrorLabel);
            }
            else
            {
                EditButton.Enabled = false;
                DeleteButton.Enabled = false;
            }
        }
Ejemplo n.º 2
0
        public void ArchivePersonTest()
        {
            var target = new PersonsDAO();

            var actual = target.CreatePerson("Test" + new Random().Next(), "Test" + new Random().Next(), "076/482.04.78", "*****@*****.**", department);

            target.ArchivePerson(actual);

            var person = target.GetPersonByID(actual);

            Assert.IsNotNull(person, "Person must not be null");
            Assert.AreEqual(true, person.Archived, "The person must be archived");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a person with the given informations. 
        /// </summary>
        /// <param name="sender">The sender of the events</param>
        /// <param name="e">The args of the event</param>
        protected void CreatePerson(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
                Extensions.SqlOperation operation = () =>
                {
                    var departmentId = DepartmentList.SelectedValue.ToInt();

                    var id = new PersonsDAO().CreatePerson(FirstNameTextBox.Text, NameTextBox.Text, PhoneTextBox.Text, MailTextBox.Text, departmentId);

                    Response.Redirect("ShowPerson.aspx?person=" + id);
                };

                this.Verified(operation, ErrorLabel);
            }
        }
Ejemplo n.º 4
0
        public void CreatePersonTest()
        {
            var target = new PersonsDAO();

            var name = "Test" + new Random().Next();
            var actual = target.CreatePerson("New", name, "076/482.04.78", "*****@*****.**", department);

            Assert.IsTrue(actual > 0, "The id must be greater than 0");

            var created = target.GetPersonByID(actual);

            Assert.AreEqual(name, created.Name, "Values must be the same");
            Assert.AreEqual("New", created.FirstName, "Values must be the same");
            Assert.AreEqual("076/482.04.78", created.Phone, "Values must be the same");
            Assert.AreEqual("*****@*****.**", created.Email, "Values must be the same");
            Assert.AreEqual(department, created.Department.Id, "Values must be the same");
            Assert.AreEqual(false, created.Archived, "Values must be the same");
        }
Ejemplo n.º 5
0
        public void SavePersonTest()
        {
            var target = new PersonsDAO(); // TODO: Initialize to an appropriate value

            var actual = target.CreatePerson("Test" + new Random().Next(), "Test" + new Random().Next(), "076/482.04.78", "*****@*****.**", department);

            var firstname = "Test" + new Random().Next();
            var name = "Test" + new Random().Next();
            var phone = "076/482.04.79";
            var email = "*****@*****.**";

            using(var connection = DBManager.GetInstance().GetNewConnection())
            {
                var transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                target.SavePerson(actual, firstname, name, phone, email, department, transaction);

                transaction.Commit();
            }

            var result = target.GetPersonByID(actual);

            Assert.AreEqual(name, result.Name, "Values must be the same");
            Assert.AreEqual(firstname, result.FirstName, "Values must be the same");
            Assert.AreEqual(phone, result.Phone, "Values must be the same");
            Assert.AreEqual(email, result.Email, "Values must be the same");
        }
Ejemplo n.º 6
0
        public void GetPersonByIDTest()
        {
            var target = new PersonsDAO();

            var actual = target.GetPersonByID(-1);
            Assert.IsNull(actual, "This person must not exists");

            //This method is already tested for correctness in CreatePersonTest
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Load the informations about the person, load the lists and fill the page. 
        /// </summary>
        /// <param name="sender">The sender of the events</param>
        /// <param name="e">The args of the event</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Request.QueryString["person"] != null)
            {
                //In order to not refill the form at postback
                if("-1".Equals(IDLabel.Text) )
                {
                    Extensions.SqlOperation operation = () =>
                    {
                        var id = Request.QueryString["person"].ToInt();

                        var connection = DBManager.GetInstance().GetNewConnection();

                        var transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                        new PersonsDAO().LockPerson(id, transaction);

                        var tr = Interlocked.Increment(ref transactionId);

                        Session["connection" + tr] = connection;
                        Session["transaction" + tr] = transaction;

                        ViewState["transaction"] = tr;

                        var person = new PersonsDAO().GetPersonByID(id, transaction);

                        EditAddLabel.Text = "Modification";
                        IDLabel.Text = person.Id.ToString();
                        NameTextBox.Text = person.Name;
                        FirstNameTextBox.Text = person.FirstName;
                        MailTextBox.Text = person.Email;
                        PhoneTextBox.Text = person.Phone;

                        SaveButton.Visible = true;

                        IDLabel.Text = id.ToString();

                        using(var connectionSelect = DBManager.GetInstance().GetNewConnection())
                        {
                            var dataSource = new InstitutionsDAO().GetInstitutions(connectionSelect);

                            InstitutionList.DataBind(dataSource, "Name", "Id");

                            InstitutionList.SelectedValue = person.Department.InstitutionId.ToString();

                            var institution = new InstitutionsDAO().GetInstitution(person.Department.InstitutionId, connectionSelect);

                            DepartmentList.DataBind(institution.Departments, "Name", "Id");

                            DepartmentList.SelectedValue = person.Department.Id.ToString();
                        }
                    };

                    this.Verified(operation, ErrorLabel);
                }
            }
            else
            {
                //In order to not refill the form at postback
                if ("-1".Equals(IDLabel.Text))
                {
                    AddButton.Visible = true;
                    EditAddLabel.Text = "Nouvelle";

                    this.Verified(LoadLists, ErrorLabel);

                    IDLabel.Text = "1";
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create a XMLDocument with contract field
        /// </summary>
        /// <returns>A XMLDocument</returns>
        private XmlDocument createXML()
        {
            var departmentTab = new int[PersonSelectedList.Items.Count + DepartmentSelectedList.Items.Count];
            var index = 0;

            var xmlDoc = new XmlDocument();

            // Write down the XML declaration
            var xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "UTF-16", null);

            // Create the root element
            var rootNode = xmlDoc.CreateElement("contract");
            rootNode.SetAttribute("noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "contract.xsd");

            rootNode.SetAttribute("title", TitleText.Text);
            rootNode.SetAttribute("startDate", StartDate.Text);
            rootNode.SetAttribute("endDate", EndDate.Text);
            rootNode.SetAttribute("contractType", ContractTypeList.SelectedValue);
            rootNode.SetAttribute("authorLogin", "");

            xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
            xmlDoc.AppendChild(rootNode);

            using (var connection = DBManager.GetInstance().GetNewConnection())
            {
                var contactsNode = xmlDoc.CreateElement("contacts");
                xmlDoc.DocumentElement.PrependChild(contactsNode);

                var personsDAO = new PersonsDAO();
                for (var i = 0; i < PersonSelectedList.Items.Count; i++)
                {
                    var w = PersonSelectedList.Items[i].Value.Split(';');
                    var person = personsDAO.GetPersonByID(w[0].ToInt(), connection);
                    var personNode = xmlDoc.CreateElement("person");
                    personNode.SetAttribute("name", person.Name);
                    personNode.SetAttribute("firstName", person.FirstName);
                    personNode.SetAttribute("phone", person.Phone);
                    personNode.SetAttribute("departmentId", person.Department.Id.ToString());
                    personNode.SetAttribute("role", w[1]);

                    departmentTab[index++] = w[0].ToInt();
                    contactsNode.AppendChild(personNode);
                }

                var destinationsNode = xmlDoc.CreateElement("destinations");
                xmlDoc.DocumentElement.PrependChild(destinationsNode);

                for (var i = 0; i < DepartmentSelectedList.Items.Count; i++)
                {
                    var id = DepartmentSelectedList.Items[i].Value.ToInt();

                    var destinationNode = xmlDoc.CreateElement("destination");
                    destinationNode.SetAttribute("id", id.ToString());
                    destinationsNode.AppendChild(destinationNode);

                    departmentTab[index++] = id;
                }

                var institutionsDAO = new InstitutionsDAO();

                var departmentsNode = xmlDoc.CreateElement("departments");
                xmlDoc.DocumentElement.PrependChild(departmentsNode);
                foreach (var id in departmentTab)
                {
                    var d = institutionsDAO.GetDepartmentById(id, connection);
                    var departmentNode = xmlDoc.CreateElement("department");
                    departmentNode.SetAttribute("id", d.Id.ToString());
                    departmentNode.SetAttribute("name", d.Name);
                    departmentNode.SetAttribute("institutionName", d.InstitutionName);
                    departmentNode.SetAttribute("institutionCity", d.InstitutionCity);
                    departmentNode.SetAttribute("institutionLanguage", d.InstitutionLanguage);
                    departmentNode.SetAttribute("institutionCountry", d.InstitutionCountry);

                    departmentsNode.AppendChild(departmentNode);
                }
            }

            return xmlDoc;
        }
Ejemplo n.º 9
0
        private void WriteDocument(Document document, IEnumerable<string> contracts, IEnumerable<string> persons)
        {
            var title = "Historique " + Request.QueryString["year"];

            document.AddTitle(title);

            document.Add(new Paragraph(title, new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD)));

            var subtitleFont = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD);

            using(var connection = DBManager.GetInstance().GetNewConnection())
            {
                var transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);

                document.Add(new Paragraph(" ", subtitleFont));
                document.Add(new Paragraph("Contrats", subtitleFont));

                var contractsDAO = new ContractsDAO();

                var contractsData = contracts.Select(contract => contract.ToInt()).Aggregate("<ul>", (current, id) => current + ("<li>" + contractsDAO.GetContractById(id, transaction) + "</li>")) + "</ul>";

                ParseHtml(document, contractsData);

                document.Add(new Paragraph(" ", subtitleFont));
                document.Add(new Paragraph("Personnes", subtitleFont));

                var personsDAO = new PersonsDAO();

                var personsData = persons.Select(person => person.ToInt()).Aggregate("<ul>", (current, id) => current + ("<li>" + personsDAO.GetPersonByID(id, transaction) + "</li>")) + "</ul>";

                ParseHtml(document, personsData);

                transaction.Commit();
            }
        }