private void btnPrint_Click(object sender, EventArgs e) { string orderID, orderdate, ordertime; SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-9CBGPDG\ASHIRAFZAL;Initial Catalog=PizzaPoint;Integrated Security=SSPI;MultipleActiveResultSets = True"); con.Open(); SqlTransaction tran = con.BeginTransaction(); SqlCommand cmd = new SqlCommand("select top 1 OrderID,Ordertime,OrderDate from Orders order by OrderID DESC", con, tran); cmd.ExecuteNonQuery(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { orderID = dr["OrderID"].ToString(); ordertime = dr["Ordertime"].ToString(); orderdate = dr["OrderDate"].ToString(); OrdersDetails obj = ordersDetailsBindingSource.Current as OrdersDetails; if (obj != null) { using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } string query = "select top 1 CustID,CustName,OrderDate,OrderID,OrderTime,ProductName,ProductPrice,ProductQuantity,TotalAmount,Totalqty from Bill order by CustID DESC "; //string query = "select CustID,CustName,OrderDate,OrderID,OrderTime,ProductName,ProductPrice,ProductQuantity,TotalAmount,Totalqty from Bill where Ordertime = '"+ ordertime +"' and orderDate = '" + orderdate +"' "; List <BillDetails> list = db.Query <BillDetails>(query, commandType: CommandType.Text).ToList(); //OrderID = '" + orderID + "' // using (BillPrint frm = new BillPrint(obj, list)) { this.Close(); frm.ShowDialog(); } } } } } }
public BillPrint(OrdersDetails orders, List <BillDetails> bill) { InitializeComponent(); _orders = orders; _bill = bill; }