How to keep all date selection in calendar? - c#

I've created a code that read dates from a database and put them into the Calendar control. All working good, but if the user select a date in the Calendar, after the population, all the date selected through code disappear. There's another way to flag the date that are previously added from the database population?
public void setFixturesControl()
{
Database.m_dbConnection.Open();
string query = "select * from date";
SQLiteCommand input = new SQLiteCommand(query, Database.m_dbConnection);
SQLiteDataReader reader = input.ExecuteReader();
while (reader.Read())
{
if (MainWindow.AppWindow.League.SelectedItem.ToString().Equals(reader["caption"].ToString()))
{
MainWindow.AppWindow.Calendar.SelectedDates.Add(DateTime.Parse(reader["data"].ToString()));
}
}
Database.m_dbConnection.Close();
}
There's a way to prevent the dates disappear after a user click? Or something that allow me to recognize the dates added by database population? Thanks.

After a long search on the net and a large documentation on the Calendar class, I could see two things:
To get what I want I have to take advantage of a custom control
Try to act via code by creating a delegate, but this is not really a
simple thing
I ran then in the first point, in particular, from the post of David Veeneman, it addresses exactly my problem.
The final result will be like this:
Exactly what I want.
In the post it is all documented, so it would be pointless to do a copy paste here. Thank this member that for me at least was able to solve a failure in the control of Microsoft. Unfortunately I am increasingly convinced that WPF is still immature and that still requires a bit 'of years to complete. I hope my answer is help, if anyone manages to solve the problem in a more elegant, well it responds well. Thank You.

Related

How do I set formatting for a dynamically added column in Infragistics WebDataGrid?

I'm currently working with a utility that was written using the Infragistics WebDataGrid control. The tool allows a user to select a table from a drop-down list at which point it runs a stored procedure to get data from SQL Server which it then binds to the grid.
Everything gets a default format, which for datetime columns is simply MM/DD/YYYY in this case. There is a request to include the time component for at least one of these columns.
After much searching I've tried to add code to the _InitializeRow event handler for the grid, but I can't seem to get it quite right. Here's what I've come up with:
if (e.Row.Index == 0)
{
foreach (GridRecordItem field in e.Row.Items)
{
if (field.Column.Key == "InsertedOnCC")
field.Column.FormatValue = "{0:g}";
}
}
This gives me an error that FormatValue cannot have a value assigned because it is a method group.
This was pieced together from several sources, none of which did quite what I wanted to do. For example, one piece of sample code just always assumed that the column in question was the first column, so I had to add the foreach loop.
I've seen a lot of mention of BoundDataField and DataFormatString, but I can't seem to actually find how to access those.
NOTE: I'm actually a SQL Developer, not a C# developer, so please be gentle. :)
Thanks!
I was able to sort this out by casting the Column as a BoundDataField then using the DataFormatString from there:
if (e.Row.Index == 0)
{
foreach (GridRecordItem gri in e.Row.Items)
{
BoundDataField field = gri.Column as BoundDataField;
if (field.Key == "InsertedOnCC")
field.DataFormatString = "{0:g}";
}
}
Using the info above, I was able to get this to work. It's cleaner. It does not require the loop:
TryCast(.Rows(0).Items.FindItemByKey("MyColumnName").Column, Infragistics.Web.UI.GridControls.BoundDataField).DataFormatString = "{0:G}"

Pause in an ASP.NET Chart Series

The problem: I've got an ASP.NET 4.0 chart object which dynamically generates a series for latency data for a modem in the field. The overall page does a lot more and the chart also displays some other stuff, but it's outside the scope of this. The series is being generated from SQL grabbing the information from a database and what I'd like to see is the the chart literally skip when the remote goes offline. I'm displaying the last hour's worth of data from when the modem was in the network, but let's say the last time it was in the network was under an hour ago and it just went offline, so I want to see its state as it went offline.
The conditions: Essentially, what if a modem was in the network, went offline, came back in, went offline, and came back all in under an hour? One would hope that there would be gaps in the chart series. At the moment, the way the SQL query handles this is that it ignores both NULLs and latency values under 300ms because that's technically an impossible value for satellite.
The question: If I were to tweak my query to not throw out the 0's, is there a way I could get it to show gaps in my graph? Can the charts support this? Would it instead require multiple series (which would be a bear to implement)? Is there another way I'm not thinking of?
The caveat: I can post code if need be, but it's not strictly necessary since this is more of a conceptual / is it possible kind of question.
I've been working on this project for weeks and am nearly done, so I've had to come back to address this issue and so few people have a good grasp on chart controls that I figured this would be the best place to ask since I haven't found anything after tweaking the query and chart settings or searching on Google for a few hours.
Thanks so much in advance for your help.
Update: It turns out there is relevant code. I had completely forgotten there were different ways to dynamically generate chart series. It's true that it could be point-by-point. If I were doing it that way, it would certainly be easier. Instead, my series handler looks like this:
protected Boolean Chart_A_Line(string query, string seriesName, int queryType, string connnectionString)
{
SqlConnection con = new SqlConnection(connnectionString);
Boolean chartEmpty = true;
using (con)
{
SqlCommand command = new SqlCommand(query, con);
switch (queryType)
{
case 0:
command.Parameters.AddWithValue("#RemoteId", remote);
break;
case 1:
command.Parameters.AddWithValue("#IRID", inrouteId);
break;
}
command.Parameters.AddWithValue("#NMS", nms);
con.Open();
SqlDataReader chartReader = command.ExecuteReader();
if (chartReader.HasRows)
{
chartEmpty = false;
LatencyCNChart.Series[seriesName].Points.DataBindXY(chartReader, "Time", chartReader, "Data");
}
con.Close();
return chartEmpty;
}
}
I'm not too sure how you're adding data to your chart, but when you add a new point to a data series, you can set its IsEmpty property to true (as explained here).
You can also use DataManipulator.InsertEmptyPoints().
As long as you know all the 0 values in your data definitely mean a gap value, then you can just make the appropriate call for each 0 value to set a gap in the graph.

