Im tyring 2day to solve this problem

Oct 27 2010 5:38 AM

Im wrighing c# applications. In 'Inventary' Form is datagridview which gets data from sql table 'Products' i have one form 'AddNew' which is adding some data with following code:

 rivate void btnOk_Click(object sender, EventArgs e)
{
if (txtBarCode.Text == "" || txtProductName.Text == "" || txtPrice.Text == "" || numericUpDown1 == null)
{

MessageBox.Show("Please Fill", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

this.Show();
txtBarCode.Focus();
return;
}
try
{
decimal price = Convert.ToDecimal(txtPrice.Text);
decimal awd;
awd = price - ((price * 18) / 100);

Program.AddProduct(txtBarCode.Text, txtArtNumber.Text, txtProductName.Text, txtPrice.Text, txtComment.Text, numericUpDown1.Value, awd.ToString(), txtSelfPrice.Text);

Inventary inv = new Inventary();
inv.save();
DialogResult = DialogResult.OK;
}
catch (Exception ex)
{

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
Inventary inv = new Inventary();
inv.load();
this.Close();
}
 
this code works fine but i want to make following : when user click on datagridviews cell double it must open this form AddNew already texbox filled which edits data . How can i catch AddNew`s btn ok click from Form Inventary. please advice me something how can i use this code on addnew`s btnOk from Inventary form :

internal static void EditProduct(string txtBarCode, string txtArtNumber, string txtProductName, string txtPrice, string txtComment, decimal NumericUpDown1, string PriceWithOutAWD, string txtSelfPrice) 
{
SqlConnection con = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand("UPDATE Products SET BarCode = @BarCode, ArtNumber = @ArtNumber, ProductName = @ProductName, Price = @Price, SelfPrice = @SelfPrice, PriceWithOutAWD = @PriceWithOutAWD, UnitsInStock = @UnitsInStock, Comment = @Comment WHERE BarCode = @bc AND ArtNumber = @an ", con);


cmd.Parameters.Add(new SqlParameter("@BarCode", txtBarCode));
cmd.Parameters.Add(new SqlParameter("@ArtNumber", txtArtNumber));
cmd.Parameters.Add(new SqlParameter("@ProductName", txtProductName));
cmd.Parameters.Add(new SqlParameter("@Price", txtPrice));
cmd.Parameters.Add(new SqlParameter("@SelfPrice", txtSelfPrice));
cmd.Parameters.Add(new SqlParameter("@PriceWithOutAWD", PriceWithOutAWD));
cmd.Parameters.Add(new SqlParameter("@UnitsInStock", NumericUpDown1));
cmd.Parameters.Add(new SqlParameter("@Comment", txtComment));
cmd.Parameters.Add(new SqlParameter("@bc", txtBarCode));
cmd.Parameters.Add(new SqlParameter("@an", txtArtNumber));
try
{
con.Open();
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}

this code is in Program.cs


Answers (1)