public BillDetailsWindow(PurchaseData salesData) { InitializeComponent(); datePicker.SelectedDate = salesData.datePurchase; invoiceNumberTB.Text = salesData.invoiceNo; customerInfoTb.Text = salesData.vendorName; long totAmount = Convert.ToInt64(salesData.totalAmount); totalAmountLabel.Content = totAmount; priceInWordLabel.Content = SPTHelper.NumberToWords(totAmount) + " Only."; paymentAmountTB.Text = salesData.payment.ToString(); ConnectFetchFromSaleslistTable(salesData.invoiceNo); SetBillingInfoFromSPTSettings(); }
private void ConnectFetchFromSaleslistTable() { //define the connection reference and initialize it msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False"); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); //define the connection used by the command object msqlCommand.Connection = msqlConnection; //open the connection msqlConnection.Open(); TimeSpan diff = (TimeSpan)(endDatePicker.SelectedDate - startDatePicker.SelectedDate); msqlCommand.CommandText = "SELECT * FROM purchaselist where date(purchaselist.datePurchase) >= DATE_SUB( @enddate, INTERVAL @diff DAY);"; msqlCommand.Parameters.AddWithValue("@enddate", endDatePicker.SelectedDate); msqlCommand.Parameters.AddWithValue("@diff", diff.Days); MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader(); _purchaseDataCollection.Clear(); while (msqlReader.Read()) { PurchaseData purchaseData = new PurchaseData(); purchaseData.vendorId = msqlReader.GetString("vendorId"); purchaseData.vendorName = msqlReader.GetString("vendorName"); purchaseData.datePurchase = msqlReader.GetDateTime("datePurchase"); purchaseData.invoiceNo = msqlReader.GetString("invoiceNo"); purchaseData.payment = msqlReader.GetDouble("payment"); purchaseData.totalAmount = msqlReader.GetDouble("totalAmount"); //purchaseData.serialNo = (_purchaseDataCollection.Count + 1).ToString(); _purchaseDataCollection.Add(purchaseData); } } catch (Exception er) { MessageBox.Show(er.Message); } finally { //always close the connection msqlConnection.Close(); } }