PeterBlum SelectedIndexCondition Not Equal functionality

Right now we are using the PeterBlum SelectedIndexCondition to control whether or not some controls are displayed using the following snippet:
PeterBlum.DES.MultiFieldStateController fsc = new PeterBlum.DES.MultiFieldStateController();
PeterBlum.DES.SelectedIndexCondition cnd2 = new PeterBlum.DES.SelectedIndexCondition();
cnd2.Index = desiredIndex
cnd2.ControlToEvaluate = ControlToEvaluate//ListBox, dropdown, etc
fsc.Condition = cnd2;
I'd like to be able to achieve this same functionality except to fire when the desired index IS NOT set. I cannot simply create a bunch of Conditions for each index other than the one I specify due to the way this is dynamically being done in my application.
Thanks in advance,
Ben
You will probably get better results if you post your question to Peter's Yahoo Forum. In my experience, he will get back to you very quickly with a good answer.

How to get out information from a DataGridView?

I am working on program that calculate the GPAs for university students in C#.
I have made a gridview that contains columns for each subject. Its mark as letter and
number. After the user "student" insert his/her subject I want to let the user click a
button that will get the mark and the number of the credit hours of each subject. Calculate the GPA for the student and put the result in a textbox.
I am having trouble getting started. Any advice for a good place to start?
To answer just the question in your title:
To get value from the current row, first capture the row:
DataGridViewRow r = MyDataGridView.CurrentRow;
To get the value from cell 0:
string v = (string)r.Cells[0].Value;
What I see from your question you are having difficulty how to put the requirement in one place.
I'm assuming you already have the user requirements (it looks very simple) and I give basic steps you go through, it is not accurate and it doesn't fit for all type of projects, but your case is very simple and I think it is enough to do the work.
first you will need to create a flow, the steps the user will go through to accomplish the process.
then you will need the basic interface to let you have at least to know what controls you will need.
after that you will make the data structure (mostly the database schema) to know how the data will be stored and related to each other.
then you will create the business logic to implement your requirements.(the coding part)
and Last you will glue all the things and attach the code that wrote to the events in the interface based on the flow you made it at the first step.
I hope this helps.
I'm not sure about what you are trying to do, but you can take a look here:
http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=191
I've solved lots of my WPF dumb design problems with these articles :P

Best Practices for a Calendar Database Schema?

I'm a beginner with C#, ASP.NET, SQL Server Express and programming in general. I'm trying to make an online calendar (on a deadline). I'll read all the other posts that are similar to this, but for now I have a question that I hope will set me on my way.
What are the steps to link a calendar to a database? Any examples of where/how this has been done would be greatly appreciated?
I see possible pitfalls when a date has more than one entry by different users, so if anyone knows how this is managed again I'm all ears.
I have wrote you a small example that shows
Connecting to a SQL Express server
Reading data
Selecting multiple dates (i.e. more than one date entry by different users)
Hope this helps!...
// The SQL connection object to connect to the database. Takes connection string.
SqlConnection connection =
new SqlConnection(#"Data Source=localhost\SQLEXPRESS;Initial Catalog=Example");
// Idealy you wouldnt pass direct SQL text for injection reasons etc, but
// for example sake I will enter a simple query to get some dates from a table.
// Notice the command object takes our connection object...
SqlCommand command = new SqlCommand("Select [Date] From Dates", connection);
// Open the connection
connection.Open();
// Execute the command
SqlDataReader reader = command.ExecuteReader();
// A list of dates to store our selected dates...
List<DateTime> dates = new List<DateTime>();
// While the SqlDataReader is reading, add the date to the list.
while (reader.Read())
{
dates.Add(reader.GetDateTime(0));
}
// Close the connection!
connection.Close();
// Use the selected dates property of the ASP.NET calendar control, add every
// date that we read from the database...
foreach (DateTime date in dates)
{
Calendar1.SelectedDates.Add(date);
}
Good luck!
Dunno if this is of any help but CodeProject seems to have some similar solution
I'd recommended finding a couple of free open source calendar applications and looking at their schemas.
MojoPortal and DotNetNuke Events both look like they have calendar portions.
You'll have a huge jump start and will avoid some basic mistakes.
Looks like someone already asked this question. Laying out a database schema for a calendar application
One word of advice is to use integer fields instead of datetime fields. They will run faster. Also don't be afraid to denormalize your tables. So you might have a date column, year column, month column, and day column.

Categories