public SupplierData getSupplierDetails(String supplierID) { SupplierData supplier = new SupplierData(); try { String query = "SELECT * from supplier where ID = @SupplierID"; conn = new SqlConnection(connectionString); SqlCommand comm = new SqlCommand(query, conn); comm.Parameters.AddWithValue("@SupplierID", supplierID); conn.Open(); reader = comm.ExecuteReader(); while (reader.Read()) { supplier.Suppliername = reader.GetString(1); supplier.CompanyName = reader.GetString(2); supplier.Address = reader.GetString(3); supplier.MobileContact = reader.GetInt32(4); supplier.HomeContact = reader.GetInt32(5); } } catch (SqlException ex) { throw ex; } finally { if (conn != null) { conn.Close(); } } return(supplier); }
public int executeSupplierUpdate(SupplierData supplier, String supplierID) { String query = "UPDATE supplier SET name = @Name, companyName = @CompanyName, address = @Address, mobile = @Mobile, homeContact = @HomeContact WHERE ID = @SupplierID "; int affectedLines = 0; try { conn = new SqlConnection(connectionString); SqlCommand comm = new SqlCommand(query, conn); comm.Parameters.AddWithValue("@SupplierID", Convert.ToInt32(supplierID)); comm.Parameters.AddWithValue("@Name", supplier.Suppliername); comm.Parameters.AddWithValue("@CompanyName", supplier.CompanyName); comm.Parameters.AddWithValue("@Address", supplier.Address); comm.Parameters.AddWithValue("@Mobile", supplier.MobileContact); comm.Parameters.AddWithValue("@HomeContact", supplier.HomeContact); conn.Open(); affectedLines = comm.ExecuteNonQuery(); } catch (SqlException ex) { throw ex; } finally { if (conn != null) { conn.Close(); } } return(affectedLines); }
public int executeSupplierEntry(SupplierData supplier) { String query = "INSERT INTO supplier(name, companyName, address, mobile, homeContact) VALUES (@Name,@CompanyName,@Address,@Mobile,@HomeContact)"; int affectedLines = 0; try { conn = new SqlConnection(connectionString); SqlCommand comm = new SqlCommand(query, conn); comm.Parameters.AddWithValue("@Name", supplier.Suppliername); comm.Parameters.AddWithValue("@CompanyName", supplier.CompanyName); comm.Parameters.AddWithValue("@Address", supplier.Address); comm.Parameters.AddWithValue("@Mobile", supplier.MobileContact); comm.Parameters.AddWithValue("@HomeContact", supplier.HomeContact); conn.Open(); affectedLines = comm.ExecuteNonQuery(); } catch (SqlException ex) { throw ex; } finally { if (conn != null) { conn.Close(); } } return(affectedLines); }
public UpdateSupplier(String supplierID) { InitializeComponent(); DataContext = this; this.supplierID = supplierID; handleDatabase = new HandleDatabase(); supplier = handleDatabase.getSupplierDetails(supplierID); }
private async void saveButton_Click(object sender, RoutedEventArgs e) { val = new Validation(); if (val.isEmpty(supplierName) || val.isEmpty(companyName) || val.isEmpty(addressLine1) || val.isEmpty(addressLine2) || val.isEmpty(mobile.ToString()) || val.isEmpty(homeContact.ToString())) { await this.ShowMessageAsync("Error", "Data Cannot be Empty", MessageDialogStyle.Affirmative); } else { int affectedLines = 0; supplier = new SupplierData(); supplier.Suppliername = SupplierName.Text; supplier.CompanyName = CompanyName.Text; supplier.Address = Address1.Text + ' ' + Address2.Text + ' ' + Address3.Text; supplier.MobileContact = Convert.ToInt32(MobileContact.Text); supplier.HomeContact = Convert.ToInt32(HomeContact.Text); supplier.CompanyName = CompanyName.Text; try { handleDatabase = new HandleDatabase(); affectedLines = handleDatabase.executeSupplierUpdate(supplier, supplierID); if (affectedLines > 0) { await this.ShowMessageAsync("Successfull", "Supplier details have been Successfully Updates", MessageDialogStyle.Affirmative); ViewSuppliers view = new ViewSuppliers(); view.Show(); this.Close(); } else { await this.ShowMessageAsync("Error", "Sorry Can not Update, Please Try again", MessageDialogStyle.Affirmative); } } catch (SqlException sqlException) { Console.WriteLine(sqlException); } } }