示例#1
0
    public static dbo_DeductClass Select_Record(String Deduct_ID)
    {
        dbo_DeductClass clsdbo_Deduct   = new dbo_DeductClass();
        SqlConnection   connection      = SAMDataClass.GetConnection();
        string          selectProcedure = "[DeductSelect]";
        SqlCommand      selectCommand   = new SqlCommand(selectProcedure, connection);

        selectCommand.CommandType = CommandType.StoredProcedure;
        selectCommand.Parameters.AddWithValue("@Deduct_ID", Deduct_ID);
        try
        {
            connection.Open();
            SqlDataReader reader
                = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
            if (reader.Read())
            {
                clsdbo_Deduct.Deduct_ID     = reader["Deduct_ID"] is DBNull ? null : reader["Deduct_ID"].ToString();
                clsdbo_Deduct.Clearing_No   = reader["Clearing_No"] is DBNull ? null : reader["Clearing_No"].ToString();
                clsdbo_Deduct.Deduct_Detail = reader["Deduct_Detail"] is DBNull ? null : reader["Deduct_Detail"].ToString();
                clsdbo_Deduct.Deduct_Amount = reader["Deduct_Amount"] is DBNull ? null : (Decimal?)reader["Deduct_Amount"];
            }
            else
            {
                clsdbo_Deduct = null;
            }
            reader.Close();
        }
        catch (SqlException ex)
        {
            logger.Error(ex.Message);
            return(clsdbo_Deduct);
        }
        finally
        {
            connection.Close();
        }
        return(clsdbo_Deduct);
    }
示例#2
0
    public static bool Update(
        dbo_DeductClass newdbo_DeductClass)
    {
        SqlConnection connection      = SAMDataClass.GetConnection();
        string        updateProcedure = "[DeductUpdate]";
        SqlCommand    updateCommand   = new SqlCommand(updateProcedure, connection);

        updateCommand.CommandType = CommandType.StoredProcedure;
        if (newdbo_DeductClass.Deduct_ID != null)
        {
            updateCommand.Parameters.AddWithValue("@NewDeduct_ID", newdbo_DeductClass.Deduct_ID);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewDeduct_ID", DBNull.Value);
        }
        if (newdbo_DeductClass.Clearing_No != null)
        {
            updateCommand.Parameters.AddWithValue("@NewClearing_No", newdbo_DeductClass.Clearing_No);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewClearing_No", DBNull.Value);
        }
        if (newdbo_DeductClass.Deduct_Detail != null)
        {
            updateCommand.Parameters.AddWithValue("@NewDeduct_Detail", newdbo_DeductClass.Deduct_Detail);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewDeduct_Detail", DBNull.Value);
        }
        if (newdbo_DeductClass.Deduct_Amount.HasValue == true)
        {
            updateCommand.Parameters.AddWithValue("@NewDeduct_Amount", newdbo_DeductClass.Deduct_Amount);
        }
        else
        {
            updateCommand.Parameters.AddWithValue("@NewDeduct_Amount", 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();
        }
    }