Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
AnswerRe: 2 Active Directory Questions Pin
Dave Kreskowiak7-Dec-17 13:11
mveDave Kreskowiak7-Dec-17 13:11 
GeneralRe: 2 Active Directory Questions Pin
Kevin Marois8-Dec-17 5:13
professionalKevin Marois8-Dec-17 5:13 
GeneralRe: 2 Active Directory Questions Pin
Dave Kreskowiak8-Dec-17 7:29
mveDave Kreskowiak8-Dec-17 7:29 
AnswerRe: 2 Active Directory Questions Pin
Eddy Vluggen7-Dec-17 14:20
professionalEddy Vluggen7-Dec-17 14:20 
QuestionHow can I add multiple headers in a ListView Control winforms c#? Pin
Dionisio Huerta Rosario7-Dec-17 6:25
Dionisio Huerta Rosario7-Dec-17 6:25 
AnswerRe: How can I add multiple headers in a ListView Control winforms c#? Pin
Gerry Schmitz7-Dec-17 20:41
mveGerry Schmitz7-Dec-17 20:41 
AnswerRe: How can I add multiple headers in a ListView Control winforms c#? Pin
Ralf Meier8-Dec-17 1:06
mveRalf Meier8-Dec-17 1:06 
QuestionDynamic HTML from Code Behind Pin
warren8r7-Dec-17 5:16
warren8r7-Dec-17 5:16 
Hello, I have inherited some C#.NET code that builds a dynamic dashboard on page load. The dynamic dashboard consists of a table and 2 rows - one row showing online devices, the other row showing offline devices. My issue is that if there are more than 5 devices on a given row, the row gets cluttered and looks terrible. I would like to break the line at 4 devices, but I am so confused by the logic. I have spent the last 48 hours swirling through this code and trying to find where to break the line and how - I am still lost. Please, any help would be very much appreciated. Please see a snapshot of the code below. Thank you so much in advance. -Jason
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (this.Session["UserID"] == null)
    {
        Response.Redirect("Login.aspx");
    }
        Response.AppendHeader("Refresh", "8");
        HtmlMeta meta = new HtmlMeta();
        meta.HttpEquiv = "Content-Language";
        meta.Content = "en";
        MetaPlaceHolder.Controls.Add(meta);
        List<TableCell> OnCells = new List<TableCell>();
        List<TableCell> OffCells = new List<TableCell>();

        DataTable dt = DatabaseObjects.UserDO.GetAllBoardID(Int32.Parse(this.Session["UserID"].ToString()));

        foreach (DataRow r in dt.Rows)
        {
            string inner = r["DeviceType"].ToString();


            TableCell cell = new TableCell();

            DataTable FonaDT = new DataTable();
            DataTable dt2 = new DataTable();
            DataTable fonaReturn = new DataTable();
            DataTable normalReturn = new DataTable();
            DateTime now = new DateTime();

            if (DatabaseObjects.UserDO.IsFona(r["BoardID"].ToString()))
            {
                FonaDT = DatabaseObjects.UserDO.GetFonaSensors(r["BoardID"].ToString());
            }
            else
            {
                dt2 = DatabaseObjects.UserDO.GetSensorIDFromBoardID(r["BoardID"].ToString());
            }
            //cell.Text = "<label style=\"color:red; font-size:large;\">Device :</label><label style=\"color:#67BCDB; font-size:large;text-decoration:underline;\">" + inner + "</label>";
            //cell.BackColor = System.Drawing.Color.Gray;
            //cell.ColumnSpan = 30;
            if (FonaDT.Rows.Count > 0)
            {
                //sensorRow.Cells.Add(cell);
                int count = 0;
                foreach (DataRow r2 in FonaDT.Rows)
                {
                    if (count > 0)
                    {
                        cell = new TableCell();
                        //cell.Text += r2["sensor_name"].ToString();
                        cell.HorizontalAlign = HorizontalAlign.Center;
                        fonaReturn = DatabaseObjects.UserDO.GetDashboardData(r["BoardID"].ToString(), r2["sensor_name"].ToString());
                        if (fonaReturn.Rows.Count > 0)
                        {
                            now = DateTime.Now;
                            DateTime LastData = DateTime.Parse(fonaReturn.Rows[0]["ts_Datetime"].ToString());
                            TimeSpan diff = now.Subtract(LastData);
                            if (diff.TotalSeconds <= 120)
                            {
                                //Its on
                                cell.Text += "<div class=\"badgeOn\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text += "</br>" + r2["sensor_name"].ToString();
                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + fonaReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OnCells.Add(cell);
                            }
                            else
                            {
                                //its off
                                cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text += "</br>" + r2["sensor_name"].ToString();
                                cell.Text += "</br> Last Online: " + LastData.ToString("MM/dd/yyyy hh:mm tt");
                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + fonaReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OffCells.Add(cell);
                            }

                        }
                        else
                        {
                            cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                            cell.Text += "</br>" + r2["sensor_name"].ToString();
                            cell.Text +=  "</br> Last Online: " + " N/A"+"</br>";
                            cell.Text += "</br> <label style=\"color:red\">" + "Last Value: N/A" + "</label>";
                            OffCells.Add(cell);

                        }
                        //cell.BorderStyle = BorderStyle.Solid;
                        //boardRow.Cells.Add(cell);

                    }
                    else
                    {
                        cell = new TableCell();
                        //cell.Text += r2["sensor_name"].ToString() + "</br>";
                        cell.HorizontalAlign = HorizontalAlign.Center;
                        fonaReturn = DatabaseObjects.UserDO.GetDashboardData(r["BoardID"].ToString(), r2["sensor_name"].ToString());
                        if (fonaReturn.Rows.Count > 0)
                        {
                            now = DateTime.Now;
                            DateTime LastData = DateTime.Parse(normalReturn.Rows[0]["ts_Datetime"].ToString());
                            TimeSpan diff = now.Subtract(LastData);
                            if (diff.TotalSeconds <= 120)
                            {
                                //Its on
                                cell.Text += "<div class=\"badgeOn\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text += "</br>" + r2["sensor_name"].ToString();

                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + fonaReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OnCells.Add(cell);
                            }
                            else
                            {
                                //its off
                                cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text += "</br>" + r2["sensor_name"].ToString();
                                cell.Text += "</br> Last Online: " + LastData.ToString("MM/dd/yyyy hh:mm tt");
                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + fonaReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OffCells.Add(cell);
                            }

                        }
                        else
                        {
                            cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                            cell.Text += "</br>" + r2["sensor_name"].ToString();
                            cell.Text += "</br> Last Online: " + " N/A" + "</br>";
                            cell.Text += "</br> <label style=\"color:red\">" + "Last Value: N/A" + "</label>";
                            cell.Text += "</div>";
                            OffCells.Add(cell);
                        }
                        //cell.BorderStyle = BorderStyle.Solid;
                        //boardRow.Cells.Add(cell);

                    }
                    count++;
                }
            }
            if (dt2.Rows.Count > 0)
            {
                //sensorRow.Cells.Add(cell);
                int count2 = 0;
                foreach (DataRow r3 in dt2.Rows)
                {

                    if (count2 > 0)
                    {
                        cell = new TableCell();
                        //cell.Text += r3["SensorID"].ToString() + "</br>";
                        cell.HorizontalAlign = HorizontalAlign.Center;
                        normalReturn = DatabaseObjects.UserDO.GetDashboardData(r["BoardID"].ToString(), r3["SensorID"].ToString());
                        if (normalReturn.Rows.Count > 0)
                        {
                            now = DateTime.Now;
                            DateTime LastData = DateTime.Parse(normalReturn.Rows[0]["ts_Datetime"].ToString());
                            TimeSpan diff = now.Subtract(LastData);
                            if (diff.TotalSeconds <= 120)
                            {
                                //Its on
                                cell.Text += "<div class=\"badgeOn\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text += "</br>" + r3["SensorID"].ToString();

                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + normalReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OnCells.Add(cell);
                            }
                            else
                            {
                                //its off - first most common
                                cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text += "</br>" + r3["SensorID"].ToString();
                                cell.Text +=  "</br> Last Online: " + LastData.ToString("MM/dd/yyyy hh:mm tt");
                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + normalReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OffCells.Add(cell);
                            }


                        }
                        else
                        {
                            cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                            cell.Text += "</br>" + r3["SensorID"].ToString();
                            cell.Text += "</br> Last Online: " + " N/A" + "</br>";
                            cell.Text += "</br> <label style=\"color:red\">" + "Last Value: N/A" + "</label>";
                            cell.Text += "</div>";
                            OffCells.Add(cell);
                        }
                        //cell.BorderStyle = BorderStyle.Solid;
                        //boardRow.Cells.Add(cell);

                    }
                    else
                    {
                        cell = new TableCell();
                        normalReturn = DatabaseObjects.UserDO.GetDashboardData(r["BoardID"].ToString(), r3["SensorID"].ToString());
                        //cell.Text += r3["SensorID"].ToString() + "</br>";
                        cell.HorizontalAlign = HorizontalAlign.Center;
                        if (normalReturn.Rows.Count > 0)
                        {
                            now = DateTime.Now;
                            DateTime LastData = DateTime.Parse(normalReturn.Rows[0]["ts_Datetime"].ToString());

                            TimeSpan diff = now.Subtract(LastData);
                            if (diff.TotalSeconds <= 120)
                            {
                                //Its on
                                cell.Text += "<div class=\"badgeOn\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text +="</br>"+ r3["SensorID"].ToString();

                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + normalReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OnCells.Add(cell);
                            }
                            else
                            {
                                //its off - second most common
                                cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important;\">" + inner + "</label>";
                                cell.Text += "</br>" + r3["SensorID"].ToString();
                                cell.Text +=  "</br> Last Online: " + LastData.ToString("MM/dd/yyyy hh:mm tt");
                                cell.Text += "</br> <label style=\"color:red\">" + "Last Value: " + normalReturn.Rows[0]["value"].ToString() + "</label>";
                                cell.Text += "</div>";
                                OffCells.Add(cell);
                            }

                        }
                        else
                        {
                            cell.Text += "<div class=\"badgeOff\">" + "<label style=\"font-size:small !important; color:#67BCDB;text-decoration:underline; font-weight:bold !important; \">" + inner + "</label>";
                            cell.Text += "</br>" + r3["SensorID"].ToString();
                            cell.Text +=  "</br> Last Online: " + " N/A"+"</br>";
                            cell.Text += "</br> <label style=\"color:red\">" + "Last Value: N/A" + "</label>";
                            cell.Text += "</div>";
                            OffCells.Add(cell);
                        }
                        //cell.BorderStyle = BorderStyle.Solid;
                        //boardRow.Cells.Add(cell);

                    }
                    count2++;
                }
            }
        }
        TableRow OnRow = new TableRow();

        TableRow OffRow = new TableRow();
        TableCell onHead = new TableCell();
        TableCell offHead = new TableCell();
        onHead.Text = "<div class=\"horoOn\">Online</div>";
        onHead.BackColor = System.Drawing.Color.Gray;
        onHead.ColumnSpan = 30;
        OnRow.Cells.Add(onHead);

        offHead.Text = "<div class=\"horoOff\">Offline</div>";


        offHead.BackColor = System.Drawing.Color.Gray;
        offHead.ColumnSpan = 30;
        OffRow.Cells.Add(offHead);
        Unit p = new Unit(200, UnitType.Pixel);
        OnRow.Width = p;
        OnRow.Height = p;
        OffRow.Width = p;
        OffRow.Height = p;
        foreach (TableCell c in OnCells)
        {


            OnRow.Cells.Add(c);

        }
        foreach (TableCell c2 in OffCells)
        {

            OffRow.Cells.Add(c2);

        }

        //row.Cells.Add(cell);
        table1.Rows.Add(OnRow);
        table1.Rows.Add(OffRow);

}

