Пример #1
0
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        private void Save()
        {
            bool exists = false;

            // Validate page
            if (Page.IsValid)
            {
                int projectIdToSave = Int32.Parse(hdfSelectedProjectId.Value);

                ProjectSelectProjectLastUsedProjectsGateway projectSelectProjectLastUsedProjectsVerifyGateway = new ProjectSelectProjectLastUsedProjectsGateway(projectSelectProjectTDS);
                ProjectSelectProjectLastUsedProjects projectSelectProjectLastUsedProjectsVerify = new ProjectSelectProjectLastUsedProjects(projectSelectProjectLastUsedProjectsVerifyGateway.Data);
                exists = projectSelectProjectLastUsedProjectsVerify.ExistProject(projectIdToSave);

                if (exists)
                {
                    // New Data
                    DateTime newLastLoggedInDate = DateTime.Now;

                    // Update if exists
                    ProjectSelectProjectLastUsedProjects model = new ProjectSelectProjectLastUsedProjects(projectSelectProjectTDS);
                    model.UpdateLogginDate(projectIdToSave, newLastLoggedInDate);

                    Session["projectSelectProjectTDS"] = projectSelectProjectTDS;
                    Session["projectLastUsedProjects"] = projectSelectProjectTDS.LastUsedProjects;
                }

                // If doesn't exists at grid
                if (!exists)
                {
                    if (projectSelectProjectLastUsedProjectsVerifyGateway.Table.Rows.Count < 5)
                    {
                        // Add data if exist at grid's
                        ProjectAdd();
                    }
                    else
                    {
                        if (projectSelectProjectLastUsedProjectsVerifyGateway.Table.Rows.Count == 5)
                        {
                            // New Data
                            int newProjectId = Int32.Parse(hdfSelectedProjectId.Value);
                            int newCompanyId = Int32.Parse(hdfCompanyId.Value);
                            int newUserId = Convert.ToInt32(Session["loginID"]);
                            DateTime newLastLoggedInDate = DateTime.Now;

                            ProjectGateway projectGateway = new ProjectGateway();
                            projectGateway.LoadByProjectId(newProjectId);
                            string newProjectName = projectGateway.GetName(newProjectId) + " (" + projectGateway.GetProjectNumber(newProjectId) + ")";

                            // Update if exists
                            ProjectSelectProjectLastUsedProjects model = new ProjectSelectProjectLastUsedProjects(projectSelectProjectTDS);
                            model.Update(newProjectId, newUserId, newLastLoggedInDate, newCompanyId, false, newProjectName);

                            Session["projectSelectProjectTDS"] = projectSelectProjectTDS;
                            Session["projectLastUsedProjects"] = projectSelectProjectTDS.LastUsedProjects;
                        }
                    }
                }

                // Update data at bd
                UpdateDatabase();
            }
        }
