Exemplo n.º 1
0
        private bool ShowTable()
        {
            try
            {
                _tableEmployees.Page          = _nScreenPage + _nScreenPageOffset;
                _tableEmployees.RecordsOnPage = _nRecordsOnPage;
                _tableEmployees.ReadFromDB(_connectionDb);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("The error was occured while reading data table: <br/>" + ex.Message);
                labelError.Visible = true;
                return(false);
            }

            if (_nRecordsOnPage > 0)
            {
                _nPagesTotal = (int)Math.Ceiling((double)_tableEmployees.CountTotal / (double)_nRecordsOnPage);
            }
            else
            {
                _nPagesTotal = 0;
            }
            ViewState["_nPagesTotal"] = _nPagesTotal;

            if (_bShowSearchStatusPanel)
            {
                if (_tableEmployees.CountTotal < 1)
                {
                    labelRecords.Text = Properties.Resources.textNoRecordsFound;
                }
                else
                {
                    labelRecords.Text = String.Format(Properties.Resources.textRecorsFound, _tableEmployees.CountTotal);
                }
            }

            string encodedDefPhotoUrl      = Server.UrlEncode(_siteUrl + _sNoProfileImageFile);
            string encodedConnectionString = Server.UrlEncode(EncryptString(_sConnectionStringPhoto, _sEncodeParams));

            // Show records
            int nRec = 0;

            foreach (EmployeeRecord rec in _tableEmployees.GetRecords())
            {
                TableRow row = new TableRow();

                string showDetailsCmd = String.Format("javascript:__doPostBack('ShowRecordDetails', '{0}');", rec.ID);

                if (_tableColumns[(int)columnNames.columnPhoto].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    string sPictureHandler = String.Format("{0}/_layouts/MriyaStaffWebparts/ShowPhoto.ashx?id={1}&npi={2}&cs={3}",
                                                           _siteUrl, rec.ID, encodedDefPhotoUrl, encodedConnectionString);

                    string sPhotoURL = string.Format("<a onmouseover=\"showMrPBPhotoDialog('{0}', '{1}'); return true;\" " +
                                                     "onmouseout=\"hideMrPBPhotoDialog('{1}'); return true;\" " +
                                                     "href=\"{3}\"> " +
                                                     "<img id=\"{0}\" width=\"23\" height=\"16\" src=\"{2}\"></a>",
                                                     this.ClientID + "_photo_img_ctl_" + nRec.ToString(),
                                                     sPictureHandler, _siteUrl + _sPhotoImageFile, showDetailsCmd);
                    lcCell.Text = sPhotoURL;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnName].Visible)
                {
                    TableCell      cell   = new TableCell();
                    HyperLink      hlCell = new HyperLink();
                    LiteralControl lcCell = new LiteralControl();

                    string sName = rec.LastName;

                    if (sName.Length > 0)
                    {
                        sName += "<br/>";
                    }

                    if (rec.FirstName.Length > 0)
                    {
                        if (sName.Length > 0)
                        {
                            sName += " ";
                        }
                        sName += rec.FirstName;
                    }
                    if (rec.MiddleName.Length > 0)
                    {
                        if (sName.Length > 0)
                        {
                            sName += " ";
                        }
                        sName += rec.MiddleName;
                    }

                    //lbCell.Command += new CommandEventHandler(buttonTableCell_Command);
                    cell.ID            = this.ClientID + "_lastname_cell_" + nRec.ToString();
                    hlCell.CssClass    = "styleMrPBookShowDetailsLink";
                    hlCell.Text        = sName;
                    hlCell.NavigateUrl = showDetailsCmd;
                    cell.Controls.Add(hlCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnEmail].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    lcCell.Text = rec.Email;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnPhoneWork].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    cell.Width = Unit.Pixel(120);

                    lcCell.Text = rec.PhoneWork;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnPhoneMobile].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    lcCell.Text = rec.PhoneMobile;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnPhones].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    cell.Width = Unit.Pixel(120);

                    lcCell.Text = rec.PhoneWork;
                    if (lcCell.Text.Length > 0)
                    {
                        lcCell.Text += "<br/>";
                    }
                    lcCell.Text += rec.PhoneMobile;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnDepartment].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    lcCell.Text = rec.Department;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnJobTitle].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    lcCell.Text = rec.JobTitle;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnJob].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    lcCell.Text = rec.Department;
                    if (lcCell.Text.Length > 0)
                    {
                        lcCell.Text += "<br/>";
                    }
                    lcCell.Text += rec.JobTitle;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }
                if (_tableColumns[(int)columnNames.columnCity].Visible)
                {
                    TableCell      cell   = new TableCell();
                    LiteralControl lcCell = new LiteralControl();

                    lcCell.Text = rec.City;
                    cell.Controls.Add(lcCell);
                    row.Cells.Add(cell);
                }

                if (nRec++ % 2 != 0)
                {
                    row.CssClass = "styleMrPBookTableRowAlt";
                }
                else
                {
                    row.CssClass = "styleMrPBookTableRow";
                }

                tableMrPBook.Rows.Add(row);
            }

            _rowTableHeader.Visible = (nRec > 0);

            if (_bShowErrorMessage)
            {
                labelError.Visible = true;
            }

            UpdateTableFooter();

            return(true);
        }
        protected void ShowResults()
        {
            if (panelResults.Visible == false)
            {
                return;
            }

            try
            {
                _tableEmployees.ReadFromDB(_connectionDb);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("The error was occured while reading data table: <br/>" + ex.Message);
                labelError.Visible = true;
                return;
            }

            if (_tableEmployees.CountTotal < 1)
            {
                labelRecords.Text    = Properties.Resources.textNoRecordsFound;
                labelRecords.Visible = true;
                return;
            }
            else
            {
                labelRecords.Text    = "";
                labelRecords.Visible = false;
            }

            string encodedDefPhotoUrl      = Server.UrlEncode(_siteUrl + _sNoProfileImageFile);
            string encodedConnectionString = Server.UrlEncode(EncryptString(_sConnectionStringPhoto, _sEncodeParams));

            int nRec = 0;

            foreach (EmployeeRecord rec in _tableEmployees.GetRecords())
            {
                TableRow row = new TableRow();

                string showDetailsCmd = String.Format("javascript:__doPostBack('ShowRecordDetails', '{0}');", rec.ID);

                TableCell      cell   = new TableCell();
                HyperLink      hlCell = new HyperLink();
                LiteralControl lcCell = new LiteralControl();

                string sName = rec.LastName;

                //if (sName.Length > 0)
                //    sName += "<br/>";

                if (rec.FirstName.Length > 0)
                {
                    if (sName.Length > 0)
                    {
                        sName += " ";
                    }
                    sName += rec.FirstName;
                }
                if (rec.MiddleName.Length > 0)
                {
                    if (sName.Length > 0)
                    {
                        sName += " ";
                    }
                    sName += rec.MiddleName;
                }

                //lbCell.Command += new CommandEventHandler(buttonTableCell_Command);
                cell.ID            = this.ClientID + "_lastname_cell_" + nRec.ToString();
                hlCell.CssClass    = "styleMrPBookMiniDetailsLink";
                hlCell.Text        = sName;
                hlCell.NavigateUrl = showDetailsCmd;
                cell.Controls.Add(hlCell);
                row.Cells.Add(cell);

                if (nRec++ % 2 != 0)
                {
                    row.CssClass = "styleMrPBookMiniRowAlt";
                }
                else
                {
                    row.CssClass = "styleMrPBookMiniRow";
                }

                tableResults.Rows.Add(row);

                if (nRec > _nMaxResults)
                {
                    labelRecords.Text    = "Уточніть пошук будь ласка...";
                    labelRecords.Visible = true;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        protected bool ShowRecords()
        {
            StringBuilder sbCards = new StringBuilder();

            try
            {
                _tableEmployees.ReadFromDB(_connectionDb);
            }
            catch (Exception ex)
            {
                ShowErrorMessage("The error was occured while reading data table: <br/>" + ex.Message);
                labelError.Visible = true;
                return(false);
            }

            List <EmployeeRecord> recordsCollectionSrc = _tableEmployees.GetRecords();
            List <EmployeeRecord> recordsCollection    = new List <EmployeeRecord>();
            int iAllCount        = recordsCollectionSrc.Count;
            int iMaxRecordNumber = (_recordNumber == int.MaxValue) ? (int.MaxValue) : (_recordNumber * _columnNumber);

            // Select records
            if (_recordSelectionType == EmployeeList.RecordSelectionType.Randomly)
            {
                var rnd   = new Random();
                int count = (iMaxRecordNumber < recordsCollectionSrc.Count) ? (iMaxRecordNumber) : (recordsCollectionSrc.Count);
                while (count > 0)
                {
                    var index = rnd.Next(recordsCollectionSrc.Count);
                    recordsCollection.Add(recordsCollectionSrc[index]);
                    recordsCollectionSrc.RemoveAt(index);
                    count--;
                }
            }
            else if (_recordSelectionType == EmployeeList.RecordSelectionType.FromTheEnd)
            {
                int max = (iMaxRecordNumber < recordsCollectionSrc.Count) ? (iMaxRecordNumber) : (recordsCollectionSrc.Count);
                for (int i = recordsCollectionSrc.Count - 1, cnt = 0; i >= 0 && cnt < max; i--, cnt++)
                {
                    recordsCollection.Add(recordsCollectionSrc[i]);
                }
            }
            else
            {
                for (int i = 0; i < recordsCollectionSrc.Count && i < _recordNumber; i++)
                {
                    recordsCollection.Add(recordsCollectionSrc[i]);
                }
            }

            if (_columnNumber > 1)
            {
                int iRecsCount = recordsCollection.Count;
                int iRec       = 0;
                sbCards.AppendLine("<table class=\"styleMrEListTable\">");
                for (int rc = 0; rc < _recordNumber; rc++)
                {
                    sbCards.AppendLine("<tr class=\"styleMrEListTableRow\">");
                    for (int cc = 0; cc < _columnNumber; cc++)
                    {
                        sbCards.AppendLine("<td>");
                        if (iRec < iRecsCount)
                        {
                            sbCards.Append(ShowRecord(recordsCollection[iRec++]));
                        }
                        sbCards.AppendLine("</td>");
                    }
                    sbCards.AppendLine("</tr>");
                    if (iRec >= iRecsCount)
                    {
                        break;
                    }
                }
                sbCards.AppendLine("</table>");
            }
            else
            {
                foreach (EmployeeRecord rec in recordsCollection)
                {
                    sbCards.Append(ShowRecord(rec));
                }
            }

            literalCards.Text = sbCards.ToString();

            if (_bShowNumberOfRecords)
            {
                linkButtonShowAll.Text = string.Format("{0} ({1})",
                                                       Properties.Resources.textButtonShowAll, iAllCount);
            }
            return(true);
        }