Пример #1
0
        public static grants Select_Record(grants grantsPara)
        {
            grants        grants          = new grants();
            SqlConnection connection      = plansoni_webstoreData.GetConnection();
            string        selectProcedure = "[grantsSelect]";
            SqlCommand    selectCommand   = new SqlCommand(selectProcedure, connection);

            selectCommand.CommandType = CommandType.StoredProcedure;
            selectCommand.Parameters.AddWithValue("@Id", grantsPara.Id);
            try
            {
                connection.Open();
                SqlDataReader reader
                    = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    grants.Id         = System.Convert.ToInt32(reader["Id"]);
                    grants.CustomerId = System.Convert.ToInt32(reader["CustomerId"]);
                    grants.PrNo       = reader["PrNo"] is DBNull ? null : reader["PrNo"].ToString();
                    grants.T1         = reader["T1"] is DBNull ? null : reader["T1"].ToString();
                    grants.AcctCode   = reader["AcctCode"] is DBNull ? null : reader["AcctCode"].ToString();
                    grants.T3         = reader["T3"] is DBNull ? null : reader["T3"].ToString();
                    grants.T5         = reader["T5"] is DBNull ? null : reader["T5"].ToString();
                    grants.T2         = reader["T2"] is DBNull ? null : reader["T2"].ToString();
                }
                else
                {
                    grants = null;
                }
                reader.Close();
            }
            catch (SqlException)
            {
                return(grants);
            }
            finally
            {
                connection.Close();
            }
            return(grants);
        }
Пример #2
0
        public static bool Delete(grants grants)
        {
            SqlConnection connection      = plansoni_webstoreData.GetConnection();
            string        deleteProcedure = "[grantsDelete]";
            SqlCommand    deleteCommand   = new SqlCommand(deleteProcedure, connection);

            deleteCommand.CommandType = CommandType.StoredProcedure;
            deleteCommand.Parameters.AddWithValue("@OldId", grants.Id);
            deleteCommand.Parameters.AddWithValue("@OldCustomerId", grants.CustomerId);
            if (grants.PrNo != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldPrNo", grants.PrNo);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldPrNo", DBNull.Value);
            }
            if (grants.T1 != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldT1", grants.T1);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldT1", DBNull.Value);
            }
            if (grants.AcctCode != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldAcctCode", grants.AcctCode);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldAcctCode", DBNull.Value);
            }
            if (grants.T3 != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldT3", grants.T3);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldT3", DBNull.Value);
            }
            if (grants.T5 != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldT5", grants.T5);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldT5", DBNull.Value);
            }
            if (grants.T2 != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldT2", grants.T2);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldT2", DBNull.Value);
            }
            deleteCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int);
            deleteCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output;
            try
            {
                connection.Open();
                deleteCommand.ExecuteNonQuery();
                int count = System.Convert.ToInt32(deleteCommand.Parameters["@ReturnValue"].Value);
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException)
            {
                return(false);
            }
            finally
            {
                connection.Close();
            }
        }