private void UpdateRecord() { using (new WaitCursor()) { Dispensation_Type oclsDispensation_Type = new Dispensation_Type(); Dispensation_Type clsDispensation_Type = new Dispensation_Type(); oclsDispensation_Type.Dispensation_Type_ID = System.Convert.ToInt16((Grid.SelectedCells[0].Column.GetCellContent(Grid.SelectedItem) as TextBlock).Text); oclsDispensation_Type = Dispensation_TypeData.Select_Record(oclsDispensation_Type); if (VerifyData() == true) { SetData(clsDispensation_Type); Boolean bSucess = new Boolean(); bSucess = Dispensation_TypeData.Update(oclsDispensation_Type, clsDispensation_Type); if (bSucess == true) { GoBack_To_Grid(); } else { MessageBox.Show("Update failed.", "Error"); } } } }
private void SetData(Dispensation_Type clsDispensation_Type) { using (new WaitCursor()) { clsDispensation_Type.Dispensation_Type_Name = System.Convert.ToString(tbDispensation_Type_Name.Text); } }
public static Dispensation_Type Select_Record(Dispensation_Type clsDispensation_TypePara) { Dispensation_Type clsDispensation_Type = new Dispensation_Type(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Dispensation_Type_ID] " + " ,[Dispensation_Type_Name] " + "FROM " + " [Dispensation_Type] " + "WHERE " + " [Dispensation_Type_ID] = @Dispensation_Type_ID " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@Dispensation_Type_ID", clsDispensation_TypePara.Dispensation_Type_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsDispensation_Type.Dispensation_Type_ID = System.Convert.ToInt16(reader["Dispensation_Type_ID"]); clsDispensation_Type.Dispensation_Type_Name = System.Convert.ToString(reader["Dispensation_Type_Name"]); } else { clsDispensation_Type = null; } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(clsDispensation_Type); }
public static bool Update(Dispensation_Type oldDispensation_Type, Dispensation_Type newDispensation_Type) { SqlConnection connection = MarriageData.GetConnection(); string updateStatement = "UPDATE " + " [Dispensation_Type] " + "SET " + " [Dispensation_Type_Name] = @NewDispensation_Type_Name " + "WHERE " + " [Dispensation_Type_ID] = @OldDispensation_Type_ID " + " AND [Dispensation_Type_Name] = @OldDispensation_Type_Name " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; updateCommand.Parameters.AddWithValue("@NewDispensation_Type_Name", newDispensation_Type.Dispensation_Type_Name); updateCommand.Parameters.AddWithValue("@OldDispensation_Type_ID", oldDispensation_Type.Dispensation_Type_ID); updateCommand.Parameters.AddWithValue("@OldDispensation_Type_Name", oldDispensation_Type.Dispensation_Type_Name); try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
private void InsertRecord() { using (new WaitCursor()) { Dispensation_Type clsDispensation_Type = new Dispensation_Type(); if (VerifyData() == true) { SetData(clsDispensation_Type); Boolean bSucess = new Boolean(); bSucess = Dispensation_TypeData.Add(clsDispensation_Type); if (bSucess == true) { GoBack_To_Grid(); } else { MessageBox.Show("Insert failed.", "Error"); } } } }
public static bool Add(Dispensation_Type clsDispensation_Type) { SqlConnection connection = MarriageData.GetConnection(); string insertStatement = "INSERT " + " [Dispensation_Type] " + " ( " + " [Dispensation_Type_Name] " + " ) " + "VALUES " + " ( " + " @Dispensation_Type_Name " + " ) " + ""; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.CommandType = CommandType.Text; insertCommand.Parameters.AddWithValue("@Dispensation_Type_Name", clsDispensation_Type.Dispensation_Type_Name); try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
private void DeleteRecord() { using (new WaitCursor()) { Dispensation_Type clsDispensation_Type = new Dispensation_Type(); clsDispensation_Type.Dispensation_Type_ID = System.Convert.ToInt16((Grid.SelectedCells[0].Column.GetCellContent(Grid.SelectedItem) as TextBlock).Text); if (MessageBox.Show("Are you sure? Delete this record?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { SetData(clsDispensation_Type); Boolean bSucess = new Boolean(); bSucess = Dispensation_TypeData.Delete(clsDispensation_Type); if (bSucess == true) { GoBack_To_Grid(); } else { MessageBox.Show("Delete failed.", "Error"); } } } }
private void GetData() { using (new WaitCursor()) { ClearRecord(); Dispensation_Type clsDispensation_Type = new Dispensation_Type(); clsDispensation_Type.Dispensation_Type_ID = System.Convert.ToInt16((Grid.SelectedCells[0].Column.GetCellContent(Grid.SelectedItem) as TextBlock).Text); clsDispensation_Type = Dispensation_TypeData.Select_Record(clsDispensation_Type); if ((clsDispensation_Type != null)) { try { nudDispensation_Type_ID.Text = System.Convert.ToInt16(clsDispensation_Type.Dispensation_Type_ID).ToString(); tbDispensation_Type_Name.Text = Convert.ToString(clsDispensation_Type.Dispensation_Type_Name); } catch { } } } }
public static bool Delete(Dispensation_Type clsDispensation_Type) { SqlConnection connection = MarriageData.GetConnection(); string deleteStatement = "DELETE FROM " + " [Dispensation_Type] " + "WHERE " + " [Dispensation_Type_ID] = @OldDispensation_Type_ID " + " AND [Dispensation_Type_Name] = @OldDispensation_Type_Name " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldDispensation_Type_ID", clsDispensation_Type.Dispensation_Type_ID); deleteCommand.Parameters.AddWithValue("@OldDispensation_Type_Name", clsDispensation_Type.Dispensation_Type_Name); try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }