コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var userIdtmp = Session["UserID"];
                if (userIdtmp == null)
                {
                    Response.Redirect("~/Default.aspx");
                }
                int userId = (int)userIdtmp;

                CompetitionDataContext competitionDataBase  = new CompetitionDataContext();
                CompetitionCountDown   competitionCountDown = new CompetitionCountDown();


                Tab1.CssClass            = "Clicked";
                MainView.ActiveViewIndex = 0;
                #region competitions
                {
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("Number", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("Budjet", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("StartDate", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("EndDate", typeof(string)));

                    List <zCompetitionsTable> competitionsList = (from a in competitionDataBase.zCompetitionsTable
                                                                  where a.Active == true && a.OpenForApplications == true
                                                                  select a).ToList();

                    foreach (zCompetitionsTable currentCompetition in competitionsList)
                    {
                        if (competitionCountDown.IsCompetitionEndDateExpired(currentCompetition.ID))
                        {
                            continue;
                        }

                        DataRow dataRow = dataTable.NewRow();
                        dataRow["ID"]        = currentCompetition.ID;
                        dataRow["Name"]      = currentCompetition.Name;
                        dataRow["Number"]    = currentCompetition.Number;
                        dataRow["Budjet"]    = Convert.ToInt32(currentCompetition.Budjet);
                        dataRow["StartDate"] = currentCompetition.StartDate.ToString().Split(' ')[0];
                        dataRow["EndDate"]   = currentCompetition.EndDate.ToString().Split(' ')[0];

                        dataTable.Rows.Add(dataRow);
                    }
                    MainGV.DataSource = dataTable;
                    MainGV.DataBind();
                }
                #endregion

                /// в  первую таблицу все те у которых конкурс еще открыт а заявка не отправлена
                /// во вторую все те у которых заявка отправлена
                /// в  третью все те у которых закрыта заявка



                #region currentApplications
                {
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("CompetitionName", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("StatusLabelEnabled", typeof(bool)));
                    dataTable.Columns.Add(new DataColumn("SendButtonEnabled", typeof(bool)));
                    List <zApplicationTable> applicationList = (from a in competitionDataBase.zApplicationTable
                                                                where a.FK_UsersTable == userId && a.Sended == false && a.Active == true
                                                                join b in competitionDataBase.zCompetitionsTable
                                                                on a.FK_CompetitionTable equals b.ID
                                                                where b.Active == true &&
                                                                b.OpenForApplications == true
                                                                select a).Distinct().ToList();

                    Status status = new Status();

                    foreach (zApplicationTable currentApplication in applicationList)
                    {
                        if (competitionCountDown.IsCompetitionEndDateExpiredByApplication(currentApplication.ID))
                        {
                            continue;
                        }

                        DataRow dataRow = dataTable.NewRow();
                        dataRow["ID"]              = currentApplication.ID;
                        dataRow["Name"]            = currentApplication.Name;
                        dataRow["CompetitionName"] = (from a in competitionDataBase.zCompetitionsTable
                                                      where a.ID == (Convert.ToInt32(currentApplication.FK_CompetitionTable))
                                                      select a.Name).FirstOrDefault();

                        if (status.IsApplicationReadyToSend(currentApplication.ID))
                        {
                            dataRow["StatusLabelEnabled"] = false;
                            dataRow["SendButtonEnabled"]  = true;
                        }
                        else
                        {
                            dataRow["StatusLabelEnabled"] = true;
                            dataRow["SendButtonEnabled"]  = false;
                        }
                        dataTable.Rows.Add(dataRow);
                    }
                    ApplicationGV.DataSource = dataTable;
                    ApplicationGV.DataBind();
                }
                #endregion
                #region applicationsArchive
                {
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("CompetitionName", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("SendedDate", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("Accept", typeof(string)));
                    List <zApplicationTable> applicationList = (from a in competitionDataBase.zApplicationTable
                                                                where a.FK_UsersTable == userId && a.Active == true && a.Sended == true
                                                                join b in competitionDataBase.zCompetitionsTable
                                                                on a.FK_CompetitionTable equals b.ID
                                                                where b.Active == true
                                                                select a).Distinct().ToList();


                    foreach (zApplicationTable currentApplication in applicationList)
                    {
                        DataRow dataRow = dataTable.NewRow();
                        dataRow["ID"]              = currentApplication.ID;
                        dataRow["Name"]            = currentApplication.Name;
                        dataRow["CompetitionName"] = (from a in competitionDataBase.zCompetitionsTable
                                                      where a.ID == (Convert.ToInt32(currentApplication.FK_CompetitionTable))
                                                      select a.Name).FirstOrDefault();
                        if (currentApplication.SendedDataTime == null)
                        {
                            dataRow["SendedDate"] = "Не отправлялось на рассмотрение";
                        }
                        else
                        {
                            dataRow["SendedDate"] = currentApplication.SendedDataTime.ToString().Split(' ')[0];
                        }
                        zApplicationTable accept = (from a in competitionDataBase.zApplicationTable
                                                    where a.ID == (Convert.ToInt32(currentApplication.ID))
                                                    select a).FirstOrDefault();
                        if (accept.Accept == true)
                        {
                            dataRow["Accept"] = "Принята";
                        }
                        else
                        {
                            dataRow["Accept"] = "На рассмотрении";
                        }

                        dataTable.Rows.Add(dataRow);
                    }
                    ArchiveApplicationGV.DataSource = dataTable;
                    ArchiveApplicationGV.DataBind();
                }
                #endregion
                #region draftApplications
                {
                    DataTable dataTable = new DataTable();
                    dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
                    dataTable.Columns.Add(new DataColumn("CompetitionName", typeof(string)));



                    List <zApplicationTable> applicationList = (from a in competitionDataBase.zApplicationTable
                                                                where a.FK_UsersTable == userId && a.Active == true
                                                                join b in competitionDataBase.zCompetitionsTable
                                                                on a.FK_CompetitionTable equals b.ID
                                                                where b.Active == true
                                                                select a).Distinct().ToList();


                    foreach (zApplicationTable currentApplication in applicationList)
                    {
                        if (competitionIsClosed(currentApplication) ||
                            competitionCountDown.IsCompetitionEndDateExpiredByApplication(currentApplication.ID))
                        {
                            DataRow dataRow = dataTable.NewRow();
                            dataRow["ID"]              = currentApplication.ID;
                            dataRow["Name"]            = currentApplication.Name;
                            dataRow["CompetitionName"] = (from a in competitionDataBase.zCompetitionsTable
                                                          where a.ID == (Convert.ToInt32(currentApplication.FK_CompetitionTable))
                                                          select a.Name).FirstOrDefault();
                            dataTable.Rows.Add(dataRow);
                        }
                    }
                    DraftGridView.DataSource = dataTable;
                    DraftGridView.DataBind();
                }
                #endregion
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                var sessionParam1 = Session["ApplicationID"];

                if ((sessionParam1 == null))
                {
                    Response.Redirect("ChooseApplication.aspx");
                }

                int applicationId = Convert.ToInt32(sessionParam1);

                CompetitionDataContext competitionDataBase = new CompetitionDataContext();
                zApplicationTable      currentApplication  = (from a in competitionDataBase.zApplicationTable
                                                              where a.ID == applicationId
                                                              select a).FirstOrDefault();
                zCompetitionsTable currentCompetition = (from a in competitionDataBase.zCompetitionsTable
                                                         where a.ID == currentApplication.FK_CompetitionTable
                                                         select a).FirstOrDefault();

                CompetitionCountDown competitionCountDown = new CompetitionCountDown();
                CountDownLabel.Text =
                    competitionCountDown.GetDaysBeforeCompetitionEndMessage(currentCompetition.ID);

                Label1.Text = currentApplication.Name;
                Label2.Text = currentCompetition.Name;

                if (currentApplication.StartProjectDate != null)
                {
                    DateTime dateTime = (DateTime)currentApplication.StartProjectDate;
                    string   tmpStr   = dateTime.ToString().Split(' ')[0];
                    string[] tmpArray = tmpStr.Split('.');
                    string   tmp2     = tmpArray[2] + "-" + tmpArray[1] + "-" + tmpArray[0];
                    startdata.Value = tmp2;
                }
                if (currentApplication.EndProjectDate != null)
                {
                    DateTime dateTime = (DateTime)currentApplication.EndProjectDate;
                    string   tmpStr   = dateTime.ToString().Split(' ')[0];
                    string[] tmpArray = tmpStr.Split('.');
                    string   tmp2     = tmpArray[2] + "-" + tmpArray[1] + "-" + tmpArray[0];
                    enddata.Value = tmp2;
                }
                DataTable dataTable = new DataTable();
                dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
                dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
                dataTable.Columns.Add(new DataColumn("CreateDate", typeof(string)));

                List <zDocumentsTable> documentsList = (from a in competitionDataBase.zDocumentsTable
                                                        where a.FK_ApplicationTable == applicationId &&
                                                        a.Active == true
                                                        select a).ToList();

                foreach (zDocumentsTable currentDocument in documentsList)
                {
                    DataRow dataRow = dataTable.NewRow();
                    dataRow["ID"]   = currentDocument.ID;
                    dataRow["Name"] = currentDocument.Name;
                    if (currentDocument.Name == null)
                    {
                        dataRow["Name"] = "ссылка";
                        if (currentDocument.LinkOut != null)
                        {
                            string linkOutString = currentDocument.LinkOut;
                            if (linkOutString.Length > 100)
                            {
                                linkOutString   = linkOutString.Remove(100) + "...";
                                dataRow["Name"] = linkOutString;
                            }
                            else
                            {
                                dataRow["Name"] = currentDocument.LinkOut;
                            }
                        }
                    }
                    dataRow["CreateDate"] = currentDocument.AddDateTime.ToString().Split(' ')[0];
                    dataTable.Rows.Add(dataRow);
                }

                DocumentsGV.DataSource = dataTable;
                DocumentsGV.DataBind();


                List <zBlockTable> currentBlock = (from a in competitionDataBase.zBlockTable
                                                   where a.Active == true
                                                   select a).ToList();

                DataTable dataTable2 = new DataTable();
                dataTable2.Columns.Add(new DataColumn("ID", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("BlockName", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("Status", typeof(string)));
                dataTable2.Columns.Add(new DataColumn("EnableButton", typeof(bool)));
                Status status        = new Status();
                int    statusHistory = 2;
                foreach (zBlockTable current  in currentBlock)
                {
                    DataRow dataRow2 = dataTable2.NewRow();
                    dataRow2["ID"]        = current.ID;
                    dataRow2["BlockName"] = current.BlockName;
                    int blockStatus = status.GetStatusIdForBlockInApplication(current.ID, currentApplication.ID);
                    dataRow2["Status"]       = status.GetStatusNameByStatusId(blockStatus);
                    dataRow2["EnableButton"] = false;
                    if (status.IsDataReady(statusHistory))
                    {
                        dataRow2["EnableButton"] = true;
                    }
                    statusHistory = blockStatus;
                    dataTable2.Rows.Add(dataRow2);
                }

                BlockGV.DataSource = dataTable2;
                BlockGV.DataBind();

                List <zPartnersTable> partners = (from a in competitionDataBase.zPartnersTable
                                                  where a.Active == true
                                                  join b in competitionDataBase.zApplicationAndPartnersMappingTable
                                                  on a.ID equals b.FK_PartnersTable
                                                  where b.Active == true && b.FK_Application == applicationId
                                                  select a).ToList();
                DataTable dataTable3 = new DataTable();
                dataTable3.Columns.Add(new DataColumn("ID", typeof(string)));
                dataTable3.Columns.Add(new DataColumn("Surname", typeof(string)));
                dataTable3.Columns.Add(new DataColumn("Name", typeof(string)));
                dataTable3.Columns.Add(new DataColumn("Patronymic", typeof(string)));
                dataTable3.Columns.Add(new DataColumn("Role", typeof(bool)));
                foreach (zPartnersTable current in partners)
                {
                    DataRow dataRow3 = dataTable3.NewRow();
                    dataRow3["ID"]         = current.ID;
                    dataRow3["Surname"]    = current.Surname;
                    dataRow3["Name"]       = current.Name;
                    dataRow3["Patronymic"] = current.Patronymic;
                    dataRow3["Role"]       = false;
                    if (current.Role == null && current.Role == false)
                    {
                        dataRow3["Role"] = false;
                    }
                    if (current.Role == true)
                    {
                        dataRow3["Role"] = true;
                    }

                    dataTable3.Rows.Add(dataRow3);
                }
                PartnersGV.DataSource = dataTable3;
                PartnersGV.DataBind();
            }
        }