|
Create your own customized Listview which basicly is a UserControl.
Inside this UserControl you have your Headers a needed (Labels) and the ListView under the Header-Labels.
|
|
|
|
|
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
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());
}
if (FonaDT.Rows.Count > 0)
{
int count = 0;
foreach (DataRow r2 in FonaDT.Rows)
{
if (count > 0)
{
cell = new TableCell();
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)
{
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
{
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);
}
}
else
{
cell = new TableCell();
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)
{
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
{
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);
}
}
count++;
}
}
if (dt2.Rows.Count > 0)
{
int count2 = 0;
foreach (DataRow r3 in dt2.Rows)
{
if (count2 > 0)
{
cell = new TableCell();
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)
{
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
{
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);
}
}
else
{
cell = new TableCell();
normalReturn = DatabaseObjects.UserDO.GetDashboardData(r["BoardID"].ToString(), r3["SensorID"].ToString());
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)
{
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
{
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);
}
}
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);
}
table1.Rows.Add(OnRow);
table1.Rows.Add(OffRow);
}
|
|
|
|
|
Any sane person will tell you to "start over"; beginning with a mockup of the intended output.
A mini death march otherwise.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
All,
I am new to C# code, I am trying to achieve copying the file from SFTP location to SQL Azure using SQL Bulk copy method. This I can achieve,but when I am trying to use foreach loop to read multiple files from SFTP file list I couldn’t able do it.
I can’t copy paste my code here, could some one out here help me out how can I achieve this specific to Azure DB ?
TIA.
Naveen A
|
|
|
|
|
Sooooo, you want help fixing your code which we can't see and can't possibly guess at what it looks like?
Good luck with that.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Maybe try one file first.
Maybe you're eating your lunch too fast.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you , I tried with one file it is working fine.When I try to loop Multiple files coming from SFTP source I am having this issue.
|
|
|
|
|
Try 2 in a row.
Wrap it in a try ... catch block and display the exception, if any.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
What issue? Unless you explain clearly what the problem is, and show the failing code then we cannot help.
|
|
|
|
|
How can I tell if Active Directory has been configured/enabled?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You're going to have to go into detail about what you mean by "configured/enabled".
Are you asking how to find out if AD is running on a remote server?
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Yes. Sorry, wasn't sure of the right term for that
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Well, you can't interrogate a single server without permissions to do so, and you're usually not going to have those.
Like Pete showed, if the machine your code is running on is part of the domain, you can just ask the domain for it's list of available domain controllers within reach of your machine.
But, it's even simpler than that. The fact that your machine is joined to a domain means there's at least one domain controller, and hence, Active Directory exists, or at least existed when the machine was joined to the domain.
If GetCurrentDomain doesn't return anything, well, there's no domain and hence, no Active Directory.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Excellent, thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I suppose one way would be to interrogate the domain controllers. Something like this might work:
public bool IsDomainEnabled()
{
return Domain.GetCurrentDomain()?.DomainControllers.Any() ?? false;
} Note, I just typed this off the top of my head so there may be a syntax error or two in there.
This space for rent
|
|
|
|
|
Hi,
I am creating a simple application for drag & drop. I am using Windows 10 OS, Visual Studio 2015 & creating windows application using c#.
I have added pannel on the form. AllowDrop is true for the panel.
I have added 3 events from event windows for Panel : private void panel1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void panel1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
}
But it is not allowing me to drop files here. Please let me know what is wrong with the code.
Gaurav Goyal
|
|
|
|
|
I just duplicated what you did, and it works fine for me - a breakpoint on the panel DragDrop event handler gets hit, and I appear to have data.
Check what you are dragging, and where you are dragging it from, as well as checking that the events are hooked to the handlers.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I am just dragging a text file & dropping here.
Gaurav Goyal
|
|
|
|
|
And what happened?
What code did you use to get the file that was dropped, and what happened when you tried - remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OK, what did you expect to happen?
That code works perfectly fine, but since your DragDrop event handler is empty, nothing is going to happen when you release the mouse. YOU have to supply the code to process whatever data is being dropped on the control. The Panel control has no clue what you want to happen with these files being dropped.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
I put some sample code there. but still not working. I am just dragging a text file from windows explorer & dropping here.
Gaurav Goyal
|
|
|
|
|
And that still doesn't explain what you think was going to happen or want to happen.
We also can't see the code you put in the Drop event handler.
Without being able to see the code, it's IMPOSSIBLE to tell you what you're doing wrong and/or how your expectations need to change.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Are you running the application in admin mode? Windows 10 blocks drag&drop for security reasons under circumstances.
|
|
|
|
|
Hallo,
I got external PHP webservice link, and need to consume that webservice in my C# application.
PHP webservice takes fromDate field, type of DateTime in format
"yyyy-MM-dd HH:mm:ss"
But when I send it from my C# app it sends in format
"yyyy-MM-ddTHH:mm:ss"
This "T" cause an error: Fromdate must be date or datetime.
I have tried to convert date in another format, but it still sends the same.
Did anyone had problems with this?
|
|
|
|
|
You did not showed your code to create the timestamp string.
Use
DateTime.ToString("yyyy-MM-dd' 'HH:mm:ss", CultureInfo.InvariantCulture); to create a string in the required format with a space instead of the 'T'.
|
|
|
|