DateTimePickers don't show the data - c#

The database contains data about movie house(cinema's). The database contains this fields : Name of movie house, Name of movie, start time and date.
I have a problems with additional task. The program should generate a report for each
cinema in the order of the sessions on the specified date.
When I choosing a date in DatePickers, database doesn't show the first movie.
Example:
value of datetimePicker1 = 13.12.2018
value of datetimePicker2 = 16.12.2018
that database show information about 14,15,16.12.2018.
for (int i = 0; i < tableDataGridView.Rows.Count - 1; i++)
{
if (Convert.ToDateTime(tableDataGridView.Rows[i].Cells[4].Value) >= dateTimePicker1.Value
&& Convert.ToDateTime(tableDataGridView.Rows[i].Cells[4].Value) <= dateTimePicker2.Value)
MessageBox.Show(tableDataGridView.Rows[i].Cells[0].Value.ToString() +
" || Movie theater: " + tableDataGridView.Rows[i].Cells[1].Value.ToString() +
" | Movie: " + tableDataGridView.Rows[i].Cells[2].Value.ToString());
}

Please make a change:
I was able to create a similar C# WindowsFormsApplication based on information you have provided and was able to replicate a similar bug and got it resolved with this:
Change:
for (int i = 0; i < tableDataGridView.Rows.Count - 1; i++)
To:
for (int i = 0; i < tableDataGridView.Rows.Count; i++)
Second:
If there is a blank line at the end of GridView, then you may need to add this line to Form1_Load event
tableDataGridView.AllowUserToAddRows = false;

Related

How to write true/false in capitalize in excel via c#

whenever i write true/false in excel via c#. it shows and convert it into uppercase "FALSE/TRUE" in excel.
what should i do to remain it's case sensitivity?
I've tried with single quote " ' ", it shows what we want but logically it holds the value of single quote as well. ex: " 'False " in excel shows as False , but in data it shows 'False .
Is there any property changes, custom settings or via c# code can do this for me?
I'm writing data via c# DataTable to Excel worksheet cells in this manner.
for (int i = 0; i < dtToExport.Rows.Count; i++)
{
for (int j = 0; j < dtToExport.Columns.Count; j++)
{
workSheet.Cells[(i + 2), (j + 1)] = dtToExport.Rows[i][j];
}
}

How do i store this data correctly? Application freezes

I'm trying to save MySQL data in a sort of session for my program.
The code I have is this:
sessionData userSession = new sessionData();
for (int i = 0; i < 7; )
{
userSession.UserData[i] = reader.GetString(i).ToString();
}
sessionData.cs
class sessionData
{
public string[] UserData = new string[7];
}
I'm then trying to access the users first name and display it like so:
welcomeBox.Text = "Hi, " + userData.UserData[1] + ".";
However, once I press Login it freezes before my application goes to the landing page.
What should I do?
Your for loop is an infinite loop, until you add the i ++ in it
for (int i = 0; i < 7; ) should change to
for (int i = 0; i < 7; i++;)
Also code review notes:
Why are your class names beginning with lower case letters? Majority of .NET projects use CamelCase.
Your question has been edited for grammer and syntax. Next time put more effort in your questions, and before falling back to stack overflow, try out things for yourself first.

Determine Item QtyStock after Order using C# and Excel

How can I cycle trough each order an check if I still have material to make that order?
For example in this image, I want to make an alert when there isn't enough material to produce the order.
I was thinking something like using a double for, but im having a really hard time getting the logic together.
If anyone can help me understand the logic in this problem I would appreciate it
On my Excel file I just used a simple formula (=F3-J3) and (=K3-J4) for the Metal Material.
I want to make an application witch reads the excel file using "Microsoft.Office.Interop.Excel" and "DataTable". I learned how to read the data and save it on the DataTable, just don't know how to cycle trough the rows and make the subtraction.
Thx.
I made a double for loop like I sugested, Im just wondering now if there is a way to optimize the code, or if there are any error, for now its seams to get the job done.
public void Method(){
for (int i = 1; i < dataGridView2.Rows.Count; i++)
{
string partnumber = dataGridView2.Rows[i - 1].Cells["PART NUMBER"].Value.ToString();
double onhand = double.Parse(dataGridView2.Rows[i - 1].Cells["TOTAL-ON-HAND"].Value.ToString());
for (int j = 1; j < dataGridView1.Rows.Count; j++)
{
string part = dataGridView1.Rows[j - 1].Cells["Part #"].Value.ToString();
double BL = double.Parse( dataGridView1.Rows[j - 1].Cells["BL"].Value.ToString());
if(partnumber == part)
{
if (onhand >= BL)
{
onhand = onhand - BL;
MessageBox.Show(partnumber.ToString() +": " + onhand.ToString());
}
else { break; }
}
}
}
Note: BL = Customer Order Qty

SSRS multi page report

I have to generate a SSRS multiple page report. I have a list "data" and have to do following.
data contains name, salary and address
data[0] = abc,1000,def
data[1] = pqr,2000,xyz
for(int i =0; i<data.Count; i++)
{
//when the value of i is 0 information must be printed on 1st page.
//when value of is 1 information must be printed on 2nd page and so on...
}
What I believe you are looking for is a for loop construct like so:
for (int i = 0; i < data.Length;)
{
int page = ++i;
// Write the data on the page in the int variable above.
}

Outlook.Items Restrict() weird behavior

I just want to filter my Mails with the Restrict-Method like so:
restriction += "[ReceivedTime] < '" + ((DateTime)time).ToString("yyyy-MM-dd HH:mm") + "'";
var count = oFolder.Items.Restrict(restriction).Count;//Cast<object>().ToList();
for (int i = 0; i < count; i++)
{
var crntReceivedTime = ((OutLook.MailItem)oFolder.Items.Restrict(restriction).Cast<object>().ToList()[i]).ReceivedTime;
if (crntReceivedTime > time)
{
string t = "";
}
}
Theoretically the line string t = ""; should never be called, because I determined the Items to never have entries which ReceivedTime's value is bigger than time.
The problem is the line gets called, what means the restricted Items Collection contains entries which its shouldn't contain.
Did I do something wrong or is the Restrict()-method just failing?
Firstly, you are using multiple dot notation. You are calling Restrict (which is expensive even if it is called once) on each step of the loop. Call it once, cache the returned (restricted) Items collection, then loop over the items in that collection.
Secondly, what is the full restriction? You are using += to add an extra restriction on ReceivedTime. What is the actual value of the restriction variable?
Edit: I had no problem with the following script executed from OutlookSpy (I am its author - click Script button, paste the script, click Run):
restriction = " [ReceivedTime] < '2011-06-11 00:00' "
set Folder = Application.ActiveExplorer.CurrentFolder
set restrItems = Folder.Items.Restrict(restriction)
for each item in restrItems
if TypeName(item) = "MailItem" Then
Debug.Print item.ReceivedTime & " - " & item.Subject
End If
next

Categories

Resources