void AddNewVendorWindowObject_OnAddNewvendorData(VendorsData vendordataobject) { int turnover = 0; vendordataobject.vendorTurnOver = turnover; vendordataobject.vendorDue = turnover; vendordataobject.vendorId = GetVendorId(); //vendordataobject.serialNo = vendorCount.ToString(); _vendorsCollection.Add(vendordataobject); }
public EditVendorWindow(VendorsData vendorToEdit) { InitializeComponent(); _vendorToEdit = vendorToEdit; NameDataTB.Text = _vendorToEdit.vendorName; AddrDataTB.Text = _vendorToEdit.vendorAdress; phDataTB.Text = _vendorToEdit.phoneNumber; vatdataTB.Text = _vendorToEdit.vendorVatNo; }
private void EditVendor(VendorsData returnEditedVendorData) { 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(); msqlCommand.Connection = msqlConnection; msqlConnection.Open(); msqlCommand.CommandText = "UPDATE vendors SET vendor_name='" + returnEditedVendorData.vendorName + "', vendor_address='" + returnEditedVendorData.vendorAdress + "', ph_no='" + returnEditedVendorData.phoneNumber + "', vat_no='" + returnEditedVendorData.vendorVatNo + "' WHERE vendor_id='" + returnEditedVendorData.vendorId + "'; "; msqlCommand.ExecuteNonQuery(); } catch (Exception er) { MessageBox.Show(er.Message); } finally { //always close the connection msqlConnection.Close(); } }
private void ShowVendorsList() { MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False"); //define the connection used by the command object msqlCommand.Connection = msqlConnection; if (msqlConnection.State != System.Data.ConnectionState.Open) msqlConnection.Open(); msqlCommand.CommandText = "SELECT * FROM vendors"; MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader(); _vendorCollection.Clear(); while (msqlReader.Read()) { VendorsData cusData = new VendorsData(); cusData.vendorName = msqlReader.GetString("vendor_name"); cusData.vendorId = msqlReader.GetString("vendor_id"); cusData.vendorAdress = msqlReader.GetString("vendor_address"); cusData.phoneNumber = msqlReader.GetString("ph_no"); _vendorCollection.Add(cusData); } msqlConnection.Close(); }
private void fetchevendorData() { 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(); msqlCommand.Connection = msqlConnection; msqlConnection.Open(); msqlCommand.CommandText = "Select * from vendors;"; MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader(); _vendorsCollection.Clear(); while (msqlReader.Read()) { VendorsData vendorsDataObject = new VendorsData(); //vendorsDataObject.serialNo = msqlReader.GetString("sl_no"); vendorsDataObject.vendorAdress = msqlReader.GetString("vendor_address"); vendorsDataObject.phoneNumber = msqlReader.GetString("ph_no"); vendorsDataObject.vendorName = msqlReader.GetString("vendor_name"); vendorsDataObject.vendorVatNo = msqlReader.GetString("vat_no"); vendorsDataObject.vendorId = msqlReader.GetString("vendor_id"); vendorsDataObject.vendorTurnOver = msqlReader.GetDouble("turn_over"); vendorsDataObject.vendorDue = msqlReader.GetDouble("due"); _vendorsCollection.Add(vendorsDataObject); } } catch (Exception er) { MessageBox.Show(er.Message); } finally { //always close the connection msqlConnection.Close(); } }
void editWindow_OnEditVendorsData(VendorsData returnEditedVendorData) { //finding the element VendorsData vData = _vendorsCollection.Where(item => item.vendorId.Equals(returnEditedVendorData.vendorId)).First(); //finding the element position int itemIdex = _vendorsCollection.IndexOf(vData); //remove the element so that the list gets refreshed _vendorsCollection.RemoveAt(itemIdex); //insert the edited element at same position _vendorsCollection.Insert(itemIdex, returnEditedVendorData); }