예제 #1
0
        /// <summary>
        /// Create a HTML page with contract
        /// </summary>
        /// <param name="id">ID of contract</param>
        /// <returns>A new HTML page</returns>
        private string CreateContractOuput(int id)
        {
            XmlDocument xmlDoc = new ContractsDAO().getContractXMLById(id);
            string outputHtml = ConvertXML(xmlDoc, Server.MapPath("contract.xslt"), new XsltArgumentList());

            return outputHtml;
        }
예제 #2
0
        /// <summary>
        /// Load the informations about the contract 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["contract"] != null)
            {
                var id = Request.QueryString["contract"].ToInt();

                Extensions.SqlOperation operation = () =>
                {
                    var contract = new ContractsDAO().GetContractById(id);

                    IDLabel.Text = contract.Id.ToString();
                    TitreLabel.Text = contract.Title;
                    dateDebutLabel.Text = contract.Start.ToString("yyyy-MM-dd");
                    dateFinLabel.Text = contract.End.ToString("yyyy-MM-dd");//TODO: A CHANGER
                    userLabel.Text = contract.User;
                    typeLabel.Text = contract.Type;
                    userLabel.Text = contract.User;
                    StateLabel.Text = contract.Archived ? "Oui" : "Non";
                    downloadFile.NavigateUrl = "ContractFile.aspx?id=" + contract.fileId;
                    viewContractXML.NavigateUrl = "ContractOutput.aspx?contract=" + id.ToString();

                    PersonList.DataSource = contract.persons;
                    PersonList.DataBind();

                    DestinationList.DataSource = contract.departments;
                    DestinationList.DataBind();
                };

                this.Verified(operation, ErrorLabel);
            }
            else{
                EditButton.Enabled = false;
                DeleteButton.Enabled = false;
            }
        }
예제 #3
0
        /// <summary>
        /// Search for persons using the entered values as criterias.
        /// </summary>
        private void Search()
        {
            var contractType = ContractTypeList.SelectedValue;
            var institution = InstitutionList.SelectedValue;
            var department = DepartmentList.SelectedValue;
            var person = PersonneList.SelectedValue;
            var yearValue = YearList.SelectedValue;

            var institutionId = "".Equals(institution) ? -1 : institution.ToInt();
            var departmentId = "".Equals(department) ? -1 : department.ToInt();
            var personId = "".Equals(person) ? -1 : person.ToInt();
            var year = "".Equals(yearValue) ? -1 : yearValue.ToInt();

            var contracts = new ContractsDAO().SearchContracts(TitleText.Text, year, contractType, institutionId, departmentId, personId, ArchivedCheck.Checked);

            ResultsView.DataSource = contracts;
            ResultsView.DataBind();
        }
예제 #4
0
        /// <summary>
        /// Generate the historique
        /// </summary>
        /// <param name="sender">The sender of the events</param>
        /// <param name="e">The args of the event</param>
        protected void SearchHisto(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {
                HistoPanel.Visible = true;

                var year = YearTextBox.Text.ToInt();
                var institutionId = "".Equals(InstitutionList.SelectedValue) ? -1 : InstitutionList.SelectedValue.ToInt();
                var departmentId = "".Equals(DepartmentList.SelectedValue) ? -1 : DepartmentList.SelectedValue.ToInt();

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

                        var contracts = new ContractsDAO().HistoSearch(transaction, year, institutionId, departmentId);

                        ContractsView.DataSource = contracts;
                        ContractsView.DataBind();

                        PersonsView.DataSource = new PersonsDAO().HistoSearch(transaction, contracts);
                        PersonsView.DataBind();

                        transaction.Commit();
                    }
                };

                this.Verified(operation, ErrorLabel);
            }
        }
예제 #5
0
        /// <summary>
        /// Submit the form 
        /// </summary>
        private void Submit()
        {
            //File
            var fileSize = UploadImageFile.PostedFile.ContentLength;
            var fileMIMEType = UploadImageFile.PostedFile.ContentType;
            var fileBinaryReader = new BinaryReader(UploadImageFile.FileContent);
            var fileBinaryBuffer = fileBinaryReader.ReadBytes(fileSize);
            fileBinaryReader.Close();

            //Persons
            var persons = new SortedList();
            for (var i = 0; i < PersonSelectedList.Items.Count; i++)
            {
                var w = PersonSelectedList.Items[i].Value.Split(';');
                persons.Add(w[0], w[1]);
            }

            //Destinations
            var destination = new int[DepartmentSelectedList.Items.Count];
            for (var i = 0; i < DepartmentSelectedList.Items.Count; i++)
            {
                destination[i] = DepartmentSelectedList.Items[i].Value.ToInt();
            }

            var xml = createXML();

            var userName = Session["userLogin"] == null ? "admin" : (string) Session["userLogin"];
            if (Request.QueryString["contract"] == null)
            {
                var id = new ContractsDAO().AddContract(TitleText.Text, StartDate.Text, EndDate.Text, ContractTypeList.SelectedItem.Value, xml.OuterXml, userName, persons, destination, fileSize, fileMIMEType, fileBinaryReader, fileBinaryBuffer);

                Response.Redirect("ShowContract.aspx?contract=" + id);
            }
            else
            {
                var id = Request.QueryString["contract"].ToInt();

                var contractFileId = -1;
                if (fileSize > 0)
                {
                    contractFileId = FileID.Text.ToInt();
                }

                var tr = (int) ViewState["transaction"];

                var transaction = (SqlTransaction) Session["transaction" + tr];
                var connection = (SqlConnection) Session["connection" + tr];

                if (transaction == null || connection == null)
                {
                    Logger.Error("No transaction or connection configured");
                }
                else
                {
                    new ContractsDAO().SaveContract(transaction, id, TitleText.Text, StartDate.Text, EndDate.Text, ContractTypeList.SelectedItem.Value, xml.OuterXml, userName, persons, destination, contractFileId, fileSize, fileMIMEType, fileBinaryBuffer);

                    transaction.Commit();

                    DBManager.GetInstance().CloseConnection(connection);

                    Response.Redirect("ShowContract.aspx?contract=" + id);
                }
            }
        }
예제 #6
0
        /// <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";
                }
            }
        }
예제 #7
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();
            }
        }