AnswerRe: Dynamic HTML from Code Behind Pin
Gerry Schmitz7-Dec-17 6:16
mveGerry Schmitz7-Dec-17 6:16 
QuestionCreating a loop for multiple files coying to SQL Server which are coming from SFTP Loaction. Pin
Naveen Reddy Ankampalli6-Dec-17 14:49
Naveen Reddy Ankampalli6-Dec-17 14:49 
AnswerRe: Creating a loop for multiple files coying to SQL Server which are coming from SFTP Loaction. Pin
Dave Kreskowiak6-Dec-17 16:45
mveDave Kreskowiak6-Dec-17 16:45 
AnswerRe: Creating a loop for multiple files coying to SQL Server which are coming from SFTP Loaction. Pin
Gerry Schmitz6-Dec-17 16:58
mveGerry Schmitz6-Dec-17 16:58 
GeneralRe: Creating a loop for multiple files coying to SQL Server which are coming from SFTP Loaction. Pin
Naveen Reddy Ankampalli6-Dec-17 17:25
Naveen Reddy Ankampalli6-Dec-17 17:25 
GeneralRe: Creating a loop for multiple files coying to SQL Server which are coming from SFTP Loaction. Pin
Gerry Schmitz6-Dec-17 17:41
mveGerry Schmitz6-Dec-17 17:41 
GeneralRe: Creating a loop for multiple files coying to SQL Server which are coming from SFTP Loaction. Pin
Richard MacCutchan6-Dec-17 22:16
mveRichard MacCutchan6-Dec-17 22:16 
QuestionC# Is Active Directory Configured Pin
Kevin Marois6-Dec-17 11:02
professionalKevin Marois6-Dec-17 11:02 
AnswerRe: C# Is Active Directory Configured Pin
Dave Kreskowiak6-Dec-17 12:05
mveDave Kreskowiak6-Dec-17 12:05 
GeneralRe: C# Is Active Directory Configured Pin
Kevin Marois6-Dec-17 12:07
professionalKevin Marois6-Dec-17 12:07 
GeneralRe: C# Is Active Directory Configured Pin
Dave Kreskowiak6-Dec-17 13:12
mveDave Kreskowiak6-Dec-17 13:12 
GeneralRe: C# Is Active Directory Configured Pin
Kevin Marois7-Dec-17 6:50
professionalKevin Marois7-Dec-17 6:50 
AnswerRe: C# Is Active Directory Configured Pin
Pete O'Hanlon6-Dec-17 12:06
mvePete O'Hanlon6-Dec-17 12:06 
QuestionDrag & Drop how to in Windows Application Pin
GauravGoyal_56-Dec-17 6:06
GauravGoyal_56-Dec-17 6:06 
AnswerRe: Drag & Drop how to in Windows Application Pin
OriginalGriff6-Dec-17 6:42
mveOriginalGriff6-Dec-17 6:42 
GeneralRe: Drag & Drop how to in Windows Application Pin
GauravGoyal_56-Dec-17 7:21
GauravGoyal_56-Dec-17 7:21 
GeneralRe: Drag & Drop how to in Windows Application Pin
OriginalGriff6-Dec-17 8:00
mveOriginalGriff6-Dec-17 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.