/// <summary> /// Add the institution. /// </summary> /// <param name="sender">The sender of the events</param> /// <param name="e">The args of the event</param> protected void AddButton_Click(object sender, EventArgs e) { Extensions.SqlOperation operation = () => { var institutionsDAO = new InstitutionsDAO(); var departments = (from ListItem department in DepartmentList.Items select new Department {Name = department.Text}).ToList(); //Intantiate institution var language = new Language { Name = LanguageList.SelectedValue }; var continent = new Continent { Name = ContinentList.SelectedValue }; var country = new Country { Name = CountryList.SelectedValue, Continent = continent }; var institution = new Institution(-1, NameText.Text, DescriptionText.Text, CityText.Text, InterestText.Text, language, country, departments, false); var institutionId = institutionsDAO.AddInstitution(institution); Response.Redirect("ShowInstitution.aspx?institution=" + institutionId); }; this.Verified(operation, ErrorLabel); }
/// <summary> /// An institution has been selected /// </summary> /// <param name="sender">The sender of the events</param> /// <param name="e">The args of the event</param> protected void InstitutionSelected(object sender, EventArgs e) { var id = InstitutionList.SelectedValue.ToInt(); var institution = new InstitutionsDAO().GetInstitution(id); if (institution != null) { DepartmentList.DataBindWithEmptyElement(institution.Departments, "Name", "Id"); } }
/// <summary> /// An institution has been selected /// </summary> /// <param name="sender">The sender of the events</param> /// <param name="e">The args of the event</param> protected void InstitutionSelected(object sender, EventArgs e) { Extensions.SqlOperation operation = () => { var id = InstitutionList.SelectedValue.ToInt(); var institution = new InstitutionsDAO().GetInstitution(id); if (institution != null) { DepartmentList.DataBind(institution.Departments, "Name", "Id"); } }; this.Verified(operation, ErrorLabel); }
/// <summary> /// Fill the page with the informations of the institution. /// </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) { Extensions.SqlOperation operation = () => { if (Request.QueryString["institution"] != null) { var institutionId = Request.QueryString["institution"].ToInt(); var institution = new InstitutionsDAO().GetInstitution(institutionId); NameLabel.Text = institution.Name; DescriptionLabel.Text = institution.Description; CityLabel.Text = institution.City; InterestLabel.Text = institution.Interest; LanguageLabel.Text = institution.Language.Name; CountryLabel.Text = institution.Country.Name; ContinentLabel.Text = institution.Country.Continent.Name; if (institution.IsArchived) { StateLabel.Text = "Oui"; ArchiveButton.Enabled = false; } else { StateLabel.Text = "Non"; } DepartmentsListView.DataSource = institution.Departments; DepartmentsListView.DataBind(); ArchiveButton.Enabled = !institution.IsArchived; } else { EditButton.Enabled = false; ArchiveButton.Enabled = false; } }; this.Verified(operation, ErrorLabel); }
public static void MyClassInitialize(TestContext testContext) { var institutions = new InstitutionsDAO().GetInstitutionsClean(); if(institutions.Count == 0) { Assert.Fail("This unit test need the institution table to contains at least one element"); } else { var inst = institutions[0]; if (inst.Departments.Count == 0) { Assert.Fail("This unit test need the department table to contains at least one element"); } else { department = inst.Departments[0].Id; } } }
/// <summary> /// An institution has been selected. /// </summary> /// <param name="sender">The sender of the events</param> /// <param name="e">The args of the event</param> protected void InstitutionSelected(object sender, EventArgs e) { if("".Equals(InstitutionList.SelectedValue)) { DepartmentList.Items.Clear(); } else { var id = InstitutionList.SelectedValue.ToInt(); Extensions.SqlOperation operation = () => { var institution = new InstitutionsDAO().GetInstitution(id); if (institution != null) { DepartmentList.DataBindWithEmptyElement(institution.Departments, "Name", "Id"); } }; this.Verified(operation, ErrorLabel); } }
/// <summary> /// Search for institutions. /// </summary> /// <param name="sender">The sender of the events</param> /// <param name="e">The args of the event</param> protected void SearchButton_Click(object sender, EventArgs e) { Extensions.SqlOperation operation = () => { var institutionsDAO = new InstitutionsDAO(); var institutions = institutionsDAO.SearchInstitutions(NameText.Text, LanguagesList.SelectedValue, ContinentsList.SelectedValue, CountriesList.SelectedValue, ArchivedCheckBox.Checked); ResultsView.DataSource = institutions; ResultsView.DataBind(); }; this.Verified(operation, ErrorLabel); }
/// <summary> /// Save the changes. /// </summary> /// <param name="sender">The sender of the events</param> /// <param name="e">The args of the event</param> protected void EditButton_Click(object sender, EventArgs e) { Extensions.SqlOperation operation = () => { var tr = (int) ViewState["transaction"]; var transaction = (SqlTransaction) Session["transaction" + tr]; var connection = (SqlConnection) Session["connection" + tr]; var institutionId = Request.QueryString["institution"].ToInt(); var institutionsDAO = new InstitutionsDAO(); //Instantiate and fill department list var departments = (from ListItem department in DepartmentList.Items select new Department {Name = department.Text}).ToList(); //Intantiate institution var language = new Language { Name = LanguageList.SelectedValue }; var continent = new Continent { Name = ContinentList.SelectedValue }; var country = new Country { Name = CountryList.SelectedValue, Continent = continent }; var institution = new Institution(institutionId, NameText.Text, DescriptionText.Text, CityText.Text, InterestText.Text, language, country, departments, false); institutionsDAO.UpdateInstitution(institution, transaction); transaction.Commit(); connection.Close(); Response.Redirect("ShowInstitution.aspx?institution=" + institutionId); }; this.Verified(operation, ErrorLabel); }
/// <summary> /// Load the page, fill the lists and load the informations about the instituion. /// </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) { DepartmentLabel.Visible = false; if (IsPostBack) return; Extensions.SqlOperation operation = () => { //Languages databound var languagesDAO = new LanguagesDAO(); var languages = languagesDAO.GetAllLanguages(); LanguageList.DataSource = languages; LanguageList.DataBind(); //Continents databound var countriesDAO = new CountriesDAO(); var continents = countriesDAO.GetAllContinents(); ContinentList.DataSource = continents; ContinentList.DataBind(); //Add institution if (Request.QueryString["institution"] == null) { EditAddLabel.Text = "Nouvelle"; EditButton.Visible = false; AddButton.Visible = true; //Contries databound var countries = countriesDAO.GetCountries(continents[0]); CountryList.DataSource = countries; CountryList.DataBind(); } //Edit institution else { EditAddLabel.Text = "Modification"; var institutionId = Request.QueryString["institution"].ToInt(); var connection = DBManager.GetInstance().GetNewConnection(); var transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted); new InstitutionsDAO().LockInstitution(institutionId, transaction); var tr = Interlocked.Increment(ref transactionId); Session["connection" + tr] = connection; Session["transaction" + tr] = transaction; ViewState["transaction"] = tr; //TODO: start transaction to commit add button click EditButton.Visible = true; AddButton.Visible = false; var institution = new InstitutionsDAO().GetInstitution(institutionId, transaction); NameText.Text = institution.Name; DescriptionText.Text = institution.Description; CityText.Text = institution.City; ContinentList.SelectedValue = institution.Country.Continent.Name; //Contries databound var countries = countriesDAO.GetCountries(institution.Country.Continent); CountryList.DataSource = countries; CountryList.DataBind(); LanguageList.SelectedValue = institution.Language.Name; InterestText.Text = institution.Interest; //Departments databound DepartmentList.DataSource = institution.Departments; DepartmentList.DataBind(); } }; this.Verified(operation, ErrorLabel); }
private void LoadLists() { var dataSource = new InstitutionsDAO().GetInstitutionsClean(); InstitutionList.DataBindWithEmptyElement(dataSource, "Name", "Id"); }
/// <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"; } } }
private void LoadLists() { var dataSource = new InstitutionsDAO().GetInstitutionsClean(); InstitutionList.DataBind(dataSource, "Name", "Id"); if (dataSource.Count > 0) { DepartmentList.DataBind(dataSource[0].Departments, "Name", "Id"); } }
/// <summary> /// Load the contract and all lists of the page. /// </summary> private void LoadContract() { using (var connectionSelect = DBManager.GetInstance().GetNewConnection()) { InstitutionList.DataBindWithEmptyElement(new InstitutionsDAO().GetInstitutions(connectionSelect), "Name", "Id"); ContractTypeList.DataBindWithEmptyElement(new TypesDAO().GetAllTypes(connectionSelect), "Name", "Name"); PersonList.DataBindWithEmptyElement(new PersonsDAO().GetAllPersons(connectionSelect), "NameFirstName", "Id"); RoleList.DataBindWithEmptyElement(new RolesDAO().GetAllRoles(connectionSelect), "Name", "Name"); if (Request.QueryString["contract"] != null) { var id = Request.QueryString["contract"].ToInt(); var connection = DBManager.GetInstance().GetNewConnection(); var transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted); new ContractsDAO().LockContract(id, transaction); var tr = Interlocked.Increment(ref transactionId); Session["connection" + tr] = connection; Session["transaction" + tr] = transaction; ViewState["transaction"] = tr; var contract = new ContractsDAO().GetContractById(id, transaction); EditAddLabel.Text = "Modification"; TitleText.Text = contract.Title; StartValue.Text = contract.Start.ToString("yyyy-MM-dd"); EndValue.Text = contract.End.ToString("yyyy-MM-dd"); if (contract.departments.Count != 0) { InstitutionList.SelectedValue = contract.departments[0].InstitutionId.ToString(); var institution = new InstitutionsDAO().GetInstitution(contract.departments[0].InstitutionId, connectionSelect); if (institution != null) { DepartmentList.DataBindWithEmptyElement(institution.Departments, "Name", "Id"); } DepartmentSelectedList.DataSource = contract.departments; DepartmentSelectedList.DataTextField = "Name"; DepartmentSelectedList.DataValueField = "Id"; DepartmentSelectedList.DataBind(); } if (contract.persons.Count != 0) { PersonSelectedList.DataSource = contract.persons; PersonSelectedList.DataTextField = "RoleFirstName"; PersonSelectedList.DataValueField = "RoleId"; PersonSelectedList.DataBind(); } ContractTypeList.SelectedValue = contract.Type; FileID.Text = contract.fileId.ToString(); downloadFile.NavigateUrl = "ContractFile.aspx?id=" + contract.fileId; Save.Visible = true; } else { Add.Visible = true; downloadFile.Visible = false; EditAddLabel.Text = "Nouveau"; } } }
/// <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; }