This question already has answers here:
Binding Listbox to List<object> in WinForms
(8 answers)
Closed 3 years ago.
I write a program, it is necessary to switch the current status in it, as well as it is necessary to plan it when you plan an event, it is perceived as an object, the object has its own fields, such as the start time and end time of the event, I want this object to be output when generated sheet boxing.
Tell me how can this be done?
List<ChangeStatus> events = new List<ChangeStatus>();
private void toPlanButton_Click(object sender, EventArgs e)
{
string comboBoxTypeNumber = comboBoxType.SelectedItem.ToString();
DateTime Time = new DateTime();
Time = dateTimePicker1.Value;
DateTime longTime = new DateTime();
longTime = dateTimePicker2.Value;
ChangeStatus statusEvent = new ChangeStatus();
statusEvent.StartEvent = Time;
statusEvent.LongEvent = longTime;
statusEvent.TypeEvent = comboBoxTypeNumber;
events.Add(statusEvent);
TimeComparer tc = new TimeComparer();
events.Sort(tc);
}
How to display an object in listbox?
It is necessary to display a list of objects, because in the future I want to make editing objects
listBoxEvent.Items.Add("type: " + statusEvent.TypeEvent + ";" + " start: " + statusEvent.StartEvent + ";" + " long: " + statusEvent.LongEvent + " min;"); - work
You can use System.Linq Linq to get the string text and can call the AddRange() method on Items collection like
List<string> listData = events.Select(x => "type: " + x.TypeEvent + ";" + " start: " + x.StartEvent + ";" + " long: " + x.LongEvent + " min;").ToList();
listBoxEvent.DataSource = listData;
Related
My database has a table with an userId, an userName, a number field that saves an ID for each datetime and a datetime field that records every time the user logs-in and logs-out.
The thing is that logs comes from a fingerprint catcher, and the software that controls the logs is not programmed for avoiding duplicate logs. So, an user can put his finger and save a log-in/log-out hour each time.
My mission is to create a program that would split the datetime field's data in two new datetime fields in another database, one for the log-in hours and another for the log-outs. To achieve that I have to use the ID field that stores a 0 value for the log-ins and 1 to 5 for the log-outs, but I'm out of ideas on how to avoid the duplicates. And if you can give me a good hint on how to achieve the split in a smooth way, it would be lovely.
I have to use ms acces 2007, visual studio 2012 and c# language. Thanks in advance for your attention.
PD: I'm from colombia, thats why my english is a little messy and old.
EDIT: here is an example of my table.
|IdUser||||||||RecordTime||||||||||||||||||||||||||||||||| RecordType |
|399---||||||||28/04/2016 06:55:36 a.m.|||||----- 0----------|
|399---||||||||28/04/2016 06:57:32 a.m.|||||------0----------|
|399---||||||||28/04/2016 05:07:15 p.m.|||||------1----------|
|399---||||||||28/04/2016 05:16:33 p.m.|||||------1----------|
|399---||||||||02/05/2016 07:04:02 a.m.|||||------0----------|
|399---||||||||02/05/2016 05:15:53 p.m.|||||------1----------|
Well, I don't know how big this database of yours is and wether it would be possible to do a cron job every week/day to port the data into the new Database, but i'm going to try explain the concept of my solutions. It's up to you to implement it.
I would use the following method:
Read all the logs of one User into an array with the following fields (If there is too much data, select ranges of datetime with every pass)
Sort that array
-> This should give you changing rows in the RecordType (eg. 0, 2, 0, 1, 0, 5..)
Then write that array (Chronologicaly!) into the new database which has a Unique ID key.
Then you remove this data from the old database in order to not port the same data twice.
Run this every day/week with a cronjob.
It's up to you to implement it. But that is the strategy i would use.
Then you should end up with the following database:
ID|||||IdUser||||||||RecordTime||||||||||||||||||||||||||||||||| RecordType |
1|||||399---||||||||28/04/2016 06:55:36 a.m.|||||----- 0----------|
2|||||399---||||||||28/04/2016 06:57:32 a.m.|||||------0----------|
3|||||399---||||||||28/04/2016 05:07:15 p.m.|||||------1----------|
4|||||399---||||||||28/04/2016 05:16:33 p.m.|||||------1----------|
5|||||399---||||||||02/05/2016 07:04:02 a.m.|||||------0----------|
6|||||399---||||||||02/05/2016 05:15:53 p.m.|||||------1----------|
I hope this helps.
First, the idea of taking two different types of data from a table, without the proper identification, is wrong. Different types of data should always be in different tables.
My boss (i do not know how), resulted to be very illustrated in the ways of programing, and he, after clarifying his needs, gave me a way to make this solution to work:
First, you take the table, and use it to fill an array of any kind, in my case, a DataGridView:
try
{
huella.Open();
OleDbCommand comando = new OleDbCommand();
comando.Connection = huella;
string consulta = "select [User].IdUser,[User].IdentificationNumber,[User].name,[Record].RecordTime," +
"[Record].RecordType from [User] inner join [Record] on [User].IdUser = [Record].IdUser " +
"where " + "[Record].IdUser=#01 and [Record].RecordTime between #time1 and #time2 order by [User].IdUser asc,[Record].RecordTime asc";
comando.CommandText = consulta;
comando.Parameters.AddWithValue("#01", IDcm.Text.ToString());
comando.Parameters.AddWithValue("#time1", dateTimePicker1.Value.Date);
comando.Parameters.AddWithValue("#time2", dateTimePicker2.Value.Date);
OleDbDataAdapter datos = new OleDbDataAdapter(comando);
// using( OleDbDataReader lector = comando.ExecuteReader())
tabla = new DataTable();
datos.Fill(tabla);
//MessageBox.Show(""+tabla);
clu.DataSource = tabla;
}
catch (Exception ex)
{
MessageBox.Show("ERROR " + ex);
}
finally
{
huella.Close();
}
Then, you loop throughout the array's data, assigning the first value of the array to a variable. Inside this loop, you start another loop, to assign the second value of the array to another variable, and finally, you compare this two variables, to assign them to their respective places (following your own criteria):
StreamWriter archivo = new StreamWriter("D:\\MAXIMUM PC.csv", true);
{
archivo.WriteLine('"' + "usuario" + '"' + ";" + '"' + "Hora de entrada" + '"' + ";" + '"' + "Hora de salida" + '"' + ";" + '"' + "Tiempo" + '"' + ";" + '"' + "Pago" + '"');
for (i = 0; i < rows; i++)
{
//assign the first variable, in my case, DateTime data types
fechaHora = Convert.ToDateTime(clu.Rows[i].Cells[0].Value.ToString());
for (j = i + 1; j < rows; j++)
{
//assign the second variable
fechaActual = Convert.ToDateTime(clu.Rows[j].Cells[0].Value.ToString());
if (fechaHora.Date == fechaActual.Date)
{
//here i start the compare process
if (fechaHora.TimeOfDay != fechaActual.TimeOfDay)
{
tiempo = fechaActual.Subtract(fechaHora);
// if the dates are the same, but their time is different..
if (tiempo.TotalHours > 7 && fechaHora.TimeOfDay > fechaActual.TimeOfDay)
{
//if the timespan between the times is over 7 hours and the first date is over the second....
entrada = fechaHora;
salida = fechaActual;
pay = Convert.ToDouble(tiempo.TotalHours * hourPay);
archivo.WriteLine(usuario + ";" + entrada + ";" + salida + ";" + tiempo.TotalHours + ";" + pay);
}
//if the timespan between the times is over 7 hours and the second date is over the fist....
else if (tiempo.TotalHours > 7 && fechaHora.TimeOfDay < fechaActual.TimeOfDay)
{
entrada = fechaHora;
salida = fechaActual;
pay = Convert.ToDouble(tiempo.TotalHours * hourPay);
archivo.WriteLine(usuario + ";" + entrada + ";" + salida + ";" + tiempo.TotalHours + ";" + pay);
}
//if the timespan between the times is under 2 hours and the first date is under or equal the second....
else if (tiempo.TotalHours < 2 && fechaHora.TimeOfDay <= fechaActual.TimeOfDay)
{
error = fechaActual;
}
}
}
}
}
}
Thanks for all your help, i hope this will be useful.
I have a method that runs through a loop that can take quite a while to complete as it requires getting data back form an API.
What I would like to do is display a message on the front end explaining how the system is progressing during each loop. Is there a way to update the front end while processing?
public static void GetScreenshot(List<string> urlList, List<DesiredCapabilities> capabilities, String platform, Literal updateNote)
{
foreach (String url in urlList)
{
String siteName = new Uri(url).Host;
String dir = AppDomain.CurrentDomain.BaseDirectory+ "/Screenshots/" + siteName + "/" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm");
foreach (DesiredCapabilities cap in capabilities)
{
String saveDirectory = "";
if (platform == "btnGenDesktopScreens")
{
saveDirectory = dir + "/" + cap.GetCapability("os") + "-" + cap.GetCapability("os_version") + "-" + cap.GetCapability("browser") + cap.GetCapability("browser_version");
}
else if(platform == "btnMobile")
{
saveDirectory = dir + "/" + cap.GetCapability("platform") + "" + cap.GetCapability("device") + "-" + cap.GetCapability("browserName");
}
updateNote.Text += "<br/>" + cap.GetCapability("platform") + " - " + cap.GetCapability("device") + "-" + cap.GetCapability("browserName");
//I'd like to display a message here
TakeScreenshot(url, cap, saveDirectory);
//I'd like to display a message here
}
}
}
Has anyone come across a method of doing this?
Depending on how you're returning the feedback to the user, you might be able to do this by using HttpResponse.Flush in a loop to push parts of the HTML response to the user a bit at a time. See https://msdn.microsoft.com/en-us/library/system.web.httpresponse.flush(v=vs.100).aspx
I am trying to export the drawing to save another drawing using "CopyBase" and "PasteClip" command. But it is does not work an error occurred. Can anyone tell how to i solve this..
i am using Copy and Paste command like this..
AcadApplication acadApp;
AcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing= acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
newThisdrawing = acapp.Documents.Add(dwgTempPath ) ;
newThisdrawing.SaveAs(expDwgName , thisdrawing.Application.Preferences.OpenSave.SaveAsType,null);
newDwgCreatBool = true;
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newthisdrawing.Activate();
comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
Thanks in Advance..
With your edit, I'm assuming this is an external exe. With that in mind and some minor modifications to your code, I got this to work with no problems in a Console exe. Before the code a couple things about it:
I compiled using the 4.5 Framework. The COM references for .NET may have been updated with their .NET API counterparts, so make sure this is the case for you too.
Add a COM reference to "AutoCAD 2015 Type Library" there's one for each language package (choose axdb20enu.tlb, but I think in the end VS may select them all after it's added).
Add a COM reference to "AcObjClassImp 1.0 Type Library", choose the one for release 20 (AcObjClassImp20.tlb)
Add the using statement "using AutoCAD;" at the top with the rest.
Here's the code I used:
static void Main(string[] args)
{
IAcadApplication acadApp;
IAcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing = acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
IAcadDocument newThisdrawing = acadApp.Documents.Add(dwgTempPath);
//Instead of the path below, use your full path, formatted correctly
newThisdrawing.SaveAs(#"C:\Acad\Test.dwg", thisdrawing.Application.Preferences.OpenSave.SaveAsType, null);
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newThisdrawing.Activate();
string comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
}
This question already has answers here:
String format currency
(8 answers)
Closed 8 years ago.
I need to format my display tostring results to a currency in C#
display = "Service Amount: " + service + "<br>" +
"Discount Amount: " + discountAmount + "<br>" +
"Total: " + total + "<br>";
lblDisplay.Text = display;
I did try the following:
display = "Service Amount: " + Console.Write(int.ToString("c",service)) + "
but I couldn't figure out what variables to put in. I just need it to display as $35.00 after the it returns the string.
Try:
display = string.Format("Service Amount: {0}",service.ToString("C"));
Console.WriteLine(display);
You can also look at StringBuilder for building strings or String.Format
String.Format("Service Amount: {0:C}<br>", service)
I have a textbox1 that lets the user input a text, a button that adds the text to textbox2.
this is my code but it doesnt create a new line when I add another text.
string date = DateTime.Now.ToString();
txt_details.Text = date + " " + txt_summary.Text.ToString() + Environment.NewLine + Environment.NewLine ;
Notice the += operator.
txt_details.Text += "\n" + date + " " + txt_summary.Text.ToString();
Looks like you should be appending (use +=); instead you are overwriting.
string date = DateTime.Now.ToString();
txt_details.Text += date + " " + txt_summary.Text.ToString() + Environment.NewLine + Environment.NewLine
Make sure Multiline is enabled.
Ensure that TextBox.Multiline property is set to true
txt_details.Multiline = true;