private void cboScript_Leave(object sender, EventArgs e) { try { Conn.Open(); ClosingStock cst; cst = new ClosingStock(); label8.Text = "Current Balance : " + cst.CalculateClosingStock(cboScript.SelectedValue.ToString(), Conn, cboHolder.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Conn.Close(); } }
public void InsertSoldEntry() { try{ Conn.Open(); cmd = new OleDbCommand(); cmd.Connection = Conn; string InsertQuery; ClosingStock ClsStock; ClsStock = new ClosingStock(); cmd.CommandText = "delete from stocksold where trnid=" + long.Parse(lblTransactionId.Text); cmd.ExecuteNonQuery(); float ClosingQty = ClsStock.CalculateClosingStock(cboScript.SelectedValue.ToString(), Conn, cboHolder.Text.ToString()); if (float.Parse("0" + txtQty.Text) > ClosingQty) { MessageBox.Show("Sold Qty should not be greater than " + ClosingQty + " (Qty in hand", "Error Saving", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } float[,] st; st = ClsStock.ReturnSellingNumbers(cboScript.SelectedValue.ToString(), Conn, float.Parse(txtQty.Text)); int i; for (i = 0; i < 10; i++) { if (st[i, 1] > 0) { InsertQuery = "insert into stockSold (scriptcode,dateofsale,qty,price,amount,holder,typeoftransaction,purchasetrnid) values('" + cboScript.SelectedValue.ToString() + "','" + dtDated.Value.ToShortDateString() + "'," + float.Parse(st[i, 1].ToString()) + "," + float.Parse(txtPrice.Text) + "," + (float.Parse(txtPrice.Text) * float.Parse(st[i, 1].ToString())) + ",'" + cboHolder.Text + "','" + cboTransactiontype.Text + "'," + st[i, 0] + ")"; cmd.CommandText = InsertQuery; cmd.ExecuteNonQuery(); } } } catch (Exception ex) { MessageBox.Show("" + ex.Message); } finally { ClearControls(); Conn.Close(); cboScript.Focus(); MainDataset(); } }