Example #1
0
        /// <summary>
        /// Update an entry in the VendorOrder table
        /// </summary>
        public static bool Update(VendorOrder vendorOrder)
        {
            bool result = false;

            SqlConnection cn = GetConnection();

            result = Update(cn, vendorOrder);
            FinishedWithConnection(cn);

            return(result);
        }
Example #2
0
        /// <summary>
        /// Get an entry from the VendorOrder table
        /// </summary>
        public static VendorOrder Get(int id)
        {
            VendorOrder result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, id);
            FinishedWithConnection(cn);

            return(result);
        }
Example #3
0
        private static VendorOrder Get(SqlConnection cn, int id)
        {
            VendorOrder result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM VendorOrder WHERE VendorOrderId=" + id, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildVendorOrder(rdr);
                    }
                }
            }
            return(result);
        }
Example #4
0
        /// <summary>
        /// Delete an entry from the VendorOrder table
        /// </summary>
        public static bool Delete(int id)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();
            VendorOrder   vendorOrder  = Get(cn, id);

            if (vendorOrder != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM VendorOrder WHERE VendorOrderId=" + id;
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
Example #5
0
        private static bool Update(SqlConnection cn, VendorOrder vendorOrder)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE VendorOrder SET VendorOrderVendorId=@VendorOrderVendorId,VendorOrderEmployeeId=@VendorOrderEmployeeId,VendorOrderEmployeeId=@VendorOrderEmployeeId WHERE VendorOrderId=@VendorOrderId";

                BuildSqlParameter(sqlCmd, "@VendorOrderId", SqlDbType.Int, vendorOrder.Id);
                BuildSqlParameter(sqlCmd, "@VendorOrderVendorId", SqlDbType.Int, vendorOrder.VendorId);
                BuildSqlParameter(sqlCmd, "@VendorOrderEmployeeId", SqlDbType.Int, vendorOrder.EmployeeId);
                BuildSqlParameter(sqlCmd, "@VendorOrderOrderedDate", SqlDbType.DateTime, vendorOrder.OrderTime);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }
Example #6
0
        /// <summary>
        /// Add a new entry to the VendorOrder table
        /// </summary>
        public static VendorOrder Add(int vendorId, int employeeId)
        {
            VendorOrder result = null;

            SqlConnection cn  = GetConnection();
            string        cmd = "AddVendorOrder";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@VendorOrderVendorId", SqlDbType.Int, vendorId);
                BuildSqlParameter(sqlCmd, "@VendorOrderEmployeeId", SqlDbType.Int, employeeId);
                BuildSqlParameter(sqlCmd, "@VendorOrderOrderedDate", SqlDbType.DateTime, null);
                BuildSqlParameter(sqlCmd, "@VendorOrderId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new VendorOrder(Convert.ToInt32(sqlCmd.Parameters["@VendorOrderId"].Value),
                                             vendorId, employeeId, null);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }