private void tsbPrint_Click(object sender, EventArgs e) { int rowcount = dgvPODetails.RowCount; PrintPO.itemcode = ""; PrintPO.quantity = ""; PrintPO.description = ""; PrintPO.unitvalue = ""; PrintPO.totalvalue = ""; for (int i = 0; i < rowcount; i++) { PrintPO.itemcode += dgvPODetails.Rows[i].Cells["ItemCode"].Value + Environment.NewLine; PrintPO.quantity += dgvPODetails.Rows[i].Cells["Quantity"].Value + Environment.NewLine; PrintPO.description += dgvPODetails.Rows[i].Cells["ItemDescription"].Value + Environment.NewLine; PrintPO.unitvalue += dgvPODetails.Rows[i].Cells["Rate"].Value + Environment.NewLine; PrintPO.totalvalue += dgvPODetails.Rows[i].Cells["Amount"].Value + Environment.NewLine; } PrintPO ppo = new PrintPO(); ppo.ShowDialog(); }
private void btnSave_Click(object sender, EventArgs e) { PrintPO.ordernumber = null; PrintPO.orderdate = null; PrintPO.supplier = null; PrintPO.totalamount = null; PrintPO.suppAddress = null; PrintPO.itemcode = null; PrintPO.quantity = null; PrintPO.description = null; PrintPO.unitvalue = null; PrintPO.totalvalue = null; if (cbSupplierName.Text == "") { MessageBox.Show("Please select a supplier", "Incomplete Purchase Order", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbSupplierName.Focus(); return; } if (cbLocation.Text == "") { MessageBox.Show("Please select a location", "Incomplete Purchase Order", MessageBoxButtons.OK, MessageBoxIcon.Warning); cbLocation.Focus(); return; } if (dgvItemDetail.Rows[0].Cells[0].Value == null) { MessageBox.Show("Please select an item to purchase", "Incomplete Purchase Order", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } adp = new SqlDataAdapter("Select * from PurchaseOrder", con); ds.Clear(); adp.Fill(ds, "PurchaseOrder"); DataTable MyTable = ds.Tables["PurchaseOrder"]; DataRow newRow = MyTable.NewRow(); newRow[0] = lblPONumber.Text; newRow[1] = cbSupplierName.Text; newRow[2] = lblDate.Text; newRow[3] = "Not Received"; newRow[4] = lblTotalValue.Text; //Adding new row to the table MyTable.Rows.Add(newRow); //Generating Insert Command SqlCommandBuilder UpdateDataCommand = new SqlCommandBuilder(adp); adp.InsertCommand = UpdateDataCommand.GetInsertCommand(); //Addding row to the dataset adp.Update(ds, "PurchaseOrder"); //Updating Database with the new row ds.AcceptChanges(); //--Storing in 'PODetails' Table-- int rows; rows = dgvItemDetail.RowCount - 1; // Retrieving deatils of the PoDetails Table SqlDataAdapter adp1 = new SqlDataAdapter("Select * from PODetails", con); DataSet ds1 = new DataSet(); ds1.Clear(); adp1.Fill(ds1, "PODetails"); //creating instance of the PODetails table DataTable MyTable1 = ds1.Tables["PODetails"]; for (int i = 0; i < rows; i++) { DataRow newRow1 = MyTable1.NewRow(); newRow1[0] = lblPONumber.Text; newRow1[1] = cbLocation.Text; newRow1[2] = dgvItemDetail.Rows[i].Cells["Item"].Value; newRow1[3] = dgvItemDetail.Rows[i].Cells["Description"].Value; newRow1[4] = dgvItemDetail.Rows[i].Cells["Quantity"].Value; newRow1[5] = dgvItemDetail.Rows[i].Cells["UnitValue"].Value; newRow1[6] = dgvItemDetail.Rows[i].Cells["TotalValue"].Value; //Adding new row to the table MyTable1.Rows.Add(newRow1); //Generating Insert Command SqlCommandBuilder UpdateDataCommand1 = new SqlCommandBuilder(adp1); adp1.InsertCommand = UpdateDataCommand1.GetInsertCommand(); //Addding row to the dataset adp1.Update(ds1, "PODetails"); //Updating Database with the new row ds1.AcceptChanges(); } con.Close(); MessageBox.Show("Purchase Order Details Saved"); // Creating a print Page PrintPO.ordernumber = lblPONumber.Text; PrintPO.orderdate = lblDate.Text; PrintPO.supplier = cbSupplierName.Text; PrintPO.totalamount = lblTotalValue.Text; SqlDataAdapter adp3 = new SqlDataAdapter("Select SuppAddress from Suppliers where SuppName = '" + cbSupplierName.Text + "'", con); DataSet ds3 = new DataSet(); ds.Clear(); adp3.Fill(ds3, "Suppliers"); PrintPO.suppAddress = ds3.Tables["Suppliers"].Rows[0]["SuppAddress"].ToString(); int rowcount = dgvItemDetail.RowCount; for (int i = 0; i < rowcount; i++) { PrintPO.itemcode += dgvItemDetail.Rows[i].Cells["Item"].Value + Environment.NewLine; PrintPO.quantity += dgvItemDetail.Rows[i].Cells["Quantity"].Value + Environment.NewLine; PrintPO.description += dgvItemDetail.Rows[i].Cells["Description"].Value + Environment.NewLine; PrintPO.unitvalue += dgvItemDetail.Rows[i].Cells["UnitValue"].Value + Environment.NewLine; PrintPO.totalvalue += dgvItemDetail.Rows[i].Cells["TotalValue"].Value + Environment.NewLine; } PrintPO ppo = new PrintPO(); ppo.ShowDialog(); //Resetting the Purchase Order Form lblTotalValue.Text = "0"; dgvItemDetail.Rows.Clear(); cbLocation.SelectedIndex = -1; cbSupplierName.SelectedIndex = -1; lblPONumber.Text = PONumber(); }