How can I fill a class with textbox data and datagridvied data, and use the collected data on another form.
I created this class, to handle collected data
public class pos_data
{
public int nr{ get; set; }
public int barcode{ get; set; }
public string name { get; set; }
public int qty { get; set; }
public float price { get; set; }
public float TOTAL { get; set; }
public float subtotal { get; set; }
public float discount { get; set; }
public float total{ get; set; }
public DateTime date{ get; set; }
public string user { get; set; }
public string client { get; set; }
public float valueofvatpcs { get; set; }
public float valuewithoutvat{ get; set; }
public int nrofarticles { get; set; }
public float totalprice{ get; set; }
public float totalvaluesVAT{ get; set; }
}
and create a method to collect data using object of class give in upper part of this question
void mbushe(object sender, EventArgs e)
{
pos_data ad = new pos_data();
for (int i = 0; i < dataTable.Rows.Count; i++)
{
ad.NR = int.Parse(txtnrfatures.Text);
ad.totalvaluesVAT = float.Parse(textBox1.Text);
ad.barcode= int.Parse(dataTable.Rows[i][0].ToString());
ad.name= dataTable.Rows[i][1].ToString();
ad.qty= int.Parse(dataTable.Rows[i][2].ToString());
ad.price= int.Parse(dataTable.Rows[i][3].ToString());
ad.vat = int.Parse(dataTable.Rows[i][4].ToString());
ad.subtotal = float.Parse(txttotali.Text);
ad.discount= float.Parse(txtzbritja.Text);
ad.total= float.Parse(totali.Text);
ad.date= DateTime.Now;
ad.user = lbluser.Text;
ad.client= cmbklienti.Text;
ad.valuevatpcs = float.Parse(dataTable.Rows[i][7].ToString());
ad.valuewithoutvat= float.Parse(dataTable.Rows[i][6].ToString());
ad.nrofarticles= int.Parse(lblnumri.Text);
ad.totalprice = float.Parse(dataTable.Rows[i][5].ToString());
Program.dta.Add(ad);
}
dta is an static list declared on Program.cs
How can i pass these data on form 2 or form 3 depend of necessity to use this data.
I tried this code to use on form2/3, where I wanted the collected data to be used during the insertion process
private void button1_Click(object sender, EventArgs e)
{
pos_data myData = new pos_data();
string faturimi = "Metoda e pagesese" + ""+ "KESH;" +"Paguar"+ txtpaguar.Text + " "+ "Kusuri"+ textBox3.Text;
con.Open();
SqlCommand cmd = new SqlCommand("insertfaturimi", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@nr", myData.NR));
cmd.Parameters.Add(new SqlParameter("@client", myData.client));
cmd.Parameters.Add(new SqlParameter("@payment", faturimi));
cmd.Parameters.Add(new SqlParameter("@subtotal", myData.subtotal));
cmd.Parameters.Add(new SqlParameter("@disount", myData.discount));
cmd.Parameters.Add(new SqlParameter("@total", myData.total));
cmd.Parameters.Add(new SqlParameter("@vatvalues", myData.totalvaluesVat));
cmd.Parameters.Add(new SqlParameter("@nrofarticles", myData.nrofarticles));
cmd.Parameters.Add(new SqlParameter("@user", myData.user));
cmd.Parameters.Add(new SqlParameter("@time", DateTime.Now));
cmd.Parameters.Add(new SqlParameter("@barcode", myData.barcode));
cmd.Parameters.Add(new SqlParameter("@name", myData.name));
cmd.Parameters.Add(new SqlParameter("@qty", myData.qty));
cmd.Parameters.Add(new SqlParameter("@vat", myData.vat));
cmd.Parameters.Add(new SqlParameter("@price", myData.price));
cmd.Parameters.Add(new SqlParameter("@totalpcs", myData.totalprice));
cmd.Parameters.Add(new SqlParameter("@valuewithoutvatpcs", myData.valuewithoutvat));
cmd.Parameters.Add(new SqlParameter("@vatvaluepcs", myData.valuevatpcs));
cmd.ExecuteNonQuery();
}
And the list declared on the Program.Cs
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static List<arka_data> dta;
}
I put a breakpoint on the line of void method mbushe : Program.dta.Add(ad), after the error is thrown , I checked the breakpoint there are no collected data just null value like:0.0, null etc attachec the image
So I think something is wrong with the void method mbushe.
But this code, thrown me an error " Procedure or function expects parameter , which was not supplied.This error is showed for each paramater of this code ( that means the data collected from class are null). So my question is what should i change on void method or class to collect data properly ?Could someone help me what to change in the code ?
What I have tried:
void mbushe(object sender, EventArgs e)
{
pos_data ad = new pos_data();
for (int i = 0; i < dataTable.Rows.Count; i++)
{
ad.NR = int.Parse(txtnrfatures.Text);
ad.totalvaluesVAT = float.Parse(textBox1.Text);
ad.barcode= int.Parse(dataTable.Rows[i][0].ToString());
ad.name= dataTable.Rows[i][1].ToString();
ad.qty= int.Parse(dataTable.Rows[i][2].ToString());
ad.price= int.Parse(dataTable.Rows[i][3].ToString());
ad.vat = int.Parse(dataTable.Rows[i][4].ToString());
ad.subtotal = float.Parse(txttotali.Text);
ad.discount= float.Parse(txtzbritja.Text);
ad.total= float.Parse(totali.Text);
ad.date= DateTime.Now;
ad.user = lbluser.Text;
ad.client= cmbklienti.Text;
ad.valuevatpcs = float.Parse(dataTable.Rows[i][7].ToString());
ad.valuewithoutvat= float.Parse(dataTable.Rows[i][6].ToString());
ad.nrofarticles= int.Parse(lblnumri.Text);
ad.totalprice = float.Parse(dataTable.Rows[i][5].ToString());
Program.dta.Add(ad);
}
dta is an static list declared on Program.cs