private void btnSave_Click(object sender, EventArgs e) { if (ReturnGrid.Rows.Count > 0) { bool result = false; sqlhelp = new SQLHelper(); result = sqlhelp.ExecuteNonQuery("insert into Payment(TransactionNo,TotalAmount,DiscountAmount,BillPaid,CreatedBy) values" + "('" + lblBillNo.Text + "'," + "-" + TotalActualAmount + "," + lblDiscount.Text + "," + txtTotalRefund.Text + "," + GlobalData.UserID + ")"); if (result == true) { string PaymentId = sqlhelp.ExecuteScalar("select max(PaymentID) from Payment"); for (int i = 0; i < ReturnGrid.Rows.Count; i++) { result = sqlhelp.ExecuteNonQuery("Update Transactions set ReturnQty= ((ReturnQty) + (" + int.Parse("-" + ReturnGrid.Rows[i].Cells["Quantity"].Value.ToString()) + ")) where TransactionID=" + ReturnGrid.Rows[i].Cells["TransactionID"].Value.ToString() + ""); result = sqlhelp.ExecuteNonQuery("Insert into Transactions(PaymentID,CategoryID,ItemID,Barcode,ItemPrice,SaleQty,ReturnQty,CreatedBy) Values" + "(" + PaymentId + "," + "" + ReturnGrid.Rows[i].Cells["CategoryID"].Value.ToString() + "," + "" + ReturnGrid.Rows[i].Cells["ItemID"].Value.ToString() + "," + "'" + ReturnGrid.Rows[i].Cells["Barcode"].Value.ToString() + "'," + "" + ReturnGrid.Rows[i].Cells["Item Price"].Value.ToString() + "," + "" + int.Parse("-" + ReturnGrid.Rows[i].Cells["Quantity"].Value.ToString()) + "," + "" + int.Parse(ReturnGrid.Rows[i].Cells["Quantity"].Value.ToString()) + "," + "" + GlobalData.UserID + ")"); result = sqlhelp.ExecuteNonQuery("update Stock set StockQuantity= (StockQuantity+" + int.Parse(ReturnGrid.Rows[i].Cells["Quantity"].Value.ToString()) + ")" + " where CategoryID=" + ReturnGrid.Rows[i].Cells["CategoryID"].Value.ToString() + "" + " and ItemID=" + ReturnGrid.Rows[i].Cells["ItemID"].Value.ToString() + " and Barcode='" + ReturnGrid.Rows[i].Cells["Barcode"].Value.ToString() + "'"); } } if (result == true) { FrmMessage.Show("Refund Transaction Successful", caption, OkButton, InformationIcon); SalesReturn f2 = new SalesReturn { MdiParent = this.MdiParent, Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))), Dock = DockStyle.Fill }; f2.Show(); } } else { FrmMessage.Show("Please select the Items which you want to return"); } }
private void btnSearch_Click(object sender, EventArgs e) { try { sqlhelp = new SQLHelper(); ds = new DataSet(); dt = new DataTable(); if (dt.Columns.Count < 1) { dt.Columns.Add("TransactionID"); dt.Columns.Add("CategoryID"); dt.Columns.Add("Category"); dt.Columns.Add("ItemID"); dt.Columns.Add("Barcode"); dt.Columns.Add("Item"); dt.Columns.Add("Quantity"); dt.Columns.Add("Item Price"); dt.Columns.Add("Total Amount"); } if (string.IsNullOrEmpty(txtSrchTransNo.Text)) { FrmMessage.Show("Please Enter Your Bill No", caption, OkButton, ErrorIcon); } else { ds = sqlhelp.ExecuteQueries("select * from TransFetch where TransactionNo='" + txtSrchTransNo.Text.Trim() + "'"); if (ds.Tables[0].Rows.Count > 0) { //dt = ds.Tables[0].Copy(); //DataView dView = new DataView(dt); //string[] arrColumns = { "TransactionNo", "Customer Name", "Phone" }; //dt = dView.ToTable(true, arrColumns); //dt.AcceptChanges(); //if (dt.Rows.Count > 0) //{ lblBillNo.Text = ds.Tables[0].Rows[0]["TransactionNo"].ToString(); lblDiscount.Text = ds.Tables[0].Rows[0]["DiscountAmount"].ToString(); lblBookingDate.Text = DateTime.Parse(ds.Tables[0].Rows[0]["CreatedDate"].ToString()).ToString("dd-MM-yyyy"); //*************binding values to gridview******************** TransGrid.DataSource = ds.Tables[0]; TransGrid.Columns["PaymentID"].Visible = false; TransGrid.Columns["TransactionNo"].Visible = false; TransGrid.Columns["CategoryID"].Visible = false; TransGrid.Columns["ItemID"].Visible = false; TransGrid.Columns["TotalAmount"].Visible = false; TransGrid.Columns["DiscountAmount"].Visible = false; TransGrid.Columns["BillPaid"].Visible = false; TransGrid.Columns["CreatedDate"].Visible = false; TransGrid.Columns["TransactionID"].Visible = false; TransGrid.Columns["RemainingQty"].Visible = false; //} //else //{ //} ReturnGrid.DataSource = dt; ReturnGrid.Columns["CategoryID"].Visible = false; ReturnGrid.Columns["ItemID"].Visible = false; ReturnGrid.Columns["TransactionID"].Visible = false; } else { FrmMessage.Show("No Records found !!!", caption, OkButton, InformationIcon); SalesReturn form = new SalesReturn { MdiParent = this.MdiParent, Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))), Dock = DockStyle.Fill }; form.Show(); } } } catch (Exception ex) { } }