Пример #2
0
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
                {
                    ddlProjectType.Visible = true;
                    ddlProjectTypeAdmin.Visible = false;
                    ddlProjectType.SelectedIndex = 0;

                    ddlProjectState.Visible = true;
                    ddlProjectStateAdmin.Visible = false;
                    ddlProjectState.SelectedIndex = 0;
                }
                else
                {
                    ddlProjectType.Visible = false;
                    ddlProjectTypeAdmin.Visible = true;
                    ddlProjectTypeAdmin.SelectedIndex = 0;

                    ddlProjectState.Visible = false;
                    ddlProjectStateAdmin.Visible = true;
                    ddlProjectStateAdmin.SelectedIndex = 0;
                }

                // Validate query string
                if ((string)Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in projects.aspx");
                }

                // Prepare initial data
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();
                Session.Remove("lastUsedProjectsDummy");
                Session.Remove("lfsProjectNavigatorTDS");
                Session.Remove("lfsLibraryTDS");
                Session.Remove("fromAttachment");

                Session["activeTabProjects"] = "0";
                Session["dialogOpenedProjects"] = "0";

                // If coming from
                projectSelectProjectTDS = new ProjectSelectProjectTDS();
                ProjectSelectProjectLastUsedProjectsGateway projectSelectProjectLastUsedProjectsGateway = new ProjectSelectProjectLastUsedProjectsGateway(projectSelectProjectTDS);
                projectSelectProjectLastUsedProjectsGateway.LoadByLoginId(Int32.Parse(hdfLoginId.Value), Int32.Parse(hdfCompanyId.Value));

                // ... Left Menu or Out
                if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "out"))
                {
                    //tdNoResults.Visible = false;
                    tNoResults.Visible = false;
                    pNoResults.Visible = false;
                }

                // ... projects2.aspx
                if (Request.QueryString["source_page"] == "projects2.aspx")
                {
                    RestoreNavigatorState();
                    if ((string)Request.QueryString["no_results"] == "yes")
                    {
                        tNoResults.Visible = true;
                        pNoResults.Visible = true;
                    }
                    else
                    {
                        tNoResults.Visible = false;
                        pNoResults.Visible = false;

                        if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
                        {
                            ddlProjectType.SelectedIndex = 0;
                            ddlProjectState.SelectedIndex = 0;
                        }
                        else
                        {
                            ddlProjectTypeAdmin.SelectedIndex = 0;
                            ddlProjectStateAdmin.SelectedIndex = 0;
                        }
                    }
                }

                // ... Store datasets
                Session["projectSelectProjectTDS"] = projectSelectProjectTDS;
                Session["projectLastUsedProjects"] = projectSelectProjectTDS.LastUsedProjects;
            }
            else
            {
                // Restore datasets
                projectSelectProjectTDS = (ProjectSelectProjectTDS)Session["projectSelectProjectTDS"];
            }
        }
