i want to know how to get this sale invoice exactly before i saved it. i save data in multiple tables but i did not find a way to update in all tables, Below full code of Sale Form
////////////
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;
namespace Windows
{
public partial class FormSale : Form
{
//SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
SqlCommand cmd;
SqlCommandBuilder cmdbuilder;
SqlDataAdapter sda;
DataTable dt;
public FormSale()
{
InitializeComponent();
}
private void txtTransporter_KeyUp(object sender, KeyEventArgs e)
{
//if (e.KeyCode==Keys.Enter)
//{
// this.SelectNextControl(txtTransporter, true, true, true, true);
//}
}
private void btninsert_KeyUp(object sender, KeyEventArgs e)
{
}
private void FormSale_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'windowsDbDataSet.SaleItem' table. You can move, or remove it, as needed.
//this.saleItemTableAdapter.Fill(this.windowsDbDataSet.SaleItem);
//autoFillFields();
fillcBoxTransporter();
fillcBoxPartyName();
fillcBoxICode();
fillcBoxLocation();
fillcBoxItemParty();
fillcBoxCashParty();
//this.ActiveControl = cBoxTransporter;
//cBoxPartyName.Focus();
// TODO: This line of code loads data into the 'windowsDbDataSet.ItemTypes' table. You can move, or remove it, as needed.
//this.itemTypesTableAdapter.Fill(this.windowsDbDataSet.ItemTypes);
autoVoucherId();
autoSaleId();
autoBillNo();
}
public void autoVoucherId()
{// To generate automatic Saleid number
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
cmd = new SqlCommand("SELECT max(VoucherId)+1 FROM Vouchers", conn);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
txtVoucherNo.Text = sdr[0].ToString();
if (txtVoucherNo.Text == "")
{
txtVoucherNo.Text = "1";
}
}
}
else
{
txtVoucherNo.Text = "1";
}
conn.Close();
}
public void autoSaleId()
{// To generate automatic Saleid number
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
cmd = new SqlCommand("SELECT max(Id)+1 FROM SaleMaster", conn);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
txtInvoiceId.Text = sdr[0].ToString();
if (txtInvoiceId.Text == "")
{
txtInvoiceId.Text = "1";
}
}
}
else
{
txtInvoiceId.Text = "1";
}
conn.Close();
}
public void autoBillNo()
{// To generate automatic Saleid number
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
cmd = new SqlCommand("SELECT max(BillNo)+1 FROM SaleMaster ", conn);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows)
{
while (sdr.Read())
{
txtGrandSale.Text = sdr[0].ToString();
if (txtGrandSale.Text == "")
{
txtGrandSale.Text = "1";
}
}
}
else
{
txtGrandSale.Text = "1";
}
conn.Close();
}
private void txtDetail_TextChanged(object sender, EventArgs e)
{
}
private void txtQty_KeyPress(object sender, KeyPressEventArgs e)
{
// if (!char.IsNumber(e.KeyChar)&&!char.IsControl(e.KeyChar))
// {
// e.Handled = true;
// }
}
private void txtSaleInvoice_TextChanged(object sender, EventArgs e)
{
}
private void txtBagsAmount_TextChanged(object sender, EventArgs e)
{
}
private void txtBagsRate_TextChanged(object sender, EventArgs e)
{
try
{
txtBagsAmount.Text = (int.Parse(txtQty.Text) * int.Parse(txtBagsRate.Text)).ToString();
}
catch
{
}
}
private void txtTotalAmount_TextChanged_1(object sender, EventArgs e)
{
}
//private void txtPacking_TextChanged_1(object sender, EventArgs e)
//{
//}
private void dataGridVSale_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void txtQty_TextChanged_1(object sender, EventArgs e)
{
try
{
txtTotalWeight.Text = (float.Parse(txtPacking.Text) * float.Parse(txtQty.Text)).ToString();
}
catch
{
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtRate_TextChanged_1(object sender, EventArgs e)
{
try
{
txtTotalAmount.Text = (float.Parse(txtTotalWeight.Text) / int.Parse(txtUnit.Text) * int.Parse(txtRate.Text)).ToString();
}
catch
{
}
}
private void txtTotalWeight_TextChanged(object sender, EventArgs e)
{
try
{
txtPacking.Text = (float.Parse(txtTotalWeight.Text) / float.Parse(txtQty.Text)).ToString();
}
catch
{
}
try
{
txtTotalAmount.Text = (float.Parse(txtTotalWeight.Text) / int.Parse(txtUnit.Text) * int.Parse(txtRate.Text)).ToString();
}
catch
{
}
}
private void txtUnit_TextChanged_1(object sender, EventArgs e)
{
try
{
txtTotalAmount.Text = (int.Parse(txtTotalWeight.Text) / int.Parse(txtUnit.Text) * int.Parse(txtRate.Text)).ToString();
}
catch
{
}
}
private void btnSave_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
//string col1 = dataGridViewSale[0, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col2 = dataGridViewSale[1, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col3 = dataGridViewSale[2, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col4 = dataGridViewSale[3, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col5 = dataGridViewSale[4, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col6 = dataGridViewSale[5, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col7 = dataGridViewSale[6, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col8 = dataGridViewSale[7, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col9 = dataGridViewSale[8, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col10 = dataGridViewSale[9, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col11 = dataGridViewSale[10, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col12 = dataGridViewSale[11, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
//string col13 = dataGridViewSale[12, dataGridViewSale.CurrentCell.RowIndex].Value.ToString();
int save = int.Parse(lblTotalAmount.Text);
lblTotalAmount.Text=save.ToString();
if (save>0)
{
for (int i = 0; i < dataGridViewSale.Rows.Count - 1; i++)
{
conn.Open();
string query = "INSERT INTO SaleItem(SaleId,BillNo,Date,PartyName,ItemCode,ItemName,Location,Qty,Packing,TotalWeight,Unit,Rate,Amount,Lot,BagsRate,BagsAmountEstimate,ItemParty)VALUES('" + txtInvoiceId.Text + "','" + txtGrandSale.Text + "','" + dateTimeSale.Text + "',N'" + txtPartyName.Text + "','" + dataGridViewSale.Rows[i].Cells[1].Value + "',N'" + dataGridViewSale.Rows[i].Cells[2].Value + "',N'" + dataGridViewSale.Rows[i].Cells[3].Value + "','" + dataGridViewSale.Rows[i].Cells[4].Value + "','" + dataGridViewSale.Rows[i].Cells[5].Value + "','" + dataGridViewSale.Rows[i].Cells[6].Value + "','" + dataGridViewSale.Rows[i].Cells[7].Value + "','" + dataGridViewSale.Rows[i].Cells[8].Value + "','" + dataGridViewSale.Rows[i].Cells[9].Value + "',N'" + dataGridViewSale.Rows[i].Cells[10].Value + "','" + dataGridViewSale.Rows[i].Cells[11].Value + "','" + dataGridViewSale.Rows[i].Cells[12].Value + "',N'" + dataGridViewSale.Rows[i].Cells[13].Value + "')";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
//اس ویلیوسے پہلے لازمی لکھناہے جو اردومیں ہو اوپروالی لائن کو غورسے دیکھیں N
sda.SelectCommand.ExecuteNonQuery();
conn.Close();
}
conn.Open();
string query1 = "INSERT INTO SaleMaster(VoucherId,BillNo,SaleDate,Transporter,PartyName,PartyNameText,Details,CashParty,Received,Remaining,TotalBill)VALUES('" + txtVoucherNo.Text + "','" + txtGrandSale.Text + "','" + dateTimeSale.Text + "',N'" + cBoxTransporter.Text + "',N'" + cBoxPartyName.Text + "',N'" + txtPartyName.Text + "',N'" + txtSDetail.Text + "',N'" + cBoxCashParty.Text + "','" + txtReceived.Text + "','" + lblRemaining.Text + "','" + lblTotalAmount.Text + "')";
SqlDataAdapter sda1 = new SqlDataAdapter(query1, conn);
sda1.SelectCommand.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Saved");
for (int i = 0; i < dataGridViewSale.Rows.Count - 1; i++)
{
conn.Open();
string query = "INSERT INTO Vouchers(SaleId,BillNo,Date,PartyName,Debit,Details)VALUES('" + txtInvoiceId.Text + "','" + txtGrandSale.Text + "','" + dateTimeSale.Text + "',N'" + cBoxPartyName.Text + "','" + dataGridViewSale.Rows[i].Cells[9].Value + "',N'" + txtSDetail.Text + "')";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
//اس ویلیوسے پہلے لازمی لکھناہے جو اردومیں ہو اوپروالی لائن کو غورسے دیکھیں N
sda.SelectCommand.ExecuteNonQuery();
conn.Close();
//SqlCommand cmd = new SqlCommand("INSERT INTO Vouchers (SaleId,BillNo,Date,PartyName,Debit,Details) values (@SaleId,@BillNo,@Date,@PartyName,@Debit,@Details)", conn);
//cmd.Parameters.AddWithValue("@SaleId", txtInvoiceId.Text);
//cmd.Parameters.AddWithValue("@BillNo", txtGrandSale.Text);
//cmd.Parameters.AddWithValue("@Date", dateTimeSale.Text);
//cmd.Parameters.AddWithValue("@PartyName", cBoxPartyName.Text);
//cmd.Parameters.AddWithValue("@Debit", dataGridViewSale.Rows[i].Cells[9].Value);
//cmd.Parameters.AddWithValue("@Details", txtSDetail.Text);
//conn.Open();
//cmd.ExecuteNonQuery();
//conn.Close();
//MessageBox.Show("Added successfully!");
}
for (int i = 0; i < dataGridViewSale.Rows.Count - 1; i++)
{
conn.Open();
string query = "INSERT INTO Vouchers(SaleId,BillNo,Date,PartyName,Credit,Details)VALUES('" + txtInvoiceId.Text + "','" + txtGrandSale.Text + "','" + dateTimeSale.Text + "',N'" + dataGridViewSale.Rows[i].Cells[13].Value + "','" + dataGridViewSale.Rows[i].Cells[9].Value + "',N'" + txtSDetail.Text + "')";
SqlDataAdapter sda = new SqlDataAdapter(query, conn);
//اس ویلیوسے پہلے لازمی لکھناہے جو اردومیں ہو اوپروالی لائن کو غورسے دیکھیں N
sda.SelectCommand.ExecuteNonQuery();
conn.Close();
}
conn.Open();
string query3 = "INSERT INTO Vouchers(SaleId,BillNo,Date,PartyName,Debit,Details)VALUES('" + txtInvoiceId.Text + "','" + txtGrandSale.Text + "','" + dateTimeSale.Text + "',N'" + cBoxCashParty.Text + "','" + txtReceived.Text + "',N'" + txtSDetail.Text + "')";
SqlDataAdapter sda3 = new SqlDataAdapter(query3, conn);
//اس ویلیوسے پہلے لازمی لکھناہے جو اردومیں ہو اوپروالی لائن کو غورسے دیکھیں N
sda3.SelectCommand.ExecuteNonQuery();
conn.Close();
conn.Open();
string query2 = "INSERT INTO Vouchers(SaleId,BillNo,Date,PartyName,Credit,Details)VALUES('" + txtInvoiceId.Text + "','" + txtGrandSale.Text + "','" + dateTimeSale.Text + "',N'" + cBoxPartyName.Text + "','" + txtReceived.Text + "',N'" + txtSDetail.Text + "')";
SqlDataAdapter sda2 = new SqlDataAdapter(query2, conn);
//اس ویلیوسے پہلے لازمی لکھناہے جو اردومیں ہو اوپروالی لائن کو غورسے دیکھیں N
sda2.SelectCommand.ExecuteNonQuery();
conn.Close();
this.dataGridViewSale.DataSource = null;
this.dataGridViewSale.Rows.Clear();
}
else
{
MessageBox.Show("No Bill Amount");
}
}
//try
//{
//}
//catch
//{
//}
private void txtReceived_TextChanged(object sender, EventArgs e)
{
try
{
lblRemaining.Text = (int.Parse(lblTotalAmount.Text) - int.Parse(txtReceived.Text)).ToString();
}
catch
{
}
}
private void txtPacking_TextChanged(object sender, EventArgs e)
{
try
{
txtTotalWeight.Text = (float.Parse(txtPacking.Text) * float.Parse(txtQty.Text)).ToString();
}
catch
{
}
}
private void btnNew_Click(object sender, EventArgs e)
{
txtSDetail.Clear();
this.Close();
FormSale sale = new FormSale();
//if ((sale.lblTotalAmount.Text)=>0)
//{
//}
sale.Show();
}
private void btnEdit_Click(object sender, EventArgs e)
{
FormSaleEdit edit = new FormSaleEdit();
edit.Show();
//FormSaleEdit saleEdit = new FormSaleEdit();
//saleEdit.Show();
}
private void txtGrandSale_TextChanged(object sender, EventArgs e)
{
}
public void SaleNo(string saleNumber)
{
saleNumber = txtGrandSale.Text;
}
//private void btnPrevious_Click(object sender, EventArgs e)
//{
// SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
// for (int i = 0; i < dataGridViewSale.Rows.Count - 1; i--)
// {
// conn.Open();
// string query = "SELECT*FROM SaleItem where BillNO='" + txtGrandSale.Text + "' ";
// sda = new SqlDataAdapter(query, conn);
// dt = new DataTable();
// sda.Fill(dt);
// dgvSale.DataSource = dt;
// conn.Close();
// }
//}
void fillcBoxTransporter()
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
sda = new SqlDataAdapter("select * from Transporter", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
cBoxTransporter.DataSource = dt;
cBoxTransporter.DisplayMember = "Name";
conn.Close();
}
void fillcBoxPartyName()
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
sda = new SqlDataAdapter("select PartyName from Parties", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
cBoxPartyName.DataSource = dt;
cBoxPartyName.DisplayMember = "PartyName";
conn.Close();
}
void fillcBoxICode()
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
sda = new SqlDataAdapter("select * from Items", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
cBoxICode.DataSource = dt;
cBoxICode.DisplayMember = "ItemCode";
conn.Close();
}
void fillcBoxLocation()
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
sda = new SqlDataAdapter("select * from Locations", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
cBoxLocation.DataSource = dt;
cBoxLocation.DisplayMember = "Location";
conn.Close();
}
void fillcBoxItemParty()
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
sda = new SqlDataAdapter("select * from Parties", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
cBoxItemParty.DataSource = dt;
cBoxItemParty.DisplayMember = "PartyName";
conn.Close();
}
void fillcBoxCashParty()
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
sda = new SqlDataAdapter("select * from Parties where Id=2", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
cBoxCashParty.DataSource = dt;
cBoxCashParty.DisplayMember = "PartyName";
conn.Close();
}
public void autoFillFields()
{ //conn = new SqlConnection();
//string query = "select *from Items where ItemCode='"+cBoxICode.Text+"' ";
//cmd = new SqlCommand(query, conn);
//SqlDataReader sdr;
//try
//{
// conn.Open();
// sdr = cmd.ExecuteReader();
// while (sdr.Read())
// {
// string iCode = sdr.GetInt32(1).ToString();
// string iParty = sdr.GetString(2);
// string iName = sdr.GetString(3);
// string iPacking = sdr.GetInt32(4).ToString();
// string iUnit = sdr.GetInt32(5).ToString();
// cBoxICode.Text = iCode;
// cBoxItemParty.Text = iParty;
// txtItemName.Text = iName;
// txtPacking.Text = iPacking;
// txtUnit.Text = iUnit;
// }
// conn.Close();
//}
//catch
//{
//}
// conn.Open();
//string query = "select *from Items where ItemCode='" + cBoxICode.SelectedItem.ToString() + "' ";
//sda = new SqlDataAdapter(query, conn);
//sda.SelectCommand.ExecuteNonQuery();
// dt = new DataTable();
// sda = new SqlDataAdapter(cmd);
// sda.Fill(dt);
// foreach (DataRow dr in dt.Rows)
// {
// cBoxICode.Text = dr["ItemCode"].ToString();
// txtItemName.Text = dr["ItemName"].ToString();
// txtPacking.Text = dr["Packing"].ToString();
// txtUnit.Text = dr["Unit"].ToString();
// cBoxItemParty.Text = dr["ItemParty"].ToString();
// }
// conn.Close();
}
private void cBoxICode_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
conn.Open();
cmd = new SqlCommand("SELECT *FROM Items where ItemCode='" + cBoxICode.Text + "' ", conn);
cmd.ExecuteNonQuery();
SqlDataReader dr;
dr = cmd.ExecuteReader();
while (dr.Read())
{
string iName = (string)dr["ItemName"].ToString();
txtItemName.Text = iName;
string iPacking = (string)dr["Packing"].ToString();
txtPacking.Text = iPacking;
string iUnit = (string)dr["Unit"].ToString();
txtUnit.Text = iUnit;
string iParty = (string)dr["ItemParty"].ToString();
cBoxItemParty.Text = iParty;
}
conn.Close();
}
private void cBoxICode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter)
{
if (string.IsNullOrEmpty(cBoxICode.Text))
{
((System.Windows.Forms.ComboBox)sender).DroppedDown = true;
}
else
{
cBoxLocation.Focus();
}
}
//else if (e.KeyCode==Keys.F1)
//{
// cBoxICode.Focus();
// ((System.Windows.Forms.ComboBox)sender).DroppedDown = true;
//}
else if (e.KeyCode==Keys.Insert)
{
txtReceived.Focus();
}
}
private void cBoxTransporter_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
cBoxPartyName.Focus();
}
else if (e.KeyCode == Keys.F1)
{
cBoxTransporter.Focus();
((System.Windows.Forms.ComboBox)sender).DroppedDown = true;
}
}
private void cBoxPartyName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
txtPartyName.Focus();
}
else if (e.KeyCode == Keys.F1)
{
cBoxPartyName.Focus();
((System.Windows.Forms.ComboBox)sender).DroppedDown = true;
}
txtPartyName.Text = cBoxPartyName.Text;
}
private void txtSDetail_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
cBoxICode.Focus();
}
}
private void cBoxLocation_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
txtQty.Focus();
}
}
private void txtQty_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
txtTotalWeight.Focus();
}
}
private void txtTotalWeight_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
txtRate.Focus();
}
}
private void txtRate_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
txtMarka.Focus();
}
}
private void txtMarka_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
txtBagsRate.Focus();
}
}
private void btnSave_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnPrint.Focus();
}
}
private void btninsert_KeyDown_1(object sender, KeyEventArgs e)
{
//if (e.KeyCode==Keys.Tab)
//{
// cBoxICode.Focus();
//}
}
private void txtBagsRate_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter)
{ DataTable dt = new DataTable();
dt.Columns.Add("LineId");
dt.Columns.Add("code");
dt.Columns.Add("item");
dt.Columns.Add("location");
dt.Columns.Add("qty");
dt.Columns.Add("packing");
dt.Columns.Add("totalWeight");
dt.Columns.Add("unit");
dt.Columns.Add("rate");
dt.Columns.Add("amount");
dt.Columns.Add("marka");
dt.Columns.Add("bagsRate");
dt.Columns.Add("bagsAmount");
dt.Columns.Add("itemParty");
DataRow row = dt.NewRow();
row["LineId"] = cBoxICode.Text;
row["code"] = cBoxICode.Text;
row["item"] = txtItemName.Text;
row["location"] = cBoxLocation.Text;
row["qty"] = txtQty.Text;
row["packing"] = txtPacking.Text;
row["totalWeight"] = txtTotalWeight.Text;
row["unit"] = txtUnit.Text;
row["rate"] = txtRate.Text;
row["amount"] = txtTotalAmount.Text;
row["marka"] = txtMarka.Text;
row["bagsRate"] = txtBagsRate.Text;
row["bagsAmount"] =txtBagsAmount.Text;
row["itemParty"] = cBoxItemParty.Text;
dt.Rows.Add(row);
foreach (DataRow Drow in dt.Rows)
{
int num = dataGridViewSale.Rows.Add();
dataGridViewSale.Rows[num].Cells[0].Value = Drow["LineId"].ToString();
dataGridViewSale.Rows[num].Cells[1].Value = Drow["code"].ToString();
dataGridViewSale.Rows[num].Cells[2].Value = Drow["item"].ToString();
dataGridViewSale.Rows[num].Cells[3].Value = Drow["location"].ToString();
dataGridViewSale.Rows[num].Cells[4].Value = Drow["qty"].ToString();
dataGridViewSale.Rows[num].Cells[5].Value = Drow["packing"].ToString();
dataGridViewSale.Rows[num].Cells[6].Value = Drow["totalWeight"].ToString();
dataGridViewSale.Rows[num].Cells[7].Value = Drow["unit"].ToString();
dataGridViewSale.Rows[num].Cells[8].Value = Drow["rate"].ToString();
dataGridViewSale.Rows[num].Cells[9].Value = Drow["amount"].ToString();
dataGridViewSale.Rows[num].Cells[10].Value = Drow["marka"].ToString();
dataGridViewSale.Rows[num].Cells[11].Value = Drow["bagsRate"].ToString();
dataGridViewSale.Rows[num].Cells[12].Value = Drow["bagsAmount"].ToString();
dataGridViewSale.Rows[num].Cells[13].Value = Drow["itemParty"].ToString();
//cBoxTransporter.Text = "";
//cBoxPartyName.Text = "";
cBoxICode.Text="";
txtItemName.Clear();
txtQty.Clear();
txtTotalWeight.Clear();
txtPacking.Clear();
txtRate.Clear();
txtTotalAmount.Clear();
//txtReceived.Clear();
try
{
int A = 0, B = 0;
for (A = 0; A < dataGridViewSale.Rows.Count; ++A)
{
B += Convert.ToInt32(dataGridViewSale.Rows[A].Cells[4].Value);
}
lblTotalTadad.Text = B.ToString();
int C = 0, D = 0;
for (C = 0; C < dataGridViewSale.Rows.Count; ++C)
{
D += Convert.ToInt32(dataGridViewSale.Rows[C].Cells[12].Value);
}
lblTotalBardana.Text = D.ToString();
}
catch
{
}
}
try
{
int E = 0, F = 0;
for (E = 0; E < dataGridViewSale.Rows.Count; ++E)
{
F += Convert.ToInt32(dataGridViewSale.Rows[E].Cells[9].Value);
}
lblTotalAmount.Text = F.ToString();
}
catch
{
}
cBoxICode.Focus();
}
}
private void btnPrint_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnNew.Focus();
}
}
private void btnNew_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
cBoxTransporter.Focus();
}
}
private void txtReceived_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter)
{
btnSave.Focus();
}
}
private void txtSDetail_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter)
{
cBoxICode.Focus();
}
}
private void txtPartyName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode==Keys.Enter)
{
txtSDetail.Focus();
}
}
private void btnNext_Click(object sender, EventArgs e)
{
}
private void btnUpdate_Click(object sender, EventArgs e)
{
//SqlConnection conn = new SqlConnection("Data Source=isolinks;Initial Catalog=WindowsDb;Integrated Security=True");
//conn.Open();
//string query = "Update Id, VoucherId, BillNo, SaleDate, Transporter,PartyId,PartyName,PartyNameText,Details,CashParty,Received,Remaining,TotalBill, LineId, ItemCode, ItemName, Location, Qty,Packing, TotalWeight, Unit,Rate, Amount, Lot, BagsRate, BagsAmountEstimate,ItemParty,ItemId, LocationId FROM SaleBillView where BillNO='" + txtGrandSale.Text + "' ";
//sda = new SqlDataAdapter(query, conn);
//dt = new DataTable();
//sda.Fill(dt);
//dgvSale.DataSource = dt;
//conn.Close();
//dbo.SaleMaster.Id, dbo.SaleMaster.VoucherId, dbo.SaleMaster.BillNo, dbo.SaleMaster.SaleDate, dbo.SaleMaster.Transporter, dbo.SaleMaster.PartyId, dbo.SaleMaster.PartyName,
// dbo.SaleMaster.PartyNameText, dbo.SaleMaster.Details, dbo.SaleMaster.CashParty, dbo.SaleMaster.Received, dbo.SaleMaster.Remaining, dbo.SaleMaster.TotalBill, dbo.SaleItem.LineId,
// dbo.SaleItem.ItemCode, dbo.SaleItem.ItemName, dbo.SaleItem.Location, dbo.SaleItem.Qty, dbo.SaleItem.Packing, dbo.SaleItem.TotalWeight, dbo.SaleItem.Unit, dbo.SaleItem.Rate, dbo.SaleItem.Amount,
// dbo.SaleItem.Lot, dbo.SaleItem.BagsRate, dbo.SaleItem.BagsAmountEstimate, dbo.SaleItem.ItemParty, dbo.SaleItem.ItemId, dbo.SaleItem.LocationId
}
}
}
What I have tried:
the codes above i have tried by different ways.