//public static GetBookingDetails GetRecordsPackages(int CusId) //{ // GetBookingDetails LGetBookingDeatils = new GetBookingDetails(); // System.Data.SqlClient.SqlDataReader reader1; // string Query1 = "select [Packages].[PkgName]as PackageName,[Packages].[PkgStartDate]," + // "[Packages].[PkgEndDate],[Packages].[PkgDesc] as PackageDesc,[Packages].[PkgBasePrice]," + // "[Bookings].[BookingDate],[Bookings].[BookingNo],[Bookings].[TravelerCount]," + // "[Customers].[CustFirstName],[Customers].[CustLastName],[Customers].[CustCity]," + // "[Customers].[CustCountry],[Customers].[CustBusPhone],[Customers].[CustEmail]," + // "[Customers].[CustPostal] from[dbo].[Customers] inner join[dbo].[Bookings] on " + // "[dbo].[Customers].[CustomerId] = [dbo].[Bookings].[CustomerId] inner join[dbo].[Packages] " + // "on [dbo].[Packages].[PackageId] = [dbo].[Bookings].[PackageId] where [Bookings].[CustomerId] = " + CusId + " "; // try // { // using (System.Data.SqlClient.SqlConnection sconn = Connection.GetConnection()) // { // sconn.Open(); // using (System.Data.SqlClient.SqlCommand command1 = new System.Data.SqlClient.SqlCommand(Query1, sconn)) // { // reader1 = command1.ExecuteReader(System.Data.CommandBehavior.CloseConnection); // while (reader1.Read()) // { // LGetBookingDeatils.PackageName = Convert.ToString(reader1["PackageName"]); // LGetBookingDeatils.PkgStartDate = Convert.ToDateTime(reader1["PkgStartDate"]); // LGetBookingDeatils.PkgEndDate = Convert.ToDateTime(reader1["PkgEndDate"]); // LGetBookingDeatils.PackageDesc = Convert.ToString(reader1["PackageDesc"]); // LGetBookingDeatils.PkgBasePrice = Convert.ToDecimal(reader1["PkgBasePrice"]); // LGetBookingDeatils.BookingDate = Convert.ToDateTime(reader1["BookingDate"]); // LGetBookingDeatils.Bookingnumber = reader1["BookingNo"].ToString(); // LGetBookingDeatils.TravelerCount = Convert.ToInt16(reader1["TravelerCount"]); // totalprice += Convert.ToDecimal(reader1["PkgBasePrice"]); // LGetBookingDeatils.TotalPrice = Convert.ToDecimal(totalprice); // LGetBookingDeatils.CusFirstName = Convert.ToString(reader1["PackageName"]); // LGetBookingDeatils.CusLastName = Convert.ToString(reader1["PackageName"]); // LGetBookingDeatils.CusCity = Convert.ToString(reader1["PackageName"]); // LGetBookingDeatils.CusCountry = Convert.ToString(reader1["PackageName"]); // LGetBookingDeatils.CusBusPhone = Convert.ToString(reader1["PackageName"]); // LGetBookingDeatils.CustPostal = Convert.ToString(reader1["PackageName"]); // } // } // sconn.Close(); // } // } // catch (System.Data.SqlClient.SqlException ex) // { // throw ex; // } // finally // { // } // return LGetBookingDeatils; //} public static List <GetBookingDetails> GetRecordsPackages(int CusId) { List <GetBookingDetails> GetBookingDeatils = new List <GetBookingDetails>(); GetBookingDetails LGetBookingDeatils = null; GetCustomerDeatils = new List <CustomersDetails>(); CustomersDetails LGetCustomer = null; System.Data.SqlClient.SqlDataReader reader1; string Query1 = "select [Packages].[PkgName]as PackageName,[Packages].[PackageId],[Packages].[PkgStartDate]," + "[Packages].[PkgEndDate],[Packages].[PkgDesc] as PackageDesc,[Packages].[PkgBasePrice]," + "[Bookings].[BookingDate],[Bookings].[BookingNo],[Bookings].[TravelerCount]," + "[Customers].[CustFirstName],[Customers].[CustLastName],[Customers].[CustCity]," + "[Customers].[CustCountry],[Customers].[CustHomePhone],[Customers].[CustEmail]," + "[Customers].[CustPostal] from[dbo].[Customers] inner join[dbo].[Bookings] on " + "[dbo].[Customers].[CustomerId] = [dbo].[Bookings].[CustomerId] inner join[dbo].[Packages] " + "on [dbo].[Packages].[PackageId] = [dbo].[Bookings].[PackageId] where [Bookings].[CustomerId] = " + CusId + " "; try { using (System.Data.SqlClient.SqlConnection sconn = Connection.GetConnection()) { sconn.Open(); using (System.Data.SqlClient.SqlCommand command1 = new System.Data.SqlClient.SqlCommand(Query1, sconn)) { reader1 = command1.ExecuteReader(System.Data.CommandBehavior.CloseConnection); totalprice = 0; while (reader1.Read()) { totalprice += (Convert.ToDecimal(reader1["PkgBasePrice"]) * Convert.ToDecimal(reader1["TravelerCount"]));; LGetBookingDeatils = new GetBookingDetails((int)reader1["PackageId"], Convert.ToString(reader1["PackageName"]).ToString(), Convert.ToDateTime(reader1["PkgStartDate"]), Convert.ToDateTime(reader1["PkgEndDate"]), Convert.ToString(reader1["PackageDesc"]), Convert.ToDouble(reader1["PkgBasePrice"]), Convert.ToDateTime(reader1["BookingDate"]), Convert.ToString(reader1["BookingNo"]), Convert.ToInt16(reader1["TravelerCount"]), totalprice); GetBookingDeatils.Add(LGetBookingDeatils); LGetCustomer = new CustomersDetails(CusId, Convert.ToString(reader1["CustFirstName"]), Convert.ToString(reader1["CustLastName"]), Convert.ToString(reader1["CustCity"]), Convert.ToString(reader1["CustCountry"]), Convert.ToString(reader1["CustHomePhone"]), Convert.ToString(reader1["CustEmail"]), Convert.ToString(reader1["CustPostal"])); GetCustomerDeatils.Add(LGetCustomer); } } sconn.Close(); } } catch (System.Data.SqlClient.SqlException ex) { throw ex; } finally { } return(GetBookingDeatils); }
public static List <CustomersDetails> GetAllCustomers() { List <CustomersDetails> customers = new List <CustomersDetails>(); CustomersDetails cust = null; System.Data.SqlClient.SqlConnection conn = Connection.GetConnection(); string selectStatement = "select CustomerId,CustFirstName,CustLastName, CustAddress, CustCity, CustProv, " + "CustPostal, CustCountry, CustHomePhone,CustBusPhone, " + "CustEmail from Customers where CustomerId = " + Users.CustomerId + ""; System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(selectStatement, conn); try { conn.Open(); System.Data.SqlClient.SqlDataReader Dreader = cmd.ExecuteReader(); while (Dreader.Read()) // while there are customers { cust = new CustomersDetails(); CustomersDetails.CustomerId = (int)Dreader["CustomerId"]; CustomersDetails.CusFirstName = (string)Dreader["CustFirstName"]; CustomersDetails.CusLastName = (string)Dreader["CustLastName"]; CustomersDetails.CusCity = (string)Dreader["CustCity"]; CustomersDetails.CustPostal = (string)Dreader["CustPostal"]; CustomersDetails.CusCountry = (string)Dreader["CustCountry"]; CustomersDetails.CusBusPhone = (string)Dreader["CustBusPhone"]; customers.Add(cust); } } catch (System.Data.SqlClient.SqlException ex) { throw ex; } finally { conn.Close(); } return(customers); }