|
Try an example that works; then get creative.
Thread Class (System.Threading) | Microsoft Docs
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Pardon me if I've misunderstood your question but it seems to me that you spawn your threads but expect them to execute synchronously which does not make any sense to me at all. So I agree with Richard that this is not the best example as it would just benefit from synchronous code as it is much simpler and as performant.
My main point is that the best parallelism is when you have no shared resources between your tasks and you should strive for it.
In case you wanted to simulate with your example the fact that it requires some effort to compute info about the student (i.e. you get it from DB) I would rather suggest you investigate async/await.
|
|
|
|
|
Hello everyone, I have a problem with my application which is designed to print purchase invoices in a shop on a thermal printer. I have a little problem when printing the invoice, I want the invoice to be printed directly without a preview.
I used ReportViewer and RDLC
If anyone has an idea please help me. thank you in advance
|
|
|
|
|
What have you tried?
Where are you stuck?
What help do you need?
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. So we have no idea what your code might even look like!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
do I have to post my code that I used?
here is the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;
namespace POS_System_Inventory
{
public partial class frmReceipt : Form
{
String store = "LISINGI PC SOFTWARE Pvt Ltd";
String address = "13ième AV N°46 C/TSHOPO-KIS";
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
DBConnection dbcon = new DBConnection();
frmCashier f;
public frmReceipt(frmCashier frm)
{
InitializeComponent();
con = new SqlConnection(dbcon.MyConnection());
f = frm;
}
private void frmReceipt_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
public void LoadReport(string paracash, string parachange)
{
try
{
ReportDataSource rptDataSource;
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + @"\Reports\Report1.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
DataSet1 ds = new DataSet1();
SqlDataAdapter da = new SqlDataAdapter();
con.Open();
da.SelectCommand = new SqlCommand("select c.id,c.transno,c.pcode,c.price,c.qty,c.disc,c.total,c.sdate,c.status,p.pdesc from tblCart as c inner join tblProduct as p on p.pcode=c.pcode where transno like '" + f.lblTrans.Text + "' ", con);
da.Fill(ds.Tables["dtSold"]);
con.Close();
ReportParameter pVatable = new ReportParameter("pVatable", f.lblVatable.Text);
ReportParameter pVat = new ReportParameter("pVat", f.lblVat.Text);
ReportParameter pDiscount = new ReportParameter("pDiscount", f.lblDiscount.Text);
ReportParameter pTotal = new ReportParameter("pTotal", f.lblTotal.Text);
ReportParameter pCash = new ReportParameter("pCash", paracash);
ReportParameter pChange = new ReportParameter("pChange", parachange);
ReportParameter pStore = new ReportParameter("pStore", store);
ReportParameter pAddress = new ReportParameter("pAddress", address);
ReportParameter pTransaction = new ReportParameter("pTransaction", "Facture N°: " + f.lblTrans.Text);
ReportParameter pCashier = new ReportParameter("pCashier", frmLogin2.UserDisplayName2.name2);
reportViewer1.LocalReport.SetParameters(pVatable);
reportViewer1.LocalReport.SetParameters(pVat);
reportViewer1.LocalReport.SetParameters(pDiscount);
reportViewer1.LocalReport.SetParameters(pTotal);
reportViewer1.LocalReport.SetParameters(pCash);
reportViewer1.LocalReport.SetParameters(pChange);
reportViewer1.LocalReport.SetParameters(pStore);
reportViewer1.LocalReport.SetParameters(pAddress);
reportViewer1.LocalReport.SetParameters(pTransaction);
reportViewer1.LocalReport.SetParameters(pCashier);
rptDataSource = new ReportDataSource("DataSet1", ds.Tables["dtSold"]);
reportViewer1.LocalReport.DataSources.Add(rptDataSource);
reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
reportViewer1.ZoomMode = ZoomMode.Percent;
reportViewer1.ZoomPercent = 50;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
modified 23-Mar-20 4:14am.
|
|
|
|
|
Not all of it - just relevant fragments.
Without any code at all, it's like you telling a garage "my car broke" and putting the phone down - they don't know where you are, much less what parts they need to bring out to help you!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
all this code posted works wonderfully, except that I want it to be printed without a print preview
|
|
|
|
|
Member 14192216 wrote:
da.SelectCommand = new SqlCommand("select c.id,c.transno,c.pcode,c.price,c.qty,c.disc,c.total,c.sdate,c.status,p.pdesc from tblCart as c inner join tblProduct as p on p.pcode=c.pcode where transno like '" + f.lblTrans.Text + "' ", con); Don't do it like that!
Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
da.SelectCommand = new SqlCommand("select c.id, c.transno, c.pcode, c.price, c.qty, c.disc, c.total, c.sdate, c.status, p.pdesc from tblCart as c inner join tblProduct as p on p.pcode = c.pcode where transno like @transno", con);
da.SelectCommand.Parameters.AddWithValue("@transno", f.lblTrans.Text);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I'm going to have a Windows Service running on a server. It will have a FileSystemWatcher running in it. When a file is dropped in, the service will process the file. Sometimes, when a user drops a file onto the server, I will need to prompt the user, from the server, with some options.
The question is, how can the server prompt the user?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It can't. The service is going to have to send a message to an app running on the client machines and that app is going to have to prompt the user. Of course, is has to be an app that is run from the registry Run key so it starts when the user is logged on. That app cannot also be a service.
|
|
|
|
|
I'v used SignalR alot. The client could register itself with the server, then the server could as the local user for any info it needs. This would work, but I'm concerned about the client side app either not starting or being turned off somehow.
Your thoughts?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Since everything launched from the Run key launches as the user that logged in, they are free to terminate the app any time they want from either the command line tools or from Task Manager.
They are also free to disconnect the network and rip out the LAN cable.
There's nothing you can do that's going to be 100% effective against losing communication or presentation.
|
|
|
|
|
"Servers" "waiting" for response(s) from "users". A new definition for "stateless".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Is it possible to add a custom property or attribute to any type of file? Say I want to add a property called "MySetting" with the value of "100" to MyFile.txt, then be able to see it in File => Right-Click => Properties => Detals. And also to be able to read that back in C#.
Is this possible in C#? I'm not really sure what to Google to research this?
Can anyone point me in the right direction?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I don't know about adding properties to files but you can add alternate file streams and store data in the alternate file stream for the file, I know it can be done with C/C++ but I have not done it for a while.
Whether you can get the properties in the file/right-click/properties/details properties I am not sure.
|
|
|
|
|
|
Thanks.
That postes says "
So this will only work with NTFS. ", so that may not work for what I need. That has me rethinking this.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi,
There is one existing property that might be sufficient for your needs: "Date Created" is a DateTime
which is set by Windows when the file gets created, and isn't modified afterwards. Internally it is stored as a 32-bit integer (often/always? with a resolution of 2 seconds), but Explorer won't show it as an integer, it will display numbers for year, day, hours, minutes, maybe month, typically not seconds.
So you could store a few small numbers in it: some range in the year, [1-31] in the day (assuming a long month), [0-23] in hours, [0-59] in minutes.
PS: when abusing Date Created, make sure there isn't any app (such as a backup utility) relying on the standard meaning of Date Created; I would hope such software relies on Date Modified, but I suggest you check that anyway.
modified 22-Mar-20 16:43pm.
|
|
|
|
|
The "100" in my post was just for illustrative porposes. I would want to write out any type of property, string, int, date/time, bool, etc
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Quote: hello gentlemen and thank you to you who bring me your help. I am almost at the end of my program and I have an update problem. I don't see any change in my stock.
I have no error when I validate but the quantity does not change in the access database
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
ref_prod = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
Qte_prod = Convert.ToInt64(dataGridView1.Rows[i].Cells[1].Value);
using (OleDbCommand cmd3 = sql_con.CreateCommand())
{
cmd3.CommandText = "INSERT INTO Detail_commandes (com_det, ref_det, qute_det) VALUES (@com_det,@ref_det,@qute_det)";
cmd3.Parameters.AddWithValue("@com_det", TxtNunCmd.Text);
cmd3.Parameters.AddWithValue("@ref_det", ref_prod);
cmd3.Parameters.AddWithValue("@qute_det", Qte_prod);
sql_con.Open();
cmd3.ExecuteNonQuery();
sql_con.Close();
}
using (OleDbCommand cmd4 = sql_con.CreateCommand())
{
OleDbCommand QteStock = sql_con.CreateCommand();
QteStock.CommandText = "SELECT Quantite FROM Catalogue";
sql_con.Open();
int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
sql_con.Close();
cmd4.CommandText = "UPDATE Catalogue SET Quantite = @Quantite - @QteStc WHERE code_article = (@code_article)";
cmd4.Parameters.AddWithValue("@Quantite", LastQteStock);
cmd4.Parameters.AddWithValue("@QteStc", Qte_prod);
cmd4.Parameters.AddWithValue("@code_article", TxtRefProduit.Text);
sql_con.Open();
cmd4.ExecuteNonQuery();
sql_con.Close();
}
}
|
|
|
|
|
Once again: use the debugger. Find out what the numbers are, find out what the code-article value is. Then before you call ExecuteNonQuery to perform the update, check your DB for the exact current values using an Access query to find the specific rows.
Work out what the new row values should be for the numbers you looked at.
Step over the ExecuteNonQuery, and look at the same set of rows. Are they the new values?
We can't do any of that for you, we don't have your DB.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Understood sir and thank you for your promptness. i will keep looking
|
|
|
|
|
Sir I am happy because I was able to find a solution, its not easy because I really did not know how to go about it to see what is wrong. but I was able to post my request in a texbox to see what was wrong. I do not know my code is clean but the update is done.
How to find the code?
using (OleDbCommand cmd4 = sql_con.CreateCommand())
{
OleDbCommand QteStock = sql_con.CreateCommand();
QteStock.CommandText = "SELECT Quantite FROM Catalogue";
sql_con.Open();
int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
sql_con.Close();
string query = "UPDATE Catalogue SET Quantite = (@quantite - @QteStc) WHERE Code_article = (@code_article)";
cmd4.CommandText = query;
MessageBox.Show(query);
cmd4.Parameters.AddWithValue("@quantite", LastQteStock);
cmd4.Parameters.AddWithValue("@QteStc", Qte_prod);
cmd4.Parameters.AddWithValue("@code_article", ref_prod);
sql_con.Open();
cmd4.ExecuteNonQuery();
sql_con.Close();
}
|
|
|
|
|
Seriously, learn to use the debugger - it will show you exactly what is happening while your code is running. It lets you look at variables to check what they contain - and compare them to what you think they should contain - execute your code line by line, and a load of other things.
It's your biggest friend in development - and the place you should be spending most of your time!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|