Пример #3
0
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if (Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in projects2.aspx");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
                {
                    ddlProjectType.Visible = true;
                    ddlProjectTypeAdmin.Visible = false;
                    ddlProjectType.SelectedIndex = 0;

                    ddlProjectState.Visible = true;
                    ddlProjectStateAdmin.Visible = false;
                    ddlProjectState.SelectedIndex = 0;
                }
                else
                {
                    ddlProjectType.Visible = false;
                    ddlProjectTypeAdmin.Visible = true;
                    ddlProjectTypeAdmin.SelectedIndex = 0;

                    ddlProjectState.Visible = false;
                    ddlProjectStateAdmin.Visible = true;
                    ddlProjectStateAdmin.SelectedIndex = 0;
                }

                // Tag Page
                Session.Remove("projectNavigatorNewDummy");
                Session.Remove("projectNavigator");
                Session.Remove("projectsSelected");
                hdfPageIndex.Value = "0";

                // Prepare initial data
                lblError.Visible = false;
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();
                Session.Remove("lastUsedProjectsDummy");

                // If coming from
                projectSelectProjectTDS = new ProjectSelectProjectTDS();
                ProjectSelectProjectLastUsedProjectsGateway projectSelectProjectLastUsedProjectsGateway = new ProjectSelectProjectLastUsedProjectsGateway(projectSelectProjectTDS);
                projectSelectProjectLastUsedProjectsGateway.LoadByLoginId(Int32.Parse(hdfLoginId.Value), Int32.Parse(hdfCompanyId.Value));

                // ... projects.aspx or projects2.aspx
                if ((Request.QueryString["source_page"] == "projects.aspx") || (Request.QueryString["source_page"] == "projects2.aspx"))
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    // Restore data
                    projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                    projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                    // Store data
                    Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }
                }

                // ... project_summary.aspx, project_edit.aspx, project_sections_navigator.aspx or project_sections_navigator2.aspx
                if ((Request.QueryString["source_page"] == "project_summary.aspx") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_navigator.aspx"))
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                        projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                        // Store data
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("lfsProjectNavigatorTDS");

                        // ... Search data with updates
                        projectNavigatorTDS = SubmitSearch();

                        // ... store datasets
                        Session["lfsProjectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }
                }

                // ... project_delete.aspx
                if (Request.QueryString["source_page"] == "project_delete.aspx")
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                        projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                        // Store data
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("lfsProjectNavigatorTDS");

                        // ... Search data with updates
                        projectNavigatorTDS = SubmitSearch();

                        // ... store datasets
                        Session["lfsProjectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNavigator"] = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;
                    }

                    //... for the total rows
                    if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }

                    // Databind
                    if (Request.QueryString["update"] != "no")
                    {
                        if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count == 0)
                        {
                            string url = "./projects.aspx?source_page=projects2.aspx&" + GetNavigatorState() + "&no_results=no";
                            Response.Redirect(url);
                        }
                    }
                }

                // ... Store datasets
                Session["projectSelectProjectTDS"] = projectSelectProjectTDS;
                Session["projectLastUsedProjects"] = projectSelectProjectTDS.LastUsedProjects;
            }
            else
            {
                // Restore datasets
                projectSelectProjectTDS = (ProjectSelectProjectTDS)Session["projectSelectProjectTDS"];

                // Restore searched data (if any)
                projectNavigatorTDS = (ProjectNavigatorTDS)Session["lfsProjectNavigatorTDS"];
                projectNavigator = projectNavigatorTDS.LFS_PROJECT_NAVIGATOR;

                //... for the total rows
                if (projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + projectNavigatorTDS.LFS_PROJECT_NAVIGATOR.Rows.Count;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
        }
        /// <summary>
        /// Save all last logged projects to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>        
        public void Save(int companyId)
        {
            ProjectSelectProjectTDS lastUsedProjectsChanges = (ProjectSelectProjectTDS)Data.GetChanges();

            if (lastUsedProjectsChanges.LastUsedProjects.Rows.Count > 0)
            {
                ProjectSelectProjectLastUsedProjectsGateway projectSelectProjectLastUsedProjectsGateway = new ProjectSelectProjectLastUsedProjectsGateway(lastUsedProjectsChanges);

                foreach (ProjectSelectProjectTDS.LastUsedProjectsRow row in (ProjectSelectProjectTDS.LastUsedProjectsDataTable)lastUsedProjectsChanges.LastUsedProjects)
                {
                    // Insert project login
                    if ((!row.Deleted)&& (!row.InDataBase))
                    {
                        ProjectLoginProjectLastLogin projectLoginProjectLastLogin = new ProjectLoginProjectLastLogin(null);
                        projectLoginProjectLastLogin.InsertDirect( row.ProjectID, row.UserID, row.LastLoggedInDate, row.COMPANY_ID, row.Deleted);
                    }

                    // Update project login
                    if ((!row.Deleted) && (row.InDataBase))
                    {
                        int projectId = row.ProjectID;
                        int userId = row.UserID;

                        // Original Values
                        int originalProjectId = projectSelectProjectLastUsedProjectsGateway.GetProjectIdOriginal(projectId, userId, companyId);
                        int originalUserId = projectSelectProjectLastUsedProjectsGateway.GetUserIdOriginal(projectId, userId, companyId);
                        DateTime originalLastLoggedInDate = projectSelectProjectLastUsedProjectsGateway.GetLastLoggedInDateOriginal(projectId, userId, companyId);
                        int originalCompanyId = projectSelectProjectLastUsedProjectsGateway.GetCompanyIdOriginal(projectId, userId, companyId);

                        // New Values
                        int newProjectId = projectSelectProjectLastUsedProjectsGateway.GetProjectId(projectId, userId, companyId);
                        int newUserId = projectSelectProjectLastUsedProjectsGateway.GetUserId(projectId, userId, companyId);
                        DateTime newLastLoggedInDate = projectSelectProjectLastUsedProjectsGateway.GetLastLoggedInDate(projectId, userId, companyId);
                        int newCompanyId = projectSelectProjectLastUsedProjectsGateway.GetCompanyId(projectId, userId, companyId);

                        ProjectLoginProjectLastLogin projectLoginProjectLastLogin = new ProjectLoginProjectLastLogin(null);
                        projectLoginProjectLastLogin.UpdateDirect(originalProjectId, originalUserId, originalLastLoggedInDate, originalCompanyId, false,  newProjectId, newUserId, newLastLoggedInDate, newCompanyId, false);
                    }
                }
            }
        }