public static dbo_CreditClass Select_Record(String Credit_ID) { dbo_CreditClass clsdbo_Credit = new dbo_CreditClass(); SqlConnection connection = SAMDataClass.GetConnection(); string selectProcedure = "[CreditSelect]"; SqlCommand selectCommand = new SqlCommand(selectProcedure, connection); selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.Parameters.AddWithValue("@Credit_ID", Credit_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsdbo_Credit.Credit_ID = reader["Credit_ID"] is DBNull ? null : reader["Credit_ID"].ToString(); clsdbo_Credit.Clearing_No = reader["Clearing_No"] is DBNull ? null : reader["Clearing_No"].ToString(); clsdbo_Credit.Customer_ID = reader["Customer_ID"] is DBNull ? null : reader["Customer_ID"].ToString(); clsdbo_Credit.Credit_Date = reader["Credit_Date"] is DBNull ? null : (DateTime?)reader["Credit_Date"]; clsdbo_Credit.Credit_Amount = reader["Credit_Amount"] is DBNull ? null : (Decimal?)reader["Credit_Amount"]; clsdbo_Credit.Total_Payment_Amount = reader["Total_Payment_Amount"] is DBNull ? null : (Decimal?)reader["Total_Payment_Amount"]; clsdbo_Credit.Balance_Outstanding_Amount = reader["Balance_Outstanding_Amount"] is DBNull ? null : (Decimal?)reader["Balance_Outstanding_Amount"]; clsdbo_Credit.Status = reader["Status"] is DBNull ? null : reader["Status"].ToString(); } else { clsdbo_Credit = null; } reader.Close(); } catch (SqlException ex) { logger.Error(ex.Message); return(clsdbo_Credit); } finally { connection.Close(); } return(clsdbo_Credit); }
public static bool Update(dbo_CreditClass newdbo_CreditClass) { SqlConnection connection = SAMDataClass.GetConnection(); string updateProcedure = "[CreditUpdate]"; SqlCommand updateCommand = new SqlCommand(updateProcedure, connection); updateCommand.CommandType = CommandType.StoredProcedure; if (newdbo_CreditClass.Credit_ID != null) { updateCommand.Parameters.AddWithValue("@NewCredit_ID", newdbo_CreditClass.Credit_ID); } else { updateCommand.Parameters.AddWithValue("@NewCredit_ID", DBNull.Value); } if (newdbo_CreditClass.Clearing_No != null) { updateCommand.Parameters.AddWithValue("@NewClearing_No", newdbo_CreditClass.Clearing_No); } else { updateCommand.Parameters.AddWithValue("@NewClearing_No", DBNull.Value); } if (newdbo_CreditClass.Customer_ID != null) { updateCommand.Parameters.AddWithValue("@NewCustomer_ID", newdbo_CreditClass.Customer_ID); } else { updateCommand.Parameters.AddWithValue("@NewCustomer_ID", DBNull.Value); } if (newdbo_CreditClass.Credit_Date.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewCredit_Date", newdbo_CreditClass.Credit_Date); } else { updateCommand.Parameters.AddWithValue("@NewCredit_Date", DBNull.Value); } if (newdbo_CreditClass.Credit_Amount.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewCredit_Amount", newdbo_CreditClass.Credit_Amount); } else { updateCommand.Parameters.AddWithValue("@NewCredit_Amount", DBNull.Value); } if (newdbo_CreditClass.Total_Payment_Amount.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewTotal_Payment_Amount", newdbo_CreditClass.Total_Payment_Amount); } else { updateCommand.Parameters.AddWithValue("@NewTotal_Payment_Amount", DBNull.Value); } if (newdbo_CreditClass.Balance_Outstanding_Amount.HasValue == true) { updateCommand.Parameters.AddWithValue("@NewBalance_Outstanding_Amount", newdbo_CreditClass.Balance_Outstanding_Amount); } else { updateCommand.Parameters.AddWithValue("@NewBalance_Outstanding_Amount", DBNull.Value); } if (newdbo_CreditClass.Status != null) { updateCommand.Parameters.AddWithValue("@NewStatus", newdbo_CreditClass.Status); } else { updateCommand.Parameters.AddWithValue("@NewStatus", DBNull.Value); } updateCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int); updateCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output; try { connection.Open(); updateCommand.ExecuteNonQuery(); int count = System.Convert.ToInt32(updateCommand.Parameters["@ReturnValue"].Value); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { logger.Error(ex.Message); return(false); } finally { connection.Close